Skip to content

Commit 5e21703

Browse files
authored
Merge pull request #15 from nrkno/bug-fix
2 parents 1950d95 + c403aa4 commit 5e21703

File tree

1 file changed

+20
-32
lines changed

1 file changed

+20
-32
lines changed

setenv.py

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -208,30 +208,6 @@ def _azure_get_token(tenant_id: str, client_id: str, client_secret: str) -> str:
208208
payload = json.load(resp)
209209
return payload["access_token"]
210210

211-
def find_value_in_dict(d: dict, search_value: str) -> tuple[dict | None, str | None]:
212-
if isinstance(d, dict):
213-
for k, v in d.items():
214-
if isinstance(v, dict):
215-
result, matching_key = find_value_in_dict(v, search_value)
216-
if result:
217-
return result, matching_key
218-
elif isinstance(v, list):
219-
for item in v:
220-
result, matching_key = find_value_in_dict(item, search_value)
221-
if result:
222-
return result, matching_key
223-
elif isinstance(v, bool):
224-
continue
225-
elif isinstance(v, (int, float)):
226-
if str(search_value) == str(v):
227-
return d, k
228-
elif isinstance(v, str):
229-
if search_value.lower() == v.lower():
230-
return d, k
231-
else:
232-
continue
233-
return None, None
234-
235211
def azure_check_resource_group(tenant_id: str, subscription_id: str, resource_group: str, token: str) -> bool:
236212
url = (
237213
f"https://management.azure.com/subscriptions/{subscription_id}"
@@ -241,21 +217,33 @@ def azure_check_resource_group(tenant_id: str, subscription_id: str, resource_gr
241217
try:
242218
with urllib.request.urlopen(req, timeout=10) as resp:
243219
payload = json.load(resp)
220+
221+
# status(f"Azure resource group access check response: {json.dumps(payload)}", args.debug, True)
222+
223+
if "value" in payload:
224+
if isinstance(payload["value"], list):
225+
for i, result in enumerate(payload["value"]):
226+
status(f"Checking resource group in id: {payload['value'][i]['id']}", args.debug, True)
227+
if resource_group.lower() in payload["value"][i]["id"].lower():
228+
status(f"Azure resource group '{resource_group}' found.", args.debug, True)
229+
return True
230+
else:
231+
status(f"Azure resource group '{resource_group}' not found in id: {payload['value'][i]['id']}", args.debug, True)
232+
return False
233+
else:
234+
status(f"Azure resource group '{resource_group}' not found.", args.debug, True)
235+
return False
236+
else:
237+
status(f"no values in response", args.debug, True)
238+
return False
244239

245-
result, matching_key = find_value_in_dict(payload, resource_group)
246-
status(f"Azure resource group access check response contains key: {matching_key} with value {result[matching_key] if result and matching_key else 'None'}", args.debug, True)
247240
except urllib.error.URLError as exc:
248241
status(f"Azure resource group access check URL error: {exc.reason}", args.debug, True)
249242
if isinstance(exc.reason, TimeoutError):
250243
status("Azure resource group access check timed out", True)
251244
return False
252245

253-
if not result:
254-
status(f"Azure resource group '{resource_group}' not found.", args.debug, True)
255-
return False
256-
257-
return True
258-
246+
return False
259247

260248
env_vars = []
261249
vault_token = ""

0 commit comments

Comments
 (0)