snapctl 0.39.2__py3-none-any.whl → 0.41.0__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 +165 -55
- snapctl/commands/byosnap.py +478 -224
- snapctl/commands/game.py +49 -25
- snapctl/commands/generate.py +48 -40
- snapctl/commands/snapend.py +225 -142
- snapctl/config/constants.py +16 -4
- snapctl/config/hashes.py +5 -3
- snapctl/main.py +106 -34
- snapctl/utils/helper.py +2 -4
- {snapctl-0.39.2.dist-info → snapctl-0.41.0.dist-info}/METADATA +66 -15
- snapctl-0.41.0.dist-info/RECORD +23 -0
- snapctl-0.39.2.dist-info/RECORD +0 -23
- {snapctl-0.39.2.dist-info → snapctl-0.41.0.dist-info}/LICENSE +0 -0
- {snapctl-0.39.2.dist-info → snapctl-0.41.0.dist-info}/WHEEL +0 -0
- {snapctl-0.39.2.dist-info → snapctl-0.41.0.dist-info}/entry_points.txt +0 -0
snapctl/commands/game.py
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"""
|
|
2
2
|
Snapend CLI commands
|
|
3
3
|
"""
|
|
4
|
-
from typing import Union
|
|
4
|
+
from typing import Union
|
|
5
5
|
import requests
|
|
6
6
|
from requests.exceptions import RequestException
|
|
7
7
|
from rich.progress import Progress, SpinnerColumn, TextColumn
|
|
8
8
|
from snapctl.config.constants import SERVER_CALL_TIMEOUT, SNAPCTL_INPUT_ERROR, \
|
|
9
9
|
SNAPCTL_GAME_CREATE_ERROR, SNAPCTL_GAME_ENUMERATE_ERROR, \
|
|
10
|
-
HTTP_ERROR_DUPLICATE_GAME_NAME, SNAPCTL_GAME_CREATE_DUPLICATE_NAME_ERROR
|
|
10
|
+
HTTP_ERROR_DUPLICATE_GAME_NAME, SNAPCTL_GAME_CREATE_DUPLICATE_NAME_ERROR, \
|
|
11
|
+
HTTP_ERROR_GAME_LIMIT_REACHED, SNAPCTL_GAME_CREATE_LIMIT_ERROR
|
|
11
12
|
from snapctl.utils.helper import snapctl_error, snapctl_success
|
|
12
13
|
|
|
13
14
|
|
|
@@ -18,11 +19,12 @@ class Game:
|
|
|
18
19
|
SUBCOMMANDS = ['create', 'enumerate']
|
|
19
20
|
|
|
20
21
|
def __init__(
|
|
21
|
-
self, subcommand: str, base_url: str, api_key: Union[str, None],
|
|
22
|
+
self, *, subcommand: str, base_url: str, api_key: Union[str, None],
|
|
23
|
+
name: Union[str, None] = None
|
|
22
24
|
) -> None:
|
|
23
25
|
self.subcommand: str = subcommand
|
|
24
26
|
self.base_url: str = base_url
|
|
25
|
-
self.api_key: str = api_key
|
|
27
|
+
self.api_key: Union[str, None] = api_key
|
|
26
28
|
self.name: Union[str, None] = name
|
|
27
29
|
# Validate input
|
|
28
30
|
self.validate_input()
|
|
@@ -33,18 +35,22 @@ class Game:
|
|
|
33
35
|
"""
|
|
34
36
|
# Check API Key and Base URL
|
|
35
37
|
if not self.api_key or self.base_url == '':
|
|
36
|
-
snapctl_error(
|
|
38
|
+
snapctl_error(
|
|
39
|
+
message="Missing API Key.", code=SNAPCTL_INPUT_ERROR)
|
|
37
40
|
# Check subcommand
|
|
38
41
|
if not self.subcommand in Game.SUBCOMMANDS:
|
|
39
|
-
snapctl_error(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
snapctl_error(
|
|
43
|
+
message="Invalid command. Valid commands are" +
|
|
44
|
+
f"{', '.join(Game.SUBCOMMANDS)}.",
|
|
45
|
+
code=SNAPCTL_INPUT_ERROR)
|
|
42
46
|
# Check sdk-download commands
|
|
43
47
|
if self.subcommand == 'create':
|
|
44
48
|
if self.name is None or self.name == '':
|
|
45
|
-
snapctl_error(
|
|
49
|
+
snapctl_error(
|
|
50
|
+
message="Missing game name.",
|
|
51
|
+
code=SNAPCTL_INPUT_ERROR)
|
|
46
52
|
|
|
47
|
-
def create(self) -> bool:
|
|
53
|
+
def create(self, no_exit: bool = False) -> bool:
|
|
48
54
|
"""
|
|
49
55
|
Create a game
|
|
50
56
|
"""
|
|
@@ -67,19 +73,31 @@ class Game:
|
|
|
67
73
|
)
|
|
68
74
|
if res.ok:
|
|
69
75
|
snapctl_success(
|
|
70
|
-
f"Game {self.name} create successful",
|
|
76
|
+
message=f"Game {self.name} create successful",
|
|
77
|
+
progress=progress, no_exit=no_exit)
|
|
78
|
+
return
|
|
71
79
|
response_json = res.json()
|
|
72
80
|
if "api_error_code" in response_json and "message" in response_json:
|
|
81
|
+
if response_json['api_error_code'] == HTTP_ERROR_GAME_LIMIT_REACHED:
|
|
82
|
+
snapctl_error(
|
|
83
|
+
message=f"Game {self.name} already exists.",
|
|
84
|
+
code=SNAPCTL_GAME_CREATE_LIMIT_ERROR, progress=progress)
|
|
73
85
|
if response_json['api_error_code'] == HTTP_ERROR_DUPLICATE_GAME_NAME:
|
|
74
|
-
snapctl_error(
|
|
75
|
-
|
|
86
|
+
snapctl_error(
|
|
87
|
+
message=f"Game {self.name} already exists.",
|
|
88
|
+
code=SNAPCTL_GAME_CREATE_DUPLICATE_NAME_ERROR, progress=progress)
|
|
76
89
|
snapctl_error(
|
|
77
|
-
f'Server error: {response_json}',
|
|
90
|
+
message=f'Server error: {response_json}',
|
|
91
|
+
code=SNAPCTL_GAME_CREATE_ERROR, progress=progress)
|
|
78
92
|
except RequestException as e:
|
|
79
|
-
snapctl_error(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
93
|
+
snapctl_error(
|
|
94
|
+
message=f"Exception: Unable to download the SDK {e}",
|
|
95
|
+
code=SNAPCTL_GAME_CREATE_ERROR, progress=progress)
|
|
96
|
+
finally:
|
|
97
|
+
progress.stop()
|
|
98
|
+
snapctl_error(
|
|
99
|
+
message='Failed to create game.',
|
|
100
|
+
code=SNAPCTL_GAME_CREATE_ERROR, progress=progress)
|
|
83
101
|
|
|
84
102
|
def enumerate(self) -> bool:
|
|
85
103
|
"""
|
|
@@ -101,11 +119,17 @@ class Game:
|
|
|
101
119
|
)
|
|
102
120
|
response_json = res.json()
|
|
103
121
|
if res.ok and 'games' in response_json:
|
|
104
|
-
snapctl_success(
|
|
105
|
-
|
|
106
|
-
|
|
122
|
+
snapctl_success(
|
|
123
|
+
message=response_json['games'], progress=progress)
|
|
124
|
+
snapctl_error(
|
|
125
|
+
message='Unable to enumerate games.',
|
|
126
|
+
code=SNAPCTL_GAME_ENUMERATE_ERROR, progress=progress)
|
|
107
127
|
except RequestException as e:
|
|
108
|
-
snapctl_error(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
128
|
+
snapctl_error(
|
|
129
|
+
message=f"Exception: Unable to update your snapend {e}",
|
|
130
|
+
code=SNAPCTL_GAME_ENUMERATE_ERROR, progress=progress)
|
|
131
|
+
finally:
|
|
132
|
+
progress.stop()
|
|
133
|
+
snapctl_error(
|
|
134
|
+
message='Failed to enumerate games.',
|
|
135
|
+
code=SNAPCTL_GAME_ENUMERATE_ERROR, progress=progress)
|
snapctl/commands/generate.py
CHANGED
|
@@ -28,9 +28,9 @@ class Generate:
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
def __init__(
|
|
31
|
-
self, subcommand: str, base_url: str, api_key: Union[str, None],
|
|
32
|
-
category: Union[str, None],
|
|
33
|
-
out_path: Union[str, None]
|
|
31
|
+
self, *, subcommand: str, base_url: str, api_key: Union[str, None],
|
|
32
|
+
category: Union[str, None] = None,
|
|
33
|
+
out_path: Union[str, None] = None
|
|
34
34
|
) -> None:
|
|
35
35
|
self.subcommand: str = subcommand
|
|
36
36
|
self.base_url: str = base_url
|
|
@@ -63,44 +63,44 @@ class Generate:
|
|
|
63
63
|
"""
|
|
64
64
|
if self.subcommand not in Generate.SUBCOMMANDS:
|
|
65
65
|
snapctl_error(
|
|
66
|
-
f"Invalid command {self.subcommand}. Valid command are " +
|
|
66
|
+
message=f"Invalid command {self.subcommand}. Valid command are " +
|
|
67
67
|
f"{Generate.SUBCOMMANDS}",
|
|
68
|
-
SNAPCTL_INPUT_ERROR
|
|
68
|
+
code=SNAPCTL_INPUT_ERROR
|
|
69
69
|
)
|
|
70
70
|
# Check path
|
|
71
71
|
if self.subcommand == 'profile':
|
|
72
72
|
if self.category not in Generate.CATEGORIES['profile']:
|
|
73
73
|
snapctl_error(
|
|
74
|
-
f"Invalid category {self.category}. Valid category are " +
|
|
74
|
+
message=f"Invalid category {self.category}. Valid category are " +
|
|
75
75
|
f"{Generate.CATEGORIES['profile']}",
|
|
76
|
-
SNAPCTL_INPUT_ERROR
|
|
76
|
+
code=SNAPCTL_INPUT_ERROR
|
|
77
77
|
)
|
|
78
78
|
if not self.out_path:
|
|
79
79
|
snapctl_error(
|
|
80
|
-
"Path is required for profile generation",
|
|
81
|
-
SNAPCTL_INPUT_ERROR
|
|
80
|
+
message="Path is required for profile generation",
|
|
81
|
+
code=SNAPCTL_INPUT_ERROR
|
|
82
82
|
)
|
|
83
83
|
elif self.subcommand == 'credentials':
|
|
84
84
|
if self.category not in Generate.CATEGORIES['credentials']:
|
|
85
85
|
snapctl_error(
|
|
86
|
-
f"Invalid category {self.category}. Valid category are " +
|
|
86
|
+
message=f"Invalid category {self.category}. Valid category are " +
|
|
87
87
|
f"{Generate.CATEGORIES['credentials']}",
|
|
88
|
-
SNAPCTL_INPUT_ERROR
|
|
88
|
+
code=SNAPCTL_INPUT_ERROR
|
|
89
89
|
)
|
|
90
90
|
if not self.out_path:
|
|
91
91
|
snapctl_error(
|
|
92
|
-
"Path is required for token generation",
|
|
93
|
-
SNAPCTL_INPUT_ERROR
|
|
92
|
+
message="Path is required for token generation",
|
|
93
|
+
code=SNAPCTL_INPUT_ERROR
|
|
94
94
|
)
|
|
95
95
|
# Now confirm that out-path is valid
|
|
96
96
|
if self.out_path and not os.path.isdir(self.out_path):
|
|
97
97
|
snapctl_error(
|
|
98
|
-
f"Invalid path {self.out_path}. Wont be able to " +
|
|
98
|
+
message=f"Invalid path {self.out_path}. Wont be able to " +
|
|
99
99
|
"store the output file",
|
|
100
|
-
SNAPCTL_INPUT_ERROR
|
|
100
|
+
code=SNAPCTL_INPUT_ERROR
|
|
101
101
|
)
|
|
102
102
|
|
|
103
|
-
def byosnap_profile(self) -> None:
|
|
103
|
+
def byosnap_profile(self, no_exit: bool = False) -> None:
|
|
104
104
|
"""
|
|
105
105
|
Generate snapser-byosnap-profile.json
|
|
106
106
|
"""
|
|
@@ -125,30 +125,34 @@ class Generate:
|
|
|
125
125
|
file_written = True
|
|
126
126
|
if file_written:
|
|
127
127
|
snapctl_success(
|
|
128
|
-
"BYOSNAP Profile generation successful. " +
|
|
128
|
+
message="BYOSNAP Profile generation successful. " +
|
|
129
129
|
f"{Generate.BYOSNAP_PROFILE_FN} saved at {file_save_path}",
|
|
130
|
-
progress
|
|
130
|
+
progress=progress,
|
|
131
|
+
no_exit=no_exit
|
|
131
132
|
)
|
|
133
|
+
return
|
|
132
134
|
except (IOError, OSError) as file_error:
|
|
133
|
-
snapctl_error(
|
|
134
|
-
|
|
135
|
+
snapctl_error(
|
|
136
|
+
message=f"File error: {file_error}",
|
|
137
|
+
code=SNAPCTL_GENERATE_PROFILE_ERROR, progress=progress)
|
|
135
138
|
except json.JSONDecodeError as json_error:
|
|
136
|
-
snapctl_error(
|
|
137
|
-
|
|
139
|
+
snapctl_error(
|
|
140
|
+
message=f"JSON error: {json_error}",
|
|
141
|
+
code=SNAPCTL_GENERATE_PROFILE_ERROR, progress=progress)
|
|
138
142
|
snapctl_error(
|
|
139
|
-
"Failed to generate BYOSNAP Profile",
|
|
140
|
-
SNAPCTL_GENERATE_PROFILE_ERROR,
|
|
141
|
-
progress
|
|
143
|
+
message="Failed to generate BYOSNAP Profile",
|
|
144
|
+
code=SNAPCTL_GENERATE_PROFILE_ERROR,
|
|
145
|
+
progress=progress
|
|
142
146
|
)
|
|
143
147
|
|
|
144
|
-
def profile(self) -> None:
|
|
148
|
+
def profile(self, no_exit: bool = False) -> None:
|
|
145
149
|
"""
|
|
146
150
|
Generate profile
|
|
147
151
|
"""
|
|
148
152
|
if self.category == 'byosnap':
|
|
149
|
-
self.byosnap_profile()
|
|
153
|
+
self.byosnap_profile(no_exit)
|
|
150
154
|
|
|
151
|
-
def ecr_credentials(self) -> None:
|
|
155
|
+
def ecr_credentials(self, no_exit: bool = False) -> None:
|
|
152
156
|
"""
|
|
153
157
|
Generate credentials
|
|
154
158
|
"""
|
|
@@ -169,9 +173,9 @@ class Generate:
|
|
|
169
173
|
# url|web_app_token|service_id|ecr_repo_url|ecr_repo_username|ecr_repo_token
|
|
170
174
|
if token_parts is None or len(token_parts) != 4:
|
|
171
175
|
snapctl_error(
|
|
172
|
-
"Unable to retrieve token.",
|
|
173
|
-
SNAPCTL_GENERATE_GENERIC_ERROR,
|
|
174
|
-
progress
|
|
176
|
+
message="Unable to retrieve token.",
|
|
177
|
+
code=SNAPCTL_GENERATE_GENERIC_ERROR,
|
|
178
|
+
progress=progress
|
|
175
179
|
)
|
|
176
180
|
token_details = {
|
|
177
181
|
'ecr_repo_url': token_parts[0],
|
|
@@ -191,20 +195,24 @@ class Generate:
|
|
|
191
195
|
file_written = True
|
|
192
196
|
if file_written:
|
|
193
197
|
snapctl_success(
|
|
194
|
-
"ECR Token generation successful. " +
|
|
198
|
+
message="ECR Token generation successful. " +
|
|
195
199
|
f"{Generate.ECR_TOKEN_FN} saved at {file_save_path}",
|
|
196
|
-
progress
|
|
200
|
+
progress=progress,
|
|
201
|
+
no_exit=no_exit
|
|
197
202
|
)
|
|
203
|
+
return
|
|
198
204
|
except (IOError, OSError) as file_error:
|
|
199
|
-
snapctl_error(
|
|
200
|
-
|
|
205
|
+
snapctl_error(
|
|
206
|
+
message=f"File error: {file_error}",
|
|
207
|
+
code=SNAPCTL_GENERATE_CREDENTIALS_ERROR, progress=progress)
|
|
201
208
|
except json.JSONDecodeError as json_error:
|
|
202
|
-
snapctl_error(
|
|
203
|
-
|
|
209
|
+
snapctl_error(
|
|
210
|
+
message=f"JSON error: {json_error}",
|
|
211
|
+
code=SNAPCTL_GENERATE_CREDENTIALS_ERROR, progress=progress)
|
|
204
212
|
snapctl_error(
|
|
205
|
-
"Failed to generate Token",
|
|
206
|
-
SNAPCTL_GENERATE_CREDENTIALS_ERROR,
|
|
207
|
-
progress
|
|
213
|
+
message="Failed to generate Token",
|
|
214
|
+
code=SNAPCTL_GENERATE_CREDENTIALS_ERROR,
|
|
215
|
+
progress=progress
|
|
208
216
|
)
|
|
209
217
|
|
|
210
218
|
def credentials(self):
|