feat: added render secret sync

This commit is contained in:
Sheen Capadngan
2025-06-13 22:53:35 +08:00
parent f9c012387c
commit 63ccfc40ac
39 changed files with 722 additions and 18 deletions
@@ -63,6 +63,7 @@ import { ValidateMsSqlConnectionCredentialsSchema } from "./mssql";
import { ValidateMySqlConnectionCredentialsSchema } from "./mysql";
import { ValidatePostgresConnectionCredentialsSchema } from "./postgres";
import { ValidateRenderConnectionCredentialsSchema } from "./render/render-connection-schema";
import { renderConnectionService } from "./render/render-connection-service";
import { ValidateTeamCityConnectionCredentialsSchema } from "./teamcity";
import { teamcityConnectionService } from "./teamcity/teamcity-connection-service";
import { ValidateTerraformCloudConnectionCredentialsSchema } from "./terraform-cloud";
@@ -511,6 +512,7 @@ export const appConnectionServiceFactory = ({
windmill: windmillConnectionService(connectAppConnectionById),
teamcity: teamcityConnectionService(connectAppConnectionById),
oci: ociConnectionService(connectAppConnectionById, licenseService),
onepass: onePassConnectionService(connectAppConnectionById)
onepass: onePassConnectionService(connectAppConnectionById),
render: renderConnectionService(connectAppConnectionById)
};
};
@@ -1,3 +1,4 @@
/* eslint-disable no-await-in-loop */
import { AxiosError } from "axios";
import { request } from "@app/lib/config/request";
@@ -6,7 +7,12 @@ import { IntegrationUrls } from "@app/services/integration-auth/integration-list
import { AppConnection } from "../app-connection-enums";
import { RenderConnectionMethod } from "./render-connection-enums";
import { TRenderConnectionConfig } from "./render-connection-types";
import {
TRawRenderService,
TRenderConnection,
TRenderConnectionConfig,
TRenderService
} from "./render-connection-types";
export const getRenderConnectionListItem = () => {
return {
@@ -16,6 +22,48 @@ export const getRenderConnectionListItem = () => {
};
};
export const listRenderServices = async (appConnection: TRenderConnection): Promise<TRenderService[]> => {
const {
credentials: { apiKey }
} = appConnection;
const services: TRenderService[] = [];
let hasMorePages = true;
const perPage = 100;
let cursor;
while (hasMorePages) {
const res: TRawRenderService[] = (
await request.get<TRawRenderService[]>(`${IntegrationUrls.RENDER_API_URL}/v1/services`, {
params: new URLSearchParams({
...(cursor ? { cursor: String(cursor) } : {}),
limit: String(perPage)
}),
headers: {
Authorization: `Bearer ${apiKey}`,
Accept: "application/json",
"Accept-Encoding": "application/json"
}
})
).data;
res.forEach((item) => {
services.push({
name: item.service.name,
id: item.service.id
});
});
if (res.length < perPage) {
hasMorePages = false;
} else {
cursor = res[res.length - 1].cursor;
}
}
return services;
};
export const validateRenderConnectionCredentials = async (config: TRenderConnectionConfig) => {
const { credentials: inputCredentials } = config;
@@ -0,0 +1,30 @@
import { logger } from "@app/lib/logger";
import { OrgServiceActor } from "@app/lib/types";
import { AppConnection } from "../app-connection-enums";
import { listRenderServices } from "./render-connection-fns";
import { TRenderConnection } from "./render-connection-types";
type TGetAppConnectionFunc = (
app: AppConnection,
connectionId: string,
actor: OrgServiceActor
) => Promise<TRenderConnection>;
export const renderConnectionService = (getAppConnection: TGetAppConnectionFunc) => {
const listServices = async (connectionId: string, actor: OrgServiceActor) => {
const appConnection = await getAppConnection(AppConnection.Render, connectionId, actor);
try {
const services = await listRenderServices(appConnection);
return services;
} catch (error) {
logger.error(error, "Failed to list services for Render connection");
return [];
}
};
return {
listServices
};
};
@@ -20,3 +20,16 @@ export type TValidateRenderConnectionCredentialsSchema = typeof ValidateRenderCo
export type TRenderConnectionConfig = DiscriminativePick<TRenderConnectionInput, "method" | "app" | "credentials"> & {
orgId: string;
};
export type TRenderService = {
name: string;
id: string;
};
export type TRawRenderService = {
cursor: string;
service: {
id: string;
name: string;
};
};