semaphoreui-client 0.1.2__py3-none-any.whl → 0.1.4__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.
@@ -1 +1 @@
1
- __version__ = "0.1.2"
1
+ __version__ = "0.1.4"
@@ -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):
@@ -41,7 +45,7 @@ class SemaphoreUIClient:
41
45
  return Token(**response.json(), client=self)
42
46
 
43
47
  def delete_token(self, id):
44
- response = self.http.post(f"{self.api_endpoint}/user/tokens/{id}")
48
+ response = self.http.delete(f"{self.api_endpoint}/user/tokens/{id}")
45
49
  assert response.status_code in (204, 404) # 404 if token was already expired
46
50
 
47
51
  def projects(self) -> typing.List["Project"]:
@@ -88,13 +92,16 @@ class SemaphoreUIClient:
88
92
  alert: bool,
89
93
  alert_chat: str,
90
94
  max_parallel_tasks: int,
91
- type: str,
95
+ type: typing.Optional[str]=None,
92
96
  ):
93
97
  response = self.http.put(
94
98
  f"{self.api_endpoint}/project/{id}",
95
99
  json={
96
100
  "name": name,
97
101
  "alert": alert,
102
+ "alert_chat": alert_chat,
103
+ "max_parallel_tasks": max_parallel_tasks,
104
+ "type": type,
98
105
  },
99
106
  )
100
107
  assert response.status_code == 204
@@ -186,11 +193,13 @@ class SemaphoreUIClient:
186
193
  ssh: typing.Optional[typing.Tuple[str, str, str]],
187
194
  ) -> "Key":
188
195
  if key_type not in ("ssh", "login_password"):
189
- raise ValueError(f"Invalid key_type: {key_type}. Acceptable values are: ssh, login_password")
196
+ raise ValueError(
197
+ f"Invalid key_type: {key_type}. Acceptable values are: ssh, login_password"
198
+ )
190
199
  if key_type == "ssh":
191
200
  if ssh is None:
192
201
  raise ValueError("ssh parameter must be set on key_type: ssh")
193
- json_data = json={
202
+ json_data = {
194
203
  "id": 0,
195
204
  "project_id": project_id,
196
205
  "name": name,
@@ -208,7 +217,9 @@ class SemaphoreUIClient:
208
217
  }
209
218
  elif key_type == "login_password":
210
219
  if login_password is None:
211
- raise ValueError("login_password parameter must be set on key_type: login_password")
220
+ raise ValueError(
221
+ "login_password parameter must be set on key_type: login_password"
222
+ )
212
223
  json_data = {
213
224
  "id": 0,
214
225
  "project_id": project_id,
@@ -219,11 +230,10 @@ class SemaphoreUIClient:
219
230
  "login": login_password[0],
220
231
  "password": login_password[1],
221
232
  },
222
- "ssh": {"login": "", "passphrase": "", "private_key": ""}
233
+ "ssh": {"login": "", "passphrase": "", "private_key": ""},
223
234
  }
224
235
  response = self.http.post(
225
- f"{self.api_endpoint}/project/{project_id}/keys",
226
- json=json_data
236
+ f"{self.api_endpoint}/project/{project_id}/keys", json=json_data
227
237
  )
228
238
  assert response.status_code == 204
229
239
 
@@ -402,12 +412,12 @@ class SemaphoreUIClient:
402
412
  type: str,
403
413
  start_version: str,
404
414
  autorun: bool,
405
- build_template_id: typing.Optional[int]=None,
415
+ build_template_id: typing.Optional[int] = None,
406
416
  ) -> "Template":
407
417
  response = self.http.post(
408
418
  f"{self.api_endpoint}/project/{project_id}/templates",
409
419
  json={
410
- "id": 1,
420
+ "id": 0,
411
421
  "project_id": project_id,
412
422
  "inventory_id": inventory_id,
413
423
  "repository_id": repository_id,
@@ -434,13 +444,69 @@ class SemaphoreUIClient:
434
444
  response.status_code == 201
435
445
  ), f"Expected response code 201, got {response.status_code}"
436
446
  return Template(**response.json(), client=self)
437
-
447
+
438
448
  def delete_project_template(self, project_id: int, id: int):
439
449
  response = self.http.delete(
440
450
  f"{self.api_endpoint}/project/{project_id}/templates/{id}"
441
451
  )
442
452
  assert response.status_code == 204
443
453
 
454
+ def get_project_schedules(self, project_id: int) -> typing.List["Schedule"]:
455
+ response = self.http.get(f"{self.api_endpoint}/project/{project_id}/schedules")
456
+ assert response.status_code == 200
457
+ return [Schedule(**schedule, client=self) for schedule in response.json()]
458
+
459
+ def create_project_schedule(
460
+ self,
461
+ project_id: int,
462
+ template_id: int,
463
+ name: str,
464
+ cron_format: str,
465
+ active: bool = True,
466
+ ):
467
+ response = self.http.post(
468
+ f"{self.api_endpoint}/project/{project_id}/schedules",
469
+ json={
470
+ "id": 0,
471
+ "project_id": project_id,
472
+ "template_id": template_id,
473
+ "name": name,
474
+ "cron_format": cron_format,
475
+ "active": active,
476
+ },
477
+ )
478
+ assert response.status_code == 201
479
+ return Schedule(**response.json(), client=self)
480
+
481
+ def update_project_schedule(
482
+ self,
483
+ project_id: int,
484
+ schedule_id: int,
485
+ template_id: int,
486
+ name: str,
487
+ cron_format: str,
488
+ active: bool,
489
+ ):
490
+ response = self.http.post(
491
+ f"{self.api_endpoint}/project/{project_id}/schedules",
492
+ json={
493
+ "id": schedule_id,
494
+ "project_id": project_id,
495
+ "template_id": template_id,
496
+ "name": name,
497
+ "cron_format": cron_format,
498
+ "active": active,
499
+ },
500
+ )
501
+ assert response.status_code == 201
502
+ return Schedule(**response.json(), client=self)
503
+
504
+ def delete_project_schedule(self, project_id: int, schedule_id: int):
505
+ response = self.http.delete(
506
+ f"{self.api_endpoint}/project/{project_id}/schedules/{schedule_id}"
507
+ )
508
+ assert response.status_code == 204
509
+
444
510
 
445
511
  @dataclass
446
512
  class Integration:
@@ -532,9 +598,9 @@ class Project:
532
598
  self,
533
599
  name: str,
534
600
  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,
601
+ override_secret: bool = False,
602
+ login_password: typing.Optional[typing.Tuple[str, str]] = None,
603
+ ssh: typing.Optional[typing.Tuple[str, str, str]] = None,
538
604
  ):
539
605
  return self.client.create_project_key(
540
606
  self.id, name, key_type, override_secret, login_password, ssh
@@ -610,7 +676,7 @@ class Project:
610
676
  type: str,
611
677
  start_version: str,
612
678
  autorun: bool,
613
- build_template_id: typing.Optional[int]=None,
679
+ build_template_id: typing.Optional[int] = None,
614
680
  ) -> "Template":
615
681
  return self.client.create_project_template(
616
682
  self.id,
@@ -635,6 +701,16 @@ class Project:
635
701
  build_template_id,
636
702
  )
637
703
 
704
+ def schedules(self) -> typing.List["Schedule"]:
705
+ return self.client.get_project_schedules(self.id)
706
+
707
+ def create_schedule(
708
+ self, template_id: int, name: str, cron_format: str, active: bool = True
709
+ ) -> "Schedule":
710
+ return self.client.create_project_schedule(
711
+ self.id, template_id, name, cron_format, active
712
+ )
713
+
638
714
 
639
715
  @dataclass
640
716
  class Permissions:
@@ -806,8 +882,32 @@ class Template:
806
882
  last_task: int
807
883
  tasks: int
808
884
 
809
-
810
885
  client: SemaphoreUIClient
811
886
 
812
887
  def delete(self):
813
888
  self.client.delete_project_template(self.project_id, self.id)
889
+
890
+
891
+ @dataclass
892
+ class Schedule:
893
+ id: int
894
+ cron_format: str
895
+ project_id: int
896
+ template_id: int
897
+ name: str
898
+ active: bool
899
+
900
+ client: SemaphoreUIClient
901
+
902
+ def save(self):
903
+ self.client.update_project_schedule(
904
+ self.project_id,
905
+ self.id,
906
+ self.template_id,
907
+ self.name,
908
+ self.cron_format,
909
+ self.active,
910
+ )
911
+
912
+ def delete(self):
913
+ 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.2
3
+ Version: 0.1.4
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=JMD28FXYHc_TM03visyUSd3UA9FZAaJMRStnfZoq50Y,21
2
+ semaphoreui_client/__init__.py,sha256=r2j1tTgwFzp3AKAktr8izDIXllRf-Y0SdHAjInYDTP0,55
3
+ semaphoreui_client/client.py,sha256=Vm1a1gr5dEGER90qZHNYBhtc_ep6iWeBb5u3LpAk9GU,27769
4
+ semaphoreui_client-0.1.4.dist-info/METADATA,sha256=bTZMXe3MPtWHLl9e9IxKuCUG_ogElY67Nd2HBosqYPE,1632
5
+ semaphoreui_client-0.1.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
6
+ semaphoreui_client-0.1.4.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,,