Join the Kedro community

Updated 2 months ago

Accessing Azure Credentials in Kedro 0.19 with OmegaConfigLoader

hi i've set-up credentials hooks (kedro 0.19) and want to access the azure_creds values from inside the pipelines file to pass them to the node function, but OmegaConfigLoader is returning an empty value, is there a solution to this ?

#hooks.py
from kedro.framework.hooks import hook_impl
from azure.keyvault.secrets import SecretClient
from azure.identity import DefaultAzureCredential


class AzureSecretsHook:
    @hook_impl
    def after_context_created(self, context) -> None:
        keyVaultName = "keyvault-0542abb"  # or os.environ["KEY_VAULT_NAME"] if you would like to provide it through environment variables
        KVUri = f"https://{keyVaultName}.vault.azure.net"

        my_credential = DefaultAzureCredential()
        client = SecretClient(vault_url=KVUri, credential=my_credential)

        secrets = {
            "abs_creds": "azure-blob-store",
            "s3_creds": "s3-bucket-creds",
        }
        azure_creds = {
            cred_name: client.get_secret(secret_name).value
            for cred_name, secret_name in secrets.items()
        }

        context.config_loader["credentials"] = {
            **context.config_loader["credentials"],
            **azure_creds,
        }

D
P
2 comments

You need an empty credentials.yml

Add a reply
Sign up and join the conversation on Slack