1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] `schemachange`, snowflake and oauth authentication in GitHub action

Discussão em 'Python' iniciado por Stack, Setembro 15, 2024.

  1. Stack

    Stack Membro Participativo

    I have been trying to use Oauth Authentication of schemachange in my github action pipeline; however, I get the following error message

    Traceback (most recent call last):

    File "/opt/actions-runner/_work/_tool/Python/3.8.18/x64/bin/schemachange", line 8, in <module>
    Using Snowflake account ***
    sys.exit(main())
    File "/opt/actions-runner/_work/_tool/Python/3.8.18/x64/lib/python3.8/site-packages/schemachange/cli.py", line 1309, in main
    deploy_command(config)
    File "/opt/actions-runner/_work/_tool/Python/3.8.18/x64/lib/python3.8/site-packages/schemachange/cli.py", line 601, in deploy_command
    session = SnowflakeSchemachangeSession(config)
    File "/opt/actions-runner/_work/_tool/Python/3.8.18/x64/lib/python3.8/site-packages/schemachange/cli.py", line 283, in __init__
    if self.set_connection_args():
    File "/opt/actions-runner/_work/_tool/Python/3.8.18/x64/lib/python3.8/site-packages/schemachange/cli.py", line 372, in set_connection_args
    oauth_token = self.get_oauth_token()
    File "/opt/actions-runner/_work/_tool/Python/3.8.18/x64/lib/python3.8/site-packages/schemachange/cli.py", line 329, in get_oauth_token
    "url": self.oauth_config["token-provider-url"],
    TypeError: 'NoneType' object is not subscriptable


    one might suspect that this is due to improper config on env variable in workflow, for that I have written a python script to get the token and authenticate with snowflake in the same pipeline, and it works. This is the Github pipleine:

    name: testing

    on:
    push:
    branches:
    - feat/*

    jobs:

    Deploy:
    runs-on: ubuntu-latest

    permissions:
    id-token: write
    contents: read

    defaults:
    run:
    shell: bash

    environment:
    name: 'Dev-WB'

    # get environment variables from the environment
    env:
    SF_ACCOUNT: ${{ secrets.SF_ACCOUNT }}
    SF_USERNAME: ${{ secrets.SF_USERNAME }}
    SF_ROLE: ${{ secrets.SF_ROLE_MULESOFT }}
    SF_ROLE_TASK: ${{ secrets.SF_ROLE_TASK }}
    SF_WAREHOUSE: ${{ vars.SF_WAREHOUSE_MULESOFT }}
    SF_DATABASE: ${{ vars.SF_DATABASE }}
    SCHEMA_AI_MODEL: ${{ vars.SCHEMA_AI_MODEL }}
    SCHEMA_FEATURE_STORE: ${{ vars.SCHEMA_FEATURE_STORE }}
    SCHEMA_REPORT: ${{ vars.SCHEMA_REPORT }}
    AZURE_ORG_GUID: ${{ vars.AZURE_ORG_GUID }}
    CLIENT_ID: ${{ vars.CLIENT_ID }}
    CLIENT_SECRET: ${{ vars.CLIENT_SECRET }}
    SCOPE_URL_TEST: ${{ vars.SCOPE_URL_TEST }}
    SNOWFLAKE_AUTHENTICATOR: oauth

    steps:
    - name: Checkout repository
    uses: actions/checkout@v4

    - name: Use Python 3.8.x
    uses: actions/setup-python@v5
    with:
    python-version: 3.8.x

    - name: Install Python dependencies
    run: |
    pip install --upgrade pip
    pip install -r code/python/requirements.txt

    - name: Run python
    run: |
    python code/python/src/snowflake_conn_tocken.py


    - name: Run schemachange to deploy the snowflake Stored Procedures
    run: |

    schemachange -f ${{ github.workspace }}/code/schemachange/stored_procedure \
    -a $SF_ACCOUNT \
    -r $SF_ROLE \
    -u $SF_USERNAME \
    -w $SF_WAREHOUSE \
    -d $SF_DATABASE \
    -c $SF_DATABASE.MRVWORK_DNA_DISCOVER.CLAIM_SCHEMACHANGE_CHANGE_HISTORY --create-change-history-table \
    --vars '{"schema_ai_model": "${{vars.SCHEMA_AI_MODEL}}", "schema_feature_store": "${{vars.SCHEMA_FEATURE_STORE}}", "schema_report": "${{vars.SCHEMA_REPORT}}"}' # schema's names change based on the environment
    --oauth-config '{"url": ${{ vars.AZURE_ORG_GUID }}, "headers": {"Content-Type": "application/x-www-form-urlencoded", "User-Agent": "python/schemachange"}, "data": {"client_id": CLIENT_ID: ${{ vars.CLIENT_ID }}, "client_secret": ${{ vars.CLIENT_SECRET }}, "grant_type": 'client_credentials', "scope": ${{ vars.SCOPE_URL_TEST }}}'



    I'm guessing the problem is that schemachange can't parse/access the env? Anyone can help me with this?

    Continue reading...

Compartilhe esta Página