diff --git a/microservices/download/service.yaml b/microservices/download/service.yaml index 2fb4ea6..2afb5db 100644 --- a/microservices/download/service.yaml +++ b/microservices/download/service.yaml @@ -5,5 +5,12 @@ metadata: spec: template: spec: + serviceAccountName: download-frontend@pulsar-357404.iam.gserviceaccount.com containers: - image: "us-west2-docker.pkg.dev/pulsar-357404/package-frontend/download:2.0.1" + env: + - name: GH_TOKEN_DOWNLOAD_MICROSERVICE + valueFrom: + secretKeyRef: + key: latest + name: GH_TOKEN_DOWNLOAD_MICROSERVICE diff --git a/microservices/download/utils.js b/microservices/download/utils.js index 6a03847..c3d9c57 100644 --- a/microservices/download/utils.js +++ b/microservices/download/utils.js @@ -1,4 +1,18 @@ const https = require("node:https"); +let TOKEN = process.env.GH_TOKEN_DOWNLOAD_MICROSERVICE; + +// Environment Variables Check + +if (typeof TOKEN === "undefined") { + if (process.env.PULSAR_STATUS === "dev") { + // We are in dev mode, assign dev values + TOKEN = "123456"; + } else { + // We are not in dev mode. Our secrets are gone and the application will fail to work + console.log("Missing Required Environment Variables! Something has gone wrong!"); + process.exit(1); + } +} function doRequest() { @@ -8,7 +22,8 @@ function doRequest() { method: 'GET', headers: { 'Accept': 'application/vnd.github+json', - 'User-Agent': 'pulsar-edit/package-frontend/microservices/download' + 'User-Agent': 'pulsar-edit/package-frontend/microservices/download', + 'Authorization': `Bearer ${TOKEN}` } };