def show(self): while True: self._name = readline("Enter a name", default=self.default['name']) # - tags & difficulties self._tags = choose(self.default['tags'], "Tags Selection", min_count=2, multi=True, custom=True) tags_str = '\n - '.join(self._tags) print(f"Selected tags:\n - {tags_str}") self._difficulties = choose(self.default['difficulties'], "Difficulties Selection", min_count=2, multi=True, custom=True) difficulties_str = '\n - '.join(self._difficulties) print(f"Selected difficulties:\n - {difficulties_str}") # - flag self._flag_prefix = readline("Enter flag prefix", default=self.default['flag_prefix']) self._flag_suffix = readline("Enter flag prefix", default=self.default['flag_suffix']) # - domain self._domain = readline("Enter domain", default=self.default['domain']) # - docker self._docker_user = readline("Enter docker user", default=self.default['docker_user']) self._docker_registry = readline("Enter docker registry host", default=self.default['docker_registry']) # confirm, abort or retry answer = confirm(f"Are you ok with this configuration:\n{json.dumps(self.result, indent=2)}", abort=True) if answer == Answer.YES: return True elif answer == Answer.ABORT: app_log.warning("user canceled the operation.") return False
async def build(api, args): '''Builds at least one challenge ''' if not args.yes and confirm( 'do you really want to perform a build?') == Answer.NO: app_log.warning("operation cancelled by user.") return False err_sep = format_text(f'{HSEP[:35]} [STDERR] {HSEP[:35]}', 'red') out_sep = format_text(f'{HSEP[:35]} [STDOUT] {HSEP[:35]}', 'blue') exc_sep = format_text(f'{HSEP[:35]} [EXCEPT] {HSEP[:35]}', 'magenta') chall_sep = format_text(HSEP, 'blue', attrs=['bold']) success = True async for build_result in api.build(tags=args.tags, categories=args.categories, slug=args.slug, dev=args.dev, timeout=args.timeout): rcode = build_result['rcode'] chall_desc = format_text(f"{build_result['slug']}", 'blue') chall_status = api.rcode2str(rcode) print(chall_sep) print(f"{chall_desc} {chall_status}") if rcode < 0: success = False print(exc_sep) print(build_result['exception']) elif rcode > 0: print(out_sep) print(build_result['stdout'].decode().strip()) print(err_sep) print(build_result['stderr'].decode().strip()) return success
async def delete(api, args): '''Deletes a challenge ''' if not args.yes and confirm( f"do you really want to run delete?") == Answer.NO: app_log.warning("operation cancelled by user.") return False result = api.delete(args.slug) return result['deleted']
async def renew_flag(api, args): '''[summary] ''' if not args.yes and confirm( 'do you really want to renew flags?') == Answer.NO: app_log.warning("operation cancelled by user.") return False renewed = [ None for _ in api.renew_flag(tags=args.tags, categories=args.categories, slug=args.slug, size=args.size) ] return renewed