feat: add dotenv and an option to check env variables
This commit is contained in:
2
package-lock.json
generated
2
package-lock.json
generated
@@ -22,7 +22,7 @@
|
||||
"eslint": "^8.54.0",
|
||||
"nodemon": "^3.0.2",
|
||||
"prettier": "^3.1.0",
|
||||
"ts-node": "^10.9.1",
|
||||
"ts-node": "^10.9.2",
|
||||
"typescript": "^5.3.2"
|
||||
}
|
||||
},
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
"eslint": "^8.54.0",
|
||||
"nodemon": "^3.0.2",
|
||||
"prettier": "^3.1.0",
|
||||
"ts-node": "^10.9.1",
|
||||
"ts-node": "^10.9.2",
|
||||
"typescript": "^5.3.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ import dotenv from 'dotenv';
|
||||
*/
|
||||
|
||||
|
||||
|
||||
abstract class Client {
|
||||
|
||||
// log env variables to verify they are loaded
|
||||
@@ -26,11 +25,10 @@ abstract class Client {
|
||||
private infisicalClient: InfisicalSDK;
|
||||
|
||||
constructor() {
|
||||
dotenv.config();
|
||||
this.infisicalClient = new InfisicalSDK({
|
||||
siteUrl: process.env.INFISICAL_URL,
|
||||
});
|
||||
dotenv.config();
|
||||
console.log("INFISICAL_URL:", process.env.INFISICAL_URL);
|
||||
}
|
||||
|
||||
init(): Effect.Effect<void, Error, never> {
|
||||
@@ -43,9 +41,13 @@ abstract class Client {
|
||||
})
|
||||
}
|
||||
|
||||
getCredential(key: string): Effect.Effect<string, Error, never> {
|
||||
getCredential(key: string, checkEnv: boolean = false): Effect.Effect<string, Error, never> {
|
||||
const self = this;
|
||||
return Effect.gen(function* (this: Client) {
|
||||
if (checkEnv && process.env[key]) {
|
||||
yield* Effect.log('Using environment variable for key: ' + key);
|
||||
return process.env[key]!;
|
||||
}
|
||||
const secret = yield* Effect.tryPromise({
|
||||
try: () => self.infisicalClient.secrets().getSecret({
|
||||
environment: "dev",
|
||||
|
||||
@@ -24,7 +24,9 @@ class StravaClient extends Client {
|
||||
const superInit = super.init();
|
||||
return Effect.gen(function* () {
|
||||
yield* superInit;
|
||||
const refreshToken = yield* self.getCredential('REFRESH_TOKEN');
|
||||
// Retrieve credentials from Infisical, for refresh token as it represents user account
|
||||
// There's an option to check env variables first
|
||||
const refreshToken = yield* self.getCredential('REFRESH_TOKEN', true);
|
||||
const clientId = yield* self.getCredential('CLIENT_ID');
|
||||
const clientSecret = yield* self.getCredential('CLIENT_SECRET');
|
||||
self.auth = makeStravaAuth(
|
||||
|
||||
Reference in New Issue
Block a user