snapctl 0.32.0__py3-none-any.whl → 0.32.2__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.
Potentially problematic release.
This version of snapctl might be problematic. Click here for more details.
- snapctl/commands/byogs.py +175 -181
- snapctl/commands/byosnap.py +378 -371
- snapctl/commands/game.py +63 -57
- snapctl/commands/generate.py +48 -32
- snapctl/commands/snapend.py +361 -281
- snapctl/config/constants.py +72 -8
- snapctl/main.py +100 -135
- snapctl/types/definitions.py +20 -4
- snapctl/utils/echo.py +10 -2
- snapctl/utils/helper.py +60 -3
- {snapctl-0.32.0.dist-info → snapctl-0.32.2.dist-info}/METADATA +120 -8
- snapctl-0.32.2.dist-info/RECORD +23 -0
- snapctl-0.32.0.dist-info/RECORD +0 -23
- {snapctl-0.32.0.dist-info → snapctl-0.32.2.dist-info}/LICENSE +0 -0
- {snapctl-0.32.0.dist-info → snapctl-0.32.2.dist-info}/WHEEL +0 -0
- {snapctl-0.32.0.dist-info → snapctl-0.32.2.dist-info}/entry_points.txt +0 -0
snapctl/commands/game.py
CHANGED
|
@@ -4,10 +4,13 @@
|
|
|
4
4
|
import requests
|
|
5
5
|
from requests.exceptions import RequestException
|
|
6
6
|
|
|
7
|
+
import typer
|
|
7
8
|
from rich.progress import Progress, SpinnerColumn, TextColumn
|
|
8
|
-
from snapctl.config.constants import SERVER_CALL_TIMEOUT
|
|
9
|
-
|
|
9
|
+
from snapctl.config.constants import SERVER_CALL_TIMEOUT, SNAPCTL_INPUT_ERROR, \
|
|
10
|
+
SNAPCTL_SUCCESS, SNAPCTL_GAME_CREATE_ERROR, SNAPCTL_GAME_ENUMERATE_ERROR, \
|
|
11
|
+
HTTP_ERROR_DUPLICATE_GAME_NAME, SNAPCTL_GAME_CREATE_DUPLICATE_NAME_ERROR
|
|
10
12
|
from snapctl.utils.echo import error, success
|
|
13
|
+
from snapctl.utils.helper import snapctl_error, snapctl_success
|
|
11
14
|
|
|
12
15
|
|
|
13
16
|
class Game:
|
|
@@ -23,85 +26,88 @@ class Game:
|
|
|
23
26
|
self.base_url: str = base_url
|
|
24
27
|
self.api_key: str = api_key
|
|
25
28
|
self.name: str | None = name
|
|
29
|
+
# Validate input
|
|
30
|
+
self.validate_input()
|
|
26
31
|
|
|
27
|
-
def validate_input(self) ->
|
|
32
|
+
def validate_input(self) -> None:
|
|
28
33
|
"""
|
|
29
34
|
Validator
|
|
30
35
|
"""
|
|
31
|
-
response: ResponseType = {
|
|
32
|
-
'error': True,
|
|
33
|
-
'msg': '',
|
|
34
|
-
'data': []
|
|
35
|
-
}
|
|
36
36
|
# Check API Key and Base URL
|
|
37
37
|
if not self.api_key or self.base_url == '':
|
|
38
|
-
|
|
39
|
-
return response
|
|
38
|
+
snapctl_error("Missing API Key.", SNAPCTL_INPUT_ERROR)
|
|
40
39
|
# Check subcommand
|
|
41
40
|
if not self.subcommand in Game.SUBCOMMANDS:
|
|
42
|
-
|
|
43
|
-
f"Invalid command. Valid commands are {', '.join(Game.SUBCOMMANDS)}."
|
|
44
|
-
|
|
41
|
+
snapctl_error(
|
|
42
|
+
f"Invalid command. Valid commands are {', '.join(Game.SUBCOMMANDS)}.",
|
|
43
|
+
SNAPCTL_INPUT_ERROR)
|
|
45
44
|
# Check sdk-download commands
|
|
46
45
|
if self.subcommand == 'create':
|
|
47
46
|
if self.name is None or self.name == '':
|
|
48
|
-
|
|
49
|
-
return response
|
|
50
|
-
# Send success
|
|
51
|
-
response['error'] = False
|
|
52
|
-
return response
|
|
47
|
+
snapctl_error("Missing game name.", SNAPCTL_INPUT_ERROR)
|
|
53
48
|
|
|
54
49
|
def create(self) -> bool:
|
|
55
50
|
"""
|
|
56
51
|
Create a game
|
|
57
52
|
"""
|
|
58
|
-
|
|
53
|
+
progress = Progress(
|
|
59
54
|
SpinnerColumn(),
|
|
60
55
|
TextColumn("[progress.description]{task.description}"),
|
|
61
56
|
transient=True,
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
57
|
+
)
|
|
58
|
+
progress.start()
|
|
59
|
+
progress.add_task(
|
|
60
|
+
description='Creating a new game on Snapser...', total=None)
|
|
61
|
+
try:
|
|
62
|
+
url = f"{self.base_url}/v1/snapser-api/games"
|
|
63
|
+
payload = {
|
|
64
|
+
'name': self.name
|
|
65
|
+
}
|
|
66
|
+
res = requests.post(
|
|
67
|
+
url, headers={'api-key': self.api_key},
|
|
68
|
+
json=payload, timeout=SERVER_CALL_TIMEOUT
|
|
69
|
+
)
|
|
70
|
+
if res.ok:
|
|
71
|
+
snapctl_success(
|
|
72
|
+
f"Game {self.name} create successful", progress)
|
|
73
|
+
response_json = res.json()
|
|
74
|
+
if "api_error_code" in response_json and "message" in response_json:
|
|
75
|
+
if response_json['api_error_code'] == HTTP_ERROR_DUPLICATE_GAME_NAME:
|
|
76
|
+
snapctl_error(f"Game {self.name} already exists.",
|
|
77
|
+
SNAPCTL_GAME_CREATE_DUPLICATE_NAME_ERROR, progress)
|
|
78
|
+
snapctl_error(
|
|
79
|
+
f'Server error: {response_json}', SNAPCTL_GAME_CREATE_ERROR, progress)
|
|
80
|
+
except RequestException as e:
|
|
81
|
+
snapctl_error(f"Exception: Unable to download the SDK {e}",
|
|
82
|
+
SNAPCTL_GAME_CREATE_ERROR, progress)
|
|
83
|
+
snapctl_error('Failed to create game.',
|
|
84
|
+
SNAPCTL_GAME_CREATE_ERROR, progress)
|
|
81
85
|
|
|
82
86
|
def enumerate(self) -> bool:
|
|
83
87
|
"""
|
|
84
88
|
Enumerate all games
|
|
85
89
|
"""
|
|
86
|
-
|
|
90
|
+
progress = Progress(
|
|
87
91
|
SpinnerColumn(),
|
|
88
92
|
TextColumn("[progress.description]{task.description}"),
|
|
89
93
|
transient=True,
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
94
|
+
)
|
|
95
|
+
progress.start()
|
|
96
|
+
progress.add_task(
|
|
97
|
+
description='Enumerating all your games...', total=None)
|
|
98
|
+
try:
|
|
99
|
+
url = f"{self.base_url}/v1/snapser-api/games"
|
|
100
|
+
res = requests.get(
|
|
101
|
+
url, headers={'api-key': self.api_key},
|
|
102
|
+
timeout=SERVER_CALL_TIMEOUT
|
|
103
|
+
)
|
|
104
|
+
response_json = res.json()
|
|
105
|
+
if res.ok and 'games' in response_json:
|
|
106
|
+
snapctl_success(response_json['games'], progress)
|
|
107
|
+
snapctl_error('Unable to enumerate games.',
|
|
108
|
+
SNAPCTL_GAME_ENUMERATE_ERROR, progress)
|
|
109
|
+
except RequestException as e:
|
|
110
|
+
snapctl_error(f"Exception: Unable to update your snapend {e}",
|
|
111
|
+
SNAPCTL_GAME_ENUMERATE_ERROR, progress)
|
|
112
|
+
snapctl_error('Failed to enumerate games.',
|
|
113
|
+
SNAPCTL_GAME_ENUMERATE_ERROR, progress)
|
snapctl/commands/generate.py
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
Generate CLI commands
|
|
3
3
|
"""
|
|
4
4
|
import json
|
|
5
|
-
from sys import platform
|
|
6
5
|
import os
|
|
7
6
|
from typing import Union
|
|
8
|
-
|
|
7
|
+
from rich.progress import Progress, SpinnerColumn, TextColumn
|
|
8
|
+
from snapctl.config.constants import SNAPCTL_INPUT_ERROR, \
|
|
9
|
+
SNAPCTL_GENERATE_GENERIC_ERROR
|
|
9
10
|
from snapctl.config.hashes import BYOSNAP_TEMPLATE
|
|
10
|
-
from snapctl.
|
|
11
|
-
from snapctl.utils.
|
|
11
|
+
from snapctl.utils.echo import error
|
|
12
|
+
from snapctl.utils.helper import snapctl_error, snapctl_success
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
class Generate:
|
|
@@ -26,52 +27,67 @@ class Generate:
|
|
|
26
27
|
self.base_url: str = base_url
|
|
27
28
|
self.api_key: str = api_key
|
|
28
29
|
self.out_path: Union[str, None] = out_path
|
|
30
|
+
# Validate input
|
|
31
|
+
self.validate_input()
|
|
29
32
|
|
|
30
33
|
# Validator
|
|
31
34
|
|
|
32
|
-
def validate_input(self) ->
|
|
35
|
+
def validate_input(self) -> None:
|
|
33
36
|
"""
|
|
34
37
|
Validator
|
|
35
38
|
"""
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
if self.subcommand not in Generate.SUBCOMMANDS:
|
|
40
|
+
snapctl_error(
|
|
41
|
+
f"Invalid command {self.subcommand}. Valid command are "
|
|
42
|
+
f"{Generate.SUBCOMMANDS}",
|
|
43
|
+
SNAPCTL_INPUT_ERROR
|
|
44
|
+
)
|
|
41
45
|
if self.subcommand in ['byosnap-profile']:
|
|
42
46
|
# Check path
|
|
43
47
|
if self.out_path and not os.path.isdir(self.out_path):
|
|
44
|
-
|
|
48
|
+
snapctl_error(
|
|
45
49
|
f"Invalid path {self.out_path}. Wont be able to "
|
|
46
|
-
"store the byosnap-profile.json file"
|
|
50
|
+
"store the byosnap-profile.json file",
|
|
51
|
+
SNAPCTL_INPUT_ERROR
|
|
47
52
|
)
|
|
48
|
-
return response
|
|
49
|
-
# Send success
|
|
50
|
-
response['error'] = False
|
|
51
|
-
return response
|
|
52
53
|
|
|
53
|
-
def byosnap_profile(self) ->
|
|
54
|
+
def byosnap_profile(self) -> None:
|
|
54
55
|
"""
|
|
55
56
|
Generate snapser-byosnap-profile.json
|
|
56
57
|
"""
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
progress = Progress(
|
|
59
|
+
SpinnerColumn(),
|
|
60
|
+
TextColumn("[progress.description]{task.description}"),
|
|
61
|
+
transient=True,
|
|
62
|
+
)
|
|
63
|
+
progress.start()
|
|
64
|
+
progress.add_task(
|
|
65
|
+
description='Promoting your staging snapend...', total=None)
|
|
64
66
|
try:
|
|
67
|
+
if self.out_path is not None:
|
|
68
|
+
file_save_path = os.path.join(
|
|
69
|
+
self.out_path, Generate.BYOSNAP_PROFILE_FN)
|
|
70
|
+
else:
|
|
71
|
+
file_save_path = os.path.join(
|
|
72
|
+
os.getcwd(), Generate.BYOSNAP_PROFILE_FN)
|
|
73
|
+
file_written = False
|
|
65
74
|
with open(file_save_path, "w") as file:
|
|
66
75
|
json.dump(BYOSNAP_TEMPLATE, file, indent=4)
|
|
67
|
-
|
|
68
|
-
|
|
76
|
+
file_written = True
|
|
77
|
+
if file_written:
|
|
78
|
+
snapctl_success(
|
|
79
|
+
"BYOSNAP Profile generation successful. "
|
|
80
|
+
f"{Generate.BYOSNAP_PROFILE_FN} saved at {file_save_path}",
|
|
81
|
+
progress
|
|
69
82
|
)
|
|
70
|
-
return True
|
|
71
83
|
except (IOError, OSError) as file_error:
|
|
72
|
-
|
|
84
|
+
snapctl_error(f"File error: {file_error}",
|
|
85
|
+
SNAPCTL_GENERATE_GENERIC_ERROR, progress)
|
|
73
86
|
except json.JSONDecodeError as json_error:
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
87
|
+
snapctl_error(f"JSON error: {json_error}",
|
|
88
|
+
SNAPCTL_GENERATE_GENERIC_ERROR, progress)
|
|
89
|
+
snapctl_error(
|
|
90
|
+
"Failed to generate BYOSNAP Profile",
|
|
91
|
+
SNAPCTL_GENERATE_GENERIC_ERROR,
|
|
92
|
+
progress
|
|
93
|
+
)
|