Files
awx/awxkit/awxkit/config.py
Mike Graves 764dcbf94b Add gateway support to awxkit (#15576)
* Add gateway support to awxkit

This updates awxkit to add support for gateway when fetching oauth
tokens, which is used during the `login` subcommand. awxkit will first
try fetching a token from gateway and if that fails, fallback to
existing behavior. This change is backwards compatible.

Signed-off-by: Mike Graves <mgraves@redhat.com>

* Address review feedback

This:
  * adds coverage for the get_oauth2_token() method
  * changes AuthUrls to a TypedDict
  * changes the url used for personal token access in gateway

* Address review feedback

This is just minor stylistic changes.

---------

Signed-off-by: Mike Graves <mgraves@redhat.com>
2024-10-16 12:01:30 -04:00

37 lines
1.0 KiB
Python

import types
import os
from .utils import (
PseudoNamespace,
load_credentials,
load_projects,
to_bool,
)
config = PseudoNamespace()
def getvalue(self, name):
return self.__getitem__(name)
if os.getenv('AWXKIT_BASE_URL'):
config.base_url = os.getenv('AWXKIT_BASE_URL')
if os.getenv('AWXKIT_CREDENTIAL_FILE'):
config.credentials = load_credentials(os.getenv('AWXKIT_CREDENTIAL_FILE'))
if os.getenv('AWXKIT_PROJECT_FILE'):
config.project_urls = load_projects(config.get('AWXKIT_PROJECT_FILE'))
# kludge to mimic pytest.config
config.getvalue = types.MethodType(getvalue, config)
config.assume_untrusted = config.get('assume_untrusted', True)
config.client_connection_attempts = int(os.getenv('AWXKIT_CLIENT_CONNECTION_ATTEMPTS', 5))
config.prevent_teardown = to_bool(os.getenv('AWXKIT_PREVENT_TEARDOWN', False))
config.use_sessions = to_bool(os.getenv('AWXKIT_SESSIONS', False))
config.api_base_path = os.getenv('AWXKIT_API_BASE_PATH', '/api/')
config.gateway_base_path = os.getenv('AWXKIT_GATEWAY_BASE_PATH', '/api/gateway/')