mirror of
https://github.com/trailofbits/algo.git
synced 2025-09-10 22:13:17 +02:00
* chore: Conservative dependency updates for security - Update Ansible from 9.1.0 to 9.2.0 (one minor version bump only) - Update Jinja2 to ~3.1.6 to fix CVE-2025-27516 (critical security fix) - Pin netaddr to 1.3.0 (current stable version) This is a minimal, conservative update focused on: 1. Critical security fix for Jinja2 2. Minor ansible update for bug fixes 3. Pinning netaddr to prevent surprises No changes to Ansible collections - keeping them unpinned for now. * fix: Address linter issues (ruff, yamllint, shellcheck) - Fixed ruff configuration by moving linter settings to [tool.ruff.lint] section - Fixed ruff code issues: - Moved imports to top of files (E402) - Removed unused variables or commented them out - Updated string formatting from % to .format() - Replaced dict() calls with literals - Fixed assert False usage in tests - Fixed yamllint issues: - Added missing newlines at end of files - Removed trailing spaces - Added document start markers (---) to YAML files - Fixed 'on:' truthy warnings in GitHub workflows - Fixed shellcheck issues: - Properly quoted variables in shell scripts - Fixed A && B || C pattern with proper if/then/else - Improved FreeBSD rc script quoting All linters now pass without errors related to our code changes. * fix: Additional yamllint fixes for GitHub workflows - Added document start markers (---) to test-effectiveness.yml - Fixed 'on:' truthy warning by quoting as 'on:' - Removed trailing spaces from main.yml - Added missing newline at end of test-effectiveness.yml
88 lines
2.6 KiB
Python
88 lines
2.6 KiB
Python
#!/usr/bin/python
|
|
|
|
|
|
|
|
import json
|
|
|
|
from ansible.module_utils.gcp_utils import GcpModule, GcpSession, navigate_hash
|
|
|
|
################################################################################
|
|
# Documentation
|
|
################################################################################
|
|
|
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
|
|
|
################################################################################
|
|
# Main
|
|
################################################################################
|
|
|
|
|
|
def main():
|
|
module = GcpModule(argument_spec={'filters': {'type': 'list', 'elements': 'str'}, 'scope': {'required': True, 'type': 'str'}})
|
|
|
|
if module._name == 'gcp_compute_image_facts':
|
|
module.deprecate("The 'gcp_compute_image_facts' module has been renamed to 'gcp_compute_regions_info'", version='2.13')
|
|
|
|
if not module.params['scopes']:
|
|
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
|
|
|
items = fetch_list(module, collection(module), query_options(module.params['filters']))
|
|
if items.get('items'):
|
|
items = items.get('items')
|
|
else:
|
|
items = []
|
|
return_value = {'resources': items}
|
|
module.exit_json(**return_value)
|
|
|
|
|
|
def collection(module):
|
|
return "https://www.googleapis.com/compute/v1/projects/{project}/{scope}".format(**module.params)
|
|
|
|
|
|
def fetch_list(module, link, query):
|
|
auth = GcpSession(module, 'compute')
|
|
response = auth.get(link, params={'filter': query})
|
|
return return_if_object(module, response)
|
|
|
|
|
|
def query_options(filters):
|
|
if not filters:
|
|
return ''
|
|
|
|
if len(filters) == 1:
|
|
return filters[0]
|
|
else:
|
|
queries = []
|
|
for f in filters:
|
|
# For multiple queries, all queries should have ()
|
|
if f[0] != '(' and f[-1] != ')':
|
|
queries.append("({})".format(''.join(f)))
|
|
else:
|
|
queries.append(f)
|
|
|
|
return ' '.join(queries)
|
|
|
|
|
|
def return_if_object(module, response):
|
|
# If not found, return nothing.
|
|
if response.status_code == 404:
|
|
return None
|
|
|
|
# If no content, return nothing.
|
|
if response.status_code == 204:
|
|
return None
|
|
|
|
try:
|
|
module.raise_for_status(response)
|
|
result = response.json()
|
|
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
|
|
module.fail_json(msg="Invalid JSON response with error: {}".format(inst))
|
|
|
|
if navigate_hash(result, ['error', 'errors']):
|
|
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
|
|
|
return result
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|