Skip to content

Commit

Permalink
fix(api): keyshade-xyz#381 made requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dark-Kernel committed Jul 28, 2024
1 parent ce8afaa commit f561f76
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 24 deletions.
2 changes: 1 addition & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"db:format": "pnpm dlx prisma format --schema=src/prisma/schema.prisma",
"db:reset": "pnpx dotenv-cli -e ../../.env -- pnpm dlx prisma migrate reset --force --schema=src/prisma/schema.prisma",
"sourcemaps": "sentry-cli sourcemaps inject ./dist && sentry-cli sourcemaps upload ./dist || echo 'Failed to upload source maps to Sentry'",
"e2e:prepare": "cd ../../ && docker compose down && docker compose -f docker-compose-test.yml up -d && sleep 3 && sleep 3 && cd apps/api && pnpm db:generate-types && cross-env NODE_ENV='e2e' DATABASE_URL='postgresql://prisma:prisma@localhost:5432/tests' pnpm run db:deploy-migrations",
"e2e:prepare": "cd ../../ && docker compose down && docker compose -f docker-compose-test.yml up -d && sleep 3 && cd apps/api && pnpm db:generate-types && cross-env NODE_ENV='e2e' DATABASE_URL='postgresql://prisma:prisma@localhost:5432/tests' pnpm run db:deploy-migrations",
"e2e": "pnpm run e2e:prepare && cross-env NODE_ENV='e2e' DATABASE_URL='postgresql://prisma:prisma@localhost:5432/tests' jest --runInBand --config=jest.e2e-config.ts --coverage --coverageDirectory=../../coverage-e2e/api --coverageReporters=json && pnpm run e2e:teardown",
"e2e:teardown": "cd ../../ && docker compose -f docker-compose-test.yml down",
"unit": "pnpm db:generate-types && jest --config=jest.config.ts"
Expand Down
1 change: 0 additions & 1 deletion apps/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"dependencies": {
"@clack/core": "^0.3.4",
"@clack/prompts": "^0.7.0",
"@nestjs/cli": "^10.0.0",
"chalk": "^4.1.2",
"cli-table": "^0.3.11",
"colors": "^1.4.0",
Expand Down
15 changes: 0 additions & 15 deletions apps/cli/src/commands/init.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export default class InitCommand extends BaseCommand {
async action({ options }: CommandActionData): Promise<void> {
let { workspace, project, environment, privateKey } = options
const { overwrite, quitOnDecryptionFailure } = options
console.log(workspace)

intro('Configure the project for live-updates')

Expand Down Expand Up @@ -89,8 +88,6 @@ export default class InitCommand extends BaseCommand {

if (!overwrite) await this.checkOverwriteExistingProjectConfig()

if (!quitOnDecryptionFailure) await this.checkQuitOnDecryptionFailureProjectConfig()

await writeProjectRootConfig({
workspace,
project,
Expand All @@ -116,16 +113,4 @@ export default class InitCommand extends BaseCommand {
}
}
}

private async checkQuitOnDecryptionFailureProjectConfig(): Promise<void> {
if (existsSync('./keyshade.json')) {
const quitOnDecryptionFailure = await confirm({
message: 'Quit on decryption failure?'
})

if (!quitOnDecryptionFailure) {
outro('Configuration cancelled')
}
}
}
}
12 changes: 5 additions & 7 deletions apps/cli/src/commands/run.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ export default class RunCommand extends BaseCommand {
Logger.info('Connecting to socket...')
const host = this.baseUrl.substring(this.baseUrl.lastIndexOf('/') + 1)
const websocketUrl = `${this.getWebsocketType(this.baseUrl)}://${host}/change-notifier`
const privateKey = (data as any).privateKey;
const quitOnDecryptionFailure = data.quitOnDecryptionFailure


const ioClient = io(websocketUrl, {
autoConnect: false,
Expand All @@ -108,15 +111,11 @@ export default class RunCommand extends BaseCommand {
`Configuration change received from API (name: ${data.name})`
)

// To test the below condition of quitOnDecryptionFailure, uncomment the below line
// data.isPlaintext = false

if (!data.isPlaintext) {
const configurations = await this.fetchConfigurations()
try {
data.value = await decrypt(configurations.privateKey, data.value)
data.value = await decrypt(privateKey, data.value)
} catch (error) {
if (configurations.quitOnDecryptionFailure) {
if (quitOnDecryptionFailure) {
Logger.error(`Decryption failed for ${data.name}. Stopping the process.`);
process.exit(1)
} else {
Expand Down Expand Up @@ -201,7 +200,6 @@ export default class RunCommand extends BaseCommand {

// Set the configurations as environmental variables
configurations.forEach((config) => {
console.log(config.name, config.value)
this.processEnvironmentalVariables[config.name] = config.value
})
}
Expand Down

0 comments on commit f561f76

Please sign in to comment.