Skip to content

Commit

Permalink
🎨 formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
georgepstaylor committed Sep 20, 2024
1 parent 9e954c8 commit 6864402
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 52 deletions.
20 changes: 18 additions & 2 deletions cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,25 @@ def update_user_home_areas(
help="Remove role from users",
is_flag=True,
)
@click.option("-uf", "--user-filter", help="Filter to find users", required=False, default="(objectclass=*)")
@click.option(
"-uf",
"--user-filter",
help="Filter to find users",
required=False,
default="(objectclass=*)",
)
@click.option("--roles-to-filter", help="Roles to filter", required=False, default="*")
def update_user_roles(roles, user_ou, root_dn, add, remove, update_notes, user_note, user_filter, roles_to_filter):
def update_user_roles(
roles,
user_ou,
root_dn,
add,
remove,
update_notes,
user_note,
user_filter,
roles_to_filter,
):
cli.ldap_cmds.user.update_roles(
roles,
user_ou,
Expand Down
4 changes: 3 additions & 1 deletion cli/database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ def connection():
log.debug("Created database connection successfully")
return conn
except Exception as e:
log.exception(f"Failed to create database connection. An exception of type {type(e).__name__} occurred: {e}")
log.exception(
f"Failed to create database connection. An exception of type {type(e).__name__} occurred: {e}"
)
raise e
16 changes: 12 additions & 4 deletions cli/git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ def get_access_token(
headers=headers,
)
except Exception as e:
logging.exception(f"Failed to get access token. An exception of type {type(e).__name__} occurred: {e}")
logging.exception(
f"Failed to get access token. An exception of type {type(e).__name__} occurred: {e}"
)
raise e

# extract the token from the response
Expand Down Expand Up @@ -66,7 +68,9 @@ def get_repo(
multi_options=multi_options,
)
except Exception as e:
logging.exception(f"Failed to clone repo. An exception of type {type(e).__name__} occurred: {e}")
logging.exception(
f"Failed to clone repo. An exception of type {type(e).__name__} occurred: {e}"
)
raise e
# if there is a token, assume auth is required and use the token and auth_type
elif token:
Expand All @@ -79,7 +83,9 @@ def get_repo(
multi_options=multi_options,
)
except Exception as e:
logging.exception(f"Failed to clone repo. An exception of type {type(e).__name__} occurred: {e}")
logging.exception(
f"Failed to clone repo. An exception of type {type(e).__name__} occurred: {e}"
)
raise e
# if there is no token, assume auth is not required and clone without
else:
Expand All @@ -91,5 +97,7 @@ def get_repo(
multi_options=multi_options,
)
except Exception as e:
logging.exception(f"Failed to clone repo. An exception of type {type(e).__name__} occurred: {e}")
logging.exception(
f"Failed to clone repo. An exception of type {type(e).__name__} occurred: {e}"
)
raise e
77 changes: 59 additions & 18 deletions cli/ldap_cmds/rbac.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,12 @@ def context_ldif(

# connect to ldap
try:
connection = ldap.initialize(f"ldap://{env.vars.get('LDAP_HOST')}:{env.vars.get('LDAP_PORT')}")
connection.simple_bind_s(env.vars.get("LDAP_USER"), env.secrets.get("LDAP_BIND_PASSWORD"))
connection = ldap.initialize(
f"ldap://{env.vars.get('LDAP_HOST')}:{env.vars.get('LDAP_PORT')}"
)
connection.simple_bind_s(
env.vars.get("LDAP_USER"), env.secrets.get("LDAP_BIND_PASSWORD")
)
except Exception as e:
log.exception(f"Failed to connect to ldap")
raise e
Expand Down Expand Up @@ -171,8 +175,12 @@ def group_ldifs(
):
# connect to ldap
try:
connection = ldap.initialize(f"ldap://{env.vars.get('LDAP_HOST')}:{env.vars.get('LDAP_PORT')}")
connection.simple_bind_s(env.vars.get("LDAP_USER"), env.secrets.get("LDAP_BIND_PASSWORD"))
connection = ldap.initialize(
f"ldap://{env.vars.get('LDAP_HOST')}:{env.vars.get('LDAP_PORT')}"
)
connection.simple_bind_s(
env.vars.get("LDAP_USER"), env.secrets.get("LDAP_BIND_PASSWORD")
)
except Exception as e:
log.exception(f"Failed to connect to ldap")
raise e
Expand Down Expand Up @@ -209,7 +217,10 @@ def group_ldifs(
if attributes.get("description"):
log.info(f"Updating description for {dn}")
try:
connection.modify(dn, [(ldap.MOD_REPLACE, "description", attributes["description"])])
connection.modify(
dn,
[(ldap.MOD_REPLACE, "description", attributes["description"])],
)
except ldap.ALREADY_EXISTS as already_exists_e:
log.info(f"{dn} already exists")
log.debug(already_exists_e)
Expand All @@ -223,8 +234,12 @@ def policy_ldifs(
):
# connect to ldap
try:
connection = ldap.initialize(f"ldap://{env.vars.get('LDAP_HOST')}:{env.vars.get('LDAP_PORT')}")
connection.simple_bind_s(env.vars.get("LDAP_USER"), env.secrets.get("LDAP_BIND_PASSWORD"))
connection = ldap.initialize(
f"ldap://{env.vars.get('LDAP_HOST')}:{env.vars.get('LDAP_PORT')}"
)
connection.simple_bind_s(
env.vars.get("LDAP_USER"), env.secrets.get("LDAP_BIND_PASSWORD")
)
except Exception as e:
log.exception(f"Failed to connect to ldap")
raise e
Expand Down Expand Up @@ -260,7 +275,9 @@ def policy_ldifs(
for entry in tree:
try:
log.debug(entry[0])
connection.delete_ext_s(entry[0], serverctrls=[ldap.controls.simple.ManageDSAITControl()])
connection.delete_ext_s(
entry[0], serverctrls=[ldap.controls.simple.ManageDSAITControl()]
)
print(f"Deleted {entry[0]}")
except ldap.NO_SUCH_OBJECT as no_such_object_e:
log.debug(f"this is the entry {entry}")
Expand Down Expand Up @@ -309,8 +326,12 @@ def role_ldifs(
):
# connect to ldap
try:
connection = ldap.initialize(f"ldap://{env.vars.get('LDAP_HOST')}:{env.vars.get('LDAP_PORT')}")
connection.simple_bind_s(env.vars.get("LDAP_USER"), env.secrets.get("LDAP_BIND_PASSWORD"))
connection = ldap.initialize(
f"ldap://{env.vars.get('LDAP_HOST')}:{env.vars.get('LDAP_PORT')}"
)
connection.simple_bind_s(
env.vars.get("LDAP_USER"), env.secrets.get("LDAP_BIND_PASSWORD")
)
except Exception as e:
log.exception(f"Failed to connect to ldap")
raise e
Expand Down Expand Up @@ -347,7 +368,10 @@ def role_ldifs(
for entry in tree:
try:
log.debug(entry[0])
connection.delete_ext_s(entry[0], serverctrls=[ldap.controls.simple.ManageDSAITControl()])
connection.delete_ext_s(
entry[0],
serverctrls=[ldap.controls.simple.ManageDSAITControl()],
)
print(f"Deleted {entry[0]}")
except ldap.NO_SUCH_OBJECT as no_such_object_e:
log.info("No such object found, 32")
Expand Down Expand Up @@ -396,13 +420,21 @@ def schema_ldifs(
):
# connect to ldap
try:
connection = ldap.initialize(f"ldap://{env.vars.get('LDAP_HOST')}:{env.vars.get('LDAP_PORT')}")
connection.simple_bind_s(env.vars.get("LDAP_USER"), env.secrets.get("LDAP_BIND_PASSWORD"))
connection = ldap.initialize(
f"ldap://{env.vars.get('LDAP_HOST')}:{env.vars.get('LDAP_PORT')}"
)
connection.simple_bind_s(
env.vars.get("LDAP_USER"), env.secrets.get("LDAP_BIND_PASSWORD")
)
except Exception as e:
log.exception(f"Failed to connect to ldap")
raise e

schema_files = [file for file in rendered_files if "delius.ldif" or "pwm.ldif" in Path(file).name]
schema_files = [
file
for file in rendered_files
if "delius.ldif" or "pwm.ldif" in Path(file).name
]

# loop through the schema files
for file in schema_files:
Expand Down Expand Up @@ -432,8 +464,12 @@ def user_ldifs(
):
# connect to ldap
try:
connection = ldap.initialize(f"ldap://{env.vars.get('LDAP_HOST')}:{env.vars.get('LDAP_PORT')}")
connection.simple_bind_s(env.vars.get("LDAP_USER"), env.secrets.get("LDAP_BIND_PASSWORD"))
connection = ldap.initialize(
f"ldap://{env.vars.get('LDAP_HOST')}:{env.vars.get('LDAP_PORT')}"
)
connection.simple_bind_s(
env.vars.get("LDAP_USER"), env.secrets.get("LDAP_BIND_PASSWORD")
)
except Exception as e:
log.exception(f"Failed to connect to ldap")
raise e
Expand Down Expand Up @@ -464,7 +500,10 @@ def user_ldifs(
for entry in tree:
try:
log.debug(entry[0])
connection.delete_ext_s(entry[0], serverctrls=[ldap.controls.simple.ManageDSAITControl()])
connection.delete_ext_s(
entry[0],
serverctrls=[ldap.controls.simple.ManageDSAITControl()],
)
print(f"Deleted {entry[0]}")
except ldap.NO_SUCH_OBJECT as no_such_object_e:
log.info("No such object found, 32")
Expand Down Expand Up @@ -557,7 +596,9 @@ def main(
f"{clone_path}/**/*",
recursive=True,
)
if Path(file).is_file() and Path(file).name.endswith(".ldif") or Path(file).name.endswith(".j2")
if Path(file).is_file()
and Path(file).name.endswith(".ldif")
or Path(file).name.endswith(".j2")
]

prep_for_templating(files)
Expand Down
Loading

0 comments on commit 6864402

Please sign in to comment.