Skip to content
Snippets Groups Projects
Commit eea5c82f authored by Mohammad Torkashvand's avatar Mohammad Torkashvand
Browse files

add API key for calling GSO endpoint

parent 435a65a9
No related branches found
No related tags found
No related merge requests found
Pipeline #85526 passed
This commit is part of merge request !3. Comments created here will be created in the context of that merge request.
......@@ -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
......@@ -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"
......
artifactory 0 → 100644
all:
children:
routers:
children:
? ''
: hosts:
rt0.ams.nl.lab.office.geant.net:
rt0.pis.it.lab.office.geant.net:
rt01.pis.it.lab.office.geant.net:
rt1.ams.nl.lab.office.geant.net:
rt1.ath.gr.lab.office.geant.net:
rt1.bil.es.lab.office.geant.net:
rt1.dub.ie.lab.office.geant.net:
rt1.lon.uk.lab.office.geant.net:
p_routers:
hosts:
rt0.ams.nl.lab.office.geant.net:
rt0.pis.it.lab.office.geant.net:
rt01.pis.it.lab.office.geant.net:
pe_routers:
hosts:
rt1.ams.nl.lab.office.geant.net:
rt1.ath.gr.lab.office.geant.net:
rt1.bil.es.lab.office.geant.net:
rt1.dub.ie.lab.office.geant.net:
rt1.lon.uk.lab.office.geant.net:
......@@ -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 to comment