def find_the_description(patterns, *, num_of_questions=10, num_of_answers=4): question_text = 'What is the description of {} pattern?' result = 0 all_patterns = list(patterns.keys()) if num_of_questions > len(patterns): num_of_questions = len(patterns) for i in range(num_of_questions): question_pattern = choice(all_patterns) all_patterns.remove(question_pattern) current_patterns = _get_patterns_for_question(patterns, question_pattern, num_of_answers) print_question(i + 1, question_text.format(question_pattern), [ patterns[name]['description'].replace(name, '*' * 5) for name in current_patterns ]) answer = validate_input(len(current_patterns)) answer = patterns[current_patterns[answer - 1]] result += check_answer(answer['description'], patterns[question_pattern]['description']) print_result(result, num_of_questions)
def generate_user_totp(ctx, directory_id, user_identifier): """DIRECTORY_ID USER_IDENTIFIER""" client = get_directory_client(directory_id, ctx.obj['factory']) response = client.generate_user_totp(user_identifier) print_result("TOTP Generated for User", { "Algorithm": response.algorithm, "Digits": response.digits, "Period": response.period, "Secret": response.secret }, color=SUCCESS_COLOR) provisioning_uri = \ f"otpauth://totp/LaunchKey%20Test%20TOTP:{user_identifier}?" \ f"digits={response.digits}" \ f"&secret={response.secret}" \ f"&algorithm={response.algorithm}" \ f"&period={response.period}" \ f"&issuer=LaunchKey+Test+TOTP" qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_Q, box_size=10, border=4, ) qr.add_data(provisioning_uri) qr.make(fit=True) qr.print_ascii()
def run_scan(self, ip_address, timeout=None, lowest_port=0, highest_port=65535): try: validate_port_range(lowest_port, highest_port) validate_timeout(timeout) except Exception as e: if hasattr(e, "message"): self.console.print(e.message, style="bold red") else: self.console.print(e, style="bold red") return start = time() for port in track( range(lowest_port, highest_port + 1), f"[bold yellow]Scanning IP {ip_address}[/bold yellow]", ): try: self.scan_ports(ip_address, port, timeout) except socket.gaierror: self.console.print( f"[bold red]{ip_address} is an invalid address[/]") except KeyboardInterrupt: end = time() elapsed_time = end - start print('\n') print_result(ip_address, elapsed_time, self.open_ports) return end = time() elapsed_time = end - start print_result(ip_address, elapsed_time, self.open_ports)
def device_link(ctx, directory_id, user_identifier, ttl): """DIRECTORY_ID USER_IDENTIFIER""" client = get_directory_client(directory_id, ctx.obj['factory']) kwargs = {} if ttl is not None: kwargs['ttl'] = ttl link_response = client.link_device(user_identifier, **kwargs) print_result("Device link request successful", { "QR Code URL": link_response.qrcode, "Linking code": link_response.code, "Device ID": link_response.device_id }, color=SUCCESS_COLOR)
def devices_list(ctx, directory_id, user_identifier): """DIRECTORY_ID USER_IDENTIFIER""" client = get_directory_client(directory_id, ctx.obj['factory']) devices = client.get_linked_devices(user_identifier) if devices: for device in devices: print_result( device.name if device.name else "Pending Device", { "ID": device.id, "Type": device.type if device.type else "N/A", "Status": device.status.status_code }) else: click.secho("No devices found for the given identifier.", fg=FAILURE_COLOR)
def test_dataplugin_fail_verify(testdir): testdir.makepyfile(PYTESTFILE) local_archive_files = {('txt', 'test-data-file'): 'test data content x'} create_test_archive(testdir, archive='.test-data.tar.gz', files=local_archive_files) testdir.makefile('ini', **{ 'pytest': [ '[pytest]', 'dataplugin-signature = 2479d9203e1f4a326fd2cb49c66ab0904ebbd54c\n' ] } ) result = testdir.runpytest_subprocess('--dataplugin-verify') print_result(result) assert result.errlines == [ 'dataplugin verify invoked, skipping collection.', 'Archive failed verification!' ] print_result(result)
def authorize(ctx, service_id, username, context, title, ttl, push_title, push_body, denial_reason_count): """SERVICE_ID USERNAME""" client = get_service_client(service_id, ctx.obj['factory']) try: denial_reasons = None if denial_reason_count: denial_reasons = [] for x in range(0, denial_reason_count): fraud = \ bool(random.randint(0, 1)) if x not in (0, 1) else bool(x) denial_reasons.append( DenialReason( denial_id=str(x), reason="{0}-{1}-{2}".format( "f" if fraud else "nf", x, ''.join( random.choice( string.ascii_uppercase + string.ascii_lowercase + string.digits + " "*10 ) for _ in range(random.randint(5, 70)) ) ), fraud=fraud ) ) auth = client.authorization_request( username, context=context, title=title, ttl=ttl, push_title=push_title, push_body=push_body, denial_reasons=denial_reasons ) print_result( "Authorization request successful", { "Auth Request": auth.auth_request, "Push Package": auth.push_package }, color=SUCCESS_COLOR ) except AuthorizationInProgress as pre_existing_auth: print_result( pre_existing_auth.message, { "Auth Request": pre_existing_auth.authorization_request_id, "Expires": pre_existing_auth.expires, "Same Service": pre_existing_auth.from_same_service }, color=FAILURE_COLOR ) return click.echo("Checking for response from user.") try: auth_response = wait_for_response( client.get_authorization_response, [auth.auth_request] ) if auth_response.authorized: message = "Authorization request approved by user." color = SUCCESS_COLOR else: message = "Authorization request rejected by user." color = FAILURE_COLOR print_result( message, { "Resp Type": auth_response.type.value if auth_response.type else None, "Resp Reason": auth_response.reason.value if auth_response.reason else None, "Denial Reason": auth_response.denial_reason, "Is Fraud": auth_response.fraud, "Auth Request": auth_response.authorization_request_id, "Device ID": auth_response.device_id, "Svc User Hash": auth_response.service_user_hash, "User Push ID": auth_response.user_push_id, "Org User Hash": auth_response.organization_user_hash, "Auth Methods": auth_response.auth_methods, "Auth Policy": auth_response.auth_policy }, color=color ) except RequestTimedOut: click.secho( "\nAuthorization request timed out.", fg=FAILURE_COLOR ) except AuthorizationRequestCanceled: click.secho( "\nAuthorization request canceled.", fg=FAILURE_COLOR )