-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e26cf51
commit 1f17945
Showing
9 changed files
with
369 additions
and
31 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,44 @@ | ||
import type { | ||
CommandActionData, | ||
CommandArgument | ||
} from '@/types/command/command.types' | ||
import BaseCommand from '@/commands/base.command' | ||
import { Logger } from '@/util/logger' | ||
import ControllerInstance from '@/util/controller-instance' | ||
|
||
export default class DeleteSecret extends BaseCommand { | ||
getName(): string { | ||
return 'delete' | ||
} | ||
|
||
getDescription(): string { | ||
return 'Deletes a secret' | ||
} | ||
|
||
getArguments(): CommandArgument[] { | ||
return [ | ||
{ | ||
name: '<Secret Slug>', | ||
description: 'Slug of the secret that you want to delete.' | ||
} | ||
] | ||
} | ||
|
||
async action({ args }: CommandActionData): Promise<void> { | ||
const [secretSlug] = args | ||
|
||
const { error, success } = | ||
await ControllerInstance.getInstance().secretController.deleteSecret( | ||
{ | ||
secretSlug | ||
}, | ||
this.headers | ||
) | ||
|
||
if (success) { | ||
Logger.info(`Secret ${secretSlug} deleted successfully!`) | ||
} else { | ||
Logger.error(`Failed to delete secret: ${error.message}`) | ||
} | ||
} | ||
} |
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,75 @@ | ||
import type { | ||
CommandActionData, | ||
CommandArgument, | ||
CommandOption | ||
} from '@/types/command/command.types' | ||
import BaseCommand from '@/commands/base.command' | ||
import ControllerInstance from '@/util/controller-instance' | ||
import { Logger } from '@/util/logger' | ||
|
||
export default class GetSecret extends BaseCommand { | ||
getName(): string { | ||
return 'get' | ||
} | ||
|
||
getDescription(): string { | ||
return 'Get all secrets under a project' | ||
} | ||
|
||
getArguments(): CommandArgument[] { | ||
return [ | ||
{ | ||
name: '<Project Slug>', | ||
description: 'Slug of the project whose secrets you want.' | ||
} | ||
] | ||
} | ||
|
||
getOptions(): CommandOption[] { | ||
return [ | ||
{ | ||
short: '-d', | ||
long: '--decrypt-value', | ||
description: | ||
'Set this to true if the project contains the private key. If set to true, the values of the secret will be in plaintext format' | ||
} | ||
] | ||
} | ||
|
||
async action({ args, options }: CommandActionData): Promise<void> { | ||
const [projectSlug] = args | ||
const { decryptValue } = await this.parseInput(options) | ||
const { data, error, success } = | ||
await ControllerInstance.getInstance().secretController.getAllSecretsOfProject( | ||
{ | ||
projectSlug, | ||
decryptValue | ||
}, | ||
this.headers | ||
) | ||
|
||
if (success) { | ||
const secrets = data.items | ||
|
||
if (secrets.length > 0) { | ||
data.items.forEach((item: any) => { | ||
const secret = item.secret | ||
Logger.info(`- ${secret.name} (${secret.slug})`) | ||
}) | ||
} else { | ||
Logger.info('No secrets found') | ||
} | ||
} else { | ||
Logger.error(`Failed fetching secrets: ${error.message}`) | ||
} | ||
} | ||
|
||
private async parseInput(options: CommandActionData['options']): Promise<{ | ||
decryptValue: boolean | ||
}> { | ||
const { decryptValue = false } = options // defaults to false | ||
return { | ||
decryptValue | ||
} | ||
} | ||
} |
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,56 @@ | ||
import type { | ||
CommandActionData, | ||
CommandArgument | ||
} from '@/types/command/command.types' | ||
import BaseCommand from '@/commands/base.command' | ||
import ControllerInstance from '@/util/controller-instance' | ||
import { Logger } from '@/util/logger' | ||
|
||
export default class ListSecret extends BaseCommand { | ||
getName(): string { | ||
return 'list' | ||
} | ||
|
||
getDescription(): string { | ||
return 'List all secrets under a project and environment' | ||
} | ||
|
||
getArguments(): CommandArgument[] { | ||
return [ | ||
{ | ||
name: '<Project Slug>', | ||
description: 'Slug of the project whose secrets you want.' | ||
}, | ||
{ | ||
name: '<Environment Slug>', | ||
description: 'Slug of the environment whose secrets you want.' | ||
} | ||
] | ||
} | ||
|
||
async action({ args }: CommandActionData): Promise<void> { | ||
const [projectSlug, environmentSlug] = args | ||
const { data, error, success } = | ||
await ControllerInstance.getInstance().secretController.getAllSecretsOfEnvironment( | ||
{ | ||
projectSlug, | ||
environmentSlug | ||
}, | ||
this.headers | ||
) | ||
|
||
if (success) { | ||
console.log(data) | ||
const secrets = data | ||
if (secrets.length > 0) { | ||
data.forEach((secret: any) => { | ||
Logger.info(`- ${secret.name} (${secret.value})`) | ||
}) | ||
} else { | ||
Logger.info('No secrets found') | ||
} | ||
} else { | ||
Logger.error(`Failed fetching secrets: ${error.message}`) | ||
} | ||
} | ||
} |
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,62 @@ | ||
import type { | ||
CommandActionData, | ||
CommandArgument | ||
} from '@/types/command/command.types' | ||
import BaseCommand from '@/commands/base.command' | ||
import ControllerInstance from '@/util/controller-instance' | ||
import { Logger } from '@/util/logger' | ||
|
||
export default class FetchSecretRevisions extends BaseCommand { | ||
getName(): string { | ||
return 'revisions' | ||
} | ||
|
||
getDescription(): string { | ||
return 'Fetch all revisions of a secret' | ||
} | ||
|
||
getArguments(): CommandArgument[] { | ||
return [ | ||
{ | ||
name: '<Secret Slug>', | ||
description: 'Slug of the secret whose revisions you want.' | ||
}, | ||
{ | ||
name: '<Environment Slug>', | ||
description: 'Environment slug of the secret whose revisions you want.' | ||
} | ||
] | ||
} | ||
|
||
async action({ args }: CommandActionData): Promise<void> { | ||
const [secretSlug, environmentSlug] = args | ||
|
||
const { data, error, success } = | ||
await ControllerInstance.getInstance().secretController.getRevisionsOfSecret( | ||
{ | ||
secretSlug, | ||
environmentSlug | ||
}, | ||
this.headers | ||
) | ||
|
||
if (success) { | ||
const revisions = data.items | ||
if (revisions.length > 0) { | ||
data.items.forEach((revision: any) => { | ||
Logger.info(`Id ${revision.id}`) | ||
Logger.info(`value ${revision.value}`) | ||
Logger.info(`version ${revision.version}`) | ||
Logger.info(`secretID ${revision.secretId}`) | ||
Logger.info(`Created On ${revision.createdOn}`) | ||
Logger.info(`Created By Id ${revision.createdById}`) | ||
Logger.info(`environmentId ${revision.environmentId}`) | ||
}) | ||
} else { | ||
Logger.info('No revisions found') | ||
} | ||
} else { | ||
Logger.error(`Failed fetching revisions: ${error.message}`) | ||
} | ||
} | ||
} |
Oops, something went wrong.