Skip to content

Commit

Permalink
Allow empty values for secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
dangtony98 committed Jan 27, 2023
1 parent d09b406 commit 13acb19
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
28 changes: 15 additions & 13 deletions backend/src/controllers/v2/secretsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,21 @@ export const createSecrets = async (req: Request, res: Response) => {
secretValueCiphertext: string;
secretValueIV: string;
secretValueTag: string;
}) => ({
version: 1,
workspace: new Types.ObjectId(workspaceId),
type,
user: type === SECRET_PERSONAL ? req.user : undefined,
environment,
secretKeyCiphertext,
secretKeyIV,
secretKeyTag,
secretValueCiphertext,
secretValueIV,
secretValueTag
}))
}) => {
return ({
version: 1,
workspace: new Types.ObjectId(workspaceId),
type,
user: type === SECRET_PERSONAL ? req.user : undefined,
environment,
secretKeyCiphertext,
secretKeyIV,
secretKeyTag,
secretValueCiphertext,
secretValueIV,
secretValueTag
});
})
);

setTimeout(async () => {
Expand Down
5 changes: 4 additions & 1 deletion backend/src/helpers/database.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import mongoose from 'mongoose';
import { ISecret, Secret } from '../models';
import { EESecretService } from '../ee/services';
import { getLogger } from '../utils/logger';

Expand All @@ -16,6 +15,10 @@ const initDatabaseHelper = async ({
}) => {
try {
await mongoose.connect(mongoURL);

// allow empty strings to pass the required validator
mongoose.Schema.Types.String.checkRequired(v => typeof v === 'string');

getLogger("database").info("Database connection established");

await EESecretService.initSecretVersioning();
Expand Down
2 changes: 1 addition & 1 deletion backend/src/routes/v2/secrets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ router.post(
!secret.secretKeyCiphertext ||
!secret.secretKeyIV ||
!secret.secretKeyTag ||
!secret.secretValueCiphertext ||
(typeof secret.secretValueCiphertext !== 'string') ||
!secret.secretValueIV ||
!secret.secretValueTag
) {
Expand Down

0 comments on commit 13acb19

Please sign in to comment.