Skip to content

Commit

Permalink
Services, Cookie Auth + Version
Browse files Browse the repository at this point in the history
#48
* Add custom payload for cookie auth
* Fix default args for services
* Cleanup old patch in services
* Removed Cython from Dockerfile (moved to packets modules setup.py requirements)
* Version 24.10.1
  • Loading branch information
gwenblum authored Nov 18, 2024
1 parent 9d7fcc6 commit feb0234
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Dockerfile
# version: 24.9.1
# version: 24.10.1

FROM python:3.12
LABEL org.opencontainers.image.authors="Riverbed Community"
Expand All @@ -21,7 +21,6 @@ RUN set -ex \
-e git+https://github.com/riverbed/steelscript-appresponse#egg=steelscript-appresponse \
-e git+https://github.com/riverbed/steelscript-netim.git#egg=steelscript-netim \
-e git+https://github.com/riverbed/steelscript-client-accelerator-controller#egg=steelscript-cacontroller \
&& pip install Cython \
&& pip install --src /src \
-e git+https://github.com/riverbed/steelscript-steelhead#egg=steelscript-steelhead \
-e git+https://github.com/riverbed/steelscript-packets.git@master#egg=steelscript-packets \
Expand Down
3 changes: 1 addition & 2 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Dockerfile.dev
# version: 24.9.1
# version: 24.10.1

FROM python:3.12
LABEL org.opencontainers.image.authors="Riverbed Community"
Expand Down Expand Up @@ -34,7 +34,6 @@ RUN set -ex \
-e /src-dev/steelscript-appresponse \
-e /src-dev/steelscript-netim \
-e /src-dev/steelscript-client-accelerator-controller \
&& pip install Cython \
&& pip install --src /src \
-e /src-dev/steelscript-steelhead \
-e /src-dev/steelscript-packets \
Expand Down
3 changes: 1 addition & 2 deletions Dockerfile.slim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Dockerfile.slim
# version: 24.9.1
# version: 24.10.1

# start with slim version
FROM python:3.12-slim
Expand Down Expand Up @@ -32,7 +32,6 @@ RUN set -ex \
-e git+https://github.com/riverbed/steelscript-appresponse#egg=steelscript-appresponse \
-e git+https://github.com/riverbed/steelscript-netim.git#egg=steelscript-netim \
-e git+https://github.com/riverbed/steelscript-client-accelerator-controller#egg=steelscript-cacontroller \
&& pip install Cython \
&& pip install --src /src \
-e git+https://github.com/riverbed/steelscript-steelhead#egg=steelscript-steelhead \
-e git+https://github.com/riverbed/steelscript-packets.git@master#egg=steelscript-packets \
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def run_tests(self):

setup_args = {
'name': 'steelscript',
'version': '24.2.1',
'version': '24.10.1',
'author': 'Riverbed Technology',
'author_email': 'community@riverbed.com',
'url': 'https://community.riverbed.com',
Expand Down
38 changes: 21 additions & 17 deletions steelscript/common/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def __init__(self, service, host=None, port=None, auth=None,
supports_auth_cookie=False, override_cookie_login_api = '/api/common/1.0/login',
supports_auth_oauth=False, override_oauth_token_api='/api/common/1.0/oauth/token',
supports_auth_oauth2_client_credentials=False,
enable_services_version_detection=True,override_services_api='/api/appliance/1.0/services'
enable_services_version_detection=True,override_services_api='/api/common/1.0/services'
):
"""Establish a connection to the named host.
Expand Down Expand Up @@ -162,7 +162,7 @@ def __init__(self, service, host=None, port=None, auth=None,
For example: '/api/common/1.0/auth_info' or '/api/common/1.0.0/auth_info'
`override_services_api the services api or set to None if not supported.
For example: '/api/appliance/1.0/services' '/api/appliance/1.0.0/services'
For example: '/api/common/1.0/services' '/api/appliance/1.0.0/services'
`supports_auth_oauth2_client_credentials` set to False to bypass the oauth2 client credentials feature
Expand Down Expand Up @@ -213,14 +213,9 @@ def __init__(self, service, host=None, port=None, auth=None,

self._services_version_detection_enabled = enable_services_version_detection
self._services_api = override_services_api

# TODO: Update steelscript-client-accelerator-controller module to remove this patch
if self.service == "cac":
self._auth_info_api = '/api/common/1.0.0/auth_info'
self._oauth_token_api = '/api/common/1.0.0/oauth/token'
self._services_api = '/api/appliance/1.0.0/services'


self.connect()

if enable_services_version_detection:
self.check_api_versions(versions)

Expand Down Expand Up @@ -252,7 +247,7 @@ def check_api_versions(self, api_versions):
"""Check that the server supports the given API versions."""
if self.conn is None:
raise RvbdException("Not connected")

try:
self.supported_versions = self._get_supported_versions()
except RvbdHTTPException as e:
Expand All @@ -267,6 +262,9 @@ def check_api_versions(self, api_versions):
logger.debug("Server supports the following services: %s" %
(",".join([str(v) for v in self.supported_versions])))

if api_versions is None:
return True

for v in api_versions:
if v in self.supported_versions:
self.api_version = v
Expand Down Expand Up @@ -318,6 +316,18 @@ def _detect_auth_methods(self):
self._supports_auth_oauth = False
self._supports_auth_oauth2_client_credentials = False

def generate_authentication_payload_for_cookie_auth(self):
"""
Generate the payload required in the authentication phase with COOKIE auth method
This class method can be overridden to provide a custom payload
"""
data = {
"username": self.auth.username,
"password": self.auth.password
}
return data


def authenticate(self, auth):
"""
Authenticate with device using the defined authentication method.
Expand Down Expand Up @@ -380,15 +390,9 @@ def authenticate(self, auth):
self.conn.add_headers({'Authorization': auth_header})
logger.info('Authenticated using OAUTH')

if self.service == "cac":
return self.conn

elif self._supports_auth_cookie and Auth.COOKIE in self.auth.methods:
path = self._cookie_login_api
data = {
"username": self.auth.username,
"password": self.auth.password
}
data = self.generate_authentication_payload_for_cookie_auth()

body, http_response = self.conn.json_request('POST', path,
body=data,
Expand Down

0 comments on commit feb0234

Please sign in to comment.