snapctl 0.4.5__py3-none-any.whl → 0.22.1__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/__main__.py +3 -0
- snapctl/commands/byogs.py +443 -311
- snapctl/commands/byosnap.py +540 -335
- snapctl/commands/snapend.py +265 -182
- snapctl/config/constants.py +6 -1
- snapctl/config/endpoints.py +8 -5
- snapctl/config/hashes.py +13 -3
- snapctl/main.py +396 -183
- snapctl/types/definitions.py +11 -3
- snapctl/utils/echo.py +18 -3
- snapctl/utils/helper.py +33 -20
- {snapctl-0.4.5.dist-info → snapctl-0.22.1.dist-info}/METADATA +218 -67
- snapctl-0.22.1.dist-info/RECORD +20 -0
- {snapctl-0.4.5.dist-info → snapctl-0.22.1.dist-info}/WHEEL +1 -1
- snapctl-0.4.5.dist-info/RECORD +0 -20
- {snapctl-0.4.5.dist-info → snapctl-0.22.1.dist-info}/entry_points.txt +0 -0
snapctl/main.py
CHANGED
|
@@ -1,231 +1,444 @@
|
|
|
1
|
+
"""
|
|
2
|
+
SnapCTL entrypoint
|
|
3
|
+
"""
|
|
1
4
|
import configparser
|
|
2
5
|
import os
|
|
6
|
+
from sys import platform
|
|
7
|
+
from typing import Union, Callable
|
|
3
8
|
import typer
|
|
4
9
|
|
|
5
10
|
from snapctl.commands.byosnap import ByoSnap
|
|
6
11
|
from snapctl.commands.byogs import ByoGs
|
|
7
12
|
from snapctl.commands.snapend import Snapend
|
|
8
|
-
from snapctl.config.constants import API_KEY, CONFIG_FILE_MAC, CONFIG_FILE_WIN, DEFAULT_PROFILE,
|
|
9
|
-
|
|
10
|
-
from snapctl.config.
|
|
13
|
+
from snapctl.config.constants import API_KEY, CONFIG_FILE_MAC, CONFIG_FILE_WIN, DEFAULT_PROFILE, \
|
|
14
|
+
VERSION, SNAPCTL_SUCCESS, SNAPCTL_ERROR
|
|
15
|
+
from snapctl.config.endpoints import END_POINTS
|
|
16
|
+
from snapctl.config.hashes import CLIENT_SDK_TYPES, SERVER_SDK_TYPES, PROTOS_TYPES, SERVICE_IDS
|
|
11
17
|
from snapctl.types.definitions import ResponseType
|
|
12
18
|
from snapctl.utils.echo import error, success, info
|
|
13
|
-
from sys import platform
|
|
14
|
-
from typing import Union
|
|
15
19
|
|
|
16
20
|
app = typer.Typer()
|
|
17
21
|
|
|
18
22
|
######### HELPER METHODS #########
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if profile is not None and profile != '' and profile != DEFAULT_PROFILE:
|
|
31
|
-
config_profile = f'profile {profile}'
|
|
32
|
-
info(f"Using Profile from input {profile}")
|
|
33
|
-
else:
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def extract_api_key(profile: str | None = None) -> object:
|
|
26
|
+
"""
|
|
27
|
+
Extracts the API Key from the environment variable and if not present from the config file
|
|
28
|
+
"""
|
|
29
|
+
result = {
|
|
30
|
+
'location': '',
|
|
31
|
+
'value': None
|
|
32
|
+
}
|
|
33
|
+
# Option 1
|
|
34
34
|
env_api_key = os.getenv(API_KEY)
|
|
35
35
|
if env_api_key is not None:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
result['location'] = 'environment-variable'
|
|
37
|
+
result['value'] = env_api_key
|
|
38
|
+
return result
|
|
39
|
+
# Option 2
|
|
40
|
+
config_file_path: str = ''
|
|
41
|
+
encoding: str | None = None
|
|
42
|
+
if platform == 'win32':
|
|
43
|
+
config_file_path = os.path.expandvars(CONFIG_FILE_WIN)
|
|
44
|
+
encoding = "utf-8-sig"
|
|
45
|
+
else:
|
|
46
|
+
config_file_path = os.path.expanduser(CONFIG_FILE_MAC)
|
|
47
|
+
if os.path.isfile(config_file_path):
|
|
48
|
+
result['location'] = 'config-file'
|
|
49
|
+
config = configparser.ConfigParser()
|
|
50
|
+
config.read(config_file_path, encoding=encoding)
|
|
51
|
+
config_profile: str = DEFAULT_PROFILE
|
|
52
|
+
if profile is not None and profile != '' and profile != DEFAULT_PROFILE:
|
|
53
|
+
result['location'] = f'config-file:profile:{profile}'
|
|
54
|
+
config_profile = f'profile {profile}'
|
|
55
|
+
info(f"Trying to extract API KEY from from profile {profile}")
|
|
56
|
+
result['value'] = config.get(
|
|
57
|
+
config_profile, API_KEY, fallback=None, raw=True
|
|
58
|
+
)
|
|
59
|
+
return result
|
|
39
60
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
61
|
+
|
|
62
|
+
def get_base_url(api_key: str | None) -> str:
|
|
63
|
+
"""
|
|
64
|
+
Returns the base url based on the api_key
|
|
65
|
+
"""
|
|
66
|
+
if api_key is None:
|
|
67
|
+
return ''
|
|
68
|
+
if api_key.startswith('dev_'):
|
|
69
|
+
return END_POINTS['DEV']
|
|
70
|
+
if api_key.startswith('playtest_'):
|
|
71
|
+
return END_POINTS['PLAYTEST']
|
|
72
|
+
return END_POINTS['PROD']
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def validate_command_context(
|
|
76
|
+
ctx: typer.Context,
|
|
77
|
+
):
|
|
78
|
+
"""
|
|
79
|
+
Validator to confirm if the context has been set properly
|
|
80
|
+
"""
|
|
81
|
+
if ctx.obj['api_key'] is None or ctx.obj['base_url'] == '':
|
|
82
|
+
error('API Key not found.')
|
|
83
|
+
raise typer.Exit(SNAPCTL_ERROR)
|
|
84
|
+
info(f"Using API Key from {ctx.obj['api_key_location']}")
|
|
46
85
|
|
|
47
86
|
######### CALLBACKS #########
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def default_context_callback(ctx: typer.Context):
|
|
90
|
+
"""
|
|
91
|
+
Common Callback to set the main app context
|
|
92
|
+
This gets called on every command right at the start
|
|
93
|
+
"""
|
|
94
|
+
# info("In default callback")
|
|
95
|
+
# Ensure ctx object is instantiated
|
|
96
|
+
ctx.ensure_object(dict)
|
|
97
|
+
# Extract the api_key
|
|
98
|
+
api_key_obj = extract_api_key()
|
|
99
|
+
ctx.obj['version'] = VERSION
|
|
100
|
+
ctx.obj['api_key'] = api_key_obj['value']
|
|
101
|
+
ctx.obj['api_key_location'] = api_key_obj['location']
|
|
102
|
+
ctx.obj['profile'] = DEFAULT_PROFILE
|
|
103
|
+
ctx.obj['base_url'] = get_base_url(api_key_obj['value'])
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def api_key_context_callback(
|
|
107
|
+
ctx: typer.Context,
|
|
108
|
+
api_key: str | None = None
|
|
109
|
+
):
|
|
110
|
+
"""
|
|
111
|
+
Callback to set the context for the api_key
|
|
112
|
+
This gets called only if the user has added a --api-key override
|
|
113
|
+
"""
|
|
114
|
+
if api_key is None:
|
|
115
|
+
return None
|
|
116
|
+
# info("In API Key callback")
|
|
117
|
+
# Ensure ctx object is instantiated
|
|
118
|
+
ctx.ensure_object(dict)
|
|
119
|
+
ctx.obj['version'] = VERSION
|
|
120
|
+
ctx.obj['api_key'] = api_key
|
|
121
|
+
ctx.obj['api_key_location'] = 'command-line-argument'
|
|
122
|
+
ctx.obj['base_url'] = get_base_url(api_key)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def profile_context_callback(
|
|
126
|
+
ctx: typer.Context,
|
|
127
|
+
profile: str | None = None
|
|
128
|
+
):
|
|
129
|
+
"""
|
|
130
|
+
Callback to set the context for the profile
|
|
131
|
+
This gets called only if the user has added a --profile override
|
|
132
|
+
"""
|
|
133
|
+
# Its important to early return if user has already entered API Key via command line
|
|
134
|
+
if profile is None or ctx.obj['api_key_location'] == 'command-line-argument':
|
|
135
|
+
return None
|
|
136
|
+
# info("In Profile Callback")
|
|
137
|
+
# Ensure ctx object is instantiated
|
|
138
|
+
ctx.ensure_object(dict)
|
|
139
|
+
api_key_obj = extract_api_key(profile)
|
|
140
|
+
if api_key_obj['value'] is None and profile is not None and profile != '':
|
|
141
|
+
conf_file = ''
|
|
142
|
+
if platform == 'win32':
|
|
143
|
+
conf_file = os.path.expandvars(CONFIG_FILE_WIN)
|
|
144
|
+
else:
|
|
145
|
+
conf_file = os.path.expanduser(CONFIG_FILE_MAC)
|
|
146
|
+
error(
|
|
147
|
+
f'Invalid profile. Please check your snap config file at {conf_file}'
|
|
148
|
+
)
|
|
149
|
+
ctx.obj['version'] = VERSION
|
|
150
|
+
ctx.obj['api_key'] = api_key_obj['value']
|
|
151
|
+
ctx.obj['api_key_location'] = api_key_obj['location']
|
|
152
|
+
ctx.obj['profile'] = profile if profile else DEFAULT_PROFILE
|
|
153
|
+
ctx.obj['base_url'] = get_base_url(api_key_obj['value'])
|
|
83
154
|
|
|
84
155
|
|
|
85
156
|
# Presently in typer this is the only way we can expose the `--version`
|
|
86
157
|
def version_callback(value: bool = True):
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
158
|
+
"""
|
|
159
|
+
Prints the version and exits
|
|
160
|
+
"""
|
|
161
|
+
if value:
|
|
162
|
+
success(f"Snapctl version: {VERSION}")
|
|
163
|
+
raise typer.Exit(SNAPCTL_SUCCESS)
|
|
164
|
+
|
|
90
165
|
|
|
91
166
|
@app.callback()
|
|
92
167
|
def common(
|
|
93
168
|
ctx: typer.Context,
|
|
94
169
|
version: bool = typer.Option(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
)
|
|
170
|
+
None, "--version",
|
|
171
|
+
help="Get the Snapctl version.",
|
|
172
|
+
callback=version_callback
|
|
173
|
+
),
|
|
99
174
|
):
|
|
100
175
|
"""
|
|
101
176
|
Snapser CLI Tool
|
|
102
177
|
"""
|
|
103
|
-
|
|
104
|
-
# Note this executes only when the user runs a command and not for --help or --version
|
|
105
|
-
if platform == 'win32':
|
|
106
|
-
config_file_path = os.path.expandvars(CONFIG_FILE_WIN)
|
|
107
|
-
else:
|
|
108
|
-
config_file_path = os.path.expanduser(CONFIG_FILE_MAC)
|
|
109
|
-
if not os.path.isfile(config_file_path):
|
|
110
|
-
error(f'Snapser configuration file not found at {config_file_path} ')
|
|
111
|
-
raise typer.Exit(SNAPCTL_ERROR)
|
|
112
|
-
# Set the main context this always sets the default context
|
|
113
|
-
set_context_callback(ctx)
|
|
178
|
+
default_context_callback(ctx)
|
|
114
179
|
|
|
115
180
|
######### TYPER COMMANDS #########
|
|
181
|
+
|
|
182
|
+
|
|
116
183
|
@app.command()
|
|
117
184
|
def validate(
|
|
118
|
-
|
|
185
|
+
ctx: typer.Context,
|
|
186
|
+
api_key: Union[str, None] = typer.Option(
|
|
187
|
+
None, "--api-key", help="API Key override.", callback=api_key_context_callback
|
|
188
|
+
),
|
|
189
|
+
profile: Union[str, None] = typer.Option(
|
|
190
|
+
None, "--profile", help="Profile to use.", callback=profile_context_callback
|
|
191
|
+
),
|
|
119
192
|
):
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
193
|
+
"""
|
|
194
|
+
Validate your Snapctl setup
|
|
195
|
+
"""
|
|
196
|
+
validate_command_context(ctx)
|
|
197
|
+
success("Setup is valid")
|
|
198
|
+
|
|
124
199
|
|
|
125
200
|
@app.command()
|
|
126
201
|
def byosnap(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
202
|
+
ctx: typer.Context,
|
|
203
|
+
# Required fields
|
|
204
|
+
subcommand: str = typer.Argument(
|
|
205
|
+
..., help="BYOSnap Subcommands: " + ", ".join(ByoSnap.SUBCOMMANDS) + "."
|
|
206
|
+
),
|
|
207
|
+
sid: str = typer.Argument(..., help="Snap Id. Should start with byosnap-"),
|
|
208
|
+
# create
|
|
209
|
+
name: str = typer.Option(
|
|
210
|
+
None, "--name", help="(req: create) Name for your snap."
|
|
211
|
+
),
|
|
212
|
+
desc: str = typer.Option(
|
|
213
|
+
None, "--desc", help="(req: create) Description for your snap"
|
|
214
|
+
),
|
|
215
|
+
platform_type: str = typer.Option(
|
|
216
|
+
None, "--platform",
|
|
217
|
+
help="(req: create) Platform for your snap - " + \
|
|
218
|
+
", ".join(ByoSnap.PLATFORMS) + "."
|
|
219
|
+
),
|
|
220
|
+
language: str = typer.Option(
|
|
221
|
+
None, "--language",
|
|
222
|
+
help="(req: create) Language of your snap - " + \
|
|
223
|
+
", ".join(ByoSnap.LANGUAGES) + "."
|
|
224
|
+
),
|
|
225
|
+
# publish-image and publish-version
|
|
226
|
+
tag: str = typer.Option(
|
|
227
|
+
None, "--tag", help="(req: build, push publish-image and publish-version) Tag for your snap"
|
|
228
|
+
),
|
|
229
|
+
# publish-image
|
|
230
|
+
path: Union[str, None] = typer.Option(
|
|
231
|
+
None, "--path", help="(req: build, publish-image) Path to your snap code"
|
|
232
|
+
),
|
|
233
|
+
docker_file: str = typer.Option(
|
|
234
|
+
"Dockerfile", help="Dockerfile name to use"
|
|
235
|
+
),
|
|
236
|
+
# publish-version
|
|
237
|
+
prefix: str = typer.Option(
|
|
238
|
+
'/v1', "--prefix", help="(req: publish-version) URL Prefix for your snap"
|
|
239
|
+
),
|
|
240
|
+
version: Union[str, None] = typer.Option(
|
|
241
|
+
None, "--version",
|
|
242
|
+
help="(req: publish-version) Snap version. Should start with v. Example vX.X.X"
|
|
243
|
+
),
|
|
244
|
+
http_port: Union[str, None] = typer.Option(
|
|
245
|
+
None, "--http-port", help="(req: publish-version) Ingress HTTP port version"
|
|
246
|
+
),
|
|
247
|
+
# overrides
|
|
248
|
+
api_key: Union[str, None] = typer.Option(
|
|
249
|
+
None, "--api-key", help="API Key override.", callback=api_key_context_callback
|
|
250
|
+
),
|
|
251
|
+
profile: Union[str, None] = typer.Option(
|
|
252
|
+
None, "--profile", help="Profile to use.", callback=profile_context_callback
|
|
253
|
+
),
|
|
147
254
|
) -> None:
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
255
|
+
"""
|
|
256
|
+
Bring your own snap commands
|
|
257
|
+
"""
|
|
258
|
+
validate_command_context(ctx)
|
|
259
|
+
byosnap_obj: ByoSnap = ByoSnap(
|
|
260
|
+
subcommand, ctx.obj['base_url'], ctx.obj['api_key'], sid,
|
|
261
|
+
name, desc, platform_type, language, tag, path, docker_file,
|
|
262
|
+
prefix, version, http_port
|
|
263
|
+
)
|
|
264
|
+
validate_input_response: ResponseType = byosnap_obj.validate_input()
|
|
265
|
+
if validate_input_response['error']:
|
|
266
|
+
error(validate_input_response['msg'])
|
|
267
|
+
raise typer.Exit(SNAPCTL_ERROR)
|
|
268
|
+
command_method = subcommand.replace('-', '_')
|
|
269
|
+
method: Callable[..., bool] = getattr(byosnap_obj, command_method)
|
|
270
|
+
if not method():
|
|
271
|
+
error(f"BYOSnap {subcommand} failed")
|
|
272
|
+
raise typer.Exit(SNAPCTL_ERROR)
|
|
273
|
+
success(f"BYOSnap {subcommand} complete")
|
|
274
|
+
|
|
163
275
|
|
|
164
276
|
@app.command()
|
|
165
277
|
def byogs(
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
278
|
+
ctx: typer.Context,
|
|
279
|
+
# Required fields
|
|
280
|
+
subcommand: str = typer.Argument(
|
|
281
|
+
..., help="BYOGs Subcommands: " + ", ".join(ByoGs.SUBCOMMANDS) + "."
|
|
282
|
+
),
|
|
283
|
+
sid: str = typer.Argument(
|
|
284
|
+
..., help="Game Server Id. Should start with byogs-"
|
|
285
|
+
),
|
|
286
|
+
# create
|
|
287
|
+
name: str = typer.Option(
|
|
288
|
+
None, "--name", help="(req: create) Name for your snap"
|
|
289
|
+
),
|
|
290
|
+
desc: str = typer.Option(
|
|
291
|
+
None, "--desc", help="(req: create) Description for your snap"
|
|
292
|
+
),
|
|
293
|
+
platform_type: str = typer.Option(
|
|
294
|
+
None, "--platform",
|
|
295
|
+
help="(req: create) Platform for your snap - " + \
|
|
296
|
+
", ".join(ByoGs.PLATFORMS) + "."
|
|
297
|
+
),
|
|
298
|
+
language: str = typer.Option(
|
|
299
|
+
None, "--language",
|
|
300
|
+
help="(req: create) Language of your snap - " + \
|
|
301
|
+
", ".join(ByoGs.LANGUAGES) + "."
|
|
302
|
+
),
|
|
303
|
+
# publish-image and publish-version
|
|
304
|
+
tag: str = typer.Option(
|
|
305
|
+
None, "--tag",
|
|
306
|
+
help="(req: build, push, publish-image and publish-version) Tag for your snap"
|
|
307
|
+
),
|
|
308
|
+
# publish-image
|
|
309
|
+
path: Union[str, None] = typer.Option(
|
|
310
|
+
None, "--path", help="(req: build, publish-image, upload-docs) Path to your snap code"
|
|
311
|
+
),
|
|
312
|
+
docker_file: str = typer.Option(
|
|
313
|
+
"Dockerfile", help="Dockerfile name to use"
|
|
314
|
+
),
|
|
315
|
+
# publish-version
|
|
316
|
+
version: Union[str, None] = typer.Option(
|
|
317
|
+
None, "--version", help="(req: publish-version) Snap version"
|
|
318
|
+
),
|
|
319
|
+
http_port: Union[str, None] = typer.Option(
|
|
320
|
+
None, "--http-port", help="(req: publish-version) Ingress HTTP port version"
|
|
321
|
+
),
|
|
322
|
+
debug_port: Union[str, None] = typer.Option(
|
|
323
|
+
None, "--debug-port", help="(optional: publish-version) Debug HTTP port version"
|
|
324
|
+
),
|
|
325
|
+
# overrides
|
|
326
|
+
api_key: Union[str, None] = typer.Option(
|
|
327
|
+
None, "--api-key", help="API Key override.", callback=api_key_context_callback
|
|
328
|
+
),
|
|
329
|
+
profile: Union[str, None] = typer.Option(
|
|
330
|
+
None, "--profile", help="Profile to use.", callback=profile_context_callback
|
|
331
|
+
),
|
|
185
332
|
) -> None:
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
333
|
+
"""
|
|
334
|
+
Bring your own game server commands
|
|
335
|
+
"""
|
|
336
|
+
validate_command_context(ctx)
|
|
337
|
+
byogs_obj: ByoGs = ByoGs(
|
|
338
|
+
subcommand, ctx.obj['base_url'], ctx.obj['api_key'], sid,
|
|
339
|
+
name, desc, platform_type, language, tag, path, docker_file,
|
|
340
|
+
version, http_port, debug_port
|
|
341
|
+
)
|
|
342
|
+
validate_input_response: ResponseType = byogs_obj.validate_input()
|
|
343
|
+
if validate_input_response['error']:
|
|
344
|
+
error(validate_input_response['msg'])
|
|
345
|
+
raise typer.Exit(SNAPCTL_ERROR)
|
|
346
|
+
command_method = subcommand.replace('-', '_')
|
|
347
|
+
method: Callable[..., bool] = getattr(byogs_obj, command_method)
|
|
348
|
+
if not method():
|
|
349
|
+
error(f"BYOGs {subcommand} failed")
|
|
350
|
+
raise typer.Exit(SNAPCTL_ERROR)
|
|
351
|
+
success(f"BYOGs {subcommand} complete")
|
|
352
|
+
|
|
200
353
|
|
|
201
354
|
@app.command()
|
|
202
355
|
def snapend(
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
356
|
+
ctx: typer.Context,
|
|
357
|
+
# Required fields
|
|
358
|
+
subcommand: str = typer.Argument(
|
|
359
|
+
..., help="Snapend Subcommands: " + ", ".join(Snapend.SUBCOMMANDS) + "."
|
|
360
|
+
),
|
|
361
|
+
snapend_id: str = typer.Argument(..., help="Snapend Id"),
|
|
362
|
+
# download
|
|
363
|
+
category: str = typer.Option(
|
|
364
|
+
None, "--category",
|
|
365
|
+
help=(
|
|
366
|
+
"(req: download) Category of the Download: " +
|
|
367
|
+
", ".join(Snapend.DOWNLOAD_CATEGORY) + "."
|
|
368
|
+
)
|
|
369
|
+
),
|
|
370
|
+
path: Union[str, None] = typer.Option(
|
|
371
|
+
None, "--path", help="(req: download) Path to save the SDK"),
|
|
372
|
+
platform_type: str = typer.Option(
|
|
373
|
+
None, "--type",
|
|
374
|
+
help=(
|
|
375
|
+
"(req: --category client-sdk|server-sdk|protos --type ) "
|
|
376
|
+
"SDK Types: client-sdk(" + ", ".join(CLIENT_SDK_TYPES.keys()) +
|
|
377
|
+
") server-sdk(" + ", ".join(SERVER_SDK_TYPES.keys()) +
|
|
378
|
+
") protos(" + ", ".join(PROTOS_TYPES.keys()) + ")"
|
|
379
|
+
)
|
|
380
|
+
),
|
|
381
|
+
auth_type: str = typer.Option(
|
|
382
|
+
'user', "--auth-type",
|
|
383
|
+
help=(
|
|
384
|
+
"(optional: download) Only applicable for --category server-sdk --auth-type"
|
|
385
|
+
"Auth-Types: ()" + ", ".join(Snapend.AUTH_TYPES) + ")"
|
|
386
|
+
)
|
|
387
|
+
),
|
|
388
|
+
snaps: Union[str, None] = typer.Option(
|
|
389
|
+
None, "--snaps",
|
|
390
|
+
help=(
|
|
391
|
+
"(optional: download) Comma separated list of snap ids to customize the "
|
|
392
|
+
"SDKs, protos or admin settings. "
|
|
393
|
+
"snaps(" + ", ".join(SERVICE_IDS)
|
|
394
|
+
)
|
|
395
|
+
),
|
|
396
|
+
# update
|
|
397
|
+
byosnaps: str = typer.Option(
|
|
398
|
+
None, "--byosnaps",
|
|
399
|
+
help=(
|
|
400
|
+
"(optional: update) Comma separated list of BYOSnap ids and versions. "
|
|
401
|
+
"Eg: service-1:v1.0.0,service-2:v1.0.0"
|
|
402
|
+
)
|
|
403
|
+
),
|
|
404
|
+
byogs: str = typer.Option(
|
|
405
|
+
None, "--byogs",
|
|
406
|
+
help=(
|
|
407
|
+
"(optional: update) Comma separated list of BYOGs fleet name, ids and versions. "
|
|
408
|
+
"Eg: fleet-1:service-1:v1.0.0,fleet-2:service-2:v1.0.0"
|
|
409
|
+
)
|
|
410
|
+
),
|
|
411
|
+
blocking: bool = typer.Option(
|
|
412
|
+
False, "--blocking",
|
|
413
|
+
help=(
|
|
414
|
+
"(optional: update) Set to true if you want to wait for the update to complete "
|
|
415
|
+
"before returning."
|
|
416
|
+
)
|
|
417
|
+
),
|
|
418
|
+
# overrides
|
|
419
|
+
api_key: Union[str, None] = typer.Option(
|
|
420
|
+
None, "--api-key", help="API Key override.", callback=api_key_context_callback
|
|
421
|
+
),
|
|
422
|
+
profile: Union[str, None] = typer.Option(
|
|
423
|
+
None, "--profile", help="Profile to use.", callback=profile_context_callback
|
|
424
|
+
),
|
|
217
425
|
) -> None:
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
426
|
+
"""
|
|
427
|
+
Snapend commands
|
|
428
|
+
"""
|
|
429
|
+
validate_command_context(ctx)
|
|
430
|
+
snapend_obj: Snapend = Snapend(
|
|
431
|
+
subcommand, ctx.obj['base_url'], ctx.obj['api_key'],
|
|
432
|
+
snapend_id, category, platform_type, auth_type,
|
|
433
|
+
path, snaps, byosnaps, byogs, blocking
|
|
434
|
+
)
|
|
435
|
+
validate_input_response: ResponseType = snapend_obj.validate_input()
|
|
436
|
+
if validate_input_response['error']:
|
|
437
|
+
error(validate_input_response['msg'])
|
|
438
|
+
raise typer.Exit(SNAPCTL_ERROR)
|
|
439
|
+
command_method = subcommand.replace('-', '_')
|
|
440
|
+
method: Callable[..., bool] = getattr(snapend_obj, command_method)
|
|
441
|
+
if not method():
|
|
442
|
+
error(f"Snapend {subcommand} failed")
|
|
443
|
+
raise typer.Exit(SNAPCTL_ERROR)
|
|
444
|
+
success(f"Snapend {subcommand} complete")
|
snapctl/types/definitions.py
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This file contains the definitions of the types used in the snapctl package.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
|
|
1
6
|
class ResponseType():
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
7
|
+
"""
|
|
8
|
+
This class represents the response type of the Snapser API.
|
|
9
|
+
"""
|
|
10
|
+
error: bool
|
|
11
|
+
msg: str
|
|
12
|
+
data: list
|