Skip to content

Commit 6aec4ec

Browse files
committed
user profile and data zone fixes
1 parent c52e64a commit 6aec4ec

File tree

3 files changed

+59
-23
lines changed

3 files changed

+59
-23
lines changed

aws2tf.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,22 @@ def main():
280280
#os.environ["AWS"] = "aws --region "+region+" "
281281

282282
# get the current env and set directory
283+
283284
if globals.debug: print("setting session region="+region)
285+
284286
try:
285-
my_session = boto3.setup_default_session(region_name=region,profile_name=globals.profile)
287+
if args.profile is None:
288+
my_session = boto3.setup_default_session(region_name=region)
289+
else:
290+
my_session = boto3.setup_default_session(region_name=region,profile_name=globals.profile)
291+
286292
except Exception as e:
287293
print("AWS Authorization Error: "+str(e))
294+
288295
if globals.debug: print("getting account")
289296
try:
290297
globals.acc = boto3.client('sts').get_caller_identity().get('Account')
298+
print("account="+globals.acc)
291299
except Exception as e:
292300
exc_type, exc_obj, exc_tb = sys.exc_info()
293301
exn=str(exc_type.__name__)
@@ -306,6 +314,7 @@ def main():
306314
print('Using region: '+region + ' account: ' + globals.acc+ " profile: "+globals.profile+"\n")
307315
#### restore form S3 if merging & serverless
308316

317+
####
309318

310319
globals.region = region
311320
globals.regionl = len(region)
@@ -334,7 +343,7 @@ def main():
334343
globals.cwd=os.getcwd()
335344
os.chdir(globals.path1)
336345
globals.tracking_message="Stage 1 of 10, Terraform Initialise ..."
337-
common.aws_tf(region)
346+
common.aws_tf(region,args)
338347

339348
# check we have it
340349
foundtf=False

code/common.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ def check_python_version():
791791
sys.exit(1)
792792

793793

794-
def aws_tf(region):
794+
def aws_tf(region,args):
795795
# os.chdir(globals.path1)
796796
#if not os.path.isfile("aws.tf"):
797797

@@ -808,7 +808,8 @@ def aws_tf(region):
808808
f3.write('}\n')
809809
f3.write('provider "aws" {\n')
810810
f3.write(' region = "' + region + '"\n')
811-
f3.write(' profile = "' + globals.profile + '"\n')
811+
if args.profile is not None:
812+
f3.write(' profile = "' + globals.profile + '"\n')
812813
if not globals.serverless: f3.write(' shared_credentials_files = ["~/.aws/credentials"]\n')
813814
f3.write('}\n')
814815

code/get_aws_resources/aws_datazone.py

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -139,28 +139,47 @@ def get_aws_datazone_domain(type, id, clfn, descfn, topkey, key, filterid):
139139
response = response + page[topkey]
140140
if response == []: print("Empty response for "+type+ " id="+str(id)+" returning"); return True
141141
for j in response:
142-
common.write_import(type,j[key],None)
142+
dzid=j[key]
143+
dv=j['domainVersion']
144+
if dv=="V1":
145+
#print(str(j))
146+
resp2=client.get_domain(identifier=j[key])
147+
sso=resp2['singleSignOn']['type']
148+
dst=resp2['status']
149+
#print("sso="+str(sso)+" dst="+str(dst)," dzid=",dzid)
150+
common.write_import(type,j[key],None)
151+
common.add_dependancy("aws_datazone_project", j[key])
152+
common.add_dependancy("aws_datazone_glossary", j[key])
153+
common.add_dependancy("aws_datazone_environment_profile", j[key])
154+
common.add_dependancy("aws_datazone_environment_blueprint_configuration", j[key])
155+
156+
if sso!="DISABLED":
157+
common.add_dependancy("aws_datazone_user_profile", j[key])
158+
else:
159+
print("skipping sso="+str(sso)+" dst="+str(dst)+" dzid="+dzid)
160+
return True
161+
162+
else:
163+
response = client.get_domain(identifier=id)
164+
if response == []: print("Empty response for "+type+ " id="+str(id)+" returning"); return True
165+
j=response
166+
dv=j['domainVersion']
167+
if dv=="V1":
168+
resp2=client.get_domain(identifier=j[key])
169+
sso=resp2['singleSignOn']['type']
170+
dst=resp2['status']
171+
#print("sso="+str(sso)+" dst="+str(dst)," dzid=",dzid)
172+
common.write_import(type,j[key],None)
143173
# provider crashes on import
144174
common.add_dependancy("aws_datazone_project", j[key])
145175
common.add_dependancy("aws_datazone_glossary", j[key])
146-
147176
common.add_dependancy("aws_datazone_environment_profile", j[key])
148177
common.add_dependancy("aws_datazone_environment_blueprint_configuration", j[key])
149-
common.add_dependancy("aws_datazone_user_profile", j[key])
150-
151-
152-
else:
153-
response = client.get_domain(identifier=id)
154-
if response == []: print("Empty response for "+type+ " id="+str(id)+" returning"); return True
155-
j=response
156-
common.write_import(type,j[key],None)
157-
# provider crashes on import
158-
common.add_dependancy("aws_datazone_project", j[key])
159-
common.add_dependancy("aws_datazone_glossary", j[key])
160-
161-
common.add_dependancy("aws_datazone_environment_profile", j[key])
162-
common.add_dependancy("aws_datazone_environment_blueprint_configuration", j[key])
163-
common.add_dependancy("aws_datazone_user_profile", j[key])
178+
if sso!="DISABLED":
179+
common.add_dependancy("aws_datazone_user_profile", j[key])
180+
else:
181+
print("skipping sso="+str(sso)+" dst="+str(dst)+" dzid="+dzid)
182+
return True
164183

165184
except Exception as e:
166185
common.handle_error(e,str(inspect.currentframe().f_code.co_name),clfn,descfn,topkey,id)
@@ -363,8 +382,15 @@ def get_aws_datazone_environment_profile(type, id, clfn, descfn, topkey, key, fi
363382
print("WARNING must pass domain id to get_aws_datazone_environment_profile")
364383
return True
365384
else:
366-
for page in paginator.paginate(domainIdentifier=id):
367-
response = response + page[topkey]
385+
try:
386+
for page in paginator.paginate(domainIdentifier=id):
387+
response = response + page[topkey]
388+
except Exception as e:
389+
print(str(e))
390+
print("WARNING: no environment profiles found for domain id "+id)
391+
globals.rproc[type+"."+id]=True
392+
return True
393+
368394
pkey=type+"."+id
369395
if response == []:
370396
if globals.debug: print("Empty response for "+type+ " id="+str(id)+" returning")

0 commit comments

Comments
 (0)