ok = True continue if not ok and rr is not None: remove_rules.append(rr) logger.debug( "Found {} rules that not longer exist locally and will be deleted remotely" .format(len(remove_rules))) # Update or create (or delete) rules as needed ## Delete first in case we need to get some order numbers free'd for r in remove_rules: logger.debug("[-] Removing rule {} ({}) from Auth0".format( r.name, r.id)) authzero.delete_rule(r.id) ## Update & Create (I believe this may be atomic swaps for updates) for r in local_rules: if r.is_new: logger.debug("[+] Creating new rule {} on Auth0".format(r.name)) ret = authzero.create_rule(r) logger.debug("+ New rule created with id {}".format(ret.get('id'))) elif r.is_the_same: logger.debug("[=] Rule {} is unchanged, will no update".format( r.name)) else: logger.debug("[~] Updating rule {} ({}) on Auth0".format( r.name, r.id)) authzero.update_rule(r.id, r) sys.exit(0)
remove_rules.append(rr) logger.debug( "Found {} rules that not longer exist locally and will be deleted remotely" .format(len(remove_rules))) # Update or create (or delete) rules as needed ## Delete first in case we need to get some order numbers free'd for r in remove_rules: logger.debug("[-] {}Removing rule {} ({}) from Auth0".format( dry_run_message, r.name, r.id)) not args.dry_run and authzero.delete_rule(r.id) ## Update & Create (I believe this may be atomic swaps for updates) for r in local_rules: if r.is_new: logger.debug("[+] {}Creating new rule {} on Auth0".format( dry_run_message, r.name)) if not args.dry_run: ret = authzero.create_rule(r) logger.debug("+ New rule created with id {}".format( ret.get('id'))) elif r.is_the_same: logger.debug("[=] Rule {} is unchanged, will not update".format( r.name)) else: logger.debug("[~] {}Updating rule {} ({}) on Auth0".format( dry_run_message, r.name, r.id)) not args.dry_run and authzero.update_rule(r.id, r) sys.exit(0)
if args.delete_all_rules_first_causing_outage: rules_to_remove = [x for x in remote_rules if x.get('name') != MAINTENANCE_RULE_NAME] logger.debug("Found {} rules that will be deleted remotely".format(len(rules_to_remove))) else: # Find dead rules (i.e. to remove/rules that only exist remotely) rules_to_remove = [x for x in remote_rules if x.get('id') not in [y.id for y in local_rules]] logger.debug("Found {} rules that not longer exist locally and will be deleted remotely".format(len(rules_to_remove))) maintenance_rule = next( x for x in local_rules if x.name == MAINTENANCE_RULE_NAME) if args.delete_all_rules_first_causing_outage: maintenance_rule.enabled = True logger.debug("[+] {}Enabling maintenance rule denying all logins globally {} {}".format( dry_run_message, maintenance_rule.name, maintenance_rule.id)) if not args.dry_run: authzero.update_rule(maintenance_rule.id, maintenance_rule) # Update or create (or delete) rules as needed ## Delete first in case we need to get some order numbers free'd for rule in rules_to_remove: logger.debug("[-] {}Removing rule {} ({}) from Auth0".format( dry_run_message, rule['name'], rule['id'])) if not args.dry_run: authzero.delete_rule(rule['id']) ## Update & Create (I believe this may be atomic swaps for updates) for local_rule in local_rules: if local_rule.is_new: if args.delete_all_rules_first_causing_outage and local_rule.name == MAINTENANCE_RULE_NAME: continue logger.debug("[+] {}Creating new rule {} on Auth0".format(