Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] authored and anitaratansingh committed Aug 22, 2024
1 parent 4b31def commit 1a6c051
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,19 @@ def vdk_configure(self, config_builder: ConfigurationBuilder) -> None:
)
config_builder.add(
TEAM_CLIENT_ID,
"",
None,
True,
"The Team's oAuth Client Id to use in authentication operations.",
)
config_builder.add(
TEAM_CLIENT_SECRET,
"",
None,
True,
"The Team's oAuth Client Secret to use in authentication operations",
)
config_builder.add(
TEAM_OAUTH_AUTHORIZE_URL,
"",
None,
True,
"The URL for Team's oAuth authorization",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
API_SERVER_KERBEROS_SERVICE_NAME = "API_SERVER_KERBEROS_SERVICE_NAME"
DISABLE_KERBEROS_LOGIN = "DISABLE_KERBEROS_LOGIN"


class KerberosPluginConfiguration:
def __init__(
self,
Expand Down Expand Up @@ -154,3 +155,8 @@ def add_definitions(config_builder: ConfigurationBuilder) -> None:
(for example, '[email protected]').
""",
)
config_builder.add(
key=DISABLE_KERBEROS_LOGIN,
default_value=False,
description="To enable/disable kerberos login.",
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright 2024-2025 Broadcom
# SPDX-License-Identifier: Apache-2.0
from vdk.internal.core.config import Configuration

from vdk.internal.core.config import Configuration, ConfigurationBuilder

CLIENT_ID = "CLIENT_ID"
CLIENT_SECRET = "CLIENT_SECRET"

Check warning on line 6 in projects/vdk-plugins/vdk-oauth-auth/src/vdk/plugin/oauth/oauth_configuration.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

projects/vdk-plugins/vdk-oauth-auth/src/vdk/plugin/oauth/oauth_configuration.py#L6

Possible hardcoded password: 'CLIENT_SECRET'

Check failure on line 6 in projects/vdk-plugins/vdk-oauth-auth/src/vdk/plugin/oauth/oauth_configuration.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

projects/vdk-plugins/vdk-oauth-auth/src/vdk/plugin/oauth/oauth_configuration.py#L6

Possible hardcoded secret key (secret)
Expand Down Expand Up @@ -45,3 +44,11 @@ def csp_access_token(self):

def disable_oauth_plugin(self):
return self.__config.get_value(DISABLE_OAUTH_LOGIN).lower() == "true"


def add_definitions(config_builder: ConfigurationBuilder) -> None:
config_builder.add(
key=DISABLE_OAUTH_LOGIN,
default_value=False,
description="To enable/disable oauth login.",
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
from vdk.internal.core.config import ConfigurationBuilder
from vdk.internal.core.context import CoreContext
from vdk.plugin.control_api_auth.auth_config import LocalFolderCredentialsCache
from vdk.plugin.oauth.oauth_configuration import add_definitions
from vdk.plugin.oauth.oauth_configuration import OauthPluginConfiguration


log = logging.getLogger(__name__)

TEAM_CLIENT_ID = "TEAM_CLIENT_ID"
TEAM_CLIENT_SECRET = "TEAM_CLIENT_SECRET"

Check warning on line 24 in projects/vdk-plugins/vdk-oauth-auth/src/vdk/plugin/oauth/oauth_plugin.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

projects/vdk-plugins/vdk-oauth-auth/src/vdk/plugin/oauth/oauth_plugin.py#L24

Possible hardcoded password: 'TEAM_CLIENT_SECRET'

Check failure on line 24 in projects/vdk-plugins/vdk-oauth-auth/src/vdk/plugin/oauth/oauth_plugin.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

projects/vdk-plugins/vdk-oauth-auth/src/vdk/plugin/oauth/oauth_plugin.py#L24

Possible hardcoded secret key (secret)
CSP_ACCESS_TOKEN = "CSP_ACCESS_TOKEN"
TEAM_ACCESS_TOKEN = "TEAM_ACCESS_TOKEN"

Check warning on line 25 in projects/vdk-plugins/vdk-oauth-auth/src/vdk/plugin/oauth/oauth_plugin.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

projects/vdk-plugins/vdk-oauth-auth/src/vdk/plugin/oauth/oauth_plugin.py#L25

Possible hardcoded password: 'TEAM_ACCESS_TOKEN'


class OauthPlugin:
Expand All @@ -31,9 +32,13 @@ def __init__(self):
self.team_name = None
self.is_oauth_creds_available = False

def __attempt_oauth_authentication(self, oauth_configuration : OauthPluginConfiguration):
def __attempt_oauth_authentication(
self, oauth_configuration: OauthPluginConfiguration
):
original_string = (
oauth_configuration.team_client_id() + ":" + oauth_configuration.team_client_secret()
oauth_configuration.team_client_id()
+ ":"
+ oauth_configuration.team_client_secret()
)

# Encoding
Expand All @@ -49,12 +54,12 @@ def __attempt_oauth_authentication(self, oauth_configuration : OauthPluginConfi

response = requests.post(url, headers=headers, data=data)
response_json = json.loads(response.text)
os.environ[CSP_ACCESS_TOKEN] = response_json["access_token"]
os.environ[TEAM_ACCESS_TOKEN] = response_json["access_token"]

@staticmethod
@hookimpl
def vdk_configure(config_builder: ConfigurationBuilder) -> None:
pass
add_definitions(config_builder)

@hookimpl
def vdk_initialize(self, context: CoreContext) -> None:
Expand All @@ -77,7 +82,9 @@ def vdk_initialize(self, context: CoreContext) -> None:
credentials = credentials_cache.read_credentials()
credentials = json.loads(credentials.replace("'", '"'))
self.access_token = credentials.get("access_token")
self.control_service_rest_api_url = oauth_configuration.control_service_rest_api_url()
self.control_service_rest_api_url = (
oauth_configuration.control_service_rest_api_url()
)
self.team_name = oauth_configuration.team()

@hookimpl(tryfirst=True)
Expand All @@ -86,7 +93,9 @@ def initialize_job(self, context: JobContext) -> None:
This is called during vdk run (job execution)
Check if Oauth enabled
"""
oauth_configuration = OauthPluginConfiguration(context.core_context.configuration)
oauth_configuration = OauthPluginConfiguration(
context.core_context.configuration
)

if oauth_configuration.disable_oauth_plugin():
return
Expand Down

0 comments on commit 1a6c051

Please sign in to comment.