mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 13:27:46 +00:00
feat(#31): implemented api for environment crud operations
This commit is contained in:
@@ -46,6 +46,7 @@ import {
|
|||||||
workspace as v2WorkspaceRouter,
|
workspace as v2WorkspaceRouter,
|
||||||
serviceTokenData as v2ServiceTokenDataRouter,
|
serviceTokenData as v2ServiceTokenDataRouter,
|
||||||
apiKeyData as v2APIKeyDataRouter,
|
apiKeyData as v2APIKeyDataRouter,
|
||||||
|
environment as v2EnvironmentRouter,
|
||||||
} from './routes/v2';
|
} from './routes/v2';
|
||||||
|
|
||||||
import { healthCheck } from './routes/status';
|
import { healthCheck } from './routes/status';
|
||||||
@@ -108,6 +109,7 @@ app.use('/api/v2/secret', v2SecretRouter); // stop supporting, TODO: revise
|
|||||||
app.use('/api/v2/secrets', v2SecretsRouter);
|
app.use('/api/v2/secrets', v2SecretsRouter);
|
||||||
app.use('/api/v2/service-token', v2ServiceTokenDataRouter); // TODO: turn into plural route
|
app.use('/api/v2/service-token', v2ServiceTokenDataRouter); // TODO: turn into plural route
|
||||||
app.use('/api/v2/api-key-data', v2APIKeyDataRouter);
|
app.use('/api/v2/api-key-data', v2APIKeyDataRouter);
|
||||||
|
app.use('/api/v2/environments', v2EnvironmentRouter);
|
||||||
|
|
||||||
// api docs
|
// api docs
|
||||||
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerFile))
|
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerFile))
|
||||||
|
|||||||
@@ -31,11 +31,17 @@ export const oAuthExchange = async (
|
|||||||
|
|
||||||
if (!INTEGRATION_SET.has(integration))
|
if (!INTEGRATION_SET.has(integration))
|
||||||
throw new Error('Failed to validate integration');
|
throw new Error('Failed to validate integration');
|
||||||
|
|
||||||
|
const environments = req.membership.workspace?.environments || [];
|
||||||
|
if(environments.length === 0){
|
||||||
|
throw new Error("Failed to get environments")
|
||||||
|
}
|
||||||
|
|
||||||
await IntegrationService.handleOAuthExchange({
|
await IntegrationService.handleOAuthExchange({
|
||||||
workspaceId,
|
workspaceId,
|
||||||
integration,
|
integration,
|
||||||
code
|
code,
|
||||||
|
environment: environments[0].slug,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
Sentry.setUser(null);
|
Sentry.setUser(null);
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import {
|
|||||||
import { pushKeys } from '../../helpers/key';
|
import { pushKeys } from '../../helpers/key';
|
||||||
import { eventPushSecrets } from '../../events';
|
import { eventPushSecrets } from '../../events';
|
||||||
import { EventService } from '../../services';
|
import { EventService } from '../../services';
|
||||||
import { ENV_SET } from '../../variables';
|
|
||||||
import { postHogClient } from '../../services';
|
import { postHogClient } from '../../services';
|
||||||
|
|
||||||
interface PushSecret {
|
interface PushSecret {
|
||||||
@@ -44,7 +43,8 @@ export const pushSecrets = async (req: Request, res: Response) => {
|
|||||||
const { workspaceId } = req.params;
|
const { workspaceId } = req.params;
|
||||||
|
|
||||||
// validate environment
|
// validate environment
|
||||||
if (!ENV_SET.has(environment)) {
|
const workspaceEnvs = req.membership.workspace.environments;
|
||||||
|
if (!workspaceEnvs.find(({ slug }: { slug: string }) => slug === environment)) {
|
||||||
throw new Error('Failed to validate environment');
|
throw new Error('Failed to validate environment');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,7 +116,8 @@ export const pullSecrets = async (req: Request, res: Response) => {
|
|||||||
const { workspaceId } = req.params;
|
const { workspaceId } = req.params;
|
||||||
|
|
||||||
// validate environment
|
// validate environment
|
||||||
if (!ENV_SET.has(environment)) {
|
const workspaceEnvs = req.membership.workspace.environments;
|
||||||
|
if (!workspaceEnvs.find(({ slug }: { slug: string }) => slug === environment)) {
|
||||||
throw new Error('Failed to validate environment');
|
throw new Error('Failed to validate environment');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,7 +184,8 @@ export const pullSecretsServiceToken = async (req: Request, res: Response) => {
|
|||||||
const { workspaceId } = req.params;
|
const { workspaceId } = req.params;
|
||||||
|
|
||||||
// validate environment
|
// validate environment
|
||||||
if (!ENV_SET.has(environment)) {
|
const workspaceEnvs = req.membership.workspace.environments;
|
||||||
|
if (!workspaceEnvs.find(({ slug }: { slug: string }) => slug === environment)) {
|
||||||
throw new Error('Failed to validate environment');
|
throw new Error('Failed to validate environment');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { Request, Response } from 'express';
|
import { Request, Response } from 'express';
|
||||||
import { ServiceToken } from '../../models';
|
import { ServiceToken } from '../../models';
|
||||||
import { createToken } from '../../helpers/auth';
|
import { createToken } from '../../helpers/auth';
|
||||||
import { ENV_SET } from '../../variables';
|
|
||||||
import { JWT_SERVICE_SECRET } from '../../config';
|
import { JWT_SERVICE_SECRET } from '../../config';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -36,7 +35,8 @@ export const createServiceToken = async (req: Request, res: Response) => {
|
|||||||
} = req.body;
|
} = req.body;
|
||||||
|
|
||||||
// validate environment
|
// validate environment
|
||||||
if (!ENV_SET.has(environment)) {
|
const workspaceEnvs = req.membership.workspace.environments;
|
||||||
|
if (!workspaceEnvs.find(({ slug }: { slug: string }) => slug === environment)) {
|
||||||
throw new Error('Failed to validate environment');
|
throw new Error('Failed to validate environment');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,167 @@
|
|||||||
|
import { Request, Response } from 'express';
|
||||||
|
import * as Sentry from '@sentry/node';
|
||||||
|
import { Secret, ServiceToken, Workspace, Integration } from '../../models';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create new workspace environment named [environmentName] under workspace with id
|
||||||
|
* @param req
|
||||||
|
* @param res
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export const createWorkspaceEnvironment = async (
|
||||||
|
req: Request,
|
||||||
|
res: Response
|
||||||
|
) => {
|
||||||
|
const { workspaceId, environmentName, environmentSlug } = req.body;
|
||||||
|
try {
|
||||||
|
// atomic create the environment
|
||||||
|
const workspace = await Workspace.findOneAndUpdate(
|
||||||
|
{
|
||||||
|
_id: workspaceId,
|
||||||
|
'environments.slug': { $ne: environmentSlug },
|
||||||
|
'environments.name': { $ne: environmentName },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$addToSet: {
|
||||||
|
environments: { name: environmentName, slug: environmentSlug },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!workspace) {
|
||||||
|
throw new Error('Failed to update workspace environment');
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
Sentry.setUser({ email: req.user.email });
|
||||||
|
Sentry.captureException(err);
|
||||||
|
return res.status(400).send({
|
||||||
|
message: 'Failed to create new workspace environment',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.status(200).send({
|
||||||
|
message: 'Successfully created new environment',
|
||||||
|
workspace: workspaceId,
|
||||||
|
environment: {
|
||||||
|
name: environmentName,
|
||||||
|
slug: environmentSlug,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rename workspace environment with new name and slug of a workspace with [workspaceId]
|
||||||
|
* Old slug [oldEnvironmentSlug] must be provided
|
||||||
|
* @param req
|
||||||
|
* @param res
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export const renameWorkspaceEnvironment = async (
|
||||||
|
req: Request,
|
||||||
|
res: Response
|
||||||
|
) => {
|
||||||
|
const { workspaceId, environmentName, environmentSlug, oldEnvironmentSlug } =
|
||||||
|
req.body;
|
||||||
|
try {
|
||||||
|
// user should pass both new slug and env name
|
||||||
|
if (!environmentSlug || !environmentName) {
|
||||||
|
throw new Error('Invalid environment given.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// atomic update the env to avoid conflict
|
||||||
|
const workspace = await Workspace.findOneAndUpdate(
|
||||||
|
{ _id: workspaceId, 'environments.slug': oldEnvironmentSlug },
|
||||||
|
{
|
||||||
|
'environments.$.name': environmentName,
|
||||||
|
'environments.$.slug': environmentSlug,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
if (!workspace) {
|
||||||
|
throw new Error('Failed to update workspace');
|
||||||
|
}
|
||||||
|
|
||||||
|
await Secret.updateMany(
|
||||||
|
{ workspace: workspaceId, environment: oldEnvironmentSlug },
|
||||||
|
{ environment: environmentSlug }
|
||||||
|
);
|
||||||
|
await ServiceToken.updateMany(
|
||||||
|
{ workspace: workspaceId, environment: oldEnvironmentSlug },
|
||||||
|
{ environment: environmentSlug }
|
||||||
|
);
|
||||||
|
await Integration.updateMany(
|
||||||
|
{ workspace: workspaceId, environment: oldEnvironmentSlug },
|
||||||
|
{ environment: environmentSlug }
|
||||||
|
);
|
||||||
|
} catch (err) {
|
||||||
|
Sentry.setUser({ email: req.user.email });
|
||||||
|
Sentry.captureException(err);
|
||||||
|
return res.status(400).send({
|
||||||
|
message: 'Failed to update workspace environment',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.status(200).send({
|
||||||
|
message: 'Successfully update environment',
|
||||||
|
workspace: workspaceId,
|
||||||
|
environment: {
|
||||||
|
name: environmentName,
|
||||||
|
slug: environmentSlug,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete workspace environment by [environmentSlug] of workspace [workspaceId] and do the clean up
|
||||||
|
* @param req
|
||||||
|
* @param res
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export const deleteWorkspaceEnvironment = async (
|
||||||
|
req: Request,
|
||||||
|
res: Response
|
||||||
|
) => {
|
||||||
|
const { workspaceId, environmentSlug } = req.body;
|
||||||
|
try {
|
||||||
|
// atomic delete the env in the workspacce
|
||||||
|
const workspace = await Workspace.findOneAndUpdate(
|
||||||
|
{ _id: workspaceId },
|
||||||
|
{
|
||||||
|
$pull: {
|
||||||
|
environments: {
|
||||||
|
slug: environmentSlug,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
if (!workspace) {
|
||||||
|
throw new Error('Failed to delete workspace environment');
|
||||||
|
}
|
||||||
|
|
||||||
|
// clean up
|
||||||
|
await Secret.deleteMany({
|
||||||
|
workspace: workspaceId,
|
||||||
|
environment: environmentSlug,
|
||||||
|
});
|
||||||
|
await ServiceToken.deleteMany({
|
||||||
|
workspace: workspaceId,
|
||||||
|
environment: environmentSlug,
|
||||||
|
});
|
||||||
|
await Integration.deleteMany({
|
||||||
|
workspace: workspaceId,
|
||||||
|
environment: environmentSlug,
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
Sentry.setUser({ email: req.user.email });
|
||||||
|
Sentry.captureException(err);
|
||||||
|
return res.status(400).send({
|
||||||
|
message: 'Failed to delete workspace environment',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.status(200).send({
|
||||||
|
message: 'Successfully deleted environment',
|
||||||
|
workspace: workspaceId,
|
||||||
|
environment: environmentSlug,
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -3,11 +3,13 @@ import * as serviceTokenDataController from './serviceTokenDataController';
|
|||||||
import * as apiKeyDataController from './apiKeyDataController';
|
import * as apiKeyDataController from './apiKeyDataController';
|
||||||
import * as secretController from './secretController';
|
import * as secretController from './secretController';
|
||||||
import * as secretsController from './secretsController';
|
import * as secretsController from './secretsController';
|
||||||
|
import * as environmentController from './environmentController';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
workspaceController,
|
workspaceController,
|
||||||
serviceTokenDataController,
|
serviceTokenDataController,
|
||||||
apiKeyDataController,
|
apiKeyDataController,
|
||||||
secretController,
|
secretController,
|
||||||
secretsController
|
secretsController,
|
||||||
|
environmentController
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import {
|
|||||||
import { pushKeys } from '../../helpers/key';
|
import { pushKeys } from '../../helpers/key';
|
||||||
import { postHogClient, EventService } from '../../services';
|
import { postHogClient, EventService } from '../../services';
|
||||||
import { eventPushSecrets } from '../../events';
|
import { eventPushSecrets } from '../../events';
|
||||||
import { ENV_SET } from '../../variables';
|
|
||||||
|
|
||||||
interface V2PushSecret {
|
interface V2PushSecret {
|
||||||
type: string; // personal or shared
|
type: string; // personal or shared
|
||||||
@@ -52,7 +51,8 @@ export const pushWorkspaceSecrets = async (req: Request, res: Response) => {
|
|||||||
const { workspaceId } = req.params;
|
const { workspaceId } = req.params;
|
||||||
|
|
||||||
// validate environment
|
// validate environment
|
||||||
if (!ENV_SET.has(environment)) {
|
const workspaceEnvs = req.membership.workspace.environments;
|
||||||
|
if (!workspaceEnvs.find(({ slug }: { slug: string }) => slug === environment)) {
|
||||||
throw new Error('Failed to validate environment');
|
throw new Error('Failed to validate environment');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,6 +129,11 @@ export const pullSecrets = async (req: Request, res: Response) => {
|
|||||||
} else if (req.serviceTokenData) {
|
} else if (req.serviceTokenData) {
|
||||||
userId = req.serviceTokenData.user._id
|
userId = req.serviceTokenData.user._id
|
||||||
}
|
}
|
||||||
|
// validate environment
|
||||||
|
const workspaceEnvs = req.membership.workspace.environments;
|
||||||
|
if (!workspaceEnvs.find(({ slug }: { slug: string }) => slug === environment)) {
|
||||||
|
throw new Error('Failed to validate environment');
|
||||||
|
}
|
||||||
|
|
||||||
secrets = await pull({
|
secrets = await pull({
|
||||||
userId,
|
userId,
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ import {
|
|||||||
import { exchangeCode, exchangeRefresh, syncSecrets } from '../integrations';
|
import { exchangeCode, exchangeRefresh, syncSecrets } from '../integrations';
|
||||||
import { BotService } from '../services';
|
import { BotService } from '../services';
|
||||||
import {
|
import {
|
||||||
ENV_DEV,
|
|
||||||
EVENT_PUSH_SECRETS,
|
|
||||||
INTEGRATION_VERCEL,
|
INTEGRATION_VERCEL,
|
||||||
INTEGRATION_NETLIFY
|
INTEGRATION_NETLIFY
|
||||||
} from '../variables';
|
} from '../variables';
|
||||||
@@ -36,11 +34,13 @@ interface Update {
|
|||||||
const handleOAuthExchangeHelper = async ({
|
const handleOAuthExchangeHelper = async ({
|
||||||
workspaceId,
|
workspaceId,
|
||||||
integration,
|
integration,
|
||||||
code
|
code,
|
||||||
|
environment
|
||||||
}: {
|
}: {
|
||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
integration: string;
|
integration: string;
|
||||||
code: string;
|
code: string;
|
||||||
|
environment: string;
|
||||||
}) => {
|
}) => {
|
||||||
let action;
|
let action;
|
||||||
let integrationAuth;
|
let integrationAuth;
|
||||||
@@ -102,9 +102,9 @@ const handleOAuthExchangeHelper = async ({
|
|||||||
// initialize new integration after exchange
|
// initialize new integration after exchange
|
||||||
await new Integration({
|
await new Integration({
|
||||||
workspace: workspaceId,
|
workspace: workspaceId,
|
||||||
environment: ENV_DEV,
|
|
||||||
isActive: false,
|
isActive: false,
|
||||||
app: null,
|
app: null,
|
||||||
|
environment,
|
||||||
integration,
|
integration,
|
||||||
integrationAuth: integrationAuth._id
|
integrationAuth: integrationAuth._id
|
||||||
}).save();
|
}).save();
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
import { Schema, model, Types } from 'mongoose';
|
import { Schema, model, Types } from 'mongoose';
|
||||||
import {
|
import {
|
||||||
ENV_DEV,
|
|
||||||
ENV_TESTING,
|
|
||||||
ENV_STAGING,
|
|
||||||
ENV_PROD,
|
|
||||||
INTEGRATION_HEROKU,
|
INTEGRATION_HEROKU,
|
||||||
INTEGRATION_VERCEL,
|
INTEGRATION_VERCEL,
|
||||||
INTEGRATION_NETLIFY,
|
INTEGRATION_NETLIFY,
|
||||||
@@ -32,7 +28,6 @@ const integrationSchema = new Schema<IIntegration>(
|
|||||||
},
|
},
|
||||||
environment: {
|
environment: {
|
||||||
type: String,
|
type: String,
|
||||||
enum: [ENV_DEV, ENV_TESTING, ENV_STAGING, ENV_PROD],
|
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
isActive: {
|
isActive: {
|
||||||
|
|||||||
@@ -2,10 +2,6 @@ import { Schema, model, Types } from 'mongoose';
|
|||||||
import {
|
import {
|
||||||
SECRET_SHARED,
|
SECRET_SHARED,
|
||||||
SECRET_PERSONAL,
|
SECRET_PERSONAL,
|
||||||
ENV_DEV,
|
|
||||||
ENV_TESTING,
|
|
||||||
ENV_STAGING,
|
|
||||||
ENV_PROD
|
|
||||||
} from '../variables';
|
} from '../variables';
|
||||||
|
|
||||||
export interface ISecret {
|
export interface ISecret {
|
||||||
@@ -53,7 +49,6 @@ const secretSchema = new Schema<ISecret>(
|
|||||||
},
|
},
|
||||||
environment: {
|
environment: {
|
||||||
type: String,
|
type: String,
|
||||||
enum: [ENV_DEV, ENV_TESTING, ENV_STAGING, ENV_PROD],
|
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
secretKeyCiphertext: {
|
secretKeyCiphertext: {
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
import { Schema, model, Types } from 'mongoose';
|
import { Schema, model, Types } from 'mongoose';
|
||||||
import { ENV_DEV, ENV_TESTING, ENV_STAGING, ENV_PROD } from '../variables';
|
|
||||||
|
|
||||||
// TODO: deprecate
|
|
||||||
export interface IServiceToken {
|
export interface IServiceToken {
|
||||||
_id: Types.ObjectId;
|
_id: Types.ObjectId;
|
||||||
name: string;
|
name: string;
|
||||||
@@ -33,7 +30,6 @@ const serviceTokenSchema = new Schema<IServiceToken>(
|
|||||||
},
|
},
|
||||||
environment: {
|
environment: {
|
||||||
type: String,
|
type: String,
|
||||||
enum: [ENV_DEV, ENV_TESTING, ENV_STAGING, ENV_PROD],
|
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
expiresAt: {
|
expiresAt: {
|
||||||
|
|||||||
@@ -4,6 +4,10 @@ export interface IWorkspace {
|
|||||||
_id: Types.ObjectId;
|
_id: Types.ObjectId;
|
||||||
name: string;
|
name: string;
|
||||||
organization: Types.ObjectId;
|
organization: Types.ObjectId;
|
||||||
|
environments: Array<{
|
||||||
|
name: string;
|
||||||
|
slug: string;
|
||||||
|
}>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const workspaceSchema = new Schema<IWorkspace>({
|
const workspaceSchema = new Schema<IWorkspace>({
|
||||||
@@ -15,7 +19,33 @@ const workspaceSchema = new Schema<IWorkspace>({
|
|||||||
type: Schema.Types.ObjectId,
|
type: Schema.Types.ObjectId,
|
||||||
ref: 'Organization',
|
ref: 'Organization',
|
||||||
required: true
|
required: true
|
||||||
}
|
},
|
||||||
|
environments: {
|
||||||
|
type: [
|
||||||
|
{
|
||||||
|
name: String,
|
||||||
|
slug: String,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: [
|
||||||
|
{
|
||||||
|
name: "development",
|
||||||
|
slug: "dev"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "test",
|
||||||
|
slug: "test"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "staging",
|
||||||
|
slug: "staging"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "production",
|
||||||
|
slug: "prod"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const Workspace = model<IWorkspace>('Workspace', workspaceSchema);
|
const Workspace = model<IWorkspace>('Workspace', workspaceSchema);
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
import express 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, COMPLETED, GRANTED } from '../../variables';
|
||||||
|
|
||||||
|
router.post(
|
||||||
|
'/:workspaceId',
|
||||||
|
requireAuth,
|
||||||
|
requireWorkspaceAuth({
|
||||||
|
acceptedRoles: [ADMIN, MEMBER],
|
||||||
|
acceptedStatuses: [COMPLETED, GRANTED],
|
||||||
|
}),
|
||||||
|
param('workspaceId').exists().trim(),
|
||||||
|
body('environmentSlug').exists().trim(),
|
||||||
|
body('environmentName').exists().trim(),
|
||||||
|
validateRequest,
|
||||||
|
environmentController.createWorkspaceEnvironment
|
||||||
|
);
|
||||||
|
|
||||||
|
router.put(
|
||||||
|
'/:workspaceId',
|
||||||
|
requireAuth,
|
||||||
|
requireWorkspaceAuth({
|
||||||
|
acceptedRoles: [ADMIN, MEMBER],
|
||||||
|
acceptedStatuses: [COMPLETED, GRANTED],
|
||||||
|
}),
|
||||||
|
param('workspaceId').exists().trim(),
|
||||||
|
body('environmentSlug').exists().trim(),
|
||||||
|
body('environmentName').exists().trim(),
|
||||||
|
body('oldEnvironmentSlug').exists().trim(),
|
||||||
|
validateRequest,
|
||||||
|
environmentController.renameWorkspaceEnvironment
|
||||||
|
);
|
||||||
|
|
||||||
|
router.delete(
|
||||||
|
'/:workspaceId',
|
||||||
|
requireAuth,
|
||||||
|
requireWorkspaceAuth({
|
||||||
|
acceptedRoles: [ADMIN],
|
||||||
|
acceptedStatuses: [GRANTED],
|
||||||
|
}),
|
||||||
|
param('workspaceId').exists().trim(),
|
||||||
|
body('environmentSlug').exists().trim(),
|
||||||
|
validateRequest,
|
||||||
|
environmentController.deleteWorkspaceEnvironment
|
||||||
|
);
|
||||||
|
|
||||||
|
export default router;
|
||||||
@@ -3,11 +3,13 @@ import secrets from './secrets';
|
|||||||
import workspace from './workspace';
|
import workspace from './workspace';
|
||||||
import serviceTokenData from './serviceTokenData';
|
import serviceTokenData from './serviceTokenData';
|
||||||
import apiKeyData from './apiKeyData';
|
import apiKeyData from './apiKeyData';
|
||||||
|
import environment from "./environment"
|
||||||
|
|
||||||
export {
|
export {
|
||||||
secret,
|
secret,
|
||||||
secrets,
|
secrets,
|
||||||
workspace,
|
workspace,
|
||||||
serviceTokenData,
|
serviceTokenData,
|
||||||
apiKeyData
|
apiKeyData,
|
||||||
}
|
environment
|
||||||
|
}
|
||||||
@@ -11,10 +11,6 @@ import {
|
|||||||
setIntegrationAuthAccessHelper,
|
setIntegrationAuthAccessHelper,
|
||||||
} from '../helpers/integration';
|
} from '../helpers/integration';
|
||||||
import { exchangeCode } from '../integrations';
|
import { exchangeCode } from '../integrations';
|
||||||
import {
|
|
||||||
ENV_DEV,
|
|
||||||
EVENT_PUSH_SECRETS
|
|
||||||
} from '../variables';
|
|
||||||
|
|
||||||
// should sync stuff be here too? Probably.
|
// should sync stuff be here too? Probably.
|
||||||
// TODO: move bot functions to IntegrationService.
|
// TODO: move bot functions to IntegrationService.
|
||||||
@@ -32,22 +28,26 @@ class IntegrationService {
|
|||||||
* - Create bot sequence for integration
|
* - Create bot sequence for integration
|
||||||
* @param {Object} obj
|
* @param {Object} obj
|
||||||
* @param {String} obj.workspaceId - id of workspace
|
* @param {String} obj.workspaceId - id of workspace
|
||||||
|
* @param {String} obj.environment - workspace environment
|
||||||
* @param {String} obj.integration - name of integration
|
* @param {String} obj.integration - name of integration
|
||||||
* @param {String} obj.code - code
|
* @param {String} obj.code - code
|
||||||
*/
|
*/
|
||||||
static async handleOAuthExchange({
|
static async handleOAuthExchange({
|
||||||
workspaceId,
|
workspaceId,
|
||||||
integration,
|
integration,
|
||||||
code
|
code,
|
||||||
|
environment
|
||||||
}: {
|
}: {
|
||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
integration: string;
|
integration: string;
|
||||||
code: string;
|
code: string;
|
||||||
|
environment: string;
|
||||||
}) {
|
}) {
|
||||||
await handleOAuthExchangeHelper({
|
await handleOAuthExchangeHelper({
|
||||||
workspaceId,
|
workspaceId,
|
||||||
integration,
|
integration,
|
||||||
code
|
code,
|
||||||
|
environment
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user