summaryrefslogtreecommitdiffstats
path: root/awxkit
diff options
context:
space:
mode:
Diffstat (limited to 'awxkit')
-rw-r--r--awxkit/awxkit/api/client.py6
-rw-r--r--awxkit/awxkit/api/mixins/has_status.py3
-rw-r--r--awxkit/awxkit/api/pages/base.py10
-rw-r--r--awxkit/awxkit/api/resources.py8
-rw-r--r--awxkit/awxkit/awx/utils.py2
-rw-r--r--awxkit/awxkit/cli/custom.py3
-rw-r--r--awxkit/awxkit/cli/stdout.py3
-rw-r--r--awxkit/awxkit/config.py1
-rw-r--r--awxkit/awxkit/utils/__init__.py2
9 files changed, 24 insertions, 14 deletions
diff --git a/awxkit/awxkit/api/client.py b/awxkit/awxkit/api/client.py
index 95e990b792..cca1bba51d 100644
--- a/awxkit/awxkit/api/client.py
+++ b/awxkit/awxkit/api/client.py
@@ -43,8 +43,8 @@ class Connection(object):
self.session = requests.Session()
self.uses_session_cookie = False
- def get_session_requirements(self, next='/api/'):
- self.get('/api/') # this causes a cookie w/ the CSRF token to be set
+ def get_session_requirements(self, next=config.api_base_path):
+ self.get(config.api_base_path) # this causes a cookie w/ the CSRF token to be set
return dict(next=next)
def login(self, username=None, password=None, token=None, **kwargs):
@@ -52,7 +52,7 @@ class Connection(object):
_next = kwargs.get('next')
if _next:
headers = self.session.headers.copy()
- response = self.post('/api/login/', headers=headers, data=dict(username=username, password=password, next=_next))
+ response = self.post(f"{config.api_base_path}login/", headers=headers, data=dict(username=username, password=password, next=_next))
# The login causes a redirect so we need to search the history of the request to find the header
for historical_response in response.history:
if 'X-API-Session-Cookie-Name' in historical_response.headers:
diff --git a/awxkit/awxkit/api/mixins/has_status.py b/awxkit/awxkit/api/mixins/has_status.py
index 0bb9992f69..ba0ca546a7 100644
--- a/awxkit/awxkit/api/mixins/has_status.py
+++ b/awxkit/awxkit/api/mixins/has_status.py
@@ -3,6 +3,7 @@ import json
from awxkit.utils import poll_until
from awxkit.exceptions import WaitUntilTimeout
+from awxkit.config import config
def bytes_to_str(obj):
@@ -83,7 +84,7 @@ class HasStatus(object):
if getattr(self, 'job_explanation', '').startswith('Previous Task Failed'):
try:
data = json.loads(self.job_explanation.replace('Previous Task Failed: ', ''))
- dependency = self.walk('/api/v2/{0}s/{1}/'.format(data['job_type'], data['job_id']))
+ dependency = self.walk('/{0}v2/{1}s/{2}/'.format(config.api_base_path, data['job_type'], data['job_id']))
if hasattr(dependency, 'failure_output_details'):
msg += '\nDependency output:\n{}'.format(dependency.failure_output_details())
else:
diff --git a/awxkit/awxkit/api/pages/base.py b/awxkit/awxkit/api/pages/base.py
index 7e9d210ab3..ec3fcd0857 100644
--- a/awxkit/awxkit/api/pages/base.py
+++ b/awxkit/awxkit/api/pages/base.py
@@ -150,19 +150,21 @@ class Base(Page):
HTTPBasicAuth(client_id, client_secret)(req)
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
resp = self.connection.post(
- '/api/o/token/', data={"grant_type": "password", "username": username, "password": password, "scope": scope}, headers=req.headers
+ f"{config.api_base_path}o/token/",
+ data={"grant_type": "password", "username": username, "password": password, "scope": scope},
+ headers=req.headers,
)
elif client_id:
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
resp = self.connection.post(
- '/api/o/token/',
+ f"{config.api_base_path}o/token/",
data={"grant_type": "password", "username": username, "password": password, "client_id": client_id, "scope": scope},
headers=req.headers,
)
else:
HTTPBasicAuth(username, password)(req)
resp = self.connection.post(
- '/api/v2/users/{}/personal_tokens/'.format(username),
+ '{0}v2/users/{1}/personal_tokens/'.format(config.api_base_path, username),
json={"description": description, "application": None, "scope": scope},
headers=req.headers,
)
@@ -207,7 +209,7 @@ class Base(Page):
jobs = []
for active_job in active_jobs:
job_type = active_job['type']
- endpoint = '/api/v2/{}s/{}/'.format(job_type, active_job['id'])
+ endpoint = '{}v2/{}s/{}/'.format(config.api_base_path, job_type, active_job['id'])
job = self.walk(endpoint)
jobs.append(job)
job.cancel()
diff --git a/awxkit/awxkit/api/resources.py b/awxkit/awxkit/api/resources.py
index d453ff4f75..17397e9c66 100644
--- a/awxkit/awxkit/api/resources.py
+++ b/awxkit/awxkit/api/resources.py
@@ -1,3 +1,6 @@
+from awxkit.config import config
+
+
class Resources(object):
_activity = r'activity_stream/\d+/'
_activity_stream = 'activity_stream/'
@@ -285,6 +288,9 @@ class Resources(object):
common = api + r'v\d+/'
v2 = api + 'v2/'
+ def __init__(self, api):
+ self.api = api
+
def __getattr__(self, resource):
if resource[:3] == '___':
raise AttributeError('No existing resource: {}'.format(resource))
@@ -299,4 +305,4 @@ class Resources(object):
return '{0}{1}'.format(getattr(self, prefix), getattr(self, resource))
-resources = Resources()
+resources = Resources(api=config.api_base_path)
diff --git a/awxkit/awxkit/awx/utils.py b/awxkit/awxkit/awx/utils.py
index df61f0b7a0..c84a58b3b2 100644
--- a/awxkit/awxkit/awx/utils.py
+++ b/awxkit/awxkit/awx/utils.py
@@ -122,5 +122,5 @@ def as_user(v, username, password=None):
def uses_sessions(connection):
- session_login = connection.get('/api/login/')
+ session_login = connection.get(f"{config.api_base_path}login/")
return session_login.status_code == 200
diff --git a/awxkit/awxkit/cli/custom.py b/awxkit/awxkit/cli/custom.py
index 6d2be2475c..909ea8caaa 100644
--- a/awxkit/awxkit/cli/custom.py
+++ b/awxkit/awxkit/cli/custom.py
@@ -4,6 +4,7 @@ import json
from .stdout import monitor, monitor_workflow
from .utils import CustomRegistryMeta, color_enabled
from awxkit import api
+from awxkit.config import config
from awxkit.exceptions import NoContent
@@ -479,7 +480,7 @@ class RoleMixin(object):
options = ', '.join(RoleMixin.roles[flag])
raise ValueError("invalid choice: '{}' must be one of {}".format(role, options))
value = kwargs[flag]
- target = '/api/v2/{}/{}'.format(resource, value)
+ target = '{}v2/{}/{}'.format(config.api_base_path, resource, value)
detail = self.page.__class__(target, self.page.connection).get()
object_roles = detail['summary_fields']['object_roles']
actual_role = object_roles[role + '_role']
diff --git a/awxkit/awxkit/cli/stdout.py b/awxkit/awxkit/cli/stdout.py
index 455d4d9805..0ed68c1889 100644
--- a/awxkit/awxkit/cli/stdout.py
+++ b/awxkit/awxkit/cli/stdout.py
@@ -6,6 +6,7 @@ import sys
import time
from .utils import cprint, color_enabled, STATUS_COLORS
+from awxkit.config import config
from awxkit.utils import to_str
@@ -17,7 +18,7 @@ def monitor_workflow(response, session, print_stdout=True, action_timeout=None,
}
def fetch(seen):
- results = response.connection.get('/api/v2/unified_jobs', payload).json()['results']
+ results = response.connection.get(f"{config.api_base_path}v2/unified_jobs", payload).json()['results']
# erase lines we've previously printed
if print_stdout and sys.stdout.isatty():
diff --git a/awxkit/awxkit/config.py b/awxkit/awxkit/config.py
index f09bf7ec6f..81c4d7938b 100644
--- a/awxkit/awxkit/config.py
+++ b/awxkit/awxkit/config.py
@@ -32,3 +32,4 @@ 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/')
diff --git a/awxkit/awxkit/utils/__init__.py b/awxkit/awxkit/utils/__init__.py
index 8b47b4e5d9..b435b76430 100644
--- a/awxkit/awxkit/utils/__init__.py
+++ b/awxkit/awxkit/utils/__init__.py
@@ -14,10 +14,8 @@ import yaml
from awxkit.words import words
from awxkit.exceptions import WaitUntilTimeout
-
log = logging.getLogger(__name__)
-
cloud_types = (
'aws',
'azure',