mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-19 11:42:52 +00:00
Add Northflank connection support
- Introduced Northflank as a new app connection option, including API token authentication. - Implemented connection schemas, validation, and service functions for Northflank. - Updated API documentation to include Northflank endpoints and integration instructions. - Added frontend components for creating and managing Northflank connections.
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
export * from "./northflank-connection-enums";
|
||||
export * from "./northflank-connection-fns";
|
||||
export * from "./northflank-connection-schemas";
|
||||
export * from "./northflank-connection-service";
|
||||
export * from "./northflank-connection-types";
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
export enum NorthflankConnectionMethod {
|
||||
ApiToken = "api-token"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
import { AxiosError } from "axios";
|
||||
|
||||
import { request } from "@app/lib/config/request";
|
||||
import { BadRequestError } from "@app/lib/errors";
|
||||
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
|
||||
|
||||
import { NorthflankConnectionMethod } from "./northflank-connection-enums";
|
||||
import { TNorthflankConnection, TNorthflankConnectionConfig, TNorthflankProject } from "./northflank-connection-types";
|
||||
|
||||
const NORTHFLANK_API_URL = "https://api.northflank.com";
|
||||
|
||||
export const getNorthflankConnectionListItem = () => {
|
||||
return {
|
||||
name: "Northflank" as const,
|
||||
app: AppConnection.Northflank as const,
|
||||
methods: Object.values(NorthflankConnectionMethod)
|
||||
};
|
||||
};
|
||||
|
||||
export const validateNorthflankConnectionCredentials = async (config: TNorthflankConnectionConfig) => {
|
||||
const { credentials } = config;
|
||||
|
||||
try {
|
||||
await request.get(`${NORTHFLANK_API_URL}/v1/projects`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${credentials.apiToken}`,
|
||||
Accept: "application/json"
|
||||
}
|
||||
});
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof AxiosError) {
|
||||
throw new BadRequestError({
|
||||
message: `Failed to validate Northflank credentials: ${error.message || "Unknown error"}`
|
||||
});
|
||||
}
|
||||
|
||||
throw new BadRequestError({
|
||||
message: `Failed to validate Northflank credentials - verify API token is correct`
|
||||
});
|
||||
}
|
||||
|
||||
return credentials;
|
||||
};
|
||||
|
||||
export const listProjects = async (appConnection: TNorthflankConnection): Promise<TNorthflankProject[]> => {
|
||||
const { credentials } = appConnection;
|
||||
|
||||
try {
|
||||
const {
|
||||
data: {
|
||||
data: { projects }
|
||||
}
|
||||
} = await request.get<{ data: { projects: TNorthflankProject[] } }>(
|
||||
`${NORTHFLANK_API_URL}/v1/projects`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${credentials.apiToken}`,
|
||||
Accept: "application/json"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return projects;
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof AxiosError) {
|
||||
throw new BadRequestError({
|
||||
message: `Failed to list Northflank projects: ${error.message || "Unknown error"}`
|
||||
});
|
||||
}
|
||||
|
||||
throw new BadRequestError({
|
||||
message: "Unable to list Northflank projects",
|
||||
error
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import z from "zod";
|
||||
|
||||
import { AppConnections } from "@app/lib/api-docs";
|
||||
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
|
||||
import {
|
||||
BaseAppConnectionSchema,
|
||||
GenericCreateAppConnectionFieldsSchema,
|
||||
GenericUpdateAppConnectionFieldsSchema
|
||||
} from "@app/services/app-connection/app-connection-schemas";
|
||||
|
||||
import { NorthflankConnectionMethod } from "./northflank-connection-enums";
|
||||
|
||||
export const NorthflankConnectionApiTokenCredentialsSchema = z.object({
|
||||
apiToken: z
|
||||
.string()
|
||||
.trim()
|
||||
.min(1, "API Token required")
|
||||
.describe(AppConnections.CREDENTIALS.NORTHFLANK.apiToken)
|
||||
});
|
||||
|
||||
const BaseNorthflankConnectionSchema = BaseAppConnectionSchema.extend({
|
||||
app: z.literal(AppConnection.Northflank)
|
||||
});
|
||||
|
||||
export const NorthflankConnectionSchema = BaseNorthflankConnectionSchema.extend({
|
||||
method: z.literal(NorthflankConnectionMethod.ApiToken),
|
||||
credentials: NorthflankConnectionApiTokenCredentialsSchema
|
||||
});
|
||||
|
||||
export const SanitizedNorthflankConnectionSchema = z.discriminatedUnion("method", [
|
||||
BaseNorthflankConnectionSchema.extend({
|
||||
method: z.literal(NorthflankConnectionMethod.ApiToken),
|
||||
credentials: NorthflankConnectionApiTokenCredentialsSchema.pick({})
|
||||
})
|
||||
]);
|
||||
|
||||
export const ValidateNorthflankConnectionCredentialsSchema = z.discriminatedUnion("method", [
|
||||
z.object({
|
||||
method: z.literal(NorthflankConnectionMethod.ApiToken).describe(
|
||||
AppConnections.CREATE(AppConnection.Northflank).method
|
||||
),
|
||||
credentials: NorthflankConnectionApiTokenCredentialsSchema.describe(
|
||||
AppConnections.CREATE(AppConnection.Northflank).credentials
|
||||
)
|
||||
})
|
||||
]);
|
||||
|
||||
export const CreateNorthflankConnectionSchema = ValidateNorthflankConnectionCredentialsSchema.and(
|
||||
GenericCreateAppConnectionFieldsSchema(AppConnection.Northflank)
|
||||
);
|
||||
|
||||
export const UpdateNorthflankConnectionSchema = z
|
||||
.object({
|
||||
credentials: NorthflankConnectionApiTokenCredentialsSchema.optional().describe(
|
||||
AppConnections.UPDATE(AppConnection.Northflank).credentials
|
||||
)
|
||||
})
|
||||
.and(GenericUpdateAppConnectionFieldsSchema(AppConnection.Northflank));
|
||||
|
||||
export const NorthflankConnectionListItemSchema = z.object({
|
||||
name: z.literal("Northflank"),
|
||||
app: z.literal(AppConnection.Northflank),
|
||||
methods: z.nativeEnum(NorthflankConnectionMethod).array()
|
||||
});
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import { logger } from "@app/lib/logger";
|
||||
import { OrgServiceActor } from "@app/lib/types";
|
||||
|
||||
import { AppConnection } from "../app-connection-enums";
|
||||
import { listProjects as getNorthflankProjects } from "./northflank-connection-fns";
|
||||
import { TNorthflankConnection } from "./northflank-connection-types";
|
||||
|
||||
type TGetAppConnectionFunc = (
|
||||
app: AppConnection,
|
||||
connectionId: string,
|
||||
actor: OrgServiceActor
|
||||
) => Promise<TNorthflankConnection>;
|
||||
|
||||
export const northflankConnectionService = (getAppConnection: TGetAppConnectionFunc) => {
|
||||
const listProjects = async (connectionId: string, actor: OrgServiceActor) => {
|
||||
const appConnection = await getAppConnection(AppConnection.Northflank, connectionId, actor);
|
||||
try {
|
||||
const projects = await getNorthflankProjects(appConnection);
|
||||
|
||||
return projects;
|
||||
} catch (error) {
|
||||
logger.error(error, "Failed to establish connection with Northflank");
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
listProjects
|
||||
};
|
||||
};
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import z from "zod";
|
||||
|
||||
import { DiscriminativePick } from "@app/lib/types";
|
||||
|
||||
import { AppConnection } from "../app-connection-enums";
|
||||
import {
|
||||
CreateNorthflankConnectionSchema,
|
||||
NorthflankConnectionSchema,
|
||||
ValidateNorthflankConnectionCredentialsSchema
|
||||
} from "./northflank-connection-schemas";
|
||||
|
||||
export type TNorthflankConnection = z.infer<typeof NorthflankConnectionSchema>;
|
||||
|
||||
export type TNorthflankConnectionInput = z.infer<typeof CreateNorthflankConnectionSchema> & {
|
||||
app: AppConnection.Northflank;
|
||||
};
|
||||
|
||||
export type TValidateNorthflankConnectionCredentialsSchema = typeof ValidateNorthflankConnectionCredentialsSchema;
|
||||
|
||||
export type TNorthflankConnectionConfig = DiscriminativePick<
|
||||
TNorthflankConnection,
|
||||
"method" | "app" | "credentials"
|
||||
> & {
|
||||
orgId: string;
|
||||
};
|
||||
|
||||
export type TNorthflankProject = {
|
||||
id: string;
|
||||
name: string;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user