-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core-server-infisical): Added library to handle env stored in In…
…fisical For more info about saving secrets and environment variables in
- Loading branch information
1 parent
a7e7e1d
commit 60ffaa3
Showing
16 changed files
with
298 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"extends": ["../../../../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"parserOptions": { | ||
"project": ["libs/core/typescript/server/infisical/tsconfig.*?.json"] | ||
}, | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"jsc": { | ||
"target": "es2017", | ||
"parser": { | ||
"syntax": "typescript", | ||
"decorators": true, | ||
"dynamicImport": true | ||
}, | ||
"transform": { | ||
"decoratorMetadata": true, | ||
"legacyDecorator": true | ||
}, | ||
"keepClassNames": true, | ||
"externalHelpers": true, | ||
"loose": true | ||
}, | ||
"module": { | ||
"type": "commonjs", | ||
"strict": true, | ||
"noInterop": true | ||
}, | ||
"sourceMaps": true, | ||
"exclude": [ | ||
"jest.config.ts", | ||
".*\\.spec.tsx?$", | ||
".*\\.test.tsx?$", | ||
"./src/jest-setup.ts$", | ||
"./**/jest-setup.ts$", | ||
".*.js$" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!-- START header --> | ||
|
||
<!-- END header --> | ||
|
||
# Core Environment Variable Management Library (Server) | ||
|
||
<!-- START doctoc --> | ||
<!-- END doctoc --> | ||
|
||
This library was generated with [Nx](https://nx.dev). | ||
|
||
## Building | ||
|
||
Run `nx build core-server-infisical` to build the library. | ||
|
||
## Running unit tests | ||
|
||
Run `nx test core-server-infisical` to execute the unit tests via [Jest](https://jestjs.io). | ||
|
||
<!-- START footer --> | ||
|
||
<!-- END footer --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* eslint-disable */ | ||
export default { | ||
displayName: "core-server-infisical", | ||
preset: "../../../../../testing/jest.preset.js", | ||
testEnvironment: "node", | ||
transform: { | ||
"^.+\\.[tj]s$": ["ts-jest", { tsconfig: "<rootDir>/tsconfig.spec.json" }] | ||
}, | ||
moduleFileExtensions: ["ts", "js", "html"], | ||
coverageDirectory: | ||
"../../../../../coverage/libs/core/typescript/server/infisical" | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "@open-system/core-server-infisical", | ||
"version": "0.0.1", | ||
"dependencies": { | ||
"infisical-node": "^1.4.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{ | ||
"name": "core-server-infisical", | ||
"$schema": "../../../../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "libs/core/typescript/server/infisical/src", | ||
"projectType": "library", | ||
"targets": { | ||
"build": { | ||
"executor": "@nx/js:swc", | ||
"outputs": ["{options.outputPath}"], | ||
"options": { | ||
"outputPath": "dist/libs/core/typescript/infisical", | ||
"tsConfig": "libs/core/typescript/server/infisical/tsconfig.lib.json", | ||
"packageJson": "libs/core/typescript/server/infisical/package.json", | ||
"main": "libs/core/typescript/server/infisical/src/index.ts", | ||
"assets": [ | ||
{ | ||
"glob": "libs/core/typescript/server/infisical/README.md", | ||
"input": ".", | ||
"output": "." | ||
} | ||
] | ||
} | ||
}, | ||
"lint": { | ||
"executor": "@nx/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": ["libs/core/typescript/server/infisical/**/*.ts"] | ||
} | ||
}, | ||
"test": { | ||
"executor": "@nx/jest:jest", | ||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"], | ||
"options": { | ||
"jestConfig": "libs/core/typescript/server/infisical/jest.config.ts", | ||
"passWithNoTests": true | ||
}, | ||
"configurations": { | ||
"ci": { | ||
"ci": true, | ||
"codeCoverage": true | ||
} | ||
} | ||
}, | ||
"semantic-release": { | ||
"executor": "@theunderscorer/nx-semantic-release:semantic-release", | ||
"options": { | ||
"github": true, | ||
"npm": false, | ||
"changelog": true, | ||
"tagFormat": "core-server-infisical-v${VERSION}" | ||
} | ||
} | ||
}, | ||
"tags": [], | ||
"implicitDependencies": [ | ||
"core-shared-utilities", | ||
"core-shared-injection", | ||
"core-shared-env" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { | ||
BaseOptions, | ||
createEnvManager, | ||
DEFAULT_OPTIONS, | ||
ENV_TOKEN | ||
} from "@open-system/core-shared-env"; | ||
import { Injector } from "@open-system/core-shared-injection"; | ||
import { EnvConfigurationError } from "@open-system/core-shared-utilities/errors/env-configuration-error"; | ||
import { getInfisicalClient } from "./infisical-client"; | ||
|
||
export const InfisicalEnvManager = createEnvManager({ | ||
...DEFAULT_OPTIONS, | ||
isServer: true, | ||
handler: async ( | ||
prop: string, | ||
options: Omit<BaseOptions, "env"> & Required<Pick<BaseOptions, "env">> | ||
) => { | ||
const { INFISICAL_TOKEN, INFISICAL_ENVIRONMENT } = options.env; | ||
if (!INFISICAL_TOKEN || typeof INFISICAL_TOKEN !== "string") { | ||
throw new EnvConfigurationError( | ||
"INFISICAL_TOKEN", | ||
`The environment variable "INFISICAL_TOKEN" is required to connect to the Infisical system.` | ||
); | ||
} | ||
|
||
return await getInfisicalClient(INFISICAL_TOKEN).getSecret(prop, { | ||
environment: INFISICAL_ENVIRONMENT as string, | ||
path: "/", | ||
type: "shared" | ||
}); | ||
} | ||
}); | ||
|
||
Injector.bind(ENV_TOKEN).toConstantValue(InfisicalEnvManager); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./env-manager"; | ||
export * from "./infisical-client"; |
14 changes: 14 additions & 0 deletions
14
libs/core/typescript/server/infisical/src/infisical-client.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import InfisicalClient from "infisical-node"; | ||
|
||
let client!: InfisicalClient; | ||
export const getInfisicalClient = (token: string) => { | ||
if (client) { | ||
return client; | ||
} | ||
|
||
client = new InfisicalClient({ | ||
token | ||
}); | ||
|
||
return client; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"extends": "../../../../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"forceConsistentCasingInFileNames": true, | ||
"noImplicitOverride": true, | ||
"noPropertyAccessFromIndexSignature": false, | ||
"noFallthroughCasesInSwitch": true, | ||
"allowSyntheticDefaultImports": true, | ||
"strict": true, | ||
"moduleResolution": "node", | ||
"types": ["node"] | ||
}, | ||
"files": [], | ||
"include": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.lib.json" | ||
}, | ||
{ | ||
"path": "./tsconfig.spec.json" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"outDir": "../../../../../dist/out-tsc", | ||
"declaration": true, | ||
"types": ["node"] | ||
}, | ||
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"], | ||
"include": ["src/**/*.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../../../../dist/out-tsc", | ||
"module": "commonjs", | ||
"types": ["jest", "node"] | ||
}, | ||
"include": [ | ||
"jest.config.ts", | ||
"src/**/*.test.ts", | ||
"src/**/*.spec.ts", | ||
"src/**/*.d.ts" | ||
] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters