Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LDAP Automation CLI Bug User ref alias incorrect #80

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import click

import cli.ldap_cmds.rbac
import cli.ldap_cmds.user

from cli import (
logger,
)
Expand Down Expand Up @@ -118,7 +118,6 @@ def update_user_home_areas(
help="Remove role from users",
is_flag=True,
)

@click.option(
"-uf",
"--user-filter",
Expand All @@ -138,6 +137,17 @@ def update_user_roles(
user_filter,
roles_to_filter,
):
cli.ldap_cmds.user.update_roles(
roles,
user_ou,
root_dn,
add,
remove,
update_notes,
user_note=user_note,
user_filter=user_filter,
roles_to_filter=roles_to_filter,
)


@click.command()
Expand Down
41 changes: 18 additions & 23 deletions cli/ldap_cmds/user.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
import oracledb

import cli.ldap_cmds

from cli.logger import (
log,
from datetime import (
datetime,
)
from cli import (
env,
from itertools import (
product,
)

import ldap
import oracledb
from ldap.controls import SimplePagedResultsControl
import ldap.modlist as modlist

from cli.ldap_cmds import (
ldap_connect,
)
from ldap3 import (
MODIFY_REPLACE,
MODIFY_DELETE,
DEREF_ALWAYS,
MODIFY_REPLACE,
)

import cli.database
from itertools import (
product,
import cli.ldap_cmds
from cli import (
env,
)

from datetime import (
datetime,
from cli.ldap_cmds import (
ldap_connect,
)
from cli.logger import (
log,
)


Expand Down Expand Up @@ -121,7 +115,7 @@ def add_roles_to_user(username, roles, user_ou="ou=Users", root_dn="dc=moj,dc=co
f"cn={role},cn={username},{user_ou},{root_dn}",
attributes={
"objectClass": ["NDRoleAssociation", "alias"],
"aliasedObjectName": f"cn={role},cn={username},cn=ndRoleCatalogue,{user_ou},{root_dn}",
"aliasedObjectName": f"cn={role},cn=ndRoleCatalogue,{user_ou},{root_dn}",
},
)
except Exception as e:
Expand Down Expand Up @@ -154,14 +148,15 @@ def process_user_roles_list(
root_dn,
)
except Exception as e:
log.exception(f"Failed to add role to user")
log.exception("Failed to add role to user")
raise e


#########################################
# Update user roles
#########################################


def update_roles(
roles,
user_ou,
Expand Down Expand Up @@ -525,7 +520,7 @@ def deactivate_crc_users(user_ou, root_dn):
connection = cli.database.connection()
for user_dn in all_users:
try:
update_sql = f"UPDATE USER_ SET END_DATE=TRUNC(CURRENT_DATE) WHERE UPPER(DISTINGUISHED_NAME)=UPPER(:user_dn)"
update_sql = "UPDATE USER_ SET END_DATE=TRUNC(CURRENT_DATE) WHERE UPPER(DISTINGUISHED_NAME)=UPPER(:user_dn)"
update_cursor = connection.cursor()
update_cursor.execute(
update_sql,
Expand Down
Loading