Skip to content

Use ANSIBLE_BASE_JWT_KEY to make Galaxy aware of Envoy #2102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions galaxy_ng/app/dynaconf_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import re
from typing import Any, Dict, List
from urllib.parse import urlparse, urlunparse
from django_auth_ldap.config import LDAPSearch
from dynaconf import Dynaconf, Validator
from galaxy_ng.app.dynamic_settings import DYNAMIC_SETTINGS_SCHEMA
Expand Down Expand Up @@ -41,6 +42,7 @@ def post(settings: Dynaconf) -> Dict[str, Any]:
data.update(configure_api_base_path(settings))
data.update(configure_legacy_roles(settings))
data.update(configure_dab_resource_registry(settings))
data.update(configure_resource_provider(settings))

# This should go last, and it needs to receive the data from the previous configuration
# functions because this function configures the rest framework auth classes based off
Expand Down Expand Up @@ -582,6 +584,28 @@ def configure_legacy_roles(settings: Dynaconf) -> Dict[str, Any]:
return data


def configure_resource_provider(settings: Dynaconf) -> Dict[str, Any]:
# The following variable is either a URL or a key file path.
ANSIBLE_BASE_JWT_KEY = settings.get("ANSIBLE_BASE_JWT_KEY")
if ANSIBLE_BASE_JWT_KEY:
data = {
"ANSIBLE_API_HOSTNAME": settings.get("ANSIBLE_API_HOSTNAME"),
"ANSIBLE_CONTENT_HOSTNAME": settings.get("ANSIBLE_CONTENT_HOSTNAME"),
}
gw_url = urlparse(ANSIBLE_BASE_JWT_KEY)
Copy link
Member

@rochacbruno rochacbruno Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So ANSIBLE_BASE_JWT_KEY is actually a URL string? or a key?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

David commented on the jira issue (here's the excerpt) ANSIBLE_BASE_JWT_KEY which can either be a URL or a key file. If ANSIBLE_BASE_JWT_KEY is a key the scheme and hostname will not be populated in the following check and nothing should change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I think it is good to add a comment so the future us will know about it when dealing with this piece of code :)

# The following variable is either a URL or a key file path.
ANSIBLE_BASE_JWT_KEY = settings.get("ANSIBLE_BASE_JWT_KEY") 

if gw_url.scheme and gw_url.hostname:
for k in data:
k_parsed = urlparse(data[k])
if gw_url.scheme and gw_url.hostname:
k_updated = k_parsed._replace(
scheme=gw_url.scheme,
netloc=gw_url.netloc,
)
data.update({k: urlunparse(k_updated)})
return data
return {}


def validate(settings: Dynaconf) -> None:
"""Validate the configuration, raise ValidationError if invalid"""
settings.validators.register(
Expand Down