update_needed = False if args.role_name is not None: print('API - Getting the Roles list ...', end='') user_role_list = pc_api.user_role_list_read() print(' done.') print() user_role_id = None for user_role in user_role_list: if user_role['name'].lower() == args.role_name.lower(): user_role_id = user_role['id'] update_needed = True break if user_role_id is None: pc_utility.error_and_exit( 400, 'Role not found. Please verify the Role name.') user['roleId'] = user_role_id if args.firstname is not None: update_needed = True user['firstName'] = args.firstname if args.lastname is not None: update_needed = True user['lastName'] = args.lastname if args.access_keys_allowed is not None: update_needed = True user['accessKeysAllowed'] = args.access_keys_allowed if update_needed:
help= '(Optional) - Add a Label (the name of the Compliance Standard) to updated Policies (requires --policy).' ) parser.add_argument('import_file_name', type=str, help='Import file name for the Compliance Standard.') parser.add_argument('import_compliance_standard_name', type=str, help='Name of the Compliance Standard to create.') args = parser.parse_args() if args.policy: if args.map_custom_policies: if not os.path.isfile(CUSTOM_POLICY_ID_MAP_FILE): pc_utility.error_and_exit( 500, 'Custom policy map file does not exist. Please run pc-policy-custom-export.py and then pc-policy-custom-import.py to generate the file.' ) # --Initialize-- # pc_utility.prompt_for_verification_to_continue(args) settings = pc_utility.get_settings(args) pc_api.configure(settings) # --Main-- # # Compliance Import import_file_data = pc_utility.read_json_file(args.import_file_name) # Validation
# Get Policy print('API - Getting the Policy list ...', end='') policy_list = pc_api.policy_list_read() print(' done.') print() # TODO: Replace with library function. policy_id = None for policy in policy_list: if policy['name'].lower() == args.policy_name.lower(): policy_id = policy['policyId'] break if policy_id is None: pc_utility.error_and_exit(500, 'Policy was not found. Please verify the Policy name.') print() print('Policy from Policy list:') print(policy_id) print() print('API - Getting the Policy ...', end='') policy = pc_api.policy_read(policy_id) print(' done.') print() print('Policy:') print(json.dumps(policy)) print()
) parser.add_argument( '-sid', '--sectionId', type=str, help= '(Optional) - Only required to find the UUID of a Section. This will be the "SECTION" from the UI. ' 'Note: This section must exist in the specified Standard and the specified Compliance Requirement. ' 'If it is in another standard, or another Requirement, the lookup will fail.' ) args = parser.parse_args() if args.sectionId is not None: if args.requirementId is None: pc_utility.error_and_exit( 400, 'A Requirement is required if you want to get the UUID of a Section. ' 'Please enter the correct Requirement for the desired Section.') # --Initialize-- # settings = pc_utility.get_settings(args) pc_api.configure(settings) # --Main-- # # Compliance Get UUID print('API - Getting the Compliance Standards list ...', end='') compliance_standard_list = pc_api.compliance_standard_list_read() compliance_standard = pc_utility.search_list_object_lower( compliance_standard_list, 'name', args.compliance_standard_name)
# --Initialize-- # pc_utility.prompt_for_verification_to_continue(args) settings = pc_utility.get_settings(args) pc_api.configure(settings) # --Main-- # # Custom Policy Import import_file_data = pc_utility.read_json_file(args.import_file_name) # Validation if 'policy_list_original' not in import_file_data: pc_utility.error_and_exit(404, 'policy_list_original section not found. Please verify the import file and name.') if 'policy_object_original' not in import_file_data: pc_utility.error_and_exit(404, 'policy_object_original section not found. Please verify the import file and name.') if 'export_file_version' not in import_file_data: pc_utility.error_and_exit(404, 'export_file_version section not found. Please verify the import file and name.') if 'search_object_original' not in import_file_data: pc_utility.error_and_exit(404, 'search_object_original section not found. Please verify the import file and name.') # The following will check the export version for the correct level. # If you have an older version that you want to try to import, you can comment out this line, # but please be aware it will be untested on older versions of an export file. # At this moment, it *should* still work... if import_file_data['export_file_version'] != DEFAULT_POLICY_IMPORT_FILE_VERSION: pc_utility.error_and_exit(404, 'Import file appears to be an unexpected export version. Please verify the import file and name.') policy_object_original = import_file_data['policy_object_original']
# --Main-- # # Compliance Export export_file_data = {} export_file_data['export_file_version'] = DEFAULT_COMPLIANCE_EXPORT_FILE_VERSION export_file_data['compliance_section_list_original'] = {} export_file_data['policy_list_original'] = [] export_file_data['policy_object_original'] = {} export_file_data['search_object_original'] = {} print('API - Getting the current list of Compliance Standards ...', end='') compliance_standard_list_current = pc_api.compliance_standard_list_read() compliance_standard_original = pc_utility.search_list_object_lower(compliance_standard_list_current, 'name', args.compliance_standard_name) if compliance_standard_original is None: pc_utility.error_and_exit(400, 'Compliance Standard to export not found. Please verify the Compliance Standard name.') export_file_data['compliance_standard_original'] = compliance_standard_original print(' done.') print() print('API - Getting the Compliance Standard Requirements ...', end='') compliance_requirement_list_original = pc_api.compliance_standard_requirement_list_read(compliance_standard_original['id']) export_file_data['compliance_requirement_list_original'] = compliance_requirement_list_original print(' done.') print() print('API - Getting the Compliance Standard Sections ...', end='') for compliance_requirement_original in compliance_requirement_list_original: compliance_section_list_original = pc_api.compliance_standard_requirement_section_list_read(compliance_requirement_original['id']) export_file_data['compliance_section_list_original'][compliance_requirement_original['id']] = compliance_section_list_original print(' done.')
try: custom_policy_id_map = json.load(open(CUSTOM_POLICY_ID_MAP_FILE, 'r')) except (ValueError, FileNotFoundError): custom_policy_id_map = {} # --Main-- # # Alert Rule Import import_file_data = pc_utility.read_json_file(args.import_file_name) # Validation if 'alert_rule_list_original' not in import_file_data: pc_utility.error_and_exit( 404, 'alert_rule_list_original section not found. Please verify the import file and name.' ) alert_rule_list_original = import_file_data['alert_rule_list_original'] if alert_rule_list_original is None: pc_utility.error_and_exit( 400, 'Alert Rules not found in the import file. Please verify the import file and name.' ) if args.alert_rule: alert_rule_export = False for alert_rule_original in alert_rule_list_original: if alert_rule_original['name'] == args.alert_rule: alert_rule_export = True if not alert_rule_export: pc_utility.error_and_exit(