def delete_challenge(args): delete_args = input_args({ challenge_constants.CHALLENGE_ID: { method_constants.INPUT: 'Enter the Challenge ID to delete', method_constants.TYPE: str, }, }) payload = { transactino_constants.SCHEMA: { model_constants.MODELS: { model_constants.CHALLENGE: { method_constants.METHODS: { challenge_constants.DELETE: delete_args, }, }, }, }, } response = requests.post( settings.URL, headers=make_headers(), data=json.dumps(payload), ) check_for_announcements(response) if method_constants.ERRORS in response.text: print(json.dumps(json.loads(response.text), indent=2)) else: print('Done.')
def create(args): print( 'INFO: Run this method leaving arguments blank to generate a Challenge for this method' ) create_args = input_args({ subscription_constants.ACTIVATION_DATE: { method_constants.INPUT: 'Enter the activation date', method_constants.TYPE: str, }, subscription_constants.DURATION_IN_DAYS: { method_constants.INPUT: 'Enter the number of days the Subscription will be active', method_constants.TYPE: int, }, }) if subscription_constants.ACTIVATION_DATE in create_args: activation_date = create_args.get( subscription_constants.ACTIVATION_DATE) unaware_datetime = parser.parse(activation_date) aware_datetime = unaware_datetime.replace(tzinfo=tz.gettz()) iso_datetime = aware_datetime.isoformat() create_args.update({ subscription_constants.ACTIVATION_DATE: iso_datetime, }) payload = { transactino_constants.SCHEMA: { model_constants.MODELS: { model_constants.SUBSCRIPTION: { method_constants.METHODS: { subscription_constants.CREATE: create_args, }, }, }, }, } response = requests.post( settings.URL, headers=make_headers(), data=json.dumps(payload), ) check_for_announcements(response) response_json = json.loads(response.text) create_json = get_path(response_json, [ transactino_constants.SCHEMA, model_constants.MODELS, model_constants.SUBSCRIPTION, method_constants.METHODS, subscription_constants.CREATE, ]) print(json.dumps(create_json, indent=2))
def create(args): print( 'INFO: Run this method leaving arguments blank to generate a Challenge for this method' ) create_args = input_args({ fee_report_constants.BLOCKS_TO_INCLUDE: { method_constants.INPUT: 'Enter the number of blocks to include in the FeeReport', method_constants.TYPE: int, }, }) if create_args: create_args.update({ fee_report_constants.IS_ACTIVE: True, }) payload = { transactino_constants.SCHEMA: { model_constants.MODELS: { model_constants.FEE_REPORT: { method_constants.METHODS: { method_constants.CREATE: create_args, }, }, }, }, } response = requests.post( settings.URL, headers=make_headers(), data=json.dumps(payload), ) check_for_announcements(response) response_json = json.loads(response.text) create_json = get_path(response_json, [ transactino_constants.SCHEMA, model_constants.MODELS, model_constants.FEE_REPORT, method_constants.METHODS, method_constants.CREATE, ]) print(json.dumps(create_json, indent=2))
def get(args): get_args = input_args({ transaction_report_constants.TRANSACTION_REPORT_ID: { method_constants.INPUT: 'Enter the TransactionReport ID or leave blank for all', method_constants.TYPE: str, }, transaction_report_constants.IS_ACTIVE: { method_constants.INPUT: 'Enter the active status of the TransactionReport', method_constants.TYPE: bool, }, }) payload = { transactino_constants.SCHEMA: { model_constants.MODELS: { model_constants.TRANSACTION_REPORT: { method_constants.METHODS: { transaction_report_constants.GET: get_args, }, }, }, }, } response = requests.post( settings.URL, headers=make_headers(), data=json.dumps(payload), ) check_for_announcements(response) response_json = json.loads(response.text) instances_json = get_path(response_json, [ transactino_constants.SCHEMA, model_constants.MODELS, model_constants.TRANSACTION_REPORT, model_constants.INSTANCES, ]) if not instances_json: print(json.dumps(response_json, indent=2)) return print(json.dumps(instances_json, indent=2))
def activate(args): activate_args = input_args({ fee_report_constants.FEE_REPORT_ID: { method_constants.INPUT: 'Enter the FeeReport ID to activate', method_constants.TYPE: str, }, fee_report_constants.IS_ACTIVE: { method_constants.INPUT: 'Indicate whether the FeeReport should be active', method_constants.TYPE: bool, }, }) payload = { transactino_constants.SCHEMA: { model_constants.MODELS: { model_constants.FEE_REPORT: { method_constants.METHODS: { fee_report_constants.ACTIVATE: activate_args, }, }, }, }, } response = requests.post( settings.URL, headers=make_headers(), data=json.dumps(payload), ) check_for_announcements(response) response_json = json.loads(response.text) activate_json = get_path(response_json, [ transactino_constants.SCHEMA, model_constants.MODELS, model_constants.FEE_REPORT, method_constants.METHODS, fee_report_constants.ACTIVATE, ]) print(json.dumps(activate_json, indent=2))
def get(args): get_args = input_args({ ip_constants.IP_ID: { method_constants.INPUT: 'Enter the IP address ID or leave blank for all', method_constants.TYPE: str, }, }) payload = { transactino_constants.SCHEMA: { model_constants.MODELS: { model_constants.IP: { method_constants.METHODS: { payment_constants.GET: get_args, }, }, }, }, } response = requests.post( settings.URL, headers=make_headers(), data=json.dumps(payload), ) check_for_announcements(response) response_json = json.loads(response.text) instances_json = get_path(response_json, [ transactino_constants.SCHEMA, model_constants.MODELS, model_constants.IP, model_constants.INSTANCES, ]) if not instances_json: print(json.dumps(response_json, indent=2)) return print(json.dumps(instances_json, indent=2))
def create(args): print('INFO: Run this method leaving arguments blank to generate a Challenge for this method') create_args = input_args({ ip_constants.VALUE: { method_constants.INPUT: 'Enter the value of the IP address', method_constants.TYPE: str, }, }) payload = { transactino_constants.SCHEMA: { model_constants.MODELS: { model_constants.IP: { method_constants.METHODS: { method_constants.CREATE: create_args, }, }, }, }, } response = requests.post( settings.URL, headers=make_headers(), data=json.dumps(payload), ) check_for_announcements(response) response_json = json.loads(response.text) instances_json = get_path(response_json, [ transactino_constants.SCHEMA, model_constants.MODELS, model_constants.IP, model_constants.INSTANCES, ]) if not instances_json: print(json.dumps(response_json, indent=2)) return print(json.dumps(instances_json, indent=2))
def get(args): get_args = input_args({ address_constants.ADDRESS_ID: { method_constants.INPUT: 'Enter an Address ID', method_constants.TYPE: str, }, }) payload = { transactino_constants.SCHEMA: { model_constants.MODELS: { model_constants.ADDRESS: { method_constants.METHODS: { address_constants.GET: get_args, }, }, }, }, } response = requests.post( settings.URL, headers=make_headers(), data=json.dumps(payload), ) check_for_announcements(response) response_json = json.loads(response.text) instances_json = get_path(response_json, [ transactino_constants.SCHEMA, model_constants.MODELS, model_constants.ADDRESS, model_constants.INSTANCES, ]) if instances_json is None: print(json.dumps(response_json, indent=2)) return print(json.dumps(instances_json, indent=2))
def delete(args): delete_args = input_args({ fee_report_constants.FEE_REPORT_ID: { method_constants.INPUT: 'Enter the FeeReport ID to delete', method_constants.TYPE: str, }, }) payload = { transactino_constants.SCHEMA: { model_constants.MODELS: { model_constants.FEE_REPORT: { method_constants.METHODS: { method_constants.DELETE: delete_args, }, }, }, }, } response = requests.post( settings.URL, headers=make_headers(), data=json.dumps(payload), ) check_for_announcements(response) response_json = json.loads(response.text) delete_json = get_path(response_json, [ transactino_constants.SCHEMA, model_constants.MODELS, model_constants.FEE_REPORT, method_constants.METHODS, method_constants.DELETE, ]) print(json.dumps(delete_json, indent=2))
def activate(args): activate_args = input_args({ subscription_constants.SUBSCRIPTION_ID: { method_constants.INPUT: 'Enter the Subscription ID to activate', method_constants.TYPE: str, }, }) payload = { transactino_constants.SCHEMA: { model_constants.MODELS: { model_constants.SUBSCRIPTION: { method_constants.METHODS: { subscription_constants.ACTIVATE: activate_args, }, }, }, }, } response = requests.post( settings.URL, headers=make_headers(), data=json.dumps(payload), ) check_for_announcements(response) response_json = json.loads(response.text) activate_json = get_path(response_json, [ transactino_constants.SCHEMA, model_constants.MODELS, model_constants.SUBSCRIPTION, method_constants.METHODS, subscription_constants.ACTIVATE, ]) print(json.dumps(activate_json, indent=2))
def dismiss(args): dismiss_args = input_args(get_config) payload = { transactino_constants.SCHEMA: { model_constants.MODELS: { model_constants.TRANSACTION_MATCH: { method_constants.METHODS: { transaction_match_constants.DISMISS: dismiss_args, }, }, }, }, } response = requests.post( settings.URL, headers=make_headers(), data=json.dumps(payload), ) check_for_announcements(response) response_json = json.loads(response.text) dismiss_json = get_path(response_json, [ transactino_constants.SCHEMA, model_constants.MODELS, model_constants.TRANSACTION_MATCH, method_constants.METHODS, transaction_match_constants.DISMISS, ]) if dismiss_json is None: print(json.dumps(response_json, indent=2)) return print(json.dumps(dismiss_json, indent=2))
def respond(args): read = 'read' in args respond_args = input_args({ challenge_constants.CHALLENGE_ID: { method_constants.INPUT: 'Enter the Challenge ID to respond to', method_constants.TYPE: str, }, }) if not read: content = input(( 'Please enter the decrypted string that has been' ' re-encrypted to the public key of the System model.' ' It should be in ASCII armor format with any newlines' ' replaced with their escaped equivalents (\\n). This is' ' for the purposes of pasting the text into the command line: \n\n' ), ) if read: challenge_id = respond_args.get(challenge_constants.CHALLENGE_ID) challenge_path = join(settings.CHALLENGE_PATH, challenge_id) if not exists(challenge_path): print('Cannot find saved challenge directory...') return encrypted_content_path = join(challenge_path, 'encrypted.asc') if not exists(encrypted_content_path): print('Cannot find file {}/encrypted.asc'.format(challenge_id)) return with open(encrypted_content_path, 'r') as encrypted_content_file: content = encrypted_content_file.read() respond_args.update({ challenge_constants.CONTENT: content, }) payload = { transactino_constants.SCHEMA: { model_constants.MODELS: { model_constants.CHALLENGE: { method_constants.METHODS: { challenge_constants.RESPOND: respond_args, }, }, }, }, } response = requests.post( settings.URL, headers=make_headers(), data=json.dumps(payload), ) check_for_announcements(response) response_json = json.loads(response.text) respond_json = get_path(response_json, [ transactino_constants.SCHEMA, model_constants.MODELS, model_constants.CHALLENGE, method_constants.METHODS, challenge_constants.RESPOND, ]) print(json.dumps(respond_json, indent=2))
def create(args): print( 'INFO: Run this method leaving arguments blank to generate a Challenge for this method' ) create_args = input_args({ transaction_report_constants.TARGET_ADDRESS: { method_constants.INPUT: 'Enter the target address', method_constants.TYPE: str, }, transaction_report_constants.VALUE_EQUAL_TO: { method_constants.INPUT: 'Enter value to match equal (leave blank if not required)', method_constants.TYPE: int, }, transaction_report_constants.VALUE_LESS_THAN: { method_constants.INPUT: 'Enter maximum value (leave blank if not required)', method_constants.TYPE: int, }, transaction_report_constants.VALUE_GREATER_THAN: { method_constants.INPUT: 'Enter minimum value (leave blank if not required)', method_constants.TYPE: int, }, }) if create_args: create_args.update({ transaction_report_constants.IS_ACTIVE: True, }) payload = { transactino_constants.SCHEMA: { model_constants.MODELS: { model_constants.TRANSACTION_REPORT: { method_constants.METHODS: { transaction_report_constants.CREATE: create_args, }, }, }, }, } response = requests.post( settings.URL, headers=make_headers(), data=json.dumps(payload), ) check_for_announcements(response) response_json = json.loads(response.text) create_json = get_path(response_json, [ transactino_constants.SCHEMA, model_constants.MODELS, model_constants.TRANSACTION_REPORT, method_constants.METHODS, transaction_report_constants.CREATE, ]) print(json.dumps(create_json, indent=2))
def get(args): closed = 'closed' in args save = 'save' in args get_args = input_args({ challenge_constants.CHALLENGE_ID: { method_constants.INPUT: 'Enter the Challenge ID or leave blank for all', method_constants.TYPE: str, }, }) get_args.update({ challenge_constants.IS_OPEN: not closed, }) payload = { transactino_constants.SCHEMA: { model_constants.MODELS: { model_constants.CHALLENGE: { method_constants.METHODS: { challenge_constants.GET: get_args, }, }, }, }, } response = requests.post( settings.URL, headers=make_headers(), data=json.dumps(payload), ) check_for_announcements(response) response_json = json.loads(response.text) instances_json = get_path(response_json, [ transactino_constants.SCHEMA, model_constants.MODELS, model_constants.CHALLENGE, model_constants.INSTANCES, ]) if instances_json is None: print(json.dumps(response_json, indent=2)) return for challenge_id, attributes_json in instances_json.items(): print('Challenge ID: ', challenge_id, '\n') encrypted_content = get_path(attributes_json, [ model_constants.ATTRIBUTES, challenge_constants.ENCRYPTED_CONTENT, ]) print(encrypted_content + '\n') if save: if not exists(settings.CHALLENGE_PATH): os.mkdir(settings.CHALLENGE_PATH) challenge_path = join(settings.CHALLENGE_PATH, challenge_id) if not exists(challenge_path): os.mkdir(challenge_path) message_path = join(challenge_path, 'message.asc') if not exists(message_path): with open(message_path, 'w') as message_file: message_file.write(encrypted_content)