snapctl 0.22.3__tar.gz → 0.26.1__tar.gz

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.

Potentially problematic release.


This version of snapctl might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: snapctl
3
- Version: 0.22.3
3
+ Version: 0.26.1
4
4
  Summary: Snapser CLI Tool
5
5
  Author: Ajinkya Apte
6
6
  Author-email: aj@snapser.com
@@ -10,6 +10,7 @@ Classifier: Programming Language :: Python :: 3.10
10
10
  Classifier: Programming Language :: Python :: 3.11
11
11
  Classifier: Programming Language :: Python :: 3.12
12
12
  Requires-Dist: configparser (>=6.0.0,<7.0.0)
13
+ Requires-Dist: pyfiglet (>=1.0.2,<2.0.0)
13
14
  Requires-Dist: requests (>=2.28.2,<3.0.0)
14
15
  Requires-Dist: typer[all] (>=0.7.0,<0.8.0)
15
16
  Description-Content-Type: text/markdown
@@ -392,7 +393,7 @@ snapctl byogs publish-version --help
392
393
  snapctl byogs publish-version $byogs_sid --tag $image_tag --prefix $prefix --version $version --http-port $ingress_port
393
394
  ```
394
395
 
395
- ### Snapend
396
+ ### Game
396
397
 
397
398
  #### 1. snapend help
398
399
 
@@ -403,27 +404,89 @@ See all the supported commands
403
404
  snapctl snapend --help
404
405
  ```
405
406
 
407
+ #### 2. Create a game
408
+ Create a game
409
+ ```
410
+ snapctl game create --name $gameName
411
+ ```
412
+
413
+ #### 3. Enumerate games
414
+ List all the games
415
+ ```
416
+ snapctl game enumerate
417
+ ```
418
+
419
+
420
+ ### Snapend
421
+
422
+ #### 1. snapend help
423
+
424
+ See all the supported commands
425
+
426
+ ```
427
+ # Help for the snapend command
428
+ snapctl snapend --help
429
+ ```
430
+
406
431
  #### 2. Snapend Downloads
407
432
 
408
- Download SDKs and Protos for your Snapend
433
+ Download Manifest, SDKs and Protos for your Snapend
409
434
 
410
435
  ```
411
- # Help for the byogs command
436
+ # Help for the download command
412
437
  snapctl snapend download --help
413
438
 
414
439
  # Download your Snapend SDK and Protos
415
440
  # $snapend_id = Cluster Id
416
- # $category = client-sdk, server-sdk, protos, admin-settings
417
- # $sdk_type = One of the supported SDK names:
418
- # client-sdk(unity, unreal, roblox, godot, cocos, ios-objc, ios-swift, android-java, android-kotlin, web-ts, web-js),
419
- # server-sdk(csharp, cpp, lua, ts, go, python, kotlin, java, c, node, js, perl, php, closure, ruby, rust),
420
- # protos(go)
441
+ # $category = snapend-manifest, client-sdk, server-sdk, protos
442
+ # $type = One of the supported types:
443
+ # snapend-manifest(yaml, json)
444
+ # client-sdk(unity, unreal, roblox, godot, cocos, ios-objc, ios-swift, android-java, android-kotlin, web-ts, web-js),
445
+ # server-sdk(csharp, cpp, lua, ts, go, python, kotlin, java, c, node, js, perl, php, closure, ruby, rust),
446
+ # protos(go, csharp, cpp, python)
421
447
  # Example:
448
+ # snapctl snapend download gx5x6bc0 --category snapend-manifest --type yaml
422
449
  # snapctl snapend download gx5x6bc0 --category client-sdk --type unity
423
- snapctl snapend download $snapend_id --category $category --type $sdk_type
450
+ snapctl snapend download $snapend_id --category $category --type $type
451
+ ```
452
+
453
+ #### 3. Clone Snapend
454
+
455
+ Clone a Snapend from an existing manifest. Passing the blocking flag ensures your CLI command waits till the new Snapend is up.
456
+
457
+ ```
458
+ # Help for the download command
459
+ snapctl snapend clone --help
460
+
461
+ # Download your Snapend SDK and Protos
462
+ # $gameId = Game Id
463
+ # $snapendName = Name of your new Snapend
464
+ # $env = One of development, staging
465
+ # $pathToManifest = Path to the manifest file; should include the file name
466
+ # Example:
467
+ # snapctl snapend clone --game-id 2581d802-aca-496c-8a76-1953ad0db165 --name new-snapend --env development --manifest-path "C:\Users\name\Downloads\snapser-ox1bcyim-manifest.json" --blocking
468
+ snapctl snapend clone --game-id $gameId --name $snapendName --env $env --manifest-path "$pathToManifest"
469
+ snapctl snapend clone --game-id $gameId --name $snapendName --env $env --manifest-path "$pathToManifest" --blocking
470
+ ```
471
+
472
+ #### 4. Apply Snapend Changes
473
+
474
+ Apply changes to your Snapend from a manifest. You should have the latest manifest before applying changes. This is to prevent
475
+ a user stomping over someone elses changes. Passing the blocking flag ensures your CLI command waits till the update is complete.
476
+
477
+ ```
478
+ # Help for the download command
479
+ snapctl snapend apply --help
480
+
481
+ # Download your Snapend SDK and Protos
482
+ # $pathToManifest = Path to the manifest file; should include the file name
483
+ # Example:
484
+ # snapctl snapend apply --manifest-path "C:\Users\name\Downloads\snapser-ox1bcyim-manifest.json" --blocking
485
+ snapctl snapend apply --manifest-path "$pathToManifest"
486
+ snapctl snapend apply --manifest-path "$pathToManifest" --blocking
424
487
  ```
425
488
 
426
- #### 3. Update Snapend BYOSnap or BYOGs versions
489
+ #### 5. Update Snapend BYOSnap or BYOGs versions
427
490
 
428
491
  Update your BYOSnap or BYOGs versions for the Snapend
429
492
 
@@ -443,7 +506,7 @@ snapctl snapend update --help
443
506
  snapctl snapend update $snapend_id --byosnaps $byosnaps --byogs $byogs --blocking
444
507
  ```
445
508
 
446
- #### 4. Get the Snapend state
509
+ #### 6. Get the Snapend state
447
510
 
448
511
  Get the Snapend state
449
512
 
@@ -376,7 +376,7 @@ snapctl byogs publish-version --help
376
376
  snapctl byogs publish-version $byogs_sid --tag $image_tag --prefix $prefix --version $version --http-port $ingress_port
377
377
  ```
378
378
 
379
- ### Snapend
379
+ ### Game
380
380
 
381
381
  #### 1. snapend help
382
382
 
@@ -387,27 +387,89 @@ See all the supported commands
387
387
  snapctl snapend --help
388
388
  ```
389
389
 
390
+ #### 2. Create a game
391
+ Create a game
392
+ ```
393
+ snapctl game create --name $gameName
394
+ ```
395
+
396
+ #### 3. Enumerate games
397
+ List all the games
398
+ ```
399
+ snapctl game enumerate
400
+ ```
401
+
402
+
403
+ ### Snapend
404
+
405
+ #### 1. snapend help
406
+
407
+ See all the supported commands
408
+
409
+ ```
410
+ # Help for the snapend command
411
+ snapctl snapend --help
412
+ ```
413
+
390
414
  #### 2. Snapend Downloads
391
415
 
392
- Download SDKs and Protos for your Snapend
416
+ Download Manifest, SDKs and Protos for your Snapend
393
417
 
394
418
  ```
395
- # Help for the byogs command
419
+ # Help for the download command
396
420
  snapctl snapend download --help
397
421
 
398
422
  # Download your Snapend SDK and Protos
399
423
  # $snapend_id = Cluster Id
400
- # $category = client-sdk, server-sdk, protos, admin-settings
401
- # $sdk_type = One of the supported SDK names:
402
- # client-sdk(unity, unreal, roblox, godot, cocos, ios-objc, ios-swift, android-java, android-kotlin, web-ts, web-js),
403
- # server-sdk(csharp, cpp, lua, ts, go, python, kotlin, java, c, node, js, perl, php, closure, ruby, rust),
404
- # protos(go)
424
+ # $category = snapend-manifest, client-sdk, server-sdk, protos
425
+ # $type = One of the supported types:
426
+ # snapend-manifest(yaml, json)
427
+ # client-sdk(unity, unreal, roblox, godot, cocos, ios-objc, ios-swift, android-java, android-kotlin, web-ts, web-js),
428
+ # server-sdk(csharp, cpp, lua, ts, go, python, kotlin, java, c, node, js, perl, php, closure, ruby, rust),
429
+ # protos(go, csharp, cpp, python)
405
430
  # Example:
431
+ # snapctl snapend download gx5x6bc0 --category snapend-manifest --type yaml
406
432
  # snapctl snapend download gx5x6bc0 --category client-sdk --type unity
407
- snapctl snapend download $snapend_id --category $category --type $sdk_type
433
+ snapctl snapend download $snapend_id --category $category --type $type
434
+ ```
435
+
436
+ #### 3. Clone Snapend
437
+
438
+ Clone a Snapend from an existing manifest. Passing the blocking flag ensures your CLI command waits till the new Snapend is up.
439
+
440
+ ```
441
+ # Help for the download command
442
+ snapctl snapend clone --help
443
+
444
+ # Download your Snapend SDK and Protos
445
+ # $gameId = Game Id
446
+ # $snapendName = Name of your new Snapend
447
+ # $env = One of development, staging
448
+ # $pathToManifest = Path to the manifest file; should include the file name
449
+ # Example:
450
+ # snapctl snapend clone --game-id 2581d802-aca-496c-8a76-1953ad0db165 --name new-snapend --env development --manifest-path "C:\Users\name\Downloads\snapser-ox1bcyim-manifest.json" --blocking
451
+ snapctl snapend clone --game-id $gameId --name $snapendName --env $env --manifest-path "$pathToManifest"
452
+ snapctl snapend clone --game-id $gameId --name $snapendName --env $env --manifest-path "$pathToManifest" --blocking
453
+ ```
454
+
455
+ #### 4. Apply Snapend Changes
456
+
457
+ Apply changes to your Snapend from a manifest. You should have the latest manifest before applying changes. This is to prevent
458
+ a user stomping over someone elses changes. Passing the blocking flag ensures your CLI command waits till the update is complete.
459
+
460
+ ```
461
+ # Help for the download command
462
+ snapctl snapend apply --help
463
+
464
+ # Download your Snapend SDK and Protos
465
+ # $pathToManifest = Path to the manifest file; should include the file name
466
+ # Example:
467
+ # snapctl snapend apply --manifest-path "C:\Users\name\Downloads\snapser-ox1bcyim-manifest.json" --blocking
468
+ snapctl snapend apply --manifest-path "$pathToManifest"
469
+ snapctl snapend apply --manifest-path "$pathToManifest" --blocking
408
470
  ```
409
471
 
410
- #### 3. Update Snapend BYOSnap or BYOGs versions
472
+ #### 5. Update Snapend BYOSnap or BYOGs versions
411
473
 
412
474
  Update your BYOSnap or BYOGs versions for the Snapend
413
475
 
@@ -427,7 +489,7 @@ snapctl snapend update --help
427
489
  snapctl snapend update $snapend_id --byosnaps $byosnaps --byogs $byogs --blocking
428
490
  ```
429
491
 
430
- #### 4. Get the Snapend state
492
+ #### 6. Get the Snapend state
431
493
 
432
494
  Get the Snapend state
433
495
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "snapctl"
3
- version = "0.22.3"
3
+ version = "0.26.1"
4
4
  description = "Snapser CLI Tool"
5
5
  authors = ["Ajinkya Apte <aj@snapser.com>"]
6
6
  readme = "README.md"
@@ -14,6 +14,7 @@ python = "^3.10"
14
14
  typer = {extras = ["all"], version = "^0.7.0"}
15
15
  requests = "^2.28.2"
16
16
  configparser = "^6.0.0"
17
+ pyfiglet = "^1.0.2"
17
18
 
18
19
 
19
20
  [build-system]
@@ -161,16 +161,18 @@ class ByoGs:
161
161
  ) as progress:
162
162
  progress.add_task(
163
163
  description='Building your snap...', total=None)
164
+ docker_file_path = f"{self.path}/{self.dockerfile}"
164
165
  if platform == "win32":
165
166
  response = subprocess.run([
166
167
  # f"docker build --no-cache -t {tag} {path}"
167
- 'docker', 'build', '--platform', build_platform, '-t', image_tag, self.path
168
+ 'docker', 'build', '--platform', build_platform, '-t', image_tag,
169
+ '-f', docker_file_path, self.path
168
170
  ], shell=True, check=False)
169
171
  # stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
170
172
  else:
171
173
  response = subprocess.run([
172
174
  # f"docker build --no-cache -t {tag} {path}"
173
- f"docker build --platform {build_platform} -t {image_tag} {self.path}"
175
+ f"docker build --platform {build_platform} -t {image_tag} -f {docker_file_path} {self.path}"
174
176
  ], shell=True, check=False)
175
177
  # stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
176
178
  if response.returncode:
@@ -169,16 +169,18 @@ class ByoSnap:
169
169
  ) as progress:
170
170
  progress.add_task(
171
171
  description='Building your snap...', total=None)
172
+ docker_file_path = f"{self.path}/{self.dockerfile}"
172
173
  if platform == "win32":
173
174
  response = subprocess.run([
174
175
  # f"docker build --no-cache -t {tag} {path}"
175
- 'docker', 'build', '--platform', build_platform, '-t', image_tag, self.path
176
+ 'docker', 'build', '--platform', build_platform, '-t', image_tag,
177
+ '-f', docker_file_path, self.path
176
178
  ], shell=True, check=False)
177
179
  # stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
178
180
  else:
179
181
  response = subprocess.run([
180
182
  # f"docker build --no-cache -t {tag} {path}"
181
- f"docker build --platform {build_platform} -t {image_tag} {self.path}"
183
+ f"docker build --platform {build_platform} -t {image_tag} -f {docker_file_path} {self.path}"
182
184
  ], shell=True, check=False)
183
185
  # stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
184
186
  if response.returncode:
@@ -0,0 +1,107 @@
1
+ """
2
+ Snapend CLI commands
3
+ """
4
+ import requests
5
+ from requests.exceptions import RequestException
6
+
7
+ from rich.progress import Progress, SpinnerColumn, TextColumn
8
+ from snapctl.config.constants import SERVER_CALL_TIMEOUT
9
+ from snapctl.types.definitions import ResponseType
10
+ from snapctl.utils.echo import error, success
11
+
12
+
13
+ class Game:
14
+ """
15
+ CLI commands exposed for a Game
16
+ """
17
+ SUBCOMMANDS = ['create', 'enumerate']
18
+
19
+ def __init__(
20
+ self, subcommand: str, base_url: str, api_key: str | None, name: str | None
21
+ ) -> None:
22
+ self.subcommand: str = subcommand
23
+ self.base_url: str = base_url
24
+ self.api_key: str = api_key
25
+ self.name: str | None = name
26
+
27
+ def validate_input(self) -> ResponseType:
28
+ """
29
+ Validator
30
+ """
31
+ response: ResponseType = {
32
+ 'error': True,
33
+ 'msg': '',
34
+ 'data': []
35
+ }
36
+ # Check API Key and Base URL
37
+ if not self.api_key or self.base_url == '':
38
+ response['msg'] = "Missing API Key."
39
+ return response
40
+ # Check subcommand
41
+ if not self.subcommand in Game.SUBCOMMANDS:
42
+ response['msg'] = \
43
+ f"Invalid command. Valid commands are {', '.join(Game.SUBCOMMANDS)}."
44
+ return response
45
+ # Check sdk-download commands
46
+ if self.subcommand == 'create':
47
+ if self.name is None or self.name == '':
48
+ response['msg'] = "Missing game name."
49
+ return response
50
+ # Send success
51
+ response['error'] = False
52
+ return response
53
+
54
+ def create(self) -> bool:
55
+ """
56
+ Create a game
57
+ """
58
+ with Progress(
59
+ SpinnerColumn(),
60
+ TextColumn("[progress.description]{task.description}"),
61
+ transient=True,
62
+ ) as progress:
63
+ progress.add_task(
64
+ description='Creating a new game on Snapser...', total=None)
65
+ try:
66
+ url = f"{self.base_url}/v1/snapser-api/games"
67
+ payload = {
68
+ 'name': self.name
69
+ }
70
+ res = requests.post(
71
+ url, headers={'api-key': self.api_key},
72
+ json=payload, timeout=SERVER_CALL_TIMEOUT
73
+ )
74
+ if res.ok:
75
+ success(f"Game {self.name} has been created successfully.")
76
+ return True
77
+ error('Unable to create a new game. Reason: ' + res.text)
78
+ except RequestException as e:
79
+ error(f"Exception: Unable to download the SDK {e}")
80
+ return False
81
+
82
+ def enumerate(self) -> bool:
83
+ """
84
+ Enumerate all games
85
+ """
86
+ with Progress(
87
+ SpinnerColumn(),
88
+ TextColumn("[progress.description]{task.description}"),
89
+ transient=True,
90
+ ) as progress:
91
+ progress.add_task(
92
+ description='Enumerating all your games...', total=None)
93
+ try:
94
+ url = f"{self.base_url}/v1/snapser-api/games"
95
+ res = requests.get(
96
+ url, headers={'api-key': self.api_key},
97
+ timeout=SERVER_CALL_TIMEOUT
98
+ )
99
+ response_json = res.json()
100
+ if res.ok:
101
+ if 'games' in response_json:
102
+ success(response_json['games'])
103
+ return True
104
+ error(response_json)
105
+ except RequestException as e:
106
+ error(f"Exception: Unable to update your snapend {e}")
107
+ return False