Skip to content

Commit

Permalink
Migrate POST /v1/secret/:workspaceId to /v2/workspace/:workspaceId/se…
Browse files Browse the repository at this point in the history
…crets and cleared room for /v2 secret routes
  • Loading branch information
dangtony98 committed Dec 27, 2022
1 parent 924e3d7 commit f93594b
Show file tree
Hide file tree
Showing 8 changed files with 315 additions and 117 deletions.
8 changes: 4 additions & 4 deletions backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ if (NODE_ENV === 'production') {
app.use(helmet());
}

// (EE) routers
// (EE) routes
app.use('/api/v1/secret', eeSecretRouter);
app.use('/api/v1/workspace', eeWorkspaceRouter);

Expand All @@ -89,9 +89,9 @@ app.use('/api/v1/stripe', v1StripeRouter);
app.use('/api/v1/integration', v1IntegrationRouter);
app.use('/api/v1/integration-auth', v1IntegrationAuthRouter);

// v2 routes (new)
app.use('/api/v1/workspace', v2WorkspaceRouter);
app.use('/api/v1/secret', v2SecretRouter);
// v2 routes
app.use('/api/v2/workspace', v2WorkspaceRouter);
app.use('/api/v2/secret', v2SecretRouter);


//* Handle unrouted requests and respond with proper error message as well as status code
Expand Down
2 changes: 1 addition & 1 deletion backend/src/controllers/v1/secretController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Request, Response } from 'express';
import * as Sentry from '@sentry/node';
import { Key, Secret } from '../../models';
import {
pushSecrets as push,
v1PushSecrets as push,
pullSecrets as pull,
reformatPullSecrets
} from '../../helpers/secret';
Expand Down
35 changes: 20 additions & 15 deletions backend/src/controllers/v2/workspaceController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
deleteWorkspace as deleteWork
} from '../../helpers/workspace';
import {
pushSecrets as push,
v2PushSecrets as push,
pullSecrets as pull,
reformatPullSecrets
} from '../../helpers/secret';
Expand All @@ -24,17 +24,20 @@ import { addMemberships } from '../../helpers/membership';
import { postHogClient, EventService } from '../../services';
import { eventPushSecrets } from '../../events';
import { ADMIN, COMPLETED, GRANTED, ENV_SET } from '../../variables';

interface PushSecret {
ciphertextKey: string;
ivKey: string;
tagKey: string;
hashKey: string;
ciphertextValue: string;
ivValue: string;
tagValue: string;
hashValue: string;
type: 'shared' | 'personal';
interface V2PushSecret {
type: string; // personal or shared
secretKeyCiphertext: string;
secretKeyIV: string;
secretKeyTag: string;
secretKeyHash: string;
secretValueCiphertext: string;
secretValueIV: string;
secretValueTag: string;
secretValueHash: string;
secretCommentCiphertext?: string;
secretCommentIV?: string;
secretCommentTag?: string;
secretCommentHash?: string;
}

/**
Expand Down Expand Up @@ -364,11 +367,11 @@ export const getWorkspaceServiceTokens = async (
* @param res
* @returns
*/
export const pushSecrets = async (req: Request, res: Response) => {
export const pushWorkspaceSecrets = async (req: Request, res: Response) => {
// upload (encrypted) secrets to workspace with id [workspaceId]

try {
let { secrets }: { secrets: PushSecret[] } = req.body;
let { secrets }: { secrets: V2PushSecret[] } = req.body;
const { keys, environment, channel } = req.body;
const { workspaceId } = req.params;

Expand All @@ -379,7 +382,7 @@ export const pushSecrets = async (req: Request, res: Response) => {

// sanitize secrets
secrets = secrets.filter(
(s: PushSecret) => s.ciphertextKey !== '' && s.ciphertextValue !== ''
(s: V2PushSecret) => s.secretKeyCiphertext !== '' && s.secretValueCiphertext !== ''
);

await push({
Expand Down Expand Up @@ -437,6 +440,8 @@ export const pushSecrets = async (req: Request, res: Response) => {
* @returns
*/
export const pullSecrets = async (req: Request, res: Response) => {
// TODO: only return secrets, do not return workspace key

let secrets;
let key;
try {
Expand Down
1 change: 0 additions & 1 deletion backend/src/helpers/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
decryptSymmetric,
decryptAsymmetric
} from '../utils/crypto';
import { decryptSecrets } from '../helpers/secret';
import { ENCRYPTION_KEY } from '../config';
import { SECRET_SHARED } from '../variables';

Expand Down
Loading

0 comments on commit f93594b

Please sign in to comment.