Skip to content

Commit

Permalink
Read client secret at runtime
Browse files Browse the repository at this point in the history
Read the Keycloak client secret from SSM at runtime instead of having
it in the Lambda environment.
  • Loading branch information
simenheg committed Mar 15, 2024
1 parent a7f0695 commit 9ca92bf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
17 changes: 15 additions & 2 deletions common/dataplatform.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
import logging
from functools import cache

from okdata.aws.ssm import get_secret
from okdata.sdk.config import Config
from okdata.sdk.data.dataset import Dataset
from okdata.sdk.data.upload import Upload
from requests.exceptions import HTTPError

logger = logging.getLogger()


@cache
def _sdk_config():
sdk_config = Config()
sdk_config.config["client_secret"] = get_secret(
"/dataplatform/okdata-data-collectors/keycloak-client-secret"
)
return sdk_config


def upload_dataset(dataset_id, filename):
logger.info(f"Uploading dataset, id={dataset_id}, file={filename}")

dataset = Dataset()
upload = Upload()
sdk_config = _sdk_config()
dataset = Dataset(sdk_config)
upload = Upload(sdk_config)

try:
version = dataset.get_latest_version(dataset_id)["version"]
Expand Down
1 change: 0 additions & 1 deletion serverless.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ provider:
SERVICE_NAME: ${self:service}
OKDATA_ENVIRONMENT: ${self:custom.okdataEnvironment.${self:provider.stage}, self:custom.okdataEnvironment.dev}
OKDATA_CLIENT_ID: ${self:service}
OKDATA_CLIENT_SECRET: ${ssm:/dataplatform/okdata-data-collectors/keycloak-client-secret}

package:
patterns:
Expand Down

0 comments on commit 9ca92bf

Please sign in to comment.