| 299 | return super(KSMCommand, self).execute_args(params, args, **kwargs) |
| 300 | |
| 301 | def execute(self, params, **kwargs): |
| 302 | |
| 303 | ksm_command = kwargs.get('command') # type: List[str] |
| 304 | ksm_helpflag = kwargs.get('helpflag') |
| 305 | |
| 306 | if len(ksm_command) == 0 or ksm_helpflag: |
| 307 | print(available_ksm_commands) |
| 308 | return |
| 309 | |
| 310 | ksm_obj = ksm_command[0] |
| 311 | ksm_action = ksm_command[1] if len(ksm_command) > 1 else None |
| 312 | |
| 313 | if ksm_obj in ['help', 'h']: |
| 314 | print(available_ksm_commands) |
| 315 | return |
| 316 | |
| 317 | if ksm_obj == 'apps' or \ |
| 318 | (ksm_obj in ['app', 'apps'] and ksm_action == 'list'): |
| 319 | format_type = kwargs.get('format', 'table') |
| 320 | return KSMCommand.print_all_apps_records(params, format_type) |
| 321 | |
| 322 | if ksm_obj == 'clients' or (ksm_obj in ['client', 'clients'] and ksm_action == 'list'): |
| 323 | print(bcolors.WARNING + "Listing clients is not available" + bcolors.ENDC) |
| 324 | return |
| 325 | |
| 326 | if ksm_obj in ['app', 'apps'] and ksm_action == 'get': |
| 327 | |
| 328 | if len(ksm_command) != 3: |
| 329 | print(f"{bcolors.WARNING}Application name is required.\n " + |
| 330 | f"Example: {bcolors.OKGREEN}secrets-manager app get {bcolors.OKBLUE}MyApp{bcolors.ENDC}") |
| 331 | return |
| 332 | |
| 333 | ksm_app_uid_or_name = ksm_command[2] |
| 334 | |
| 335 | ksm_app = KSMCommand.get_app_record(params, ksm_app_uid_or_name) |
| 336 | |
| 337 | if not ksm_app: |
| 338 | format_type = kwargs.get('format', 'table') |
| 339 | if format_type == 'json': |
| 340 | return json.dumps({"error": f"Application '{ksm_app_uid_or_name}' not found."}) |
| 341 | else: |
| 342 | print((bcolors.WARNING + "Application '%s' not found." + bcolors.ENDC) % ksm_app_uid_or_name) |
| 343 | return |
| 344 | |
| 345 | format_type = kwargs.get('format', 'table') |
| 346 | result = KSMCommand.get_and_print_app_info(params, ksm_app.get('record_uid'), format_type) |
| 347 | if format_type == 'json' and result: |
| 348 | return result |
| 349 | return |
| 350 | |
| 351 | if ksm_obj in ['client'] and ksm_action == 'get': |
| 352 | print(bcolors.WARNING + "Viewing clients is not available" + bcolors.ENDC) |
| 353 | return |
| 354 | |
| 355 | if ksm_obj in ['app', 'apps'] and ksm_action in ['add', 'create']: |
| 356 | if len(ksm_command) < 3: |
| 357 | print( |
| 358 | f'''{bcolors.WARNING}Application name is missing.{bcolors.ENDC}\n''' |