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 31 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
13 changes: 11 additions & 2 deletions apps/api/src/user/service/user.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import { ConflictException, Inject, Injectable, Logger, UnauthorizedException } from '@nestjs/common'
import {
ConflictException,
Inject,
Injectable,
Logger,
UnauthorizedException
} from '@nestjs/common'
import { UpdateUserDto } from '../dto/update.user/update.user'
import { AuthProvider, User } from '@prisma/client'
import { PrismaService } from '../../prisma/prisma.service'
import { CreateUserDto } from '../dto/create.user/create.user'
import { IMailService, MAIL_SERVICE } from '../../mail/services/interface.service'
import {
IMailService,
MAIL_SERVICE
} from '../../mail/services/interface.service'
import createUser from '../../common/create-user'
import generateOtp from '../../common/generate-otp'
import { EnvSchema } from '../../common/env/env.schema'
Expand Down
4 changes: 3 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,7 +24,8 @@
"fs": "0.0.1-security",
"nodemon": "^3.1.4",
"socket.io-client": "^4.7.5",
"typescript": "^5.5.2"
"typescript": "^5.5.2",
"@keyshade/api-client": "workspace:*"
},
"devDependencies": {
"@swc/cli": "^0.4.0",
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 { spinner, text, intro, outro } 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: '--desc <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) {
console.error('Project ID is required')
return
}

const apiKey = this.apiKey

const environmentData = {
name,
description,
projectId
}

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

const spin = spinner()
try {
intro('Creating Environment')
const createdEnvironment = await EnvironmentController.createEnvironment(
environmentData,
headers
)
spin.message(`- Name: ${createdEnvironment.name}`)
vr-varad marked this conversation as resolved.
Show resolved Hide resolved
spin.message(`- ID: ${createdEnvironment.id}`)
vr-varad marked this conversation as resolved.
Show resolved Hide resolved
outro('Environment Created Successfully.')
spin.stop()
} catch (error) {
Logger.error(error.message as string)
}
}

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 }
}
}
53 changes: 53 additions & 0 deletions apps/cli/src/commands/environment/delete.environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import BaseCommand from '../base.command'
import { intro, outro } from '@clack/prompts'
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) {
console.error('Environment ID is required')
return
}

const apiKey = this.apiKey

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

try {
intro('Deleting Environment..')
await EnvironmentController.deleteEnvironment(
{ id: environmentId },
headers
)
outro(`Environment ${environmentId} has been deleted successfully.`)
} catch (error) {
Logger.info(error.message as string)
}
}
}
58 changes: 58 additions & 0 deletions apps/cli/src/commands/environment/get.environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Logger } from '@/util/logger'
import BaseCommand from '../base.command'
import { spinner, intro, outro } from '@clack/prompts'
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) {
console.error('Environment ID is required')
return
}

const apiKey = this.apiKey

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

const spin = spinner()
try {
intro('Getting Environment...')
const environment = await EnvironmentController.getEnvironmentById(
{ id: environmentId },
headers
)
spin.start(`Environment ${environmentId}:`)
vr-varad marked this conversation as resolved.
Show resolved Hide resolved
spin.message(`- Name: ${environment.name}`)
vr-varad marked this conversation as resolved.
Show resolved Hide resolved
spin.message(`- Description: ${environment.description}`)
outro('Successfully Fetched the Environment.')
spin.stop()
} catch (error) {
Logger.error(error.message as string)
}
}
}
66 changes: 66 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,66 @@
import BaseCommand from '../base.command'
import { EnvironmentController } from '@keyshade/api-client'
import { intro, spinner, outro } from '@clack/prompts'
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) {
console.error('Project ID is required')
return
}

const apiKey = this.apiKey

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

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

intro(`Fetching environments for project ${projectId}...`)

const spin = spinner()

try {
intro(`Getting all Environment for Project ${projectId}`)
const environments =
await EnvironmentController.getAllEnvironmentsOfProject(
{ projectId },
headers
)
spin.start(`Environments for project ${projectId}:`)
spin.message(JSON.stringify(environments))
outro('Fetched all Environments.')
spin.stop()
} catch (error) {
Logger.error(error.message as string)
}
}
}
Loading