Skip to content

Commit

Permalink
refactor: Update Slack and Twitter workflows to use environment varia…
Browse files Browse the repository at this point in the history
…bles directly

- Removed DLT__ prefixed access token variables from Slack and Twitter workflow files.
- Updated Slack and Twitter pipeline scripts to retrieve tokens from environment variables instead of DLT secrets.
- Ensured that appropriate error handling is in place for missing environment variables.
  • Loading branch information
edmundmiller committed Jan 8, 2025
1 parent 6b4cadb commit f20d559
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/run_slack_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ name: Run Slack Pipeline

env:
# DLT specific environment variables
# DLT__SECRETS__SOURCES__SLACK__ACCESS_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
motherduck_token: ${{ secrets.MOTHERDUCK_TOKEN }}

# Optional: Add any other environment variables needed
# Remove the DLT__ prefixed version since we're using direct env vars
PYTHONUNBUFFERED: "1"

jobs:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/run_twitter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ name: Run Twitter Pipeline

env:
# DLT specific environment variables
# DLT__SECRETS__SOURCES__TWITTER__BEARER_TOKEN: ${{ secrets.TWITTER_BEARER_TOKEN }}
TWITTER_BEARER_TOKEN: ${{ secrets.TWITTER_BEARER_TOKEN }}
motherduck_token: ${{ secrets.MOTHERDUCK_TOKEN }}

Expand Down
9 changes: 5 additions & 4 deletions pipeline/slack_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@
from datetime import datetime
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError
import os

@dlt.source(name="slack")
def slack_source():
"""DLT source for Slack workspace statistics"""
# Get token explicitly from secrets
access_token = dlt.secrets.get("sources.slack_pipeline.access_token")
if not access_token:
raise ValueError("Slack access token not found in secrets")
token = os.getenv("SLACK_BOT_TOKEN")
if not token:
raise ValueError("SLACK_BOT_TOKEN environment variable is not set")

client = WebClient(token=access_token)
client = WebClient(token=token)
return slack_stats_resource(client)

@dlt.resource(name="workspace_stats", write_disposition="merge", primary_key=["timestamp"])
Expand Down
2 changes: 1 addition & 1 deletion pipeline/twitter_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

def get_twitter_headers():
"""Get Twitter API headers with bearer token authentication"""
access_token = dlt.secrets.get("sources.twitter.bearer_token")
access_token = os.getenv("TWITTER_BEARER_TOKEN")
if not access_token:
raise ValueError("TWITTER_BEARER_TOKEN environment variable is not set")
return {
Expand Down

0 comments on commit f20d559

Please sign in to comment.