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)
## 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( dry_run_message, local_rule.name)) if not args.dry_run: result = authzero.create_rule(local_rule) logger.debug("+ New rule created with id {}".format(result.get('id'))) elif local_rule.is_the_same: logger.debug("[=] Rule {} is unchanged, will not update".format(local_rule.name)) else: logger.debug("[~] {}Updating rule {} ({}) on Auth0".format( dry_run_message, local_rule.name, local_rule.id)) if not args.dry_run: authzero.update_rule(local_rule.id, local_rule) if args.delete_all_rules_first_causing_outage: maintenance_rule.enabled = False logger.debug("[-] {}Disabling maintenance rule {} {}".format( dry_run_message, maintenance_rule.name, maintenance_rule.id)) if not args.dry_run: authzero.update_rule(maintenance_rule.id, maintenance_rule)