Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): Add functionality to operate on Environments #324

Merged
merged 39 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
9bcb60e
Initial Commit on Environment Implementation
Jul 6, 2024
48e962f
merge develop
Jul 8, 2024
417d7f3
Basic Structure of Environment Cli Command
Jul 8, 2024
7e4ad56
Added List Environment Implementation
Jul 9, 2024
bfb5535
Commands Done with some errors
Jul 10, 2024
c4baa7d
Debugging CreateEnv
Jul 11, 2024
4e08865
Added Api-Client Controllers
Jul 11, 2024
f82577f
Some minor changes
Jul 12, 2024
d2d47bf
Merge branch 'develop' into cli/env
Jul 12, 2024
465d1b9
Merge branch 'develop' into cli/env
rajdip-b Jul 12, 2024
b71b3e8
fixed errors
rajdip-b Jul 12, 2024
b896220
Merge branch 'develop' into cli/env
Jul 13, 2024
964f688
Merge branch 'keyshade-xyz:develop' into cli/env
vr-varad Jul 16, 2024
2a64e93
Merge branch 'develop' into cli/env
Jul 16, 2024
44d9d6c
Merge branch 'cli/env' of https://github.com/vr-varad/keyshade into c…
Jul 16, 2024
ba5ea23
Added Environment controller via api-client
Jul 16, 2024
b0b56c3
Merge branch 'keyshade-xyz:develop' into cli/env
vr-varad Jul 17, 2024
1cd9430
Added Requested Changes
Jul 17, 2024
6791f26
Added GetArguments for Environment Subcommmands
Jul 17, 2024
b7a5c50
Added Options for Environment Subcommmands
Jul 17, 2024
5f4c91c
Merge branch 'keyshade-xyz:develop' into cli/env
vr-varad Jul 17, 2024
bbcaac8
Resolving Errors
Jul 17, 2024
0f64321
Merge branch 'develop' into cli/env
rajdip-b Jul 18, 2024
7e601df
Merge remote-tracking branch 'varad/cli/env' into cli/env
rajdip-b Jul 18, 2024
940db1a
Merge branch 'keyshade-xyz:develop' into cli/env
vr-varad Jul 21, 2024
55ce8b8
Merge branch 'keyshade-xyz:develop' into cli/env
vr-varad Jul 23, 2024
498a79f
Resolving Errors As suggested
Jul 23, 2024
3ec251c
Merge branch 'cli/env' of https://github.com/vr-varad/keyshade into c…
Jul 23, 2024
8a99095
Merge branch 'keyshade-xyz:develop' into cli/env
vr-varad Jul 27, 2024
ac905bf
Fine Tuning
Jul 29, 2024
b9a451b
Resolved Issues
Jul 30, 2024
533aad0
Spinner and Logger
Jul 31, 2024
fcc9619
Resolving Merge conflict
Jul 31, 2024
7551597
Spinner Issues
Jul 31, 2024
c8fef77
Resolving Merge Conflict
Jul 31, 2024
665feba
Merge branch 'develop' into cli/env
rajdip-b Jul 31, 2024
6082a9e
fixed errors
rajdip-b Jul 31, 2024
93d61a5
Merge branch 'develop' into cli/env
rajdip-b Jul 31, 2024
b2d4a69
finishing up
rajdip-b Jul 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apps/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.0",
"description": "CLI for keyshade",
"main": "index.js",
"private": false,
"type": "commonjs",
"scripts": {
"build": "swc src --out-dir dist",
Expand All @@ -23,13 +24,15 @@
"figlet": "^1.7.0",
"fs": "0.0.1-security",
"nodemon": "^3.1.4",
"socket.io-client": "^4.7.5"
"socket.io-client": "^4.7.5",
"@keyshade/api-client": "workspace:../../packages/api-client"
},
"devDependencies": {
"@swc/cli": "^0.4.0",
"@swc/core": "^1.6.13",
"@types/cli-table": "^0.3.4",
"@types/figlet": "^1.5.8",
"@types/eccrypto": "^1.1.6",
"@types/node": "^20.14.10",
"eslint-config-standard-with-typescript": "^43.0.1"
}
Expand Down
26 changes: 26 additions & 0 deletions apps/cli/src/commands/environment.command.ts
vr-varad marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import BaseCommand from './base.command'
import { CreateEnvironment } from './environment/create.environment'
import { DeleteEnvironment } from './environment/delete.environment'
import { GetEnvironment } from './environment/get.environment'
import { ListEnvironment } from './environment/list.environment'
import { UpdateEnvironment } from './environment/update.environment'

export default class EnvironmentCommand extends BaseCommand {
getName(): string {
return 'environment'
}

getDescription(): string {
return 'Manage your environments in keyshade.'
}

getSubCommands(): BaseCommand[] {
return [
new CreateEnvironment(),
new DeleteEnvironment(),
new GetEnvironment(),
new ListEnvironment(),
new UpdateEnvironment()
]
}
}
97 changes: 97 additions & 0 deletions apps/cli/src/commands/environment/create.environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import BaseCommand from '../base.command'
import { text } from '@clack/prompts'
import {
type CommandActionData,
type CommandArgument,
type CommandOption
} from 'src/types/command/command.types'
import { EnvironmentController } from '@keyshade/api-client'
import { Logger } from '@/util/logger'
export class CreateEnvironment extends BaseCommand {
getName(): string {
return 'create'
}

getDescription(): string {
return 'Create a new environment'
}

getOptions(): CommandOption[] {
return [
{
short: '-n',
long: '--name <string>',
description: 'Name of the Environment'
},
{
short: '-d',
long: '--description <string>',
description: 'Description about the Environment'
}
]
}

getArguments(): CommandArgument[] {
return [
{
name: '<Project ID>',
description:
'ID of the project under which you want to add the environment'
}
]
}

async action({ options, args }: CommandActionData): Promise<void> {
const [projectId] = args
const { name, description } = await this.parseInput(options)

if (!projectId) {
Logger.error('Project ID is required')
return
}

const apiKey = this.apiKey

const environmentData = {
name,
description,
projectId
}

const headers = {
'x-keyshade-token': apiKey
}

const environmentController = new EnvironmentController(this.baseUrl)
Logger.info('Creating Environment...')

const {
data: environment,
error,
success
} = await environmentController.createEnvironment(environmentData, headers)

if (success) {
Logger.info(`Environment created:${environment.name} (${environment.id})`)
} else {
Logger.error(`Failed to create environment: ${error.message}`)
}
}

private async parseInput(options: CommandActionData['options']): Promise<{
name: string
description?: string
}> {
let { name } = options
const { description } = options

if (!name) {
name = await text({
message: 'Enter the name of the Environment',
placeholder: 'env'
})
}

return { name, description }
}
}
55 changes: 55 additions & 0 deletions apps/cli/src/commands/environment/delete.environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import BaseCommand from '../base.command'
import { EnvironmentController } from '@keyshade/api-client'
import {
type CommandActionData,
type CommandArgument
} from 'src/types/command/command.types'
import { Logger } from '@/util/logger'

export class DeleteEnvironment extends BaseCommand {
getName(): string {
return 'delete'
}

getDescription(): string {
return 'Delete an environment'
}

getArguments(): CommandArgument[] {
return [
{
name: '<Environment ID>',
description: 'ID of the environment which you want to delete.'
}
]
}

async action({ args }: CommandActionData): Promise<void> {
const [environmentId] = args

if (!environmentId) {
Logger.error('Environment ID is required')
return
}

const apiKey = this.apiKey

const headers = {
'x-keyshade-token': apiKey
}

const environmentController = new EnvironmentController(this.baseUrl)
Logger.info('Deleting Environment...')

vr-varad marked this conversation as resolved.
Show resolved Hide resolved
const { success, error } = await environmentController.deleteEnvironment(
{ id: environmentId },
headers
)

if (success) {
Logger.info('Environment deleted successfully')
} else {
Logger.error(error.message)
}
}
}
62 changes: 62 additions & 0 deletions apps/cli/src/commands/environment/get.environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Logger } from '@/util/logger'
import BaseCommand from '../base.command'
import { EnvironmentController } from '@keyshade/api-client'
import {
type CommandActionData,
type CommandArgument
} from 'src/types/command/command.types'

export class GetEnvironment extends BaseCommand {
getName(): string {
return 'get'
}

getDescription(): string {
return 'Get an environment'
}

getArguments(): CommandArgument[] {
return [
{
name: '<Environment ID>',
description: 'ID of the environment which you want to fetch.'
}
]
}

async action({ args }: CommandActionData): Promise<void> {
const [environmentId] = args

if (!environmentId) {
Logger.error('Environment ID is required')
return
}

const apiKey = this.apiKey

const headers = {
'x-keyshade-token': apiKey
}

const environmentController = new EnvironmentController(this.baseUrl)
Logger.info('Fetching Environment...')

const {
success,
error,
data: environment
} = await environmentController.getEnvironmentById(
{ id: environmentId },
headers
)

if (success) {
Logger.info('Environment fetched successfully:')
Logger.info(
`Environment ID: ${environment.id}, Name: ${environment.name}, Description: ${environment.description}`
)
} else {
Logger.error(error.message)
}
}
}
69 changes: 69 additions & 0 deletions apps/cli/src/commands/environment/list.environment.ts
vr-varad marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import BaseCommand from '../base.command'
import { EnvironmentController } from '@keyshade/api-client'
import {
type CommandActionData,
type CommandArgument
} from 'src/types/command/command.types'
import { Logger } from '@/util/logger'

export class ListEnvironment extends BaseCommand {
getName(): string {
return 'list'
}

getDescription(): string {
return 'List all environments under a project'
}

getArguments(): CommandArgument[] {
return [
{
name: '<Project ID>',
description: 'ID of the project whose environments you want.'
}
]
}

async action({ args }: CommandActionData): Promise<void> {
const [projectId] = args

if (!projectId) {
Logger.error('Project ID is required')
return
}

const apiKey = this.apiKey

const headers = {
'x-keyshade-token': apiKey
}

if (!apiKey) {
Logger.error('Base URL and API Key must be set as environment variables')
return
}

const environmentController = new EnvironmentController(this.baseUrl)
Logger.info('Fetching all environments...')

const {
success,
data: environments,
error
} = await environmentController.getAllEnvironmentsOfProject(
{ projectId },
headers
)

if (success) {
Logger.info('Fetched environments:')
environments.items.forEach((environment) => {
Logger.info(
`- ID: ${environment.id}, Name: ${environment.name}, Description: ${environment.description}`
)
})
} else {
Logger.error(`Failed to fetch environments: ${error.message}`)
}
}
}
Loading
Loading