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 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, VERSION, SNAPCTL_SUCCESS, SNAPCTL_ERROR
9
- from snapctl.config.endpoints import ENDPOINTS
10
- from snapctl.config.hashes import CLIENT_SDK_TYPES, SERVER_SDK_TYPES, PROTOS_TYPES
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
- def extract_api_key(profile: str | None = None) -> str:
20
- '''
21
- Extracts the API Key from the
22
- '''
23
- # Parse the config
24
- config = configparser.ConfigParser()
25
- if platform == 'win32':
26
- config.read(os.path.expandvars(CONFIG_FILE_WIN), encoding="utf-8-sig")
27
- else:
28
- config.read(os.path.expanduser(CONFIG_FILE_MAC))
29
- config_profile: str = DEFAULT_PROFILE
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
- config_profile = f'profile {env_api_key}'
37
- info(f"Using Profile environment variable {profile}")
38
- return config.get(config_profile, API_KEY, fallback=None, raw=True)
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
- def get_base_url(api_key: str) -> str:
41
- if api_key.startswith('dev_'):
42
- return ENDPOINTS['DEV']
43
- elif api_key.startswith('playtest_'):
44
- return ENDPOINTS['PLAYTEST']
45
- return ENDPOINTS['PROD']
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
- def set_context_callback(ctx: typer.Context, profile: str | None = None):
49
- '''
50
- Sets the context for the command
51
- This method will always set the context for the default profile
52
- Then if the command has a --profile override it will apply it
53
- '''
54
- # Ensure ctx object is instantiated
55
- ctx.ensure_object(dict)
56
-
57
- # If the user has not overriden the profile you can early exit
58
- # this is because when you come here from `def common` the context
59
- # setup happens considering the default profile
60
- # So only if the user has overriden the profile is when we want to run this
61
- # method again
62
- if 'profile' in ctx.obj and ctx.obj['profile'] == profile:
63
- return
64
-
65
- # Extract the api_key
66
- api_key = extract_api_key(profile)
67
- if api_key is None:
68
- if profile is not None and profile != '':
69
- conf_file = ''
70
- if platform == 'win32':
71
- conf_file = os.path.expandvars(CONFIG_FILE_WIN)
72
- else:
73
- conf_file = os.path.expanduser(CONFIG_FILE_MAC)
74
- error(f'Invalid profile. Please check your snap config file at {conf_file} and try again.')
75
- else:
76
- error('API Key not found. Please generate a new one from the Snapser dashboard.')
77
- raise typer.Exit(SNAPCTL_ERROR)
78
- # Set the context
79
- ctx.obj['version'] = VERSION
80
- ctx.obj['api_key'] = api_key
81
- ctx.obj['profile'] = profile if profile else DEFAULT_PROFILE
82
- ctx.obj['base_url'] = get_base_url(api_key)
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
- if value:
88
- success(f"Snapctl version: {VERSION}")
89
- raise typer.Exit(SNAPCTL_SUCCESS)
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
- None, "--version",
96
- help="Get the Snapctl version.",
97
- callback=version_callback
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
- # Verify if the user has a config
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
- profile: str = typer.Option(None, "--profile", help="Profile to use.", callback=set_context_callback),
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
- Validate your Snapctl setup
122
- """
123
- success("Setup is valid")
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
- ctx: typer.Context,
128
- # Required fields
129
- subcommand: str = typer.Argument(..., help="BYOSnap Subcommands: " + ", ".join(ByoSnap.SUBCOMMANDS) + "."),
130
- sid: str = typer.Argument(..., help="Snap Id. Should start with byosnap-"),
131
- # create
132
- name: str = typer.Option(None, "--name", help="(req: create) Name for your snap."),
133
- desc: str = typer.Option(None, "--desc", help="(req: create) Description for your snap"),
134
- platform: str = typer.Option(None, "--platform", help="(req: create) Platform for your snap - " + ", ".join(ByoSnap.PLATFORMS) + "."),
135
- language: str = typer.Option(None, "--language", help="(req: create) Language of your snap - " + ", ".join(ByoSnap.LANGUAGES) + "."),
136
- # publish-image and publish-version
137
- tag: str = typer.Option(None, "--tag", help="(req: publish-image and publish-version) Tag for your snap"),
138
- # publish-image
139
- path: Union[str, None] = typer.Option(None, "--path", help="(req: publish-image) Path to your snap code"),
140
- docker_file: str = typer.Option("Dockerfile", help="Dockerfile name to use"),
141
- # publish-version
142
- prefix: str = typer.Option('/v1', "--prefix", help="(req: publish-version) URL Prefix for your snap"),
143
- version: Union[str, None] = typer.Option(None, "--version", help="(req: publish-version) Snap version. Should start with v. Example vX.X.X"),
144
- http_port: Union[str, None] = typer.Option(None, "--http-port", help="(req: publish-version) Ingress HTTP port version"),
145
- # profile override
146
- profile: Union[str, None] = typer.Option(None, "--profile", help="Profile to use.", callback=set_context_callback),
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
- Bring your own snap commands
150
- """
151
- # token = get_composite_token(ctx.obj['base_url'], ctx.obj['api_key'], ctx.command.name, {'service_id': sid})
152
- byosnap: ByoSnap = ByoSnap(subcommand, ctx.obj['base_url'], ctx.obj['api_key'], sid, name, desc, platform, language, tag, path, docker_file, prefix, version, http_port)
153
- validate_input_response: ResponseType = byosnap.validate_input()
154
- if validate_input_response['error']:
155
- error(validate_input_response['msg'])
156
- raise typer.Exit(SNAPCTL_ERROR)
157
- command_method = subcommand.replace('-', '_')
158
- method: function = getattr(byosnap, command_method)
159
- if not method():
160
- error(f"BYOSnap {subcommand} failed")
161
- raise typer.Exit(SNAPCTL_ERROR)
162
- success(f"BYOSnap {subcommand} complete")
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
- ctx: typer.Context,
167
- # Required fields
168
- subcommand: str = typer.Argument(..., help="BYOGs Subcommands: " + ", ".join(ByoGs.SUBCOMMANDS) + "."),
169
- sid: str = typer.Argument(..., help="Game Server Id. Should start with byogs-"),
170
- # create
171
- name: str = typer.Option(None, "--name", help="(req: create) Name for your snap"),
172
- desc: str = typer.Option(None, "--desc", help="(req: create) Description for your snap"),
173
- platform: str = typer.Option(None, "--platform", help="(req: create) Platform for your snap - " + ", ".join(ByoGs.PLATFORMS) + "."),
174
- language: str = typer.Option(None, "--language", help="(req: create) Language of your snap - " + ", ".join(ByoGs.LANGUAGES) + "."),
175
- # publish-image and publish-version
176
- tag: str = typer.Option(None, "--tag", help="(req: publish-image and publish-version) Tag for your snap"),
177
- # publish-image
178
- path: Union[str, None] = typer.Option(None, "--path", help="(req: publish-image, upload-docs) Path to your snap code"),
179
- docker_file: str = typer.Option("Dockerfile", help="Dockerfile name to use"),
180
- # publish-version
181
- version: Union[str, None] = typer.Option(None, "--version", help="(req: publish-version) Snap version"),
182
- http_port: Union[str, None] = typer.Option(None, "--http-port", help="(req: publish-version) Ingress HTTP port version"),
183
- # profile override
184
- profile: Union[str, None] = typer.Option(None, "--profile", help="Profile to use.", callback=set_context_callback),
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
- Bring your own game server commands
188
- """
189
- byogs: ByoGs = ByoGs(subcommand, ctx.obj['base_url'], ctx.obj['api_key'], sid, name, desc, platform, language, tag, path, docker_file, version, http_port)
190
- validate_input_response: ResponseType = byogs.validate_input()
191
- if validate_input_response['error']:
192
- error(validate_input_response['msg'])
193
- raise typer.Exit(SNAPCTL_ERROR)
194
- command_method = subcommand.replace('-', '_')
195
- method: function = getattr(byogs, command_method)
196
- if not method():
197
- error(f"BYOGs {subcommand} failed")
198
- raise typer.Exit(SNAPCTL_ERROR)
199
- success(f"BYOGs {subcommand} complete")
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
- ctx: typer.Context,
204
- # Required fields
205
- subcommand: str = typer.Argument(..., help="Snapend Subcommands: " + ", ".join(Snapend.SUBCOMMANDS) + "."),
206
- snapend_id: str = typer.Argument(..., help="Snapend Id"),
207
- # download
208
- category: str = typer.Option(None, "--category", help="(req: download) Category of the Download: " + ", ".join(Snapend.DOWNLOAD_TYPES) + "."),
209
- download_type: str = typer.Option(None, "--type", help="(req: download) SDK Types: client-sdk(" + ", ".join(CLIENT_SDK_TYPES.keys()) + ") server-sdk(" + ", ".join(SERVER_SDK_TYPES.keys()) + ") protos(" + ", ".join(PROTOS_TYPES.keys()) + ")"),
210
- path: Union[str, None] = typer.Option(None, "--path", help="(req: download) Path to save the SDK"),
211
- snaps: Union[str, None] = typer.Option(None, "--snaps", help="(optional: download) Comma separated list of snap ids to include in the SDK"),
212
- # update
213
- byosnaps: str = typer.Option(None, "--byosnaps", help="(optional: update) Comma separated list of BYOSnap ids and versions. Eg: service-1:v1.0.0,service-2:v1.0.0"),
214
- byogs: str = typer.Option(None, "--byogs", help="(optional: update) Comma separated list of BYOGs fleet name, ids and versions. Eg: fleet-1:service-1:v1.0.0,fleet-2:service-2:v1.0.0"),
215
- blocking: bool = typer.Option(False, "--blocking", help="(optional: update) Set to true if you want to wait for the update to complete before returning."),
216
- profile: Union[str, None] = typer.Option(None, "--profile", help="Profile to use.", callback=set_context_callback),
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
- Snapend commands
220
- """
221
- snapend: Snapend = Snapend(subcommand, ctx.obj['base_url'], ctx.obj['api_key'], snapend_id, category, download_type, path, snaps, byosnaps, byogs, blocking)
222
- validate_input_response: ResponseType = snapend.validate_input()
223
- if validate_input_response['error']:
224
- error(validate_input_response['msg'])
225
- raise typer.Exit(SNAPCTL_ERROR)
226
- command_method = subcommand.replace('-', '_')
227
- method: function = getattr(snapend, command_method)
228
- if not method():
229
- error(f"Snapend {subcommand} failed")
230
- raise typer.Exit(SNAPCTL_ERROR)
231
- success(f"Snapend {subcommand} complete")
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")
@@ -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
- error: bool
3
- msg: str
4
- data: list
7
+ """
8
+ This class represents the response type of the Snapser API.
9
+ """
10
+ error: bool
11
+ msg: str
12
+ data: list