Skip to content
Snippets Groups Projects
Commit ca63c15c 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 #85517 failed
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 ...@@ -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 host_vars_dir=/path/to/base/hostvars/dir
export vars_file_name=wfo_vars.yaml export vars_file_name=wfo_vars.yaml
export hosts_file_dir=/path/to/base/hosts/dir 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 ansible_inventory_generator
\ No newline at end of file
...@@ -100,7 +100,7 @@ def safe_write(temp_dir: Path, old_vars_dir: Path, old_hosts_file: Path) -> Gene ...@@ -100,7 +100,7 @@ def safe_write(temp_dir: Path, old_vars_dir: Path, old_hosts_file: Path) -> Gene
def generate_inventory_from_api() -> None: def generate_inventory_from_api() -> None:
settings = load_settings() settings = load_settings()
"""Generate Ansible inventory from API.""" """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={"access_token": settings.gso_api_key})
response.raise_for_status() response.raise_for_status()
try: try:
router_subscriptions = response.json() router_subscriptions = response.json()
......
...@@ -6,6 +6,7 @@ class Settings(BaseSettings): ...@@ -6,6 +6,7 @@ class Settings(BaseSettings):
host_vars_dir: str host_vars_dir: str
vars_file_name: str vars_file_name: str
hosts_file_dir: str hosts_file_dir: str
gso_api_key: str
class Config: class Config:
env_file = "../.env" env_file = "../.env"
......
...@@ -2,3 +2,4 @@ api_url=http://127.0.0.1:8080/api/v1/subscriptions/routers ...@@ -2,3 +2,4 @@ api_url=http://127.0.0.1:8080/api/v1/subscriptions/routers
host_vars_dir=/path/to/base/hostvars/dir host_vars_dir=/path/to/base/hostvars/dir
vars_file_name=wfo_vars.yaml vars_file_name=wfo_vars.yaml
hosts_file_dir=/path/to/base/hosts/dir hosts_file_dir=/path/to/base/hosts/dir
gso_api_key=askjdhaskhdaksjhdkajshdkashd
...@@ -157,6 +157,7 @@ def setup_test(tmp_dir, mocked_subscription_api_data): ...@@ -157,6 +157,7 @@ def setup_test(tmp_dir, mocked_subscription_api_data):
host_vars_dir=str(tmp_dir), host_vars_dir=str(tmp_dir),
vars_file_name="wfo_vars.yaml", vars_file_name="wfo_vars.yaml",
hosts_file_dir=str(tmp_dir), hosts_file_dir=str(tmp_dir),
gso_api_key='random_gso_api_key'
) )
mock_get.return_value.json.return_value = mocked_subscription_api_data 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