mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-05 17:26:36 +00:00
Update qovery integration
This commit is contained in:
@@ -406,7 +406,7 @@ export const getIntegrationAuthQoveryProjects = async (req: Request, res: Respon
|
|||||||
params: { integrationAuthId },
|
params: { integrationAuthId },
|
||||||
query: { orgId }
|
query: { orgId }
|
||||||
} = await validateRequest(reqValidator.GetIntegrationAuthQoveryProjectsV1, req);
|
} = await validateRequest(reqValidator.GetIntegrationAuthQoveryProjectsV1, req);
|
||||||
|
|
||||||
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
||||||
const { integrationAuth, accessToken } = await getIntegrationAuthAccessHelper({
|
const { integrationAuth, accessToken } = await getIntegrationAuthAccessHelper({
|
||||||
integrationAuthId: new ObjectId(integrationAuthId)
|
integrationAuthId: new ObjectId(integrationAuthId)
|
||||||
@@ -420,28 +420,37 @@ export const getIntegrationAuthQoveryProjects = async (req: Request, res: Respon
|
|||||||
ProjectPermissionActions.Read,
|
ProjectPermissionActions.Read,
|
||||||
ProjectPermissionSub.Integrations
|
ProjectPermissionSub.Integrations
|
||||||
);
|
);
|
||||||
|
|
||||||
const { data } = await standardRequest.get(
|
interface Project {
|
||||||
`${INTEGRATION_QOVERY_API_URL}/organization/${orgId}/project`,
|
name: string;
|
||||||
{
|
projectId: string;
|
||||||
headers: {
|
}
|
||||||
Authorization: `Token ${accessToken}`,
|
|
||||||
"Accept": "application/json",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
interface QoveryProject {
|
interface QoveryProject {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let projects: Project[] = [];
|
||||||
|
|
||||||
|
if (orgId && orgId !== "") {
|
||||||
|
const { data } = await standardRequest.get(
|
||||||
|
`${INTEGRATION_QOVERY_API_URL}/organization/${orgId}/project`,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: `Token ${accessToken}`,
|
||||||
|
"Accept": "application/json",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const projects = data.results.map((a: QoveryProject) => {
|
projects = data.results.map((a: QoveryProject) => {
|
||||||
return {
|
return {
|
||||||
name: a.name,
|
name: a.name,
|
||||||
projectId: a.id,
|
projectId: a.id,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
projects
|
projects
|
||||||
@@ -449,7 +458,7 @@ export const getIntegrationAuthQoveryProjects = async (req: Request, res: Respon
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return list of Qovery Environments for a specific projectId
|
* Return list of Qovery environments for project with id [projectId]
|
||||||
* @param req
|
* @param req
|
||||||
* @param res
|
* @param res
|
||||||
*/
|
*/
|
||||||
@@ -472,28 +481,37 @@ export const getIntegrationAuthQoveryEnvironments = async (req: Request, res: Re
|
|||||||
ProjectPermissionActions.Read,
|
ProjectPermissionActions.Read,
|
||||||
ProjectPermissionSub.Integrations
|
ProjectPermissionSub.Integrations
|
||||||
);
|
);
|
||||||
|
|
||||||
const { data } = await standardRequest.get(
|
interface Environment {
|
||||||
`${INTEGRATION_QOVERY_API_URL}/project/${projectId}/environment`,
|
name: string;
|
||||||
{
|
environmentId: string;
|
||||||
headers: {
|
}
|
||||||
Authorization: `Token ${accessToken}`,
|
|
||||||
"Accept": "application/json",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
interface QoveryEnvironment {
|
interface QoveryEnvironment {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let environments: Environment[] = [];
|
||||||
|
|
||||||
|
if (projectId && projectId !== "" && projectId !== "none") { // TODO: fix
|
||||||
|
const { data } = await standardRequest.get(
|
||||||
|
`${INTEGRATION_QOVERY_API_URL}/project/${projectId}/environment`,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: `Token ${accessToken}`,
|
||||||
|
"Accept": "application/json",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const environments = data.results.map((a: QoveryEnvironment) => {
|
environments = data.results.map((a: QoveryEnvironment) => {
|
||||||
return {
|
return {
|
||||||
name: a.name,
|
name: a.name,
|
||||||
environmentId: a.id,
|
environmentId: a.id,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
environments
|
environments
|
||||||
@@ -501,7 +519,7 @@ export const getIntegrationAuthQoveryEnvironments = async (req: Request, res: Re
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return list of Qovery Apps for a specific environmentId
|
* Return list of Qovery apps for environment with id [environmentId]
|
||||||
* @param req
|
* @param req
|
||||||
* @param res
|
* @param res
|
||||||
*/
|
*/
|
||||||
@@ -524,28 +542,37 @@ export const getIntegrationAuthQoveryApps = async (req: Request, res: Response)
|
|||||||
ProjectPermissionActions.Read,
|
ProjectPermissionActions.Read,
|
||||||
ProjectPermissionSub.Integrations
|
ProjectPermissionSub.Integrations
|
||||||
);
|
);
|
||||||
|
|
||||||
const { data } = await standardRequest.get(
|
interface App {
|
||||||
`${INTEGRATION_QOVERY_API_URL}/environment/${environmentId}/application`,
|
name: string;
|
||||||
{
|
appId: string;
|
||||||
headers: {
|
}
|
||||||
Authorization: `Token ${accessToken}`,
|
|
||||||
"Accept": "application/json",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
interface QoveryApp {
|
interface QoveryApp {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let apps: App[] = [];
|
||||||
|
|
||||||
|
if (environmentId && environmentId !== "") {
|
||||||
|
const { data } = await standardRequest.get(
|
||||||
|
`${INTEGRATION_QOVERY_API_URL}/environment/${environmentId}/application`,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: `Token ${accessToken}`,
|
||||||
|
"Accept": "application/json",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const apps = data.results.map((a: QoveryApp) => {
|
apps = data.results.map((a: QoveryApp) => {
|
||||||
return {
|
return {
|
||||||
name: a.name,
|
name: a.name,
|
||||||
appId: a.id,
|
appId: a.id,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
apps
|
apps
|
||||||
@@ -553,7 +580,7 @@ export const getIntegrationAuthQoveryApps = async (req: Request, res: Response)
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return list of Qovery Containers for a specific environmentId
|
* Return list of Qovery containers for environment with id [environmentId]
|
||||||
* @param req
|
* @param req
|
||||||
* @param res
|
* @param res
|
||||||
*/
|
*/
|
||||||
@@ -576,28 +603,37 @@ export const getIntegrationAuthQoveryContainers = async (req: Request, res: Resp
|
|||||||
ProjectPermissionActions.Read,
|
ProjectPermissionActions.Read,
|
||||||
ProjectPermissionSub.Integrations
|
ProjectPermissionSub.Integrations
|
||||||
);
|
);
|
||||||
|
|
||||||
const { data } = await standardRequest.get(
|
interface Container {
|
||||||
`${INTEGRATION_QOVERY_API_URL}/environment/${environmentId}/container`,
|
name: string;
|
||||||
{
|
appId: string;
|
||||||
headers: {
|
}
|
||||||
Authorization: `Token ${accessToken}`,
|
|
||||||
"Accept": "application/json",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
interface QoveryContainer {
|
interface QoveryContainer {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let containers: Container[] = [];
|
||||||
|
|
||||||
|
if (environmentId && environmentId !== "") {
|
||||||
|
const { data } = await standardRequest.get(
|
||||||
|
`${INTEGRATION_QOVERY_API_URL}/environment/${environmentId}/container`,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: `Token ${accessToken}`,
|
||||||
|
"Accept": "application/json",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const containers = data.results.map((a: QoveryContainer) => {
|
containers = data.results.map((a: QoveryContainer) => {
|
||||||
return {
|
return {
|
||||||
name: a.name,
|
name: a.name,
|
||||||
appId: a.id,
|
appId: a.id,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
containers
|
containers
|
||||||
@@ -605,7 +641,7 @@ export const getIntegrationAuthQoveryContainers = async (req: Request, res: Resp
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return list of Qovery Jobs for a specific environmentId
|
* Return list of Qovery jobs for environment with id [environmentId]
|
||||||
* @param req
|
* @param req
|
||||||
* @param res
|
* @param res
|
||||||
*/
|
*/
|
||||||
@@ -628,28 +664,37 @@ export const getIntegrationAuthQoveryJobs = async (req: Request, res: Response)
|
|||||||
ProjectPermissionActions.Read,
|
ProjectPermissionActions.Read,
|
||||||
ProjectPermissionSub.Integrations
|
ProjectPermissionSub.Integrations
|
||||||
);
|
);
|
||||||
|
|
||||||
const { data } = await standardRequest.get(
|
|
||||||
`${INTEGRATION_QOVERY_API_URL}/environment/${environmentId}/job`,
|
|
||||||
{
|
|
||||||
headers: {
|
|
||||||
Authorization: `Token ${accessToken}`,
|
|
||||||
"Accept": "application/json",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
|
interface Job {
|
||||||
|
name: string;
|
||||||
|
appId: string;
|
||||||
|
}
|
||||||
|
|
||||||
interface QoveryJob {
|
interface QoveryJob {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let jobs: Job[] = [];
|
||||||
|
|
||||||
|
if (environmentId && environmentId !== "") {
|
||||||
|
const { data } = await standardRequest.get(
|
||||||
|
`${INTEGRATION_QOVERY_API_URL}/environment/${environmentId}/job`,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: `Token ${accessToken}`,
|
||||||
|
"Accept": "application/json",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const jobs = data.results.map((a: QoveryJob) => {
|
jobs = data.results.map((a: QoveryJob) => {
|
||||||
return {
|
return {
|
||||||
name: a.name,
|
name: a.name,
|
||||||
appId: a.id,
|
appId: a.id,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
jobs
|
jobs
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ export const createIntegration = async (req: Request, res: Response) => {
|
|||||||
appId,
|
appId,
|
||||||
owner,
|
owner,
|
||||||
region,
|
region,
|
||||||
|
scope,
|
||||||
targetService,
|
targetService,
|
||||||
targetServiceId,
|
targetServiceId,
|
||||||
integrationAuthId,
|
integrationAuthId,
|
||||||
@@ -42,7 +43,7 @@ export const createIntegration = async (req: Request, res: Response) => {
|
|||||||
metadata
|
metadata
|
||||||
}
|
}
|
||||||
} = await validateRequest(reqValidator.CreateIntegrationV1, req);
|
} = await validateRequest(reqValidator.CreateIntegrationV1, req);
|
||||||
|
|
||||||
const integrationAuth = await IntegrationAuth.findById(integrationAuthId)
|
const integrationAuth = await IntegrationAuth.findById(integrationAuthId)
|
||||||
.populate<{ workspace: IWorkspace }>("workspace")
|
.populate<{ workspace: IWorkspace }>("workspace")
|
||||||
.select(
|
.select(
|
||||||
@@ -90,6 +91,7 @@ export const createIntegration = async (req: Request, res: Response) => {
|
|||||||
owner,
|
owner,
|
||||||
path,
|
path,
|
||||||
region,
|
region,
|
||||||
|
scope,
|
||||||
secretPath,
|
secretPath,
|
||||||
integration: integrationAuth.integration,
|
integration: integrationAuth.integration,
|
||||||
integrationAuth: new Types.ObjectId(integrationAuthId),
|
integrationAuth: new Types.ObjectId(integrationAuthId),
|
||||||
|
|||||||
@@ -2151,8 +2151,9 @@ const syncSecretsQovery = async ({
|
|||||||
secrets: Record<string, { value: string; comment?: string }>;
|
secrets: Record<string, { value: string; comment?: string }>;
|
||||||
accessToken: string;
|
accessToken: string;
|
||||||
}) => {
|
}) => {
|
||||||
|
|
||||||
const getSecretsRes = (
|
const getSecretsRes = (
|
||||||
await standardRequest.get(`${INTEGRATION_QOVERY_API_URL}/${integration.metadata?.scope?.toLowerCase()}/${integration.appId}/environmentVariable`, {
|
await standardRequest.get(`${INTEGRATION_QOVERY_API_URL}/${integration.scope}/${integration.appId}/environmentVariable`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Token ${accessToken}`,
|
Authorization: `Token ${accessToken}`,
|
||||||
"Accept-Encoding": "application/json"
|
"Accept-Encoding": "application/json"
|
||||||
@@ -2172,7 +2173,7 @@ const syncSecretsQovery = async ({
|
|||||||
// case: secret does not exist in qovery
|
// case: secret does not exist in qovery
|
||||||
// -> add secret
|
// -> add secret
|
||||||
await standardRequest.post(
|
await standardRequest.post(
|
||||||
`${INTEGRATION_QOVERY_API_URL}/${integration.metadata?.scope?.toLowerCase()}/${integration.appId}/environmentVariable`,
|
`${INTEGRATION_QOVERY_API_URL}/${integration.scope}/${integration.appId}/environmentVariable`,
|
||||||
{
|
{
|
||||||
key,
|
key,
|
||||||
value: secrets[key].value
|
value: secrets[key].value
|
||||||
@@ -2191,7 +2192,7 @@ const syncSecretsQovery = async ({
|
|||||||
|
|
||||||
if (secrets[key].value !== getSecretsRes[key].value) {
|
if (secrets[key].value !== getSecretsRes[key].value) {
|
||||||
await standardRequest.put(
|
await standardRequest.put(
|
||||||
`${INTEGRATION_QOVERY_API_URL}/${integration.metadata?.scope?.toLowerCase()}/${integration.appId}/environmentVariable/${getSecretsRes[key].id}`,
|
`${INTEGRATION_QOVERY_API_URL}/${integration.scope}/${integration.appId}/environmentVariable/${getSecretsRes[key].id}`,
|
||||||
{
|
{
|
||||||
key,
|
key,
|
||||||
value: secrets[key].value
|
value: secrets[key].value
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ export interface IIntegration {
|
|||||||
targetServiceId: string;
|
targetServiceId: string;
|
||||||
path: string;
|
path: string;
|
||||||
region: string;
|
region: string;
|
||||||
|
scope: string;
|
||||||
secretPath: string;
|
secretPath: string;
|
||||||
integration:
|
integration:
|
||||||
| "azure-key-vault"
|
| "azure-key-vault"
|
||||||
@@ -121,11 +122,13 @@ const integrationSchema = new Schema<IIntegration>(
|
|||||||
},
|
},
|
||||||
targetService: {
|
targetService: {
|
||||||
// railway-specific service
|
// railway-specific service
|
||||||
|
// qovery-specific project
|
||||||
type: String,
|
type: String,
|
||||||
default: null,
|
default: null,
|
||||||
},
|
},
|
||||||
targetServiceId: {
|
targetServiceId: {
|
||||||
// railway-specific service
|
// railway-specific service
|
||||||
|
// qovery specific project
|
||||||
type: String,
|
type: String,
|
||||||
default: null,
|
default: null,
|
||||||
},
|
},
|
||||||
@@ -145,6 +148,11 @@ const integrationSchema = new Schema<IIntegration>(
|
|||||||
type: String,
|
type: String,
|
||||||
default: null,
|
default: null,
|
||||||
},
|
},
|
||||||
|
scope: {
|
||||||
|
// qovery-specific scope
|
||||||
|
type: String,
|
||||||
|
default: null
|
||||||
|
},
|
||||||
integration: {
|
integration: {
|
||||||
type: String,
|
type: String,
|
||||||
enum: [
|
enum: [
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
|
|
||||||
// TODO: in the future separate metadata
|
|
||||||
// into distinct types by integration
|
|
||||||
export type Metadata = {
|
export type Metadata = {
|
||||||
secretPrefix?: string;
|
secretPrefix?: string;
|
||||||
secretSuffix?: string;
|
secretSuffix?: string;
|
||||||
@@ -8,5 +5,4 @@ export type Metadata = {
|
|||||||
labelName: string;
|
labelName: string;
|
||||||
labelValue: string;
|
labelValue: string;
|
||||||
}
|
}
|
||||||
scope?: "Job" | "Application" | "Container";
|
|
||||||
}
|
}
|
||||||
@@ -76,6 +76,7 @@ export const CreateIntegrationV1 = z.object({
|
|||||||
owner: z.string().trim().optional(),
|
owner: z.string().trim().optional(),
|
||||||
path: z.string().trim().optional(),
|
path: z.string().trim().optional(),
|
||||||
region: z.string().trim().optional(),
|
region: z.string().trim().optional(),
|
||||||
|
scope: z.string().trim().optional(),
|
||||||
metadata: z.object({
|
metadata: z.object({
|
||||||
secretPrefix: z.string().optional(),
|
secretPrefix: z.string().optional(),
|
||||||
secretSuffix: z.string().optional(),
|
secretSuffix: z.string().optional(),
|
||||||
@@ -83,13 +84,6 @@ export const CreateIntegrationV1 = z.object({
|
|||||||
labelName: z.string(),
|
labelName: z.string(),
|
||||||
labelValue: z.string()
|
labelValue: z.string()
|
||||||
}).optional(),
|
}).optional(),
|
||||||
org: z.string().optional(),
|
|
||||||
orgId: z.string().optional(),
|
|
||||||
project: z.string().optional(),
|
|
||||||
projectId: z.string().optional(),
|
|
||||||
environment: z.string().optional(),
|
|
||||||
environmentId: z.string().optional(),
|
|
||||||
scope: z.string().optional()
|
|
||||||
}).optional()
|
}).optional()
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ const integrationAuthKeys = {
|
|||||||
}: {
|
}: {
|
||||||
integrationAuthId: string;
|
integrationAuthId: string;
|
||||||
environmentId: string;
|
environmentId: string;
|
||||||
scope: "Job" | "Application" | "Container";
|
scope: "job" | "application" | "container";
|
||||||
}) => [{ integrationAuthId, environmentId, scope }, "integrationAuthQoveryScopes"] as const,
|
}) => [{ integrationAuthId, environmentId, scope }, "integrationAuthQoveryScopes"] as const,
|
||||||
getIntegrationAuthRailwayEnvironments: ({
|
getIntegrationAuthRailwayEnvironments: ({
|
||||||
integrationAuthId,
|
integrationAuthId,
|
||||||
@@ -206,9 +206,9 @@ const fetchIntegrationAuthQoveryScopes = async ({
|
|||||||
}: {
|
}: {
|
||||||
integrationAuthId: string;
|
integrationAuthId: string;
|
||||||
environmentId: string;
|
environmentId: string;
|
||||||
scope: "Job" | "Application" | "Container";
|
scope: "job" | "application" | "container";
|
||||||
}) => {
|
}) => {
|
||||||
if (scope === "Application") {
|
if (scope === "application") {
|
||||||
const {
|
const {
|
||||||
data: { apps }
|
data: { apps }
|
||||||
} = await apiRequest.get<{ apps: App[] }>(
|
} = await apiRequest.get<{ apps: App[] }>(
|
||||||
@@ -223,7 +223,7 @@ const fetchIntegrationAuthQoveryScopes = async ({
|
|||||||
return apps;
|
return apps;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scope === "Container") {
|
if (scope === "container") {
|
||||||
const {
|
const {
|
||||||
data: { containers }
|
data: { containers }
|
||||||
} = await apiRequest.get<{ containers: App[] }>(
|
} = await apiRequest.get<{ containers: App[] }>(
|
||||||
@@ -238,7 +238,7 @@ const fetchIntegrationAuthQoveryScopes = async ({
|
|||||||
return containers;
|
return containers;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scope === "Job") {
|
if (scope === "job") {
|
||||||
const {
|
const {
|
||||||
data: { jobs }
|
data: { jobs }
|
||||||
} = await apiRequest.get<{ jobs: App[] }>(
|
} = await apiRequest.get<{ jobs: App[] }>(
|
||||||
@@ -463,7 +463,7 @@ export const useGetIntegrationAuthQoveryScopes = ({
|
|||||||
}: {
|
}: {
|
||||||
integrationAuthId: string;
|
integrationAuthId: string;
|
||||||
environmentId: string;
|
environmentId: string;
|
||||||
scope: "Job" | "Application" | "Container";
|
scope: "job" | "application" | "container";
|
||||||
}) => {
|
}) => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: integrationAuthKeys.getIntegrationAuthQoveryScopes({
|
queryKey: integrationAuthKeys.getIntegrationAuthQoveryScopes({
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ export const useCreateIntegration = () => {
|
|||||||
owner,
|
owner,
|
||||||
path,
|
path,
|
||||||
region,
|
region,
|
||||||
|
scope,
|
||||||
secretPath,
|
secretPath,
|
||||||
metadata
|
metadata
|
||||||
}: {
|
}: {
|
||||||
@@ -56,16 +57,10 @@ export const useCreateIntegration = () => {
|
|||||||
owner?: string;
|
owner?: string;
|
||||||
path?: string;
|
path?: string;
|
||||||
region?: string;
|
region?: string;
|
||||||
|
scope?: string;
|
||||||
metadata?: {
|
metadata?: {
|
||||||
secretPrefix?: string;
|
secretPrefix?: string;
|
||||||
secretSuffix?: string;
|
secretSuffix?: string;
|
||||||
org?: string;
|
|
||||||
orgId?: string;
|
|
||||||
project?: string;
|
|
||||||
projectId?: string;
|
|
||||||
environment?: string;
|
|
||||||
environmentId?: string;
|
|
||||||
scope?: string;
|
|
||||||
}
|
}
|
||||||
}) => {
|
}) => {
|
||||||
const { data: { integration } } = await apiRequest.post("/api/v1/integration", {
|
const { data: { integration } } = await apiRequest.post("/api/v1/integration", {
|
||||||
@@ -80,6 +75,7 @@ export const useCreateIntegration = () => {
|
|||||||
targetServiceId,
|
targetServiceId,
|
||||||
owner,
|
owner,
|
||||||
path,
|
path,
|
||||||
|
scope,
|
||||||
region,
|
region,
|
||||||
secretPath,
|
secretPath,
|
||||||
metadata
|
metadata
|
||||||
|
|||||||
@@ -24,16 +24,38 @@ import {
|
|||||||
import {
|
import {
|
||||||
useCreateIntegration
|
useCreateIntegration
|
||||||
} from "@app/hooks/api";
|
} from "@app/hooks/api";
|
||||||
import { useGetIntegrationAuthQoveryEnvironments, useGetIntegrationAuthQoveryOrgs, useGetIntegrationAuthQoveryProjects, useGetIntegrationAuthQoveryScopes } from "@app/hooks/api/integrationAuth/queries";
|
import {
|
||||||
|
useGetIntegrationAuthQoveryEnvironments,
|
||||||
|
useGetIntegrationAuthQoveryOrgs,
|
||||||
|
useGetIntegrationAuthQoveryProjects,
|
||||||
|
useGetIntegrationAuthQoveryScopes
|
||||||
|
} from "@app/hooks/api/integrationAuth/queries";
|
||||||
|
|
||||||
import { useGetIntegrationAuthById } from "../../../hooks/api/integrationAuth";
|
import { useGetIntegrationAuthById } from "../../../hooks/api/integrationAuth";
|
||||||
import { useGetWorkspaceById } from "../../../hooks/api/workspace";
|
import { useGetWorkspaceById } from "../../../hooks/api/workspace";
|
||||||
|
|
||||||
|
const qoveryScopes = [
|
||||||
|
{ label: "Application", value: "application" },
|
||||||
|
{ label: "Container", value: "container" },
|
||||||
|
{ label: "Job", value: "job" }
|
||||||
|
];
|
||||||
|
|
||||||
enum TabSections {
|
enum TabSections {
|
||||||
InfisicalSettings = "infisicalSettings",
|
InfisicalSettings = "infisicalSettings",
|
||||||
QoverySettings = "qoverySettings"
|
QoverySettings = "qoverySettings"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Follow the logic:
|
||||||
|
* - Access token
|
||||||
|
* -> Get organizations (orgId) - select an organization
|
||||||
|
* -> Get projects belonging to the organization - select project
|
||||||
|
* -> Get environments belonging to the project - select environmnet
|
||||||
|
* -> Get qovery scopes / application (this is the application to sync to)
|
||||||
|
*
|
||||||
|
* Do we even need to get organizations?
|
||||||
|
*/
|
||||||
|
|
||||||
export default function QoveryCreateIntegrationPage() {
|
export default function QoveryCreateIntegrationPage() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { mutateAsync } = useCreateIntegration();
|
const { mutateAsync } = useCreateIntegration();
|
||||||
@@ -43,40 +65,34 @@ export default function QoveryCreateIntegrationPage() {
|
|||||||
const { data: workspace } = useGetWorkspaceById(localStorage.getItem("projectData.id") ?? "");
|
const { data: workspace } = useGetWorkspaceById(localStorage.getItem("projectData.id") ?? "");
|
||||||
const { data: integrationAuth } = useGetIntegrationAuthById((integrationAuthId as string) ?? "");
|
const { data: integrationAuth } = useGetIntegrationAuthById((integrationAuthId as string) ?? "");
|
||||||
|
|
||||||
const [scope, setScope] = useState("Application");
|
const [scope, setScope] = useState("application");
|
||||||
const [selectedSourceEnvironment, setSelectedSourceEnvironment] = useState("");
|
const [selectedSourceEnvironment, setSelectedSourceEnvironment] = useState("");
|
||||||
const [secretPath, setSecretPath] = useState("/");
|
const [secretPath, setSecretPath] = useState("/");
|
||||||
|
|
||||||
const { data: integrationAuthOrgs } = useGetIntegrationAuthQoveryOrgs((integrationAuthId as string) ?? "");
|
const { data: integrationAuthOrgs } = useGetIntegrationAuthQoveryOrgs((integrationAuthId as string) ?? "");
|
||||||
const [targetOrg, setTargetOrg] = useState("");
|
|
||||||
const [targetOrgId, setTargetOrgId] = useState("");
|
const [targetOrgId, setTargetOrgId] = useState("");
|
||||||
|
|
||||||
const { data: integrationAuthProjects } = useGetIntegrationAuthQoveryProjects({
|
const { data: integrationAuthProjects } = useGetIntegrationAuthQoveryProjects({
|
||||||
integrationAuthId: (integrationAuthId as string) ?? "",
|
integrationAuthId: (integrationAuthId as string) ?? "",
|
||||||
orgId: targetOrgId
|
orgId: targetOrgId
|
||||||
});
|
});
|
||||||
const [targetProject, setTargetProject] = useState("");
|
|
||||||
const [targetProjectId, setTargetProjectId] = useState("");
|
const [targetProjectId, setTargetProjectId] = useState("");
|
||||||
|
|
||||||
const { data: integrationAuthEnvironments } = useGetIntegrationAuthQoveryEnvironments({
|
const { data: integrationAuthEnvironments } = useGetIntegrationAuthQoveryEnvironments({
|
||||||
integrationAuthId: (integrationAuthId as string) ?? "",
|
integrationAuthId: (integrationAuthId as string) ?? "",
|
||||||
projectId: targetProjectId
|
projectId: targetProjectId
|
||||||
});
|
});
|
||||||
const [targetEnvironment, setTargetEnvironment] = useState("");
|
|
||||||
const [targetEnvironmentId, setTargetEnvironmentId] = useState("");
|
const [targetEnvironmentId, setTargetEnvironmentId] = useState("");
|
||||||
|
|
||||||
const { data: integrationAuthApps, isLoading: isIntegrationAuthAppsLoading } = useGetIntegrationAuthQoveryScopes({
|
const { data: integrationAuthApps, isLoading: isIntegrationAuthAppsLoading } = useGetIntegrationAuthQoveryScopes({
|
||||||
integrationAuthId: (integrationAuthId as string) ?? "",
|
integrationAuthId: (integrationAuthId as string) ?? "",
|
||||||
environmentId: targetEnvironmentId,
|
environmentId: targetEnvironmentId,
|
||||||
scope: (scope as ("Job" | "Application" | "Container"))
|
scope: (scope as ("job" | "application" | "container"))
|
||||||
});
|
});
|
||||||
const [targetApp, setTargetApp] = useState("");
|
|
||||||
const [targetAppId, setTargetAppId] = useState("");
|
const [targetAppId, setTargetAppId] = useState("");
|
||||||
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
const scopes = ["Application", "Container", "Job"];
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (workspace) {
|
if (workspace) {
|
||||||
setSelectedSourceEnvironment(workspace.environments[0].slug);
|
setSelectedSourceEnvironment(workspace.environments[0].slug);
|
||||||
@@ -86,29 +102,19 @@ export default function QoveryCreateIntegrationPage() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (integrationAuthApps) {
|
if (integrationAuthApps) {
|
||||||
if (integrationAuthApps.length > 0) {
|
if (integrationAuthApps.length > 0) {
|
||||||
setTargetApp(integrationAuthApps[0].name);
|
|
||||||
setTargetAppId(String(integrationAuthApps[0].appId));
|
setTargetAppId(String(integrationAuthApps[0].appId));
|
||||||
} else {
|
} else {
|
||||||
setTargetApp("none");
|
setTargetAppId("none");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [integrationAuthApps]);
|
}, [integrationAuthApps]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (integrationAuthApps) {
|
|
||||||
if (integrationAuthApps.length > 0) {
|
|
||||||
setTargetAppId(String(integrationAuthApps.filter(app => app.name === targetApp)[0].appId));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [targetApp]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (integrationAuthOrgs) {
|
if (integrationAuthOrgs) {
|
||||||
if (integrationAuthOrgs.length > 0) {
|
if (integrationAuthOrgs.length > 0) {
|
||||||
setTargetOrg(integrationAuthOrgs[0].name);
|
|
||||||
setTargetOrgId(String(integrationAuthOrgs[0].orgId));
|
setTargetOrgId(String(integrationAuthOrgs[0].orgId));
|
||||||
} else {
|
} else {
|
||||||
setTargetOrg("none");
|
setTargetOrgId("none");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [integrationAuthOrgs]);
|
}, [integrationAuthOrgs]);
|
||||||
@@ -116,10 +122,9 @@ export default function QoveryCreateIntegrationPage() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (integrationAuthProjects) {
|
if (integrationAuthProjects) {
|
||||||
if (integrationAuthProjects.length > 0) {
|
if (integrationAuthProjects.length > 0) {
|
||||||
setTargetProject(integrationAuthProjects[0].name);
|
|
||||||
setTargetProjectId(String(integrationAuthProjects[0].projectId));
|
setTargetProjectId(String(integrationAuthProjects[0].projectId));
|
||||||
} else {
|
} else {
|
||||||
setTargetProject("none");
|
setTargetProjectId("none");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [integrationAuthProjects]);
|
}, [integrationAuthProjects]);
|
||||||
@@ -127,10 +132,9 @@ export default function QoveryCreateIntegrationPage() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (integrationAuthEnvironments) {
|
if (integrationAuthEnvironments) {
|
||||||
if (integrationAuthEnvironments.length > 0) {
|
if (integrationAuthEnvironments.length > 0) {
|
||||||
setTargetEnvironment(integrationAuthEnvironments[0].name);
|
|
||||||
setTargetEnvironmentId(String(integrationAuthEnvironments[0].environmentId));
|
setTargetEnvironmentId(String(integrationAuthEnvironments[0].environmentId));
|
||||||
} else {
|
} else {
|
||||||
setTargetEnvironment("none");
|
setTargetEnvironmentId("none");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [integrationAuthEnvironments]);
|
}, [integrationAuthEnvironments]);
|
||||||
@@ -141,22 +145,24 @@ export default function QoveryCreateIntegrationPage() {
|
|||||||
|
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
|
||||||
|
const targetOrg = integrationAuthOrgs?.find((integrationAuthOrg) => integrationAuthOrg.orgId === targetOrgId)?.name;
|
||||||
|
const targetProject = integrationAuthProjects?.find((integrationAuthProject) => integrationAuthProject.projectId === targetProjectId)?.name;
|
||||||
|
const targetEnvironment = integrationAuthEnvironments?.find((integrationAuthEnvironment) => integrationAuthEnvironment.environmentId === targetEnvironmentId)?.name;
|
||||||
|
const targetApp = integrationAuthApps?.find((integrationAuthApp) => integrationAuthApp.appId === targetAppId)?.name;
|
||||||
|
|
||||||
await mutateAsync({
|
await mutateAsync({
|
||||||
integrationAuthId: integrationAuth?._id,
|
integrationAuthId: integrationAuth?._id,
|
||||||
isActive: true,
|
isActive: true,
|
||||||
app: targetApp,
|
app: targetApp,
|
||||||
appId: targetAppId,
|
appId: targetAppId,
|
||||||
|
scope,
|
||||||
sourceEnvironment: selectedSourceEnvironment,
|
sourceEnvironment: selectedSourceEnvironment,
|
||||||
secretPath,
|
targetEnvironment,
|
||||||
metadata: {
|
targetEnvironmentId,
|
||||||
scope,
|
targetService: targetProject,
|
||||||
org: targetOrg,
|
targetServiceId: targetProjectId,
|
||||||
orgId: targetOrgId,
|
owner: targetOrg,
|
||||||
project: targetProject,
|
secretPath
|
||||||
projectId: targetProjectId,
|
|
||||||
environment: targetEnvironment,
|
|
||||||
environmentId: targetEnvironmentId,
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
@@ -166,7 +172,7 @@ export default function QoveryCreateIntegrationPage() {
|
|||||||
console.error(err);
|
console.error(err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return integrationAuth &&
|
return integrationAuth &&
|
||||||
workspace &&
|
workspace &&
|
||||||
selectedSourceEnvironment ? (
|
selectedSourceEnvironment ? (
|
||||||
@@ -255,28 +261,28 @@ export default function QoveryCreateIntegrationPage() {
|
|||||||
onValueChange={(val) => setScope(val)}
|
onValueChange={(val) => setScope(val)}
|
||||||
className="w-full border border-mineshaft-500"
|
className="w-full border border-mineshaft-500"
|
||||||
>
|
>
|
||||||
{scopes.map((tempScope) => (
|
{qoveryScopes.map((qoveryScope) => (
|
||||||
<SelectItem
|
<SelectItem
|
||||||
value={tempScope}
|
value={qoveryScope.value}
|
||||||
key={`target-app-${tempScope}`}
|
key={`target-app-${qoveryScope.value}`}
|
||||||
>
|
>
|
||||||
{tempScope}
|
{qoveryScope.label}
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
{integrationAuthOrgs && <FormControl label="Qovery Organization">
|
{integrationAuthOrgs && <FormControl label="Qovery Organization">
|
||||||
<Select
|
<Select
|
||||||
value={targetOrg}
|
value={targetOrgId}
|
||||||
onValueChange={(val) => setTargetOrg(val)}
|
onValueChange={(val) => setTargetOrgId(val)}
|
||||||
className="w-full border border-mineshaft-500"
|
className="w-full border border-mineshaft-500"
|
||||||
isDisabled={integrationAuthOrgs.length === 0}
|
isDisabled={integrationAuthOrgs.length === 0}
|
||||||
>
|
>
|
||||||
{integrationAuthOrgs.length > 0 ? (
|
{integrationAuthOrgs.length > 0 ? (
|
||||||
integrationAuthOrgs.map((integrationAuthOrg) => (
|
integrationAuthOrgs.map((integrationAuthOrg) => (
|
||||||
<SelectItem
|
<SelectItem
|
||||||
value={integrationAuthOrg.name}
|
value={integrationAuthOrg.orgId}
|
||||||
key={`target-app-${integrationAuthOrg.name}`}
|
key={`target-app-${integrationAuthOrg.orgId}`}
|
||||||
>
|
>
|
||||||
{integrationAuthOrg.name}
|
{integrationAuthOrg.name}
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
@@ -290,16 +296,16 @@ export default function QoveryCreateIntegrationPage() {
|
|||||||
</FormControl>}
|
</FormControl>}
|
||||||
{integrationAuthProjects && <FormControl label="Qovery Project">
|
{integrationAuthProjects && <FormControl label="Qovery Project">
|
||||||
<Select
|
<Select
|
||||||
value={targetProject}
|
value={targetProjectId}
|
||||||
onValueChange={(val) => setTargetProject(val)}
|
onValueChange={(val) => setTargetProjectId(val)}
|
||||||
className="w-full border border-mineshaft-500"
|
className="w-full border border-mineshaft-500"
|
||||||
isDisabled={integrationAuthProjects.length === 0}
|
isDisabled={integrationAuthProjects.length === 0}
|
||||||
>
|
>
|
||||||
{integrationAuthProjects.length > 0 ? (
|
{integrationAuthProjects.length > 0 ? (
|
||||||
integrationAuthProjects.map((integrationAuthProject) => (
|
integrationAuthProjects.map((integrationAuthProject) => (
|
||||||
<SelectItem
|
<SelectItem
|
||||||
value={integrationAuthProject.name}
|
value={integrationAuthProject.projectId}
|
||||||
key={`target-app-${integrationAuthProject.name}`}
|
key={`target-app-${integrationAuthProject.projectId}`}
|
||||||
>
|
>
|
||||||
{integrationAuthProject.name}
|
{integrationAuthProject.name}
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
@@ -313,16 +319,16 @@ export default function QoveryCreateIntegrationPage() {
|
|||||||
</FormControl>}
|
</FormControl>}
|
||||||
{integrationAuthEnvironments && <FormControl label="Qovery Environment">
|
{integrationAuthEnvironments && <FormControl label="Qovery Environment">
|
||||||
<Select
|
<Select
|
||||||
value={targetEnvironment}
|
value={targetEnvironmentId}
|
||||||
onValueChange={(val) => setTargetEnvironment(val)}
|
onValueChange={(val) => setTargetEnvironmentId(val)}
|
||||||
className="w-full border border-mineshaft-500"
|
className="w-full border border-mineshaft-500"
|
||||||
isDisabled={integrationAuthEnvironments.length === 0}
|
isDisabled={integrationAuthEnvironments.length === 0}
|
||||||
>
|
>
|
||||||
{integrationAuthEnvironments.length > 0 ? (
|
{integrationAuthEnvironments.length > 0 ? (
|
||||||
integrationAuthEnvironments.map((integrationAuthEnvironment) => (
|
integrationAuthEnvironments.map((integrationAuthEnvironment) => (
|
||||||
<SelectItem
|
<SelectItem
|
||||||
value={integrationAuthEnvironment.name}
|
value={integrationAuthEnvironment.environmentId}
|
||||||
key={`target-app-${integrationAuthEnvironment.name}`}
|
key={`target-app-${integrationAuthEnvironment.environmentId}`}
|
||||||
>
|
>
|
||||||
{integrationAuthEnvironment.name}
|
{integrationAuthEnvironment.name}
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
@@ -336,23 +342,23 @@ export default function QoveryCreateIntegrationPage() {
|
|||||||
</FormControl>}
|
</FormControl>}
|
||||||
{(scope && integrationAuthApps) && <FormControl label={`Qovery ${scope.charAt(0).toUpperCase() + scope.slice(1)}`}>
|
{(scope && integrationAuthApps) && <FormControl label={`Qovery ${scope.charAt(0).toUpperCase() + scope.slice(1)}`}>
|
||||||
<Select
|
<Select
|
||||||
value={targetApp}
|
value={targetAppId}
|
||||||
onValueChange={(val) => setTargetApp(val)}
|
onValueChange={(val) => setTargetAppId(val)}
|
||||||
className="w-full border border-mineshaft-500"
|
className="w-full border border-mineshaft-500"
|
||||||
isDisabled={integrationAuthApps.length === 0}
|
isDisabled={integrationAuthApps.length === 0}
|
||||||
>
|
>
|
||||||
{integrationAuthApps.length > 0 ? (
|
{integrationAuthApps.length > 0 ? (
|
||||||
integrationAuthApps.map((integrationAuthApp) => (
|
integrationAuthApps.map((integrationAuthApp) => (
|
||||||
<SelectItem
|
<SelectItem
|
||||||
value={integrationAuthApp.name}
|
value={(integrationAuthApp.appId as string)}
|
||||||
key={`target-app-${integrationAuthApp.name}`}
|
key={`target-app-${integrationAuthApp.appId}`}
|
||||||
>
|
>
|
||||||
{integrationAuthApp.name}
|
{integrationAuthApp.name}
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
))
|
))
|
||||||
) : (
|
) : (
|
||||||
<SelectItem value="none" key="target-app-none">
|
<SelectItem value="none" key="target-app-none">
|
||||||
No {scope.toLowerCase()}s found
|
No {scope}s found
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
)}
|
)}
|
||||||
</Select>
|
</Select>
|
||||||
|
|||||||
+3
-3
@@ -101,19 +101,19 @@ export const IntegrationsSection = ({
|
|||||||
<div className="ml-2 flex flex-col">
|
<div className="ml-2 flex flex-col">
|
||||||
<FormLabel label="Org" />
|
<FormLabel label="Org" />
|
||||||
<div className="rounded-md border border-mineshaft-700 bg-mineshaft-900 px-3 py-2 font-inter text-sm text-bunker-200">
|
<div className="rounded-md border border-mineshaft-700 bg-mineshaft-900 px-3 py-2 font-inter text-sm text-bunker-200">
|
||||||
{integration?.metadata?.org || "-"}
|
{integration?.owner || "-"}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="ml-2 flex flex-col">
|
<div className="ml-2 flex flex-col">
|
||||||
<FormLabel label="Project" />
|
<FormLabel label="Project" />
|
||||||
<div className="rounded-md border border-mineshaft-700 bg-mineshaft-900 px-3 py-2 font-inter text-sm text-bunker-200">
|
<div className="rounded-md border border-mineshaft-700 bg-mineshaft-900 px-3 py-2 font-inter text-sm text-bunker-200">
|
||||||
{integration?.metadata?.project || "-"}
|
{integration?.targetService || "-"}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="ml-2 flex flex-col">
|
<div className="ml-2 flex flex-col">
|
||||||
<FormLabel label="Env" />
|
<FormLabel label="Env" />
|
||||||
<div className="rounded-md border border-mineshaft-700 bg-mineshaft-900 px-3 py-2 font-inter text-sm text-bunker-200">
|
<div className="rounded-md border border-mineshaft-700 bg-mineshaft-900 px-3 py-2 font-inter text-sm text-bunker-200">
|
||||||
{integration?.metadata?.environment || "-"}
|
{integration?.targetEnvironment || "-"}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user