Skip to content

Commit ee1014e

Browse files
last fixes for project group setup script pr
1 parent 30227b1 commit ee1014e

File tree

5 files changed

+58
-32
lines changed

5 files changed

+58
-32
lines changed

comanage_scripts_utils.py renamed to comanage_utils.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,24 @@
88
import urllib.request
99
from ldap3 import Server, Connection, ALL, ALL_ATTRIBUTES, SAFE_SYNC
1010

11+
#PRODUCTION VALUES
12+
13+
PRODUCTION_ENDPOINT = "https://registry.cilogon.org/registry/"
14+
PRODUCTION_LDAP_SERVER = "ldaps://ldap.cilogon.org"
15+
PRODUCTION_LDAP_USER = "uid=readonly_user,ou=system,o=OSG,o=CO,dc=cilogon,dc=org"
16+
PRODUCTION_OSG_CO_ID = 7
17+
PRODUCTION_UNIX_CLUSTER_ID = 1
18+
PRODUCTION_LDAP_TARGET_ID = 6
19+
20+
#TEST VALUES
21+
22+
TEST_ENDPOINT = "https://registry-test.cilogon.org/registry/"
23+
TEST_LDAP_SERVER = "ldaps://ldap-test.cilogon.org"
24+
TEST_LDAP_USER ="uid=registry_user,ou=system,o=OSG,o=CO,dc=cilogon,dc=org"
25+
TEST_OSG_CO_ID = 8
26+
TEST_UNIX_CLUSTER_ID = 10
27+
TEST_LDAP_TARGET_ID = 9
28+
1129

1230
MIN_TIMEOUT = 5
1331
MAX_TIMEOUT = 625
@@ -153,7 +171,7 @@ def identifier_from_list(id_list, id_type):
153171
def identifier_matches(id_list, id_type, regex_string):
154172
pattern = re.compile(regex_string)
155173
value = identifier_from_list(id_list, id_type)
156-
return (value is not None) & (pattern.match(value) is not None)
174+
return (value is not None) and (pattern.match(value) is not None)
157175

158176

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

create_project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import getopt
88
import urllib.error
99
import urllib.request
10-
import comanage_scripts_utils as utils
10+
import comanage_utils as utils
1111

1212

1313
SCRIPT = os.path.basename(__file__)

group_fixup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import collections
88
import urllib.error
99
import urllib.request
10-
import comanage_scripts_utils as utils
10+
import comanage_utils as utils
1111

1212

1313
SCRIPT = os.path.basename(__file__)

osg-comanage-project-usermap.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
import collections
77
import urllib.error
88
import urllib.request
9-
import comanage_scripts_utils as utils
9+
import comanage_utils as utils
1010

1111

1212
SCRIPT = os.path.basename(__file__)
13-
ENDPOINT = "https://registry-test.cilogon.org/registry/"
14-
OSG_CO_ID = 8
13+
ENDPOINT = "https://registry.cilogon.org/registry/"
14+
OSG_CO_ID = 7
1515

1616

1717
_usage = f"""\
@@ -45,7 +45,7 @@ def usage(msg=None):
4545

4646
class Options:
4747
endpoint = ENDPOINT
48-
user = "co_8.project_script"
48+
user = "co_7.project_script"
4949
osg_co_id = OSG_CO_ID
5050
outfile = None
5151
authstr = None
@@ -170,6 +170,5 @@ def main(args):
170170
if __name__ == "__main__":
171171
try:
172172
main(sys.argv[1:])
173-
except urllib.error.HTTPError as e:
174-
print(e, file=sys.stderr)
175-
sys.exit(1)
173+
except Exception as e:
174+
sys.exit(e)

project_group_setup.py

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
import os
44
import sys
55
import getopt
6-
import comanage_scripts_utils as utils
6+
import comanage_utils as utils
77

88
SCRIPT = os.path.basename(__file__)
9-
ENDPOINT = "https://registry-test.cilogon.org/registry/"
10-
LDAP_SERVER = "ldaps://ldap-test.cilogon.org"
11-
LDAP_USER = "uid=registry_user,ou=system,o=OSG,o=CO,dc=cilogon,dc=org"
12-
OSG_CO_ID = 8
13-
UNIX_CLUSTER_ID = 10
14-
LDAP_TARGET_ID = 9
9+
ENDPOINT = "https://registry.cilogon.org/registry/"
10+
LDAP_SERVER = "ldaps://ldap.cilogon.org"
11+
LDAP_USER = "uid=readonly_user,ou=system,o=OSG,o=CO,dc=cilogon,dc=org"
12+
OSG_CO_ID = 7
13+
UNIX_CLUSTER_ID = 1
14+
LDAP_TARGET_ID = 6
1515

1616
OSPOOL_PROJECT_PREFIX_STR = "Yes-"
1717
PROJECT_GIDS_START = 200000
@@ -25,6 +25,8 @@
2525
-c OSG_CO_ID specify OSG CO ID (default = {OSG_CO_ID})
2626
-g CLUSTER_ID specify UNIX Cluster ID (default = {UNIX_CLUSTER_ID})
2727
-l LDAP_TARGET specify LDAP Provsion ID (defult = {LDAP_TARGET_ID})
28+
-s LDAP_SERVER specify LDAP server
29+
-y LDAP_USER specify LDAP server user
2830
-p LDAP authtok specify LDAP server authtok
2931
-d passfd specify open fd to read PASS
3032
-f passfile specify path to file to open and read PASS
@@ -43,18 +45,20 @@
4345

4446
def usage(msg=None):
4547
if msg:
46-
print(msg + "\n", file=sys.stderr)
48+
print(f"{msg}\n", file=sys.stderr)
4749

4850
print(_usage, file=sys.stderr)
4951
sys.exit()
5052

5153

5254
class Options:
5355
endpoint = ENDPOINT
54-
user = "co_8.william_test"
56+
user = "co_7.project_script"
5557
osg_co_id = OSG_CO_ID
5658
ucid = UNIX_CLUSTER_ID
5759
provision_target = LDAP_TARGET_ID
60+
ldap_user = LDAP_USER
61+
ldap_server = LDAP_SERVER
5862
outfile = None
5963
authstr = None
6064
ldap_authtok = None
@@ -66,7 +70,7 @@ class Options:
6670

6771
def parse_options(args):
6872
try:
69-
ops, args = getopt.getopt(args, "u:c:g:l:p:d:f:e:o:h")
73+
ops, args = getopt.getopt(args, "u:c:g:l:p:d:f:e:o:s:y:h")
7074
except getopt.GetoptError:
7175
usage()
7276

@@ -97,6 +101,10 @@ def parse_options(args):
97101
options.endpoint = arg
98102
if op == "-o":
99103
options.outfile = arg
104+
if op == "-s":
105+
options.ldap_server = arg
106+
if op == "-y":
107+
options.ldap_user = arg
100108

101109
try:
102110
user, passwd = utils.getpw(options.user, passfd, passfile)
@@ -106,7 +114,7 @@ def parse_options(args):
106114

107115

108116
def append_if_project(project_groups, group):
109-
# If this group has a ospoolproject id, and it starts with "Yes-", it's a project
117+
"""If this group has a ospoolproject id, and it starts with "Yes-", it's a project"""
110118
if utils.identifier_matches(group["ID_List"], "ospoolproject", (OSPOOL_PROJECT_PREFIX_STR + "*")):
111119
# Add a dict of the relavent data for this project to the project_groups list
112120
project_groups.append(group)
@@ -116,9 +124,9 @@ def update_highest_osggid(highest_osggid, group):
116124
# Get the value of the osggid identifier, if this group has one
117125
osggid = utils.identifier_from_list(group["ID_List"], "osggid")
118126
# If this group has a osggid, keep a hold of the highest one we've seen so far
119-
if osggid is not None:
127+
try:
120128
return max(highest_osggid, int(osggid))
121-
else:
129+
except TypeError:
122130
return highest_osggid
123131

124132

@@ -128,8 +136,8 @@ def get_comanage_data():
128136

129137
co_groups = utils.get_osg_co_groups(options.osg_co_id, options.endpoint, options.authstr)["CoGroups"]
130138
for group_data in co_groups:
131-
try:
132-
identifier_list = utils.get_co_group_identifiers(group_data["Id"], options.endpoint, options.authstr)
139+
identifier_list = utils.get_co_group_identifiers(group_data["Id"], options.endpoint, options.authstr)
140+
if identifier_list is not None:
133141
# Store this groups data in a dictionary to avoid repeated API calls
134142
group = {"Gid": group_data["Id"], "Name": group_data["Name"], "ID_List": identifier_list["Identifiers"]}
135143

@@ -138,8 +146,6 @@ def get_comanage_data():
138146

139147
# Update highest_osggid, if this group has an osggid and it's higher than the current highest osggid.
140148
highest_osggid = update_highest_osggid(highest_osggid, group)
141-
except TypeError:
142-
pass
143149
return (projects_list, highest_osggid)
144150

145151

@@ -169,12 +175,14 @@ def get_projects_needing_cluster_groups(project_groups):
169175
)
170176
return projects_needing_unix_groups
171177
except TypeError:
178+
print("ERROR: TypeError raised while trying to determine which projects need UNIX cluster groups\n"
179+
+f"clustered group ids: {clustered_group_ids} and project_gids: {project_gids}")
172180
return set()
173181

174182

175183
def get_projects_needing_provisioning(project_groups):
176184
# project groups provisioned in LDAP
177-
ldap_group_osggids = utils.get_ldap_groups(LDAP_SERVER, LDAP_USER, options.ldap_authtok)
185+
ldap_group_osggids = utils.get_ldap_groups(options.ldap_server, options.ldap_user, options.ldap_authtok)
178186
try:
179187
# All project osggids
180188
project_osggids = set(
@@ -190,6 +198,8 @@ def get_projects_needing_provisioning(project_groups):
190198
)
191199
return projects_to_provision
192200
except TypeError:
201+
print("TypeError raised while trying to determine which projects need provisioning\n"
202+
+f"ldap group osggids: {ldap_group_osggids} and project osggids: {project_osggids}")
193203
return set()
194204

195205

@@ -241,7 +251,7 @@ def provision_groups(project_list):
241251
def main(args):
242252
parse_options(args)
243253

244-
# Make all of the nessisary calls to COManage's API for the data we'll need to set up projects.
254+
# Make all of the necessary calls to COManage's API for the data we'll need to set up projects.
245255
# Projects is a List of dicts with keys Gid, Name, and Identifiers, the project's list of identifiers.
246256
# Highest_current_osggid is the highest OSGGID that's currently assigned to any CO Group.
247257
projects, highest_current_osggid = get_comanage_data()
@@ -265,6 +275,5 @@ def main(args):
265275
if __name__ == "__main__":
266276
try:
267277
main(sys.argv[1:])
268-
except OSError as e:
269-
print(e, file=sys.stderr)
270-
sys.exit(1)
278+
except Exception as e:
279+
sys.exit(e)

0 commit comments

Comments
 (0)