mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 13:27:22 +00:00
Revise Northflank integration
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
ALGORITHM_AES_256_GCM,
|
||||
ENCODING_SCHEME_UTF8,
|
||||
INTEGRATION_BITBUCKET_API_URL,
|
||||
INTEGRATION_NORTHFLANK_API_URL,
|
||||
INTEGRATION_RAILWAY_API_URL,
|
||||
INTEGRATION_SET,
|
||||
INTEGRATION_VERCEL_API_URL,
|
||||
@@ -445,6 +446,79 @@ export const getIntegrationAuthBitBucketWorkspaces = async (req: Request, res: R
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Return list of secret groups for Northflank project with id [appId]
|
||||
* @param req
|
||||
* @param res
|
||||
* @returns
|
||||
*/
|
||||
export const getIntegrationAuthNorthflankSecretGroups = async (req: Request, res: Response) => {
|
||||
const appId = req.query.appId as string;
|
||||
|
||||
interface NorthflankSecretGroup {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
priority: number;
|
||||
projectId: string;
|
||||
}
|
||||
|
||||
interface SecretGroup {
|
||||
name: string;
|
||||
groupId: string;
|
||||
}
|
||||
|
||||
const secretGroups: SecretGroup[] = [];
|
||||
|
||||
if (appId && appId !== "") {
|
||||
let page = 1;
|
||||
const perPage = 10;
|
||||
let hasMorePages = true;
|
||||
|
||||
while(hasMorePages) {
|
||||
const params = new URLSearchParams({
|
||||
page: String(page),
|
||||
per_page: String(perPage),
|
||||
filter: "all",
|
||||
});
|
||||
|
||||
const {
|
||||
data: {
|
||||
data: {
|
||||
secrets
|
||||
}
|
||||
}
|
||||
} = await standardRequest.get<{ data: { secrets: NorthflankSecretGroup[] }}>(
|
||||
`${INTEGRATION_NORTHFLANK_API_URL}/v1/projects/${appId}/secrets`,
|
||||
{
|
||||
params,
|
||||
headers: {
|
||||
Authorization: `Bearer ${req.accessToken}`,
|
||||
"Accept-Encoding": "application/json",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
secrets.forEach((a: any) => {
|
||||
secretGroups.push({
|
||||
name: a.name,
|
||||
groupId: a.id
|
||||
});
|
||||
});
|
||||
|
||||
if (secrets.length < perPage) {
|
||||
hasMorePages = false;
|
||||
}
|
||||
|
||||
page++;
|
||||
}
|
||||
}
|
||||
|
||||
return res.status(200).send({
|
||||
secretGroups
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete integration authorization with id [integrationAuthId]
|
||||
* @param req
|
||||
@@ -461,3 +535,4 @@ export const deleteIntegrationAuth = async (req: Request, res: Response) => {
|
||||
integrationAuth
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -27,8 +27,7 @@ export const createIntegration = async (req: Request, res: Response) => {
|
||||
owner,
|
||||
path,
|
||||
region,
|
||||
secretPath,
|
||||
secretGroup
|
||||
secretPath
|
||||
} = req.body;
|
||||
|
||||
const folders = await Folder.findOne({
|
||||
@@ -62,7 +61,6 @@ export const createIntegration = async (req: Request, res: Response) => {
|
||||
path,
|
||||
region,
|
||||
secretPath,
|
||||
secretGroup,
|
||||
integration: req.integrationAuth.integration,
|
||||
integrationAuth: new Types.ObjectId(integrationAuthId)
|
||||
}).save();
|
||||
|
||||
@@ -877,7 +877,8 @@ const getAppsBitBucket = async ({
|
||||
});
|
||||
return apps;
|
||||
}
|
||||
/* Return list of projects for Northflank integration
|
||||
|
||||
/** Return list of projects for Northflank integration
|
||||
* @param {Object} obj
|
||||
* @param {String} obj.accessToken - access token for Northflank API
|
||||
* @returns {Object[]} apps - names of Northflank apps
|
||||
@@ -903,36 +904,10 @@ const getAppsNorthflank = async ({ accessToken }: { accessToken: string }) => {
|
||||
const apps = projects.map((a: any) => {
|
||||
return {
|
||||
name: a.name,
|
||||
appId: a.id,
|
||||
secretGroups: []
|
||||
appId: a.id
|
||||
};
|
||||
});
|
||||
|
||||
for (let i = 0; i < apps.length; i++) {
|
||||
const appName = apps[i].name;
|
||||
const {
|
||||
data: {
|
||||
data: {
|
||||
secrets
|
||||
}
|
||||
}
|
||||
} = await standardRequest.get(
|
||||
`${INTEGRATION_NORTHFLANK_API_URL}/v1/projects/${appName}/secrets`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
"Accept-Encoding": "application/json",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const secretGroups = secrets.map((a: any) => {
|
||||
return a.id
|
||||
});
|
||||
|
||||
apps[i].secretGroups = secretGroups
|
||||
}
|
||||
|
||||
return apps;
|
||||
};
|
||||
|
||||
|
||||
@@ -2375,7 +2375,7 @@ const syncSecretsCloud66 = async ({
|
||||
}
|
||||
};
|
||||
|
||||
/* Sync/push [secrets] to Northflank
|
||||
/** Sync/push [secrets] to Northflank
|
||||
* @param {Object} obj
|
||||
* @param {IIntegration} obj.integration - integration details
|
||||
* @param {Object} obj.secrets - secrets to push to integration (object where keys are secret keys and values are secret values)
|
||||
@@ -2390,16 +2390,13 @@ const syncSecretsNorthflank = async ({
|
||||
secrets: any;
|
||||
accessToken: string;
|
||||
}) => {
|
||||
|
||||
const modifiedFormatForSecretInjection = {
|
||||
secrets: {
|
||||
variables: secrets
|
||||
}
|
||||
}
|
||||
|
||||
await standardRequest.post(
|
||||
`${INTEGRATION_NORTHFLANK_API_URL}/v1/projects/${integration.appId}/secrets/${integration.secretGroup}`,
|
||||
modifiedFormatForSecretInjection,
|
||||
await standardRequest.patch(
|
||||
`${INTEGRATION_NORTHFLANK_API_URL}/v1/projects/${integration.appId}/secrets/${integration.targetServiceId}`,
|
||||
{
|
||||
secrets: {
|
||||
variables: secrets
|
||||
}
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
|
||||
@@ -42,7 +42,6 @@ export interface IIntegration {
|
||||
path: string;
|
||||
region: string;
|
||||
secretPath: string;
|
||||
secretGroup: string;
|
||||
integration:
|
||||
| "azure-key-vault"
|
||||
| "aws-parameter-store"
|
||||
@@ -175,12 +174,7 @@ const integrationSchema = new Schema<IIntegration>(
|
||||
type: String,
|
||||
required: true,
|
||||
default: "/",
|
||||
},
|
||||
secretGroup: {
|
||||
// northflank-specific service
|
||||
type: String,
|
||||
default: null,
|
||||
},
|
||||
}
|
||||
},
|
||||
{
|
||||
timestamps: true,
|
||||
|
||||
@@ -37,7 +37,6 @@ router.post(
|
||||
body("owner").trim(),
|
||||
body("path").trim(),
|
||||
body("region").trim(),
|
||||
body("secretGroup").isString().trim(),
|
||||
validateRequest,
|
||||
integrationController.createIntegration
|
||||
);
|
||||
|
||||
@@ -155,6 +155,20 @@ router.get(
|
||||
integrationAuthController.getIntegrationAuthBitBucketWorkspaces
|
||||
);
|
||||
|
||||
router.get(
|
||||
"/:integrationAuthId/northflank/secret-groups",
|
||||
requireAuth({
|
||||
acceptedAuthModes: [AUTH_MODE_JWT],
|
||||
}),
|
||||
requireIntegrationAuthorizationAuth({
|
||||
acceptedRoles: [ADMIN, MEMBER],
|
||||
}),
|
||||
param("integrationAuthId").exists().isString(),
|
||||
query("appId").exists().isString(),
|
||||
validateRequest,
|
||||
integrationAuthController.getIntegrationAuthNorthflankSecretGroups
|
||||
);
|
||||
|
||||
router.delete(
|
||||
"/:integrationAuthId",
|
||||
requireAuth({
|
||||
|
||||
Reference in New Issue
Block a user