Last active
April 10, 2025 11:39
-
-
Save venkata-qa/ede2342e676a2514783fdb28be767d29 to your computer and use it in GitHub Desktop.
Revisions
-
venkata-qa revised this gist
Apr 10, 2025 . 1 changed file with 40 additions and 25 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,45 +10,60 @@ with open("apis.yaml") as f: yaml_data = yaml.safe_load(f) # Output files TXT_FILE = "missing_tokens_report.txt" MD_FILE = "missing_tokens_report.md" # Build Vault token pairs vault_pairs = set() for token in vault_data.get("tokens", []): svc = token.get("service") cons = token.get("consumer") if svc and cons: vault_pairs.add((svc, cons)) # Group missing tokens by API missing_by_api = defaultdict(list) for entry in yaml_data: api_number = entry.get("api_number") service = entry.get("service") consumers = entry.get("consumers", []) for consumer in consumers: if (service, consumer) not in vault_pairs: missing_by_api[api_number].append((service, consumer)) # Write results to both files with open(TXT_FILE, "w") as txt, open(MD_FILE, "w") as md: def write(line=""): txt.write(line + "\n") md.write(line + "\n") write("🔐 Vault Token Validation Report (Missing Only)") write("=================================================") write() if not missing_by_api: write("✅ All services and consumers have valid Vault tokens.") else: for api, missing_pairs in missing_by_api.items(): write(f"API: {api}") md.write(f"\n### API: `{api}`\n") grouped = defaultdict(list) for svc, con in missing_pairs: grouped[svc].append(con) for svc, cons_list in grouped.items(): write(f" Service: {svc}") md.write(f"- **Service**: `{svc}`\n") for con in cons_list: write(f" - Missing token for consumer: {con}") md.write(f" - ❌ Missing token for consumer: `{con}`\n") write() write(f"❌ Total APIs with missing tokens: {len(missing_by_api)}") write("\n✅ Validation complete.") print(f"✅ Reports saved as:\n- {TXT_FILE}\n- {MD_FILE}") -
venkata-qa revised this gist
Apr 10, 2025 . 1 changed file with 26 additions and 20 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,47 +2,53 @@ import yaml from collections import defaultdict # Load Vault JSON with open("vaultfile.json") as f: vault_data = json.load(f) # Load YAML config with open("apis.yaml") as f: yaml_data = yaml.safe_load(f) # Build set of (service, consumer) tokens from Vault vault_pairs = set() for token in vault_data.get("tokens", []): service = token.get("service") consumer = token.get("consumer") if service and consumer: vault_pairs.add((service, consumer)) # Track missing entries: api_number -> list of missing consumers missing_by_api = defaultdict(list) for entry in yaml_data: api_number = entry.get("api_number") service = entry.get("service") consumers = entry.get("consumers", []) for consumer in consumers: if (service, consumer) not in vault_pairs: missing_by_api[api_number].append((service, consumer)) # Output report print("\n🔐 Vault Token Validation Report (Missing Only)") print("=================================================\n") if not missing_by_api: print("✅ All services and consumers have valid Vault tokens.\n") else: for api, missing_pairs in missing_by_api.items(): print(f"API: {api}") grouped_by_service = defaultdict(list) for service, consumer in missing_pairs: grouped_by_service[service].append(consumer) for service, consumers in grouped_by_service.items(): print(f" Service: {service}") for consumer in consumers: print(f" - Missing token for consumer: {consumer}") print() print(f"❌ Total APIs with missing tokens: {len(missing_by_api)}") print("\n✅ Validation complete.\n") -
venkata-qa revised this gist
Apr 10, 2025 . 1 changed file with 19 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,24 @@ import json import yaml from collections import defaultdict # Load VAULTFILE (JSON) with open("vaultfile.json") as f: vault_data = json.load(f) # Load YAML with open("apis.yaml") as f: yaml_data = yaml.safe_load(f) # Build set of (service, consumer) pairs from vault vault_pairs = set() for token in vault_data.get("tokens", []): service = token.get("service") consumer = token.get("consumer") if service and consumer: vault_pairs.add((service, consumer)) # Track missing (service -> [consumers]) missing_by_service = defaultdict(list) -
venkata-qa created this gist
Apr 10, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ from collections import defaultdict # Track missing (service -> [consumers]) missing_by_service = defaultdict(list) # Validate each (service, consumer) pair for entry in yaml_data: service = entry.get("service") consumers = entry.get("consumers", []) for consumer in consumers: if (service, consumer) not in vault_pairs: missing_by_service[service].append(consumer) # Output results print("\n🔐 Vault Token Validation Report") print("====================================") if not missing_by_service: print("✅ All (service, consumer) combinations are present in Vault.") else: print(f"❌ Missing Token Pairs (grouped by service):\n") for service, consumers in missing_by_service.items(): print(f"Service: {service}") for consumer in consumers: print(f" - {consumer}") print() # Blank line between services print("✅ Validation complete.\n")