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 6 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
25 changes: 25 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,25 @@
import BaseCommand from './base.command'
import { CreateEnvironment } from './environment/create.env'
import { DeleteEnvironment } from './environment/delete.env'
import { GetEnvironment } from './environment/get.env'
import { ListEnvironment } from './environment/list.env'
import { UpdateEnvironment } from './environment/update.env'

export 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()
]
}
}
84 changes: 84 additions & 0 deletions apps/cli/src/commands/environment/create.env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import BaseCommand from '../base.command'
import Logger from '../../util/logger'
import EnvironmentController from '../../http/project'
import {
CommandActionData,
CommandOption
} from 'src/types/command/command.types'
import { EnvironmentData } from 'src/types/command/environment.types'
import {text} from '@clack/prompts'
export class CreateEnvironment extends BaseCommand {
private environmentController = new EnvironmentController()

getName(): string {
return 'create'
}

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

getOptions(): CommandOption[] {
return []
rajdip-b marked this conversation as resolved.
Show resolved Hide resolved
}

vr-varad marked this conversation as resolved.
Show resolved Hide resolved
async action({ options, args }: CommandActionData): Promise<void> {
const [project_id] = args
const {name, description} = await this.parseInput(options)

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

const baseUrl = this.baseUrl
const apiKey = this.apiKey

const environmentData: EnvironmentData = {
rajdip-b marked this conversation as resolved.
Show resolved Hide resolved
name: name,
description: description
}

vr-varad marked this conversation as resolved.
Show resolved Hide resolved
try {
const createdEnvironment =
await this.environmentController.createEnvironment(
baseUrl,
apiKey,
project_id,
environmentData
)
Logger.log(`Created environment:`)
Logger.log(`- Name: ${createdEnvironment.name}`)
Logger.log(`- ID: ${createdEnvironment.id}`)
Logger.log(`- API Key: ${createdEnvironment.apiKey}`)
Logger.log(`- Base URL: ${createdEnvironment.baseUrl}`)
} catch (error) {
Logger.error(error.message)
}
}

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

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

let apiKey = this.apiKey as string | symbol;

if (!apiKey) {
rajdip-b marked this conversation as resolved.
Show resolved Hide resolved
apiKey = await text({
message: 'Enter the private key for the profile',
placeholder: 'ks_************'
})
}

return { name,description }
}
}
46 changes: 46 additions & 0 deletions apps/cli/src/commands/environment/delete.env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import BaseCommand from '../base.command'
import Logger from '../../util/logger'
import EnvironmentController from '../../http/project'
import {
CommandActionData,
CommandOption
} from 'src/types/command/command.types'

export class DeleteEnvironment extends BaseCommand {
private environmentController = new EnvironmentController()

getName(): string {
return 'delete'
}

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

getOptions(): CommandOption[] {
return []
}

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

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

const baseUrl = process.env.BASE_URL
const apiKey = process.env.API_KEY

try {
await this.environmentController.deleteEnvironment(
baseUrl,
apiKey,
environment_id
)
Logger.log(`Environment ${environment_id} has been deleted successfully.`)
} catch (error) {
Logger.error(error.message)
}
}
}
48 changes: 48 additions & 0 deletions apps/cli/src/commands/environment/get.env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import BaseCommand from '../base.command'
import Logger from '../../util/logger'
import EnvironmentController from '../../http/project'
import {
CommandActionData,
CommandOption
} from 'src/types/command/command.types'

export class GetEnvironment extends BaseCommand {
private environmentController = new EnvironmentController()

getName(): string {
return 'get'
}

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

getOptions(): CommandOption[] {
return []
}

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

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

const baseUrl = process.env.BASE_URL
const apiKey = process.env.API_KEY

try {
const environment = await this.environmentController.getEnvironmentById(
baseUrl,
apiKey,
environment_id
)
Logger.log(`Environment ${environment_id}:`)
Logger.log(`- Name: ${environment.name}`)
Logger.log(`- Description: ${environment.description}`)
} catch (error) {
Logger.error(error.message)
}
}
}
57 changes: 57 additions & 0 deletions apps/cli/src/commands/environment/list.env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import BaseCommand from '../base.command'
import Logger from '../../util/logger'
import EnvironmentController from '../../http/project'
import {
CommandActionData,
CommandOption
} from 'src/types/command/command.types'

export class ListEnvironment extends BaseCommand {
private environmentController = new EnvironmentController()

getName(): string {
return 'list'
}

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

getOptions(): CommandOption[] {
return []
}

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

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

const baseUrl = process.env.BASE_URL
const apiKey = process.env.API_KEY

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

try {
const environments =
await this.environmentController.getAllEnvironmentByProjectId(
baseUrl,
apiKey,
project
)
Logger.log(`Environments for project ${project}:`)
environments.forEach((environment: any) => {
Logger.log(
`- ${environment.name} (Description: ${environment.description})`
)
})
} catch (error) {
Logger.error(error.message)
}
}
}
55 changes: 55 additions & 0 deletions apps/cli/src/commands/environment/update.env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import BaseCommand from '../base.command'
import Logger from '../../util/logger'
import EnvironmentController from '../../http/project'
import {
CommandActionData,
CommandOption
} from 'src/types/command/command.types'
import { EnvironmentData } from 'src/types/command/environment.types'

export class UpdateEnvironment extends BaseCommand {
private environmentController = new EnvironmentController()

getName(): string {
return 'update'
}
getDescription(): string {
return 'Update a environment'
}

getOptions(): CommandOption[] {
return []
}

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

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

const baseUrl = process.env.BASE_URL
const apiKey = process.env.API_KEY

const environmentData: EnvironmentData = {
name: '',
description: ''
}

try {
const environments = await this.environmentController.updateEnvironment(
baseUrl,
apiKey,
environment_id,
environmentData
)
Logger.log(`Environments for project ${environment_id}:`)
environments.forEach((environment: any) => {
Logger.log(`- ${environment.name} (ID: ${environment.id})`)
})
} catch (error) {
Logger.error(error.message)
}
}
}
8 changes: 7 additions & 1 deletion apps/cli/src/http/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import SecretController from './secret'
import VariableController from './variable'
import AuthController from './auth'
import EnvironmentController from './project'

export { SecretController, VariableController, AuthController }
export {
SecretController,
VariableController,
AuthController,
EnvironmentController
}
Loading