Skip to content

Commit

Permalink
Support X_CG_APIKEY env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
BelgianNoise committed Mar 23, 2024
1 parent 65d16fc commit 2dcff9f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/scraper.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
- run: 'echo "${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}" > key.json'
# Not the best way to handle these secrets lol
- run: 'echo "GOOGLE_APPLICATION_CREDENTIALS=\"key.json\"" >> .env'
- run: 'echo "X_CG_APIKEY=${{ secrets.X_CG_APIKEY }}" >> .env'
- run: 'echo "USE_PROXY=${{ secrets.USE_PROXY }}" >> .env'
- run: 'echo "USE_PRIVATE_PROXY=${{ secrets.USE_PRIVATE_PROXY }}" >> .env'
- run: 'echo "PRIVATE_PROXY_HOST=${{ secrets.PRIVATE_PROXY_HOST }}" >> .env'
Expand Down
2 changes: 0 additions & 2 deletions go.work
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
go 1.21

toolchain go1.21.6

use (
./comparer
./inserter
Expand Down
2 changes: 0 additions & 2 deletions scraper/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module scraper

go 1.21

toolchain go1.21.6

require (
cloud.google.com/go/storage v1.30.1
github.com/joho/godotenv v1.5.1
Expand Down
7 changes: 6 additions & 1 deletion scraper/pkg/do-api-call.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ func GetAllProducts() (
// Retrieve a valid X-CG-APIKey from the xframe.js script.
// Not providing this header will result in a 401.
func GetXCGAPIKey() (XCGAPIKey string, err error) {
// if the token is in the env variables, return it
if e := os.Getenv("X_CG_APIKEY"); e != "" {
return e, nil
}

var browser *rod.Browser
var l *launcher.Launcher
if os.Getenv("HEADLESS") == "false" {
Expand Down Expand Up @@ -195,7 +200,7 @@ func GetXCGAPIKey() (XCGAPIKey string, err error) {
}
}

return "", fmt.Errorf("No API key found after 90 seconds.")
return "", fmt.Errorf("no API key found after 90 seconds")
}

func GetAllProductsWithParams(
Expand Down

0 comments on commit 2dcff9f

Please sign in to comment.