mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 22:46:24 +00:00
Complete v1 API reference docs, pre-launch
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import express, { Response, Request } from 'express';
|
||||
const router = express.Router();
|
||||
import { body, param } from 'express-validator';
|
||||
import { environmentController } from '../../controllers/v2';
|
||||
import {
|
||||
requireAuth,
|
||||
requireWorkspaceAuth,
|
||||
validateRequest,
|
||||
} from '../../middleware';
|
||||
import { ADMIN, MEMBER } from '../../variables';
|
||||
|
||||
router.post(
|
||||
'/:workspaceId/environments',
|
||||
requireAuth({
|
||||
acceptedAuthModes: ['jwt'],
|
||||
}),
|
||||
requireWorkspaceAuth({
|
||||
acceptedRoles: [ADMIN, MEMBER],
|
||||
}),
|
||||
param('workspaceId').exists().trim(),
|
||||
body('environmentSlug').exists().trim(),
|
||||
body('environmentName').exists().trim(),
|
||||
validateRequest,
|
||||
environmentController.createWorkspaceEnvironment
|
||||
);
|
||||
|
||||
router.put(
|
||||
'/:workspaceId/environments',
|
||||
requireAuth({
|
||||
acceptedAuthModes: ['jwt'],
|
||||
}),
|
||||
requireWorkspaceAuth({
|
||||
acceptedRoles: [ADMIN, MEMBER],
|
||||
}),
|
||||
param('workspaceId').exists().trim(),
|
||||
body('environmentSlug').exists().trim(),
|
||||
body('environmentName').exists().trim(),
|
||||
body('oldEnvironmentSlug').exists().trim(),
|
||||
validateRequest,
|
||||
environmentController.renameWorkspaceEnvironment
|
||||
);
|
||||
|
||||
router.delete(
|
||||
'/:workspaceId/environments',
|
||||
requireAuth({
|
||||
acceptedAuthModes: ['jwt'],
|
||||
}),
|
||||
requireWorkspaceAuth({
|
||||
acceptedRoles: [ADMIN],
|
||||
}),
|
||||
param('workspaceId').exists().trim(),
|
||||
body('environmentSlug').exists().trim(),
|
||||
validateRequest,
|
||||
environmentController.deleteWorkspaceEnvironment
|
||||
);
|
||||
|
||||
export default router;
|
||||
@@ -4,6 +4,7 @@ import secrets from './secrets';
|
||||
import workspace from './workspace';
|
||||
import serviceTokenData from './serviceTokenData';
|
||||
import apiKeyData from './apiKeyData';
|
||||
import environment from "./environment"
|
||||
|
||||
export {
|
||||
users,
|
||||
@@ -11,5 +12,6 @@ export {
|
||||
secrets,
|
||||
workspace,
|
||||
serviceTokenData,
|
||||
apiKeyData
|
||||
}
|
||||
apiKeyData,
|
||||
environment
|
||||
}
|
||||
@@ -8,8 +8,8 @@ import {
|
||||
} from '../../middleware';
|
||||
import { query, check, body } from 'express-validator';
|
||||
import { secretsController } from '../../controllers/v2';
|
||||
import {
|
||||
ADMIN,
|
||||
import {
|
||||
ADMIN,
|
||||
MEMBER,
|
||||
SECRET_PERSONAL,
|
||||
SECRET_SHARED
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
router.post(
|
||||
'/',
|
||||
body('workspaceId').exists().isString().trim(),
|
||||
body('environment').exists().isString().trim().isIn(['dev', 'staging', 'prod', 'test']),
|
||||
body('environment').exists().isString().trim(),
|
||||
body('secrets')
|
||||
.exists()
|
||||
.custom((value) => {
|
||||
@@ -27,7 +27,7 @@ router.post(
|
||||
if (value.length === 0) throw new Error('secrets cannot be an empty array')
|
||||
for (const secret of value) {
|
||||
if (
|
||||
!secret.type ||
|
||||
!secret.type ||
|
||||
!(secret.type === SECRET_PERSONAL || secret.type === SECRET_SHARED) ||
|
||||
!secret.secretKeyCiphertext ||
|
||||
!secret.secretKeyIV ||
|
||||
@@ -42,7 +42,7 @@ router.post(
|
||||
} else if (typeof value === 'object') {
|
||||
// case: update 1 secret
|
||||
if (
|
||||
!value.type ||
|
||||
!value.type ||
|
||||
!(value.type === SECRET_PERSONAL || value.type === SECRET_SHARED) ||
|
||||
!value.secretKeyCiphertext ||
|
||||
!value.secretKeyIV ||
|
||||
@@ -52,13 +52,13 @@ router.post(
|
||||
!value.secretValueTag
|
||||
) {
|
||||
throw new Error('secrets object is missing required secret properties');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new Error('secrets must be an object or an array of objects')
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}),
|
||||
}),
|
||||
validateRequest,
|
||||
requireAuth({
|
||||
acceptedAuthModes: ['jwt']
|
||||
@@ -73,7 +73,7 @@ router.post(
|
||||
router.get(
|
||||
'/',
|
||||
query('workspaceId').exists().trim(),
|
||||
query('environment').exists().trim().isIn(['dev', 'staging', 'prod', 'test']),
|
||||
query('environment').exists().trim(),
|
||||
validateRequest,
|
||||
requireAuth({
|
||||
acceptedAuthModes: ['jwt', 'serviceToken']
|
||||
@@ -95,36 +95,24 @@ router.patch(
|
||||
if (value.length === 0) throw new Error('secrets cannot be an empty array')
|
||||
for (const secret of value) {
|
||||
if (
|
||||
!secret.id ||
|
||||
!secret.secretKeyCiphertext ||
|
||||
!secret.secretKeyIV ||
|
||||
!secret.secretKeyTag ||
|
||||
!secret.secretValueCiphertext ||
|
||||
!secret.secretValueIV ||
|
||||
!secret.secretValueTag
|
||||
!secret.id
|
||||
) {
|
||||
throw new Error('secrets array must contain objects that have required secret properties');
|
||||
throw new Error('Each secret must contain a ID property');
|
||||
}
|
||||
}
|
||||
} else if (typeof value === 'object') {
|
||||
// case: update 1 secret
|
||||
if (
|
||||
!value.id ||
|
||||
!value.secretKeyCiphertext ||
|
||||
!value.secretKeyIV ||
|
||||
!value.secretKeyTag ||
|
||||
!value.secretValueCiphertext ||
|
||||
!value.secretValueIV ||
|
||||
!value.secretValueTag
|
||||
!value.id
|
||||
) {
|
||||
throw new Error('secrets object is missing required secret properties');
|
||||
}
|
||||
throw new Error('secret must contain a ID property');
|
||||
}
|
||||
} else {
|
||||
throw new Error('secrets must be an object or an array of objects')
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}),
|
||||
}),
|
||||
validateRequest,
|
||||
requireAuth({
|
||||
acceptedAuthModes: ['jwt']
|
||||
@@ -142,13 +130,13 @@ router.delete(
|
||||
.custom((value) => {
|
||||
// case: delete 1 secret
|
||||
if (typeof value === 'string') return true;
|
||||
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
// case: delete multiple secrets
|
||||
if (value.length === 0) throw new Error('secrets cannot be an empty array');
|
||||
return value.every((id: string) => typeof id === 'string')
|
||||
}
|
||||
|
||||
|
||||
throw new Error('secretIds must be a string or an array of strings');
|
||||
})
|
||||
.not()
|
||||
|
||||
Reference in New Issue
Block a user