-
-
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
Showing
29 changed files
with
617 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
pnpm lint && pnpm format && pnpm test:api && pnpm test:api-client | ||
pnpm lint && pnpm format |
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
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,30 @@ | ||
import BaseCommand from '@/commands/base.command' | ||
import CreateWorkspace from '@/commands/workspace/create.workspace' | ||
import DeleteWorkspace from '@/commands/workspace/delete.workspace' | ||
import ExportWorkspace from '@/commands/workspace/export.workspace' | ||
import GetWorkspace from '@/commands/workspace/get.workspace' | ||
import ListWorkspace from '@/commands/workspace/list.workspace' | ||
import SearchWorkspace from '@/commands/workspace/search.workspace' | ||
import UpdateWorkspace from '@/commands/workspace/update.workspace' | ||
|
||
export default class WorkspaceCommand extends BaseCommand { | ||
getName(): string { | ||
return 'workspace' | ||
} | ||
|
||
getDescription(): string { | ||
return 'Manages the workspaces on keyshade' | ||
} | ||
|
||
getSubCommands(): BaseCommand[] { | ||
return [ | ||
new CreateWorkspace(), | ||
new DeleteWorkspace(), | ||
new ExportWorkspace(), | ||
new GetWorkspace(), | ||
new ListWorkspace(), | ||
new SearchWorkspace(), | ||
new UpdateWorkspace() | ||
] | ||
} | ||
} |
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,71 @@ | ||
import BaseCommand from '@/commands/base.command' | ||
import { | ||
type CommandActionData, | ||
type CommandOption | ||
} from '@/types/command/command.types' | ||
import ControllerInstance from '@/util/controller-instance' | ||
import { Logger } from '@/util/logger' | ||
import { text } from '@clack/prompts' | ||
|
||
export default class CreateWorkspace extends BaseCommand { | ||
getName(): string { | ||
return 'create' | ||
} | ||
|
||
getDescription(): string { | ||
return 'Creates a new workspace' | ||
} | ||
|
||
getOptions(): CommandOption[] { | ||
return [ | ||
{ | ||
short: '-n', | ||
long: '--name <Workspace Name>', | ||
description: 'Name of the workspace.' | ||
}, | ||
{ | ||
short: '-i', | ||
long: '--icon <Workspace Icon>', | ||
description: 'Icon of the workspace.' | ||
} | ||
] | ||
} | ||
|
||
async action({ options }: CommandActionData): Promise<void> { | ||
const { name, icon } = await this.parseInput(options) | ||
|
||
const { data, error, success } = | ||
await ControllerInstance.getInstance().workspaceController.createWorkspace( | ||
{ | ||
name, | ||
icon | ||
}, | ||
this.headers | ||
) | ||
|
||
if (success) { | ||
Logger.info(`Workspace ${data.name} (${data.slug}) created successfully!`) | ||
Logger.info(`Created at ${data.createdAt}`) | ||
Logger.info(`Updated at ${data.updatedAt}`) | ||
} else { | ||
Logger.error(`Failed to create workspace: ${error.message}`) | ||
} | ||
} | ||
|
||
private async parseInput(options: CommandActionData['options']): Promise<{ | ||
name: string | ||
icon?: string | ||
}> { | ||
let { name } = options | ||
const { icon } = options | ||
|
||
if (!name) { | ||
name = await text({ | ||
message: 'Enter the name of the Workspace', | ||
placeholder: 'My Workspace' | ||
}) | ||
} | ||
|
||
return { name, icon } | ||
} | ||
} |
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 BaseCommand from '@/commands/base.command' | ||
import { | ||
type CommandActionData, | ||
type CommandArgument | ||
} from '@/types/command/command.types' | ||
import ControllerInstance from '@/util/controller-instance' | ||
import { Logger } from '@/util/logger' | ||
|
||
export default class DeleteWorkspace extends BaseCommand { | ||
getName(): string { | ||
return 'delete' | ||
} | ||
|
||
getDescription(): string { | ||
return 'Deletes an existing workspace' | ||
} | ||
|
||
getArguments(): CommandArgument[] { | ||
return [ | ||
{ | ||
name: '<Workspace Slug>', | ||
description: 'Slug of the workspace which you want to delete.' | ||
} | ||
] | ||
} | ||
|
||
async action({ args }: CommandActionData): Promise<void> { | ||
const [workspaceSlug] = args | ||
|
||
const { error, success } = | ||
await ControllerInstance.getInstance().workspaceController.deleteWorkspace( | ||
{ | ||
workspaceSlug | ||
}, | ||
this.headers | ||
) | ||
|
||
if (success) { | ||
Logger.info(`Workspace ${workspaceSlug} deleted successfully!`) | ||
} else { | ||
Logger.error(`Failed to delete workspace: ${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,68 @@ | ||
import BaseCommand from '@/commands/base.command' | ||
import { | ||
type CommandActionData, | ||
type CommandArgument, | ||
type CommandOption | ||
} from '@/types/command/command.types' | ||
import { Logger } from '@/util/logger' | ||
import ControllerInstance from '@/util/controller-instance' | ||
import { writeFileSync } from 'fs' | ||
|
||
export default class ExportWorkspace extends BaseCommand { | ||
getName(): string { | ||
return 'export' | ||
} | ||
|
||
getDescription(): string { | ||
return 'Exports all projects, environments, secrets, variables and roles of a workspace' | ||
} | ||
|
||
getArguments(): CommandArgument[] { | ||
return [ | ||
{ | ||
name: '<Workspace Slug>', | ||
description: 'Slug of the workspace which you want to export.' | ||
} | ||
] | ||
} | ||
|
||
getOptions(): CommandOption[] { | ||
return [ | ||
{ | ||
short: '-s', | ||
long: '--save-to-file <file>', | ||
description: 'Saves the exported data to a file.' | ||
} | ||
] | ||
} | ||
|
||
async action({ args, options }: CommandActionData): Promise<void> { | ||
const [workspaceSlug] = args | ||
const { saveToFile } = options as { saveToFile: string } | ||
|
||
Logger.info('Exporting workspace...') | ||
|
||
const { data, error, success } = | ||
await ControllerInstance.getInstance().workspaceController.exportWorkspaceData( | ||
{ | ||
workspaceSlug | ||
}, | ||
this.headers | ||
) | ||
|
||
if (success) { | ||
if (saveToFile) { | ||
const filePath = saveToFile | ||
const fileContent = JSON.stringify(data, null, 2) | ||
|
||
writeFileSync(saveToFile, fileContent) | ||
|
||
Logger.info(`Workspace exported to file: ${filePath}`) | ||
} else { | ||
Logger.info(JSON.stringify(data)) | ||
} | ||
} else { | ||
Logger.error(`Failed exporting workspace: ${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,50 @@ | ||
import BaseCommand from '@/commands/base.command' | ||
import { | ||
type CommandActionData, | ||
type CommandArgument | ||
} from '@/types/command/command.types' | ||
import { Logger } from '@/util/logger' | ||
import ControllerInstance from '@/util/controller-instance' | ||
|
||
export default class GetWorkspace extends BaseCommand { | ||
getName(): string { | ||
return 'get' | ||
} | ||
|
||
getDescription(): string { | ||
return 'Fetches a particular workspace' | ||
} | ||
|
||
getArguments(): CommandArgument[] { | ||
return [ | ||
{ | ||
name: '<Workspace Slug>', | ||
description: 'Slug of the workspace which you want to fetch.' | ||
} | ||
] | ||
} | ||
|
||
async action({ args }: CommandActionData): Promise<void> { | ||
const [workspaceSlug] = args | ||
|
||
Logger.info('Fetching workspace...') | ||
|
||
const { data, error, success } = | ||
await ControllerInstance.getInstance().workspaceController.getWorkspace( | ||
{ | ||
workspaceSlug | ||
}, | ||
this.headers | ||
) | ||
|
||
if (success) { | ||
Logger.info('Workspace fetched successfully:') | ||
Logger.info(`Workspace: ${data.name} (${data.slug})`) | ||
Logger.info(`Created at: ${data.createdAt}`) | ||
Logger.info(`Updated at: ${data.updatedAt}`) | ||
Logger.info(`Is default workspace: ${data.isDefault}`) | ||
} else { | ||
Logger.error(`Failed fetching workspace: ${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,31 @@ | ||
import BaseCommand from '@/commands/base.command' | ||
import { Logger } from '@/util/logger' | ||
import ControllerInstance from '@/util/controller-instance' | ||
|
||
export default class ListWorkspace extends BaseCommand { | ||
getName(): string { | ||
return 'list' | ||
} | ||
|
||
getDescription(): string { | ||
return 'Fetches all the workspace you have access to' | ||
} | ||
|
||
async action(): Promise<void> { | ||
Logger.info('Fetching all workspaces...') | ||
|
||
const { success, data, error } = | ||
await ControllerInstance.getInstance().workspaceController.getWorkspacesOfUser( | ||
{}, | ||
this.headers | ||
) | ||
|
||
if (success) { | ||
data.items.forEach((workspace: any) => { | ||
Logger.info(`- ${workspace.name} (${workspace.slug})`) | ||
}) | ||
} else { | ||
Logger.error(`Failed fetching workspaces: ${error.message}`) | ||
} | ||
} | ||
} |
Oops, something went wrong.