semaphoreui-client 0.1.2__py3-none-any.whl → 0.1.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- semaphoreui_client/__about__.py +1 -1
- semaphoreui_client/client.py +111 -14
- {semaphoreui_client-0.1.2.dist-info → semaphoreui_client-0.1.3.dist-info}/METADATA +1 -1
- semaphoreui_client-0.1.3.dist-info/RECORD +6 -0
- semaphoreui_client-0.1.2.dist-info/RECORD +0 -6
- {semaphoreui_client-0.1.2.dist-info → semaphoreui_client-0.1.3.dist-info}/WHEEL +0 -0
semaphoreui_client/__about__.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "0.1.
|
1
|
+
__version__ = "0.1.3"
|
semaphoreui_client/client.py
CHANGED
@@ -7,8 +7,12 @@ import requests
|
|
7
7
|
|
8
8
|
class SemaphoreUIClient:
|
9
9
|
|
10
|
-
def __init__(self, host, path="/api"):
|
10
|
+
def __init__(self, host: str, path: str="/api"):
|
11
11
|
self.http = requests.Session()
|
12
|
+
if host.endswith("/"):
|
13
|
+
host = host.strip("/")
|
14
|
+
if not path.startswith("/"):
|
15
|
+
path = f"/{path}"
|
12
16
|
self.api_endpoint = f"{host}{path}"
|
13
17
|
|
14
18
|
def login(self, user, password):
|
@@ -186,11 +190,13 @@ class SemaphoreUIClient:
|
|
186
190
|
ssh: typing.Optional[typing.Tuple[str, str, str]],
|
187
191
|
) -> "Key":
|
188
192
|
if key_type not in ("ssh", "login_password"):
|
189
|
-
raise ValueError(
|
193
|
+
raise ValueError(
|
194
|
+
f"Invalid key_type: {key_type}. Acceptable values are: ssh, login_password"
|
195
|
+
)
|
190
196
|
if key_type == "ssh":
|
191
197
|
if ssh is None:
|
192
198
|
raise ValueError("ssh parameter must be set on key_type: ssh")
|
193
|
-
json_data =
|
199
|
+
json_data = {
|
194
200
|
"id": 0,
|
195
201
|
"project_id": project_id,
|
196
202
|
"name": name,
|
@@ -208,7 +214,9 @@ class SemaphoreUIClient:
|
|
208
214
|
}
|
209
215
|
elif key_type == "login_password":
|
210
216
|
if login_password is None:
|
211
|
-
raise ValueError(
|
217
|
+
raise ValueError(
|
218
|
+
"login_password parameter must be set on key_type: login_password"
|
219
|
+
)
|
212
220
|
json_data = {
|
213
221
|
"id": 0,
|
214
222
|
"project_id": project_id,
|
@@ -219,11 +227,10 @@ class SemaphoreUIClient:
|
|
219
227
|
"login": login_password[0],
|
220
228
|
"password": login_password[1],
|
221
229
|
},
|
222
|
-
"ssh": {"login": "", "passphrase": "", "private_key": ""}
|
230
|
+
"ssh": {"login": "", "passphrase": "", "private_key": ""},
|
223
231
|
}
|
224
232
|
response = self.http.post(
|
225
|
-
f"{self.api_endpoint}/project/{project_id}/keys",
|
226
|
-
json=json_data
|
233
|
+
f"{self.api_endpoint}/project/{project_id}/keys", json=json_data
|
227
234
|
)
|
228
235
|
assert response.status_code == 204
|
229
236
|
|
@@ -402,7 +409,7 @@ class SemaphoreUIClient:
|
|
402
409
|
type: str,
|
403
410
|
start_version: str,
|
404
411
|
autorun: bool,
|
405
|
-
build_template_id: typing.Optional[int]=None,
|
412
|
+
build_template_id: typing.Optional[int] = None,
|
406
413
|
) -> "Template":
|
407
414
|
response = self.http.post(
|
408
415
|
f"{self.api_endpoint}/project/{project_id}/templates",
|
@@ -434,13 +441,69 @@ class SemaphoreUIClient:
|
|
434
441
|
response.status_code == 201
|
435
442
|
), f"Expected response code 201, got {response.status_code}"
|
436
443
|
return Template(**response.json(), client=self)
|
437
|
-
|
444
|
+
|
438
445
|
def delete_project_template(self, project_id: int, id: int):
|
439
446
|
response = self.http.delete(
|
440
447
|
f"{self.api_endpoint}/project/{project_id}/templates/{id}"
|
441
448
|
)
|
442
449
|
assert response.status_code == 204
|
443
450
|
|
451
|
+
def get_project_schedules(self, project_id: int) -> typing.List["Schedule"]:
|
452
|
+
response = self.http.get(f"{self.api_endpoint}/project/{project_id}/schedules")
|
453
|
+
assert response.status_code == 200
|
454
|
+
return [Schedule(**schedule, client=self) for schedule in response.json()]
|
455
|
+
|
456
|
+
def create_project_schedule(
|
457
|
+
self,
|
458
|
+
project_id: int,
|
459
|
+
template_id: int,
|
460
|
+
name: str,
|
461
|
+
cron_format: str,
|
462
|
+
active: bool = True,
|
463
|
+
):
|
464
|
+
response = self.http.post(
|
465
|
+
f"{self.api_endpoint}/project/{project_id}/schedules",
|
466
|
+
json={
|
467
|
+
"id": 0,
|
468
|
+
"project_id": project_id,
|
469
|
+
"template_id": template_id,
|
470
|
+
"name": name,
|
471
|
+
"cron_format": cron_format,
|
472
|
+
"active": active,
|
473
|
+
},
|
474
|
+
)
|
475
|
+
assert response.status_code == 201
|
476
|
+
return Schedule(**response.json(), client=self)
|
477
|
+
|
478
|
+
def update_project_schedule(
|
479
|
+
self,
|
480
|
+
project_id: int,
|
481
|
+
schedule_id: int,
|
482
|
+
template_id: int,
|
483
|
+
name: str,
|
484
|
+
cron_format: str,
|
485
|
+
active: bool,
|
486
|
+
):
|
487
|
+
response = self.http.post(
|
488
|
+
f"{self.api_endpoint}/project/{project_id}/schedules",
|
489
|
+
json={
|
490
|
+
"id": schedule_id,
|
491
|
+
"project_id": project_id,
|
492
|
+
"template_id": template_id,
|
493
|
+
"name": name,
|
494
|
+
"cron_format": cron_format,
|
495
|
+
"active": active,
|
496
|
+
},
|
497
|
+
)
|
498
|
+
assert response.status_code == 201
|
499
|
+
return Schedule(**response.json(), client=self)
|
500
|
+
|
501
|
+
def delete_project_schedule(self, project_id: int, schedule_id: int):
|
502
|
+
response = self.http.get(
|
503
|
+
f"{self.api_endpoint}/project/{project_id}/schedules/{schedule_id}"
|
504
|
+
)
|
505
|
+
assert response.status_code == 204
|
506
|
+
|
444
507
|
|
445
508
|
@dataclass
|
446
509
|
class Integration:
|
@@ -532,9 +595,9 @@ class Project:
|
|
532
595
|
self,
|
533
596
|
name: str,
|
534
597
|
key_type: str,
|
535
|
-
override_secret: bool=False,
|
536
|
-
login_password: typing.Optional[typing.Tuple[str, str]]=None,
|
537
|
-
ssh: typing.Optional[typing.Tuple[str, str, str]]=None,
|
598
|
+
override_secret: bool = False,
|
599
|
+
login_password: typing.Optional[typing.Tuple[str, str]] = None,
|
600
|
+
ssh: typing.Optional[typing.Tuple[str, str, str]] = None,
|
538
601
|
):
|
539
602
|
return self.client.create_project_key(
|
540
603
|
self.id, name, key_type, override_secret, login_password, ssh
|
@@ -610,7 +673,7 @@ class Project:
|
|
610
673
|
type: str,
|
611
674
|
start_version: str,
|
612
675
|
autorun: bool,
|
613
|
-
build_template_id: typing.Optional[int]=None,
|
676
|
+
build_template_id: typing.Optional[int] = None,
|
614
677
|
) -> "Template":
|
615
678
|
return self.client.create_project_template(
|
616
679
|
self.id,
|
@@ -635,6 +698,16 @@ class Project:
|
|
635
698
|
build_template_id,
|
636
699
|
)
|
637
700
|
|
701
|
+
def schedules(self) -> typing.List["Schedule"]:
|
702
|
+
return self.client.get_project_schedules(self.id)
|
703
|
+
|
704
|
+
def create_schedule(
|
705
|
+
self, template_id: int, name: str, cron_format: str, active: bool = True
|
706
|
+
) -> "Schedule":
|
707
|
+
return self.client.create_project_schedule(
|
708
|
+
self.id, template_id, name, cron_format, active
|
709
|
+
)
|
710
|
+
|
638
711
|
|
639
712
|
@dataclass
|
640
713
|
class Permissions:
|
@@ -806,8 +879,32 @@ class Template:
|
|
806
879
|
last_task: int
|
807
880
|
tasks: int
|
808
881
|
|
809
|
-
|
810
882
|
client: SemaphoreUIClient
|
811
883
|
|
812
884
|
def delete(self):
|
813
885
|
self.client.delete_project_template(self.project_id, self.id)
|
886
|
+
|
887
|
+
|
888
|
+
@dataclass
|
889
|
+
class Schedule:
|
890
|
+
id: int
|
891
|
+
cron_format: str
|
892
|
+
project_id: int
|
893
|
+
template_id: int
|
894
|
+
name: str
|
895
|
+
active: bool
|
896
|
+
|
897
|
+
client: SemaphoreUIClient
|
898
|
+
|
899
|
+
def save(self):
|
900
|
+
self.client.update_project_schedule(
|
901
|
+
self.project_id,
|
902
|
+
self.id,
|
903
|
+
self.template_id,
|
904
|
+
self.name,
|
905
|
+
self.cron_format,
|
906
|
+
self.active,
|
907
|
+
)
|
908
|
+
|
909
|
+
def delete(self):
|
910
|
+
self.client.delete_project_schedule(self.project_id, self.id)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: semaphoreui-client
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.3
|
4
4
|
Summary: An api client for interacting with Semaphore UI
|
5
5
|
Project-URL: Documentation, https://github.com/rockstar/semaphoreui-client#readme
|
6
6
|
Project-URL: Issues, https://github.com/rockstar/semaphoreui-client/issues
|
@@ -0,0 +1,6 @@
|
|
1
|
+
semaphoreui_client/__about__.py,sha256=R5TtpJu7Qu6sOarfDpp-5Oyy8Pi2Ir3VewCvsCQiAgo,21
|
2
|
+
semaphoreui_client/__init__.py,sha256=r2j1tTgwFzp3AKAktr8izDIXllRf-Y0SdHAjInYDTP0,55
|
3
|
+
semaphoreui_client/client.py,sha256=AvZ1v4_aMFzRDM-YKb7CQd6Od9EgoKty-YXrf51ecsA,27612
|
4
|
+
semaphoreui_client-0.1.3.dist-info/METADATA,sha256=VW8KWzF_RjLzD1D7ooiLIb8kP8nI0MzTlWmPQ7wMoIw,1632
|
5
|
+
semaphoreui_client-0.1.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
6
|
+
semaphoreui_client-0.1.3.dist-info/RECORD,,
|
@@ -1,6 +0,0 @@
|
|
1
|
-
semaphoreui_client/__about__.py,sha256=K5SiDdEGYMpdqXThrqwTqECJJBOQNTQDrnpc2K5mzKs,21
|
2
|
-
semaphoreui_client/__init__.py,sha256=r2j1tTgwFzp3AKAktr8izDIXllRf-Y0SdHAjInYDTP0,55
|
3
|
-
semaphoreui_client/client.py,sha256=CBw2BUELSuwguRGt1hczE0yEUMTG63uHkWvh9VO4_4Y,24716
|
4
|
-
semaphoreui_client-0.1.2.dist-info/METADATA,sha256=D7_PSIOOZichIN1JmhIMxuwiuv0HbV7z6wGoDsoeJj8,1632
|
5
|
-
semaphoreui_client-0.1.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
6
|
-
semaphoreui_client-0.1.2.dist-info/RECORD,,
|
File without changes
|