Skip to content
Snippets Groups Projects
Commit d3b9edfb authored by Neda Moeini's avatar Neda Moeini
Browse files

Merge branch 'feature/NAT-425-add-gso-api-key' into 'develop'

add API key for calling GSO endpoint

See merge request !3
parents 435a65a9 11ee0478
No related branches found
No related tags found
1 merge request!3add API key for calling GSO endpoint
Pipeline #85530 passed
......@@ -21,5 +21,6 @@ export api_url=http://127.0.0.1:8080/api/v1/subscriptions/routers
export host_vars_dir=/path/to/base/hostvars/dir
export vars_file_name=wfo_vars.yaml
export hosts_file_dir=/path/to/base/hosts/dir
export gso_api_key=get_this_token_from_gso_admin_based_on_your_environment
ansible_inventory_generator
\ No newline at end of file
ansible_inventory_generator
......@@ -100,7 +100,9 @@ def safe_write(temp_dir: Path, old_vars_dir: Path, old_hosts_file: Path) -> Gene
def generate_inventory_from_api() -> None:
settings = load_settings()
"""Generate Ansible inventory from API."""
response = requests.get(settings.api_url, timeout=API_TIMEOUT_SEC)
response = requests.get(
settings.api_url, timeout=API_TIMEOUT_SEC, headers={"Authorization": f"Bearer {settings.gso_api_key}"}
)
response.raise_for_status()
try:
router_subscriptions = response.json()
......
......@@ -6,6 +6,7 @@ class Settings(BaseSettings):
host_vars_dir: str
vars_file_name: str
hosts_file_dir: str
gso_api_key: str
class Config:
env_file = "../.env"
......
......@@ -2,3 +2,4 @@ api_url=http://127.0.0.1:8080/api/v1/subscriptions/routers
host_vars_dir=/path/to/base/hostvars/dir
vars_file_name=wfo_vars.yaml
hosts_file_dir=/path/to/base/hosts/dir
gso_api_key=askjdhaskhdaksjhdkajshdkashd
......@@ -4,7 +4,7 @@ setup(
name="ansible_inventory_generator",
version="0.1",
author="GEANT",
author_email="swd@geant.org",
author_email="gap@geant.org",
description="Ansible inventory generator for WFO",
url="https://gitlab.software.geant.org/goat/gap/ansible_inventory_generator",
packages=find_packages(),
......
......@@ -157,6 +157,7 @@ def setup_test(tmp_dir, mocked_subscription_api_data):
host_vars_dir=str(tmp_dir),
vars_file_name="wfo_vars.yaml",
hosts_file_dir=str(tmp_dir),
gso_api_key="random_gso_api_key",
)
mock_get.return_value.json.return_value = mocked_subscription_api_data
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment