Skip to content

Commit

Permalink
feat(core-server-infisical): Added library to handle env stored in In…
Browse files Browse the repository at this point in the history
…fisical

For more info about saving secrets and environment variables in
  • Loading branch information
sullivanpj committed Aug 23, 2023
1 parent a7e7e1d commit 60ffaa3
Show file tree
Hide file tree
Showing 16 changed files with 298 additions and 5 deletions.
7 changes: 4 additions & 3 deletions .env
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
CI=true
TYPESENSE_API_KEY=xyz
#NODE_OPTIONS=--openssl-legacy-provider
NODE_OPTIONS="--trace-warnings --require helios-opentelemetry-sdk --heapsnapshot-near-heap-limit=3 --heapsnapshot-signal=SIGTERM"

ROOT_HOST=192.168.1.18
HOST_SERVER=host.docker.internal
AKKA_STREAMS_KAFKA_TEST_FILE_LOGGING=true
RUST_BACKTRACE=full
#PUPPETEER_SKIP_DOWNLOAD=true
# PUPPETEER_SKIP_DOWNLOAD=true

NODE_OPTIONS="--trace-warnings --require helios-opentelemetry-sdk --heapsnapshot-near-heap-limit=3 --heapsnapshot-signal=SIGTERM"
HS_SERVICE_NAME="@open-system/repo"
# HS_DEBUG=true

Expand Down Expand Up @@ -39,3 +38,5 @@ PRISMA_GENERATE_DATAPROXY=true
STORM_RUNTIME_MODULE="dist/.storm"

NO_D1_WARNING=true

INFISICAL_ENVIRONMENT="prod"
11 changes: 10 additions & 1 deletion .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"Hsts",
"ICRUD",
"indexeddb",
"infisical",
"Inversify",
"Invision",
"jsbi",
Expand Down Expand Up @@ -136,7 +137,15 @@
"wundergraph",
"zenstack"
],
"enableFiletypes": ["txt", "js", "jsx", "ts", "tsx", "md", "mdx"],
"enableFiletypes": [
"txt",
"js",
"jsx",
"ts",
"tsx",
"md",
"mdx"
],
"ignorePaths": [
"**/.git/**",
"**/node_modules/**",
Expand Down
21 changes: 21 additions & 0 deletions libs/core/typescript/server/infisical/.eslintrc.json
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": {}
}
]
}
31 changes: 31 additions & 0 deletions libs/core/typescript/server/infisical/.swcrc
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$"
]
}
22 changes: 22 additions & 0 deletions libs/core/typescript/server/infisical/README.md
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 -->
12 changes: 12 additions & 0 deletions libs/core/typescript/server/infisical/jest.config.ts
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"
};
7 changes: 7 additions & 0 deletions libs/core/typescript/server/infisical/package.json
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"
}
}
61 changes: 61 additions & 0 deletions libs/core/typescript/server/infisical/project.json
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"
]
}
35 changes: 35 additions & 0 deletions libs/core/typescript/server/infisical/src/env-manager.ts
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);
2 changes: 2 additions & 0 deletions libs/core/typescript/server/infisical/src/index.ts
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 libs/core/typescript/server/infisical/src/infisical-client.ts
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;
};
24 changes: 24 additions & 0 deletions libs/core/typescript/server/infisical/tsconfig.json
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"
}
]
}
11 changes: 11 additions & 0 deletions libs/core/typescript/server/infisical/tsconfig.lib.json
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"]
}
14 changes: 14 additions & 0 deletions libs/core/typescript/server/infisical/tsconfig.spec.json
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"
]
}
25 changes: 24 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@
"@open-system/core-server-graphql/*": [
"libs/core/typescript/server/graphql/src/*"
],
"@open-system/core-server-infisical": [
"libs/core/typescript/server/infisical/src/index.ts"
],
"@open-system/core-server-infisical/*": [
"libs/core/typescript/server/infisical/src/*"
],
"@open-system/core-server-kafka": [
"libs/core/typescript/server/kafka/src/index.ts"
],
Expand Down

0 comments on commit 60ffaa3

Please sign in to comment.