Skip to content

Commit 4d4d8b2

Browse files
Apply suggestions from code review
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 2edda0b commit 4d4d8b2

2 files changed

Lines changed: 33 additions & 16 deletions

File tree

comanage_utils.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
MAX_ATTEMPTS = 5
3232

3333
# HTTP return codes we shouldn't attempt to retry
34-
HTTP_NO_RETRY_CODES = {401, 404, 405, 500}
34+
HTTP_NO_RETRY_CODES = {401, 403, 404, 405, 500}
3535

3636
GET = "GET"
3737
PUT = "PUT"
@@ -206,8 +206,7 @@ def update_co_person_identifier(id_, type, identifier, person_id, endpoint, auth
206206
}
207207
]
208208
}
209-
return call_api3(PUT, "/api/v2/identifiers" % id_, id_data, endpoint, authstr, )
210-
#return call_api3(PUT, "identifiers/%s.json" % id_, id_data, endpoint, authstr)
209+
return call_api3(PUT, "identifiers/%s.json" % id_, id_data, endpoint, authstr)
211210

212211

213212
def delete_identifier(id_, endpoint, authstr):
@@ -271,7 +270,7 @@ def create_co_group(groupname, description, coId, endpoint, authstr, open=False,
271270
"RequestType" : "CoGroups",
272271
"Version" : "1.0"
273272
}
274-
return call_api3(POST, "co_groups/.json", data, endpoint, authstr)
273+
return call_api3(POST, "co_groups.json", data, endpoint, authstr)
275274

276275

277276
def rename_co_group(gid, group, newname, endpoint, authstr):

mass_person_create_modify.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,41 @@ def parse_options(args):
6363
if op == '-g': options.import_group_id = arg
6464
if op == '-o': options.import_cou_id = arg
6565

66+
missing = []
67+
if options.input_file is None:
68+
missing.append("-i <input_file>")
69+
if options.mapping_file is None:
70+
missing.append("-m <mapping_file>")
71+
if options.import_group_id is None:
72+
missing.append("-g <import_group_id>")
73+
if options.import_cou_id is None:
74+
missing.append("-o <import_cou_id>")
75+
if missing:
76+
usage("Missing required options: " + ", ".join(missing))
77+
6678
try:
6779
user, passwd = utils.getpw(options.user, passfd, passfile)
6880
options.authstr = utils.mkauthstr(user, passwd)
6981
except PermissionError:
7082
usage("PASS required")
7183

72-
7384
def read_data_dump():
74-
data_json = []
7585
with open(options.input_file, 'r', encoding='utf-8') as input_file:
7686
data_json = json.load(input_file)
77-
for entry in range(len(data_json)):
78-
for key_index in range(len(data_json[entry]["public_keys"])):
79-
key = data_json[entry]["public_keys"][key_index]
80-
key_sections = str(key).split()
81-
if len(key_sections) >= 2:
82-
data_json[entry]["public_keys"][key_index] = {"type" : key_sections[0], "pkey" : key_sections[1]}
83-
if len(key_sections) >= 3:
84-
data_json[entry]["public_keys"][key_index].update({"authenticator" : key_sections[2]})
87+
88+
for entry in data_json:
89+
parsed_keys = []
90+
for key in entry.get("public_keys", []):
91+
key_sections = str(key).split()
92+
if len(key_sections) < 2:
93+
print(f"Warning: ignoring invalid SSH public key for user {entry.get('username', '<unknown>')}: {key!r}")
94+
continue
95+
key_obj = {"type": key_sections[0], "pkey": key_sections[1]}
96+
if len(key_sections) >= 3:
97+
key_obj["authenticator"] = " ".join(key_sections[2:])
98+
parsed_keys.append(key_obj)
99+
entry["public_keys"] = parsed_keys
100+
85101
with open(options.mapping_file, 'r', encoding='utf-8') as mapping_file:
86102
mapping_json = json.load(mapping_file)
87103
return data_json, mapping_json
@@ -166,8 +182,10 @@ def fix_username(co_person_record, new_username):
166182

167183
def create_unix_cluster_group(co_person_record):
168184
identifiers_list = co_person_record["Identifier"]
169-
username = next((item["identifier"] for item in identifiers_list if item["type"] == "osguser"))
170-
uid = next((item["identifier"] for item in identifiers_list if item["type"] == "uid"))
185+
username = next((item["identifier"] for item in identifiers_list if item.get("type") == "osguser"), None)
186+
uid = next((item["identifier"] for item in identifiers_list if item.get("type") == "uid"), None)
187+
if username is None or uid is None:
188+
raise ValueError(f"Missing required identifiers (osguser/uid) in CO Person record: {identifiers_list}")
171189
description = f"Unix Cluster Group for {username}"
172190
result = utils.create_co_group(username, description, options.osg_co_id, options.endpoint, options.authstr)
173191
ucg = None

0 commit comments

Comments
 (0)