def run(run_zap): cli = RaftCLI() run_zap_config = RaftJobConfig(file_path=run_zap, substitutions={'{defaults.deploymentName}' : cli.definitions.deployment}) zap_job = cli.new_job(run_zap_config) print(zap_job) cli.poll(zap_job['jobId'])
def run(replay, fuzz_job_id, replay_job_id=None): cli = RaftCLI() substitutions = { '{defaults.deploymentName}': cli.definitions.deployment, '{jobRunId}': fuzz_job_id } replay_job_config = RaftJobConfig(file_path=replay, substitutions=substitutions) print('Replay') isIdle = False for task in replay_job_config.config['tasks']: isIdle = isIdle or task['isIdling'] if isIdle and replay_job_id: cli.update_job(replay_job_id, replay_job_config) print(f'Idle Job: {replay_job_id}') else: # create new fuzz job configuration replay_job_id = cli.new_job(replay_job_config) if isIdle: print(f'New Idle Job: {replay_job_id}') else: print(f'New Job: {replay_job_id}') if not isIdle: # wait for job ID from fuzz_job to finish the run cli.poll(replay_job_id['jobId'])
def run(compile, fuzz, host): # instantiate RAFT CLI cli = RaftCLI() # will replace {sample.host} with the value of host variable # see sample.restler.compile.json and sample.restler.fuzz.json subs = {'{sample.host}': host} # Create compilation job configuration compile_job_config = RaftJobConfig(file_path=compile, substitutions=subs) # add webhook metadata that will be included in every triggered webhook by Compile job compile_job_config.add_metadata({"branch": "wizbangFeature"}) print('Compile') # submit a new job with the Compile config and get new job ID compile_job = cli.new_job(compile_job_config) # wait for a job with ID from compile_job to finish the run cli.poll(compile_job['jobId']) # use compile job as input for fuzz job subs['{compile.jobId}'] = compile_job['jobId'] # create a new job config with Fuzz configuration JSON fuzz_job_config = RaftJobConfig(file_path=fuzz, substitutions=subs) print('Fuzz') # add webhook metadata that will included in every triggered webhook by Fuzz job fuzz_job_config.add_metadata({"branch": "wizbangFeature"}) # create new fuzz job configuration fuzz_job = cli.new_job(fuzz_job_config) # wait for job ID from fuzz_job to finish the run cli.poll(fuzz_job['jobId'])
def run(compile, fuzz, sample_host): # instantiate RAFT CLI cli = RaftCLI() substitutions = { '{sample.host}' : sample_host } # Create compilation step job configuratin compile_job_config = RaftJobConfig(file_path = compile, substitutions=substitutions) # add webhook metadata that will be included in every triggered webhook by Compile job compile_job_config.add_metadata({"branch":"wizbangFeature"}) print('Compile') # create a new job with the Compile config and get new job ID # in compile_job compile_job = cli.new_job(compile_job_config) # wait for a job with ID from compile_job to finish the run cli.poll(compile_job['jobId']) substitutions['{compile.jobId}'] = compile_job['jobId'] # create a new job config with Fuzz configuration JSON fuzz_job_config = RaftJobConfig(file_path = fuzz, substitutions=substitutions) print('Fuzz') # add webhook metadata that will included in every triggered webhook by Fuzz job fuzz_job_config.add_metadata({"branch":"wizbangFeature"}) # create new fuzz job configuration fuzz_job = cli.new_job(fuzz_job_config) # wait for job ID from fuzz_job to finish the run cli.poll(fuzz_job['jobId'])
def run(run_config): cli = RaftCLI() substitutions = { '{defaults.deploymentName}': cli.definitions.deployment } run_job_config = RaftJobConfig(file_path=run_config, substitutions=substitutions) run_job = cli.new_job(run_job_config) # wait for a job with ID from compile_job to finish the run cli.poll(run_job['jobId'])
def run(compile, test): cli = RaftCLI() substitutions = {} compile_job_config = RaftJobConfig(file_path=compile, substitutions=substitutions) compile_task = compile_job_config.config['testtasks']['tasks'][0] #use first task as template and create 30 compile task compile_tasks = [] for t in range(30): new_task = copy.deepcopy(compile_task) new_task['outputFolder'] = compile_task['outputFolder'] + f"-{t}" new_task['toolConfiguration']['compileConfiguration'] = {} new_task['toolConfiguration']['compileConfiguration'][ 'mutationsSeed'] = random.randint(0, 1000) compile_tasks.append(new_task) compile_job_config.config['testtasks']['tasks'] = compile_tasks print('Compile') # create a new job with the Compile config and get new job ID # in compile_job compile_json = json.dumps(compile_job_config.config) compile_job = cli.new_job(compile_job_config) # wait for a job with ID from compile_job to finish the run cli.poll(compile_job['jobId']) substitutions['{compile.jobId}'] = compile_job['jobId'] print('Test') test_job_config = RaftJobConfig(file_path=test, substitutions=substitutions) task_test_fuzz_lean = test_job_config.config['testtasks']['tasks'][0] task_test = test_job_config.config['testtasks']['tasks'][1] test_tasks = [] for t in range(30): new_task_test = copy.deepcopy(task_test) new_task_test_fuzz_lean = copy.deepcopy(task_test_fuzz_lean) new_task_test['outputFolder'] = task_test['outputFolder'] + f"-{t}" new_task_test['toolConfiguration']['runConfiguration'][ 'inputFolderPath'] += '/' + compile_tasks[t]['outputFolder'] new_task_test_fuzz_lean[ 'outputFolder'] = task_test_fuzz_lean['outputFolder'] + f"-{t}" new_task_test_fuzz_lean['toolConfiguration']['runConfiguration'][ 'inputFolderPath'] += '/' + compile_tasks[t]['outputFolder'] test_tasks.append(new_task_test) test_tasks.append(new_task_test_fuzz_lean) test_job_config.config['testtasks']['tasks'] = test_tasks test_job = cli.new_job(test_job_config) cli.poll(test_job['jobId'])
def run(compile, test, fuzz): # instantiate RAFT CLI cli = RaftCLI() # Create compilation job configuration compile_job_config = RaftJobConfig(file_path=compile) print('Compile') # submit a new job with the Compile config and get new job ID compile_job = cli.new_job(compile_job_config) # wait for a job with ID from compile_job to finish the run cli.poll(compile_job['jobId']) # use compile job as input for fuzz job subs = {} subs['{compile.jobId}'] = compile_job['jobId'] test_job_config = RaftJobConfig(file_path=test, substitutions=subs) print('Test') # create new fuzz job configuration test_job = cli.new_job(test_job_config) # wait for job ID from fuzz_job to finish the run cli.poll(test_job['jobId']) # create a new job config with Fuzz configuration JSON fuzz_job_config = RaftJobConfig(file_path=fuzz, substitutions=subs) print('Fuzz') # create new fuzz job configuration fuzz_job = cli.new_job(fuzz_job_config) # wait for job ID from fuzz_job to finish the run cli.poll(fuzz_job['jobId'])
def run(compile, test, fuzz): # instantiate RAFT CLI cli = RaftCLI() substitutions = {'{defaults.deploymentName}': cli.definitions.deployment} compile_job_config = RaftJobConfig(file_path=compile, substitutions=substitutions) print('Compile') # create a new job with the Compile config and get new job ID # in compile_job compile_job = cli.new_job(compile_job_config) # wait for a job with ID from compile_job to finish the run cli.poll(compile_job['jobId']) substitutions['{compile.jobId}'] = compile_job['jobId'] print('Test') test_job_config = RaftJobConfig(file_path=test, substitutions=substitutions) test_job = cli.new_job(test_job_config) cli.poll(test_job['jobId']) print('Fuzz') fuzz_job_config = RaftJobConfig(file_path=fuzz, substitutions=substitutions) fuzz_job = cli.new_job(fuzz_job_config) cli.poll(fuzz_job['jobId'])
def run(compile, test, fuzz, replay): # instantiate RAFT CLI cli = RaftCLI() # Create compilation job configuration compile_job_config = RaftJobConfig(file_path=compile) print('Compile') # submit a new job with the Compile config and get new job ID compile_job = cli.new_job(compile_job_config) # wait for a job with ID from compile_job to finish the run cli.poll(compile_job['jobId']) subs = {} # use compile job as input for fuzz job subs['{compile.jobId}'] = compile_job['jobId'] test_job_config = RaftJobConfig(file_path=test, substitutions=subs) print('Test') # create new fuzz job configuration test_job = cli.new_job(test_job_config) # wait for job ID from fuzz_job to finish the run cli.poll(test_job['jobId']) subs['{outputFolder}'] = 'fuzz' # create a new job config with Fuzz configuration JSON fuzz_job_config = RaftJobConfig(file_path=fuzz, substitutions=subs) print('Fuzz') # create new fuzz job configuration fuzz_job = cli.new_job(fuzz_job_config) # wait for job ID from fuzz_job to finish the run cli.poll(fuzz_job['jobId']) status = cli.job_status(fuzz_job['jobId']) experiment = None for s in status: if (s['agentName'] != s['jobId']): if (int(s['details']['numberOfBugsFound']) > 0): experiment = s['details']['experiment'] else: print("Did not find any bugs") subs['{experiment}'] = experiment subs['{jobId}'] = fuzz_job['jobId'] replay_job_config = RaftJobConfig(file_path=replay, substitutions=subs) replay_job = cli.new_job(replay_job_config) cli.poll(replay_job['jobId'])
def run(args): def validate(defaults): s = defaults.get('subscription') d = defaults.get('deploymentName') r = defaults.get('region') return (s and d and r) defaults_path = args['defaults_context_path'] defaults_json = args['defaults_context_json'] if defaults_json: print(f"Loading defaults from command line: {defaults_json}") defaults = json.loads(defaults_json) if not validate(defaults): print(defaults_help) return # check if defaults.json is set in the context and it exists elif os.path.isfile(defaults_path): with open(defaults_path, 'r') as d: defaults = json.load(d) if not validate(defaults): print(defaults_help) return else: with open(defaults_path, 'w') as d: d.write(fresh_defaults) print(defaults_help) return defaults['secret'] = args.get('secret') if 'metricsOptIn' not in defaults: defaults['metricsOptIn'] = True if defaults.get('useAppInsights') is None: defaults['useAppInsights'] = True cli_action = args.get('logout') service_action = args.get('service-action') job_action = args.get('job-action') webhook_action = args.get('webhook-action') if cli_action == 'logout': raft_sdk.raft_common.delete_token_cache() elif service_action: service_cli = RaftServiceCLI(defaults, defaults_path, args.get('secret')) if service_action == 'restart': service_cli.restart() elif service_action == 'info': info = service_cli.service_info() print(info) elif service_action == 'deploy': skip_sp_deployment = args.get('skip_sp_deployment') service_cli.deploy( args['sku'], skip_sp_deployment and skip_sp_deployment is True) elif service_action == 'upload-tools': utils_file_share = f'{uuid.uuid4()}' service_cli.upload_utils(utils_file_share, args.get('custom_tools_path')) service_cli.restart() else: raise Exception(f'Unhandled service argument: {service_action}') elif job_action: cli = RaftCLI() if job_action == 'create': json_config_path = args.get('file') if json_config_path is None: ArgumentRequired('--file') substitutionDictionary = {} substitutionParameter = args.get('substitute') if substitutionParameter: substitutionDictionary = json.loads(substitutionParameter) job_config = RaftJobConfig(file_path=json_config_path, substitutions=substitutionDictionary) print(job_config.config) duration = args.get('duration') if duration: job_config.config['duration'] = duration metadata = args.get('metadata') if metadata: job_config.config['metadata'] = json.loads(metadata) newJob = cli.new_job(job_config, args.get('region')) poll_interval = args.get('poll') if poll_interval: print(newJob) cli.poll(newJob['jobId'], poll_interval) else: print(newJob) elif job_action == 'status': job_id = args.get('job_id') if job_id is None: ArgumentRequired('--job-id') job_status = cli.job_status(job_id) poll_interval = args.get('poll') cli.print_status(job_status) if poll_interval: cli.poll(job_id, poll_interval) elif job_action == 'list': jobs_list = cli.list_jobs(args['look_back_hours']) sorted = {} for job in jobs_list: if sorted.get(job['jobId']): sorted[job['jobId']].append(job) else: sorted[job['jobId']] = [job] for s in sorted: cli.print_status(sorted[s]) print() print(f"Total number of jobs: {len(sorted)}") elif job_action == 'update': json_config_path = args.get('file') if json_config_path is None: ArgumentRequired('--file') substitutionDictionary = {} substitutionParameter = args.get('substitute') if substitutionParameter: substitutionDictionary = json.loads(substitutionParameter) job_update = cli.update_job( args.get('job_id'), RaftJobConfig(file_path=json_config_path, substitutions=substitutionDictionary)) print(job_update) elif job_action == 'results': job_id = args.get('job_id') if job_id is None: ArgumentRequired('--job-id') url = cli.result_url(job_id) print(url) elif job_action == 'delete': job_id = args.get('job_id') if job_id is None: ArgumentRequired('--job-id') job_delete = cli.delete_job(job_id) print(job_delete) elif webhook_action: cli = RaftCLI() if webhook_action == 'events': webhook_events = cli.list_available_webhooks_events() print(webhook_events) elif webhook_action == 'create': name_parameter = args.get('name') if name_parameter is None: ArgumentRequired('--name') event_parameter = args.get('event') if event_parameter is None: ArgumentRequired('--event') uri_parameter = args.get('url') if uri_parameter is None: ArgumentRequired('--url') webhook_create_or_update = cli.set_webhooks_subscription( name_parameter, event_parameter, uri_parameter) print(webhook_create_or_update) elif webhook_action == 'test': name_parameter = args.get('name') if name_parameter is None: ArgumentRequired('--name') event_parameter = args.get('event') if event_parameter is None: ArgumentRequired('--event') webhook_test = cli.test_webhook(name_parameter, event_parameter) print(webhook_test) elif webhook_action == 'delete': name_parameter = args.get('name') if name_parameter is None: ArgumentRequired('--name') event_parameter = args.get('event') if event_parameter is None: ArgumentRequired('--event') webhook_delete = cli.delete_webhook(name_parameter, event_parameter) print(webhook_delete) elif webhook_action == 'list': name_parameter = args.get('name') if name_parameter is None: ArgumentRequired('--name') # the event name is not required. # If not supplied all events will be listed. event_parameter = args.get('event') webhooks_list = cli.list_webhooks(name_parameter, event_parameter) print(webhooks_list) else: raise Exception('Expected arguments could not be found in args')