Skip to content

Commit 4791b3c

Browse files
committed
new functions to add project identifiers to group (SOFTWARE-5058)
1 parent 476fbf2 commit 4791b3c

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

create_project.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,41 @@ def show_group_identifiers(gid):
248248

249249
# fixup functions
250250

251+
def add_project_identifier_to_group(gid, project_name):
252+
identifier_name = "Yes-%s" % project_name
253+
type_ = "ospoolproject"
254+
return add_identifier_to_group(gid, type_, identifier_name)
255+
256+
257+
def add_identifier_to_group(gid, type_, identifier_name):
258+
new_identifier_info = {
259+
"Version" : "1.0",
260+
"Type" : type_,
261+
"Identifier" : identifier_name,
262+
"Login" : False,
263+
"Person" : {"Type": "Group", "Id": str(gid)},
264+
"Status" : "Active"
265+
}
266+
data = {
267+
"RequestType" : "Identifiers",
268+
"Version" : "1.0",
269+
"Identifiers" : [new_identifier_info]
270+
}
271+
return call_api3(POST, "identifiers.json", data)
272+
273+
274+
def gname_to_gid(gname):
275+
groups = get_osg_co_groups() | get_datalist("CoGroups")
276+
matching = [ g for g in groups if g["Name"] == gname ]
277+
278+
if len(matching) > 1:
279+
raise RuntimeError("Multiple groups found with Name '%s'" % gname)
280+
elif not matching:
281+
raise RuntimeError("No group found with Name '%s'" % gname)
282+
283+
group = matching[0]
284+
return group["Id"]
285+
251286

252287
def delete_identifier(id_):
253288
return call_api2(DELETE, "identifiers/%d.json" % id_)

0 commit comments

Comments
 (0)