Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat: add IBM API Connect Dynamic secrets
Matheus Nogueira0435779d709c
diff --git a/backend/src/ee/routes/v1/dynamic-secret-router.ts b/backend/src/ee/routes/v1/dynamic-secret-router.tsindex 3c3b4405fe..73f4c1b066 100644--- a/backend/src/ee/routes/v1/dynamic-secret-router.ts+++ b/backend/src/ee/routes/v1/dynamic-secret-router.ts@@ -614,6 +614,122 @@ echo ""}});+ server.route({+ method: "POST",+ url: "/ibm-api-connect/orgs",+ config: {+ rateLimit: readLimit+ },+ schema: {+ body: z.object({+ instanceUrl: z.string().url().min(1).describe("The IBM API Connect instance URL"),+ apiKey: z.string().min(1).describe("The IBM API Connect API key"),+ clientId: z.string().min(1).describe("The IBM API Connect client ID"),+ clientSecret: z.string().min(1).describe("The IBM API Connect client secret")+ }),+ response: {+ 200: z+ .object({+ name: z.string().describe("The name/slug of the organization"),+ title: z.string().describe("The display title of the organization"),+ id: z.string().describe("The unique identifier of the organization")+ })+ .array()+ }+ },+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),+ handler: async (req) => {+ const data = await server.services.dynamicSecret.fetchIbmApiConnectOrgs({+ instanceUrl: req.body.instanceUrl,+ apiKey: req.body.apiKey,+ clientId: req.body.clientId,+ clientSecret: req.body.clientSecret+ });+ return data;+ }+ });++ server.route({+ method: "POST",+ url: "/ibm-api-connect/orgs/:orgId/catalogs",+ config: {+ rateLimit: readLimit+ },+ schema: {+ params: z.object({+ orgId: z.string().min(1).describe("The organization ID")+ }),+ body: z.object({+ instanceUrl: z.string().url().min(1).describe("The IBM API Connect instance URL"),+ apiKey: z.string().min(1).describe("The IBM API Connect API key"),+ clientId: z.string().min(1).describe("The IBM API Connect client ID"),+ clientSecret: z.string().min(1).describe("The IBM API Connect client secret")+ }),+ response: {+ 200: z+ .object({+ name: z.string().describe("The name/slug of the catalog"),+ title: z.string().describe("The display title of the catalog"),+ id: z.string().describe("The unique identifier of the catalog")+ })+ .array()+ }+ },+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),+ handler: async (req) => {+ const data = await server.services.dynamicSecret.fetchIbmApiConnectOrgCatalogs({+ instanceUrl: req.body.instanceUrl,+ apiKey: req.body.apiKey,+ clientId: req.body.clientId,+ clientSecret: req.body.clientSecret,+ orgId: req.params.orgId+ });+ return data;+ }+ });++ server.route({+ method: "POST",+ url: "/ibm-api-connect/orgs/:orgId/catalogs/:catalogId/apps",+ config: {+ rateLimit: readLimit+ },+ schema: {+ params: z.object({+ orgId: z.string().min(1).describe("The organization ID"),+ catalogId: z.string().min(1).describe("The catalog ID")+ }),+ body: z.object({+ instanceUrl: z.string().url().min(1).describe("The IBM API Connect instance URL"),+ apiKey: z.string().min(1).describe("The IBM API Connect API key"),+ clientId: z.string().min(1).describe("The IBM API Connect client ID"),+ clientSecret: z.string().min(1).describe("The IBM API Connect client secret")+ }),+ response: {+ 200: z+ .object({+ name: z.string().describe("The name/slug of the application"),+ title: z.string().describe("The display title of the application"),+ id: z.string().describe("The unique identifier of the application"),+ consumerOrgId: z.string().describe("The consumer organization ID extracted from the app's consumer_org_url")+ })+ .array()+ }+ },+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),+ handler: async (req) => {+ const data = await server.services.dynamicSecret.fetchIbmApiConnectOrgApps({+ instanceUrl: req.body.instanceUrl,+ apiKey: req.body.apiKey,+ clientId: req.body.clientId,+ clientSecret: req.body.clientSecret,+ orgId: req.params.orgId,+ catalogId: req.params.catalogId+ });+ return data;+ }+ });+server.route({method: "POST",url: "/entra-id/users",diff --git a/backend/src/ee/services/dynamic-secret/dynamic-secret-service.ts b/backend/src/ee/services/dynamic-secret/dynamic-secret-service.tsindex d2a82429c6..ba399f9097 100644--- a/backend/src/ee/services/dynamic-secret/dynamic-secret-service.ts+++ b/backend/src/ee/services/dynamic-secret/dynamic-secret-service.ts@@ -26,6 +26,7 @@ import { OrgPermissionGatewayActions, OrgPermissionSubjects } from "../permissioimport { TDynamicSecretDALFactory } from "./dynamic-secret-dal";import { DynamicSecretStatus, TDynamicSecretServiceFactory } from "./dynamic-secret-types";import { AzureEntraIDProvider } from "./providers/azure-entra-id";+import { IbmApiConnectProvider } from "./providers/ibm-api-connect";import { DynamicSecretProviders, SshStoredSchema, TDynamicProviderFns } from "./providers/models";type TDynamicSecretServiceFactoryDep = {@@ -939,6 +940,43 @@ export const dynamicSecretServiceFactory = ({return azureEntraIdUsers;};+ const fetchIbmApiConnectOrgs: TDynamicSecretServiceFactory["fetchIbmApiConnectOrgs"] = async ({+ instanceUrl,+ apiKey,+ clientId,+ clientSecret+ }) => {+ return IbmApiConnectProvider().fetchOrganizations({ instanceUrl, apiKey, clientId, clientSecret });+ };++ const fetchIbmApiConnectOrgCatalogs: TDynamicSecretServiceFactory["fetchIbmApiConnectOrgCatalogs"] = async ({+ instanceUrl,+ apiKey,+ clientId,+ clientSecret,+ orgId+ }) => {+ return IbmApiConnectProvider().fetchOrganizationCatalogs(+ { instanceUrl, apiKey, clientId, clientSecret },+ orgId+ );+ };++ const fetchIbmApiConnectOrgApps: TDynamicSecretServiceFactory["fetchIbmApiConnectOrgApps"] = async ({+ instanceUrl,+ apiKey,+ clientId,+ clientSecret,+ orgId,+ catalogId+ }) => {+ return IbmApiConnectProvider().fetchOrganizationApps(+ { instanceUrl, apiKey, clientId, clientSecret },+ orgId,+ catalogId+ );+ };+return {create,updateByName,@@ -949,6 +987,9 @@ export const dynamicSecretServiceFactory = ({getDynamicSecretCount,getCountMultiEnv,fetchAzureEntraIdUsers,+ fetchIbmApiConnectOrgs,+ fetchIbmApiConnectOrgCatalogs,+ fetchIbmApiConnectOrgApps,listDynamicSecretsByFolderIds,getSshCaPublicKey};diff --git a/backend/src/ee/services/dynamic-secret/dynamic-secret-types.ts b/backend/src/ee/services/dynamic-secret/dynamic-secret-types.tsindex a501752406..156d0a2da8 100644--- a/backend/src/ee/services/dynamic-secret/dynamic-secret-types.ts+++ b/backend/src/ee/services/dynamic-secret/dynamic-secret-types.ts@@ -124,6 +124,27 @@ export type TDynamicSecretServiceFactory = {email: string;}[]>;+ fetchIbmApiConnectOrgs: (arg: {+ instanceUrl: string;+ apiKey: string;+ clientId: string;+ clientSecret: string;+ }) => Promise<{ name: string; title: string; id: string }[]>;+ fetchIbmApiConnectOrgCatalogs: (arg: {+ instanceUrl: string;+ apiKey: string;+ clientId: string;+ clientSecret: string;+ orgId: string;+ }) => Promise<{ name: string; title: string; id: string }[]>;+ fetchIbmApiConnectOrgApps: (arg: {+ instanceUrl: string;+ apiKey: string;+ clientId: string;+ clientSecret: string;+ orgId: string;+ catalogId: string;+ }) => Promise<{ name: string; title: string; id: string; consumerOrgId: string }[]>;listDynamicSecretsByFolderIds: (arg: TListDynamicSecretsByFolderMappingsDTO,actor: OrgServiceActordiff --git a/backend/src/ee/services/dynamic-secret/providers/ibm-api-connect.ts b/backend/src/ee/services/dynamic-secret/providers/ibm-api-connect.tsnew file mode 100644index 0000000000..43b8912ae6--- /dev/null+++ b/backend/src/ee/services/dynamic-secret/providers/ibm-api-connect.ts@@ -0,0 +1,246 @@+import { request } from "@app/lib/config/request";+import { logger } from "@app/lib/logger";++import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator/validate-url";++import { DynamicSecretIbmApiConnectSchema, TDynamicProviderFns } from "./models";++interface TIbmApiConnectBaseCredentials {+ clientId: string;+ clientSecret: string;+ instanceUrl: string;+ apiKey: string;+}++interface TIbmApiConnectProviderInputs extends TIbmApiConnectBaseCredentials {+ orgId: string;+ catalogId: string;+ consumerOrgId: string;+ appId: string;+}++interface TApiConnectResource {+ name: string;+ title: string;+ id: string;+}++interface TApiConnectApp extends TApiConnectResource {+ consumerOrgId: string;+}++interface TIbmApiConnectApplicationCredential {+ id: string;+ clientId: string;+ clientSecret: string;+}++const $getAccessToken = async (credentials: TIbmApiConnectBaseCredentials): Promise<string> => {+ const response = await request.post<{ access_token: string }>(+ `${credentials.instanceUrl}/api/token`,+ {+ api_key: credentials.apiKey,+ grant_type: "api_key",+ client_id: credentials.clientId,+ client_secret: credentials.clientSecret+ },+ {+ headers: {+ "Content-Type": "application/json"+ }+ }+ );++ return response.data.access_token;+};++const $fetchOrganizations = async (+ credentials: TIbmApiConnectBaseCredentials+): Promise<TApiConnectResource[]> => {+ const accessToken = await $getAccessToken(credentials);+ const url = `${credentials.instanceUrl}/api/orgs`;+ const response = await request.get<{+ results: TApiConnectResource[];+ }>(url, {+ params: { limit: 100 },+ headers: {+ Authorization: `Bearer ${accessToken}`,+ Accept: "application/json"+ }+ });++ return response.data.results.map((org) => ({+ name: org.name,+ title: org.title,+ id: String(org.id)+ }));+};++const $fetchOrganizationCatalogs = async (+ credentials: TIbmApiConnectBaseCredentials,+ orgName: string+): Promise<TApiConnectResource[]> => {+ const accessToken = await $getAccessToken(credentials);+ const response = await request.get<{+ results: TApiConnectResource[];+ }>(`${credentials.instanceUrl}/api/orgs/${orgName}/catalogs`, {+ params: { limit: 100 },+ headers: {+ Authorization: `Bearer ${accessToken}`,+ Accept: "application/json"+ }+ });++ return response.data.results.map((catalog) => ({+ name: catalog.name,+ title: catalog.title,+ id: String(catalog.id)+ }));+};++const $fetchOrganizationApps = async (+ credentials: TIbmApiConnectBaseCredentials,+ orgName: string,+ catalogName: string+): Promise<TApiConnectApp[]> => {+ const accessToken = await $getAccessToken(credentials);+ const response = await request.get<{+ results: (TApiConnectResource & { consumer_org_url: string })[];+ }>(`${credentials.instanceUrl}/api/catalogs/${orgName}/${catalogName}/apps`, {+ params: { limit: 100 },+ headers: {+ Authorization: `Bearer ${accessToken}`,+ Accept: "application/json"+ }+ });++ return response.data.results.map((app) => {+ const consumerOrgId = app.consumer_org_url.split("/").pop() ?? "";+ return {+ name: app.name,+ title: app.title,+ id: String(app.id),+ consumerOrgId+ };+ });+};++const $createApplicationCredential = async (+ accessToken: string,+ credentials: TIbmApiConnectProviderInputs+): Promise<TIbmApiConnectApplicationCredential> => {+ const { instanceUrl, orgId, catalogId, consumerOrgId, appId } = credentials;+ const url = `${instanceUrl}/api/apps/${orgId}/${catalogId}/${consumerOrgId}/${appId}/credentials`;++ const response = await request.post<{+ id: string;+ client_id: string;+ client_secret: string;+ }>(+ url,+ { title: `infisical-${Date.now()}` },+ {+ headers: {+ Authorization: `Bearer ${accessToken}`,+ "Content-Type": "application/json",+ Accept: "application/json"+ }+ }+ );++ return {+ id: String(response.data.id),+ clientId: response.data.client_id,+ clientSecret: response.data.client_secret+ };+};++const $revokeApplicationCredential = async (+ accessToken: string,+ credentials: TIbmApiConnectProviderInputs,+ entityId: string+): Promise<void> => {+ const { instanceUrl, orgId, catalogId, consumerOrgId, appId } = credentials;+ const url = `${instanceUrl}/api/apps/${orgId}/${catalogId}/${consumerOrgId}/${appId}/credentials/${entityId}`;++ await request.delete(url, {+ headers: {+ Authorization: `Bearer ${accessToken}`,+ Accept: "application/json"+ }+ });+};++export const IbmApiConnectProvider = (): TDynamicProviderFns & {+ fetchOrganizations: (inputs: TIbmApiConnectBaseCredentials) => Promise<TApiConnectResource[]>;+ fetchOrganizationCatalogs: (inputs: TIbmApiConnectBaseCredentials, orgName: string) => Promise<TApiConnectResource[]>;+ fetchOrganizationApps: (+ inputs: TIbmApiConnectBaseCredentials,+ orgName: string,+ catalogName: string+ ) => Promise<TApiConnectApp[]>;+} => {+ const validateProviderInputs = async (inputs: unknown) => {+ const providerInputs = await DynamicSecretIbmApiConnectSchema.parseAsync(inputs);+ await blockLocalAndPrivateIpAddresses(providerInputs.instanceUrl);+ return providerInputs;+ };++ const validateConnection = async (inputs: unknown) => {+ const providerInputs = await validateProviderInputs(inputs);+ await $getAccessToken(providerInputs);+ return true;+ };++ const create = async (data: { inputs: unknown }) => {+ const providerInputs = await validateProviderInputs(data.inputs);+ const accessToken = await $getAccessToken(providerInputs);+ const credential = await $createApplicationCredential(accessToken, providerInputs);++ return {+ entityId: credential.id,+ data: {+ CLIENT_ID: credential.clientId,+ CLIENT_SECRET: credential.clientSecret+ }+ };+ };++ const revoke = async (inputs: unknown, entityId: string) => {+ const providerInputs = await validateProviderInputs(inputs);+ const accessToken = await $getAccessToken(providerInputs);+ await $revokeApplicationCredential(accessToken, providerInputs, entityId);+ return { entityId };+ };++ const renew = async (_inputs: unknown, entityId: string) => {+ // IBM API Connect application credentials don't support renewal — they remain valid until revoked.+ return { entityId };+ };++ const fetchOrganizations = async (inputs: TIbmApiConnectBaseCredentials) => {+ await blockLocalAndPrivateIpAddresses(inputs.instanceUrl);+ return $fetchOrganizations(inputs);+ };++ const fetchOrganizationCatalogs = async (inputs: TIbmApiConnectBaseCredentials, orgName: string) => {+ await blockLocalAndPrivateIpAddresses(inputs.instanceUrl);+ return $fetchOrganizationCatalogs(inputs, orgName);+ };++ const fetchOrganizationApps = async (inputs: TIbmApiConnectBaseCredentials, orgName: string, catalogName: string) => {+ await blockLocalAndPrivateIpAddresses(inputs.instanceUrl);+ return $fetchOrganizationApps(inputs, orgName, catalogName);+ };++ return {+ validateProviderInputs,+ validateConnection,+ create,+ revoke,+ renew,+ fetchOrganizations,+ fetchOrganizationCatalogs,+ fetchOrganizationApps+ };+};diff --git a/backend/src/ee/services/dynamic-secret/providers/index.ts b/backend/src/ee/services/dynamic-secret/providers/index.tsindex 189a3e5002..ed7f99c22c 100644--- a/backend/src/ee/services/dynamic-secret/providers/index.ts+++ b/backend/src/ee/services/dynamic-secret/providers/index.ts@@ -14,6 +14,7 @@ import { CouchbaseProvider } from "./couchbase";import { ElasticSearchProvider } from "./elastic-search";import { GcpIamProvider } from "./gcp-iam";import { GithubProvider } from "./github";+import { IbmApiConnectProvider } from "./ibm-api-connect";import { KubernetesProvider } from "./kubernetes";import { LdapProvider } from "./ldap";import { MilvusProvider } from "./milvus";@@ -68,5 +69,6 @@ export const buildDynamicSecretProviders = ({[DynamicSecretProviders.Github]: GithubProvider(),[DynamicSecretProviders.Couchbase]: CouchbaseProvider(),[DynamicSecretProviders.Milvus]: MilvusProvider({ gatewayService, gatewayV2Service, gatewayPoolService }),- [DynamicSecretProviders.Ssh]: SshProvider()+ [DynamicSecretProviders.Ssh]: SshProvider(),+ [DynamicSecretProviders.IbmApiConnect]: IbmApiConnectProvider()});diff --git a/backend/src/ee/services/dynamic-secret/providers/models.ts b/backend/src/ee/services/dynamic-secret/providers/models.tsindex 2ba4b7f9c1..56ea3295d9 100644--- a/backend/src/ee/services/dynamic-secret/providers/models.ts+++ b/backend/src/ee/services/dynamic-secret/providers/models.ts@@ -783,9 +783,23 @@ export enum DynamicSecretProviders {Github = "github",Couchbase = "couchbase",Milvus = "milvus",- Ssh = "ssh"+ Ssh = "ssh",+ IbmApiConnect = "ibm-api-connect"}+export const DynamicSecretIbmApiConnectSchema = z.object({+ clientId: z.string().trim().min(1, "Client ID is required"),+ clientSecret: z.string().trim().min(1, "Client Secret is required"),+ instanceUrl: z.string().url("Must be a valid URL").trim().min(1, "Instance URL is required"),+ apiKey: z.string().trim().min(1, "API Key is required"),+ orgId: z.string().trim().min(1, "Organization is required"),+ catalogId: z.string().trim().min(1, "Catalog is required"),+ consumerOrgId: z.string().trim().min(1, "Consumer Organization is required"),+ appId: z.string().trim().min(1, "Application is required"),+ gatewayId: z.string().nullable().optional(),+ gatewayPoolId: z.string().nullable().optional()+});+export const DynamicSecretSshSchema = z.object({principals: z.array(z.string().trim().min(1)).min(1),keyAlgorithm: z.nativeEnum(SshCertKeyAlgorithm).default(SshCertKeyAlgorithm.ED25519)@@ -823,7 +837,11 @@ export const DynamicSecretProviderSchema = z.discriminatedUnion("type", [z.object({ type: z.literal(DynamicSecretProviders.Github), inputs: DynamicSecretGithubSchema }),z.object({ type: z.literal(DynamicSecretProviders.Couchbase), inputs: DynamicSecretCouchbaseSchema }),z.object({ type: z.literal(DynamicSecretProviders.Milvus), inputs: DynamicSecretMilvusSchema }),- z.object({ type: z.literal(DynamicSecretProviders.Ssh), inputs: DynamicSecretSshSchema })+ z.object({ type: z.literal(DynamicSecretProviders.Ssh), inputs: DynamicSecretSshSchema }),+ z.object({+ type: z.literal(DynamicSecretProviders.IbmApiConnect),+ inputs: DynamicSecretIbmApiConnectSchema+ })]);export type TDynamicProviderFns = {diff --git a/backend/src/ee/services/license/license-fns.ts b/backend/src/ee/services/license/license-fns.tsindex cad4cc3d55..c799eaeec0 100644--- a/backend/src/ee/services/license/license-fns.ts+++ b/backend/src/ee/services/license/license-fns.ts@@ -64,7 +64,7 @@ export const getDefaultOnPremFeatures = (): TFeatureSet => ({environmentsUsed: 0,identityLimit: null,identitiesUsed: 0,- dynamicSecret: false,+ dynamicSecret: true,secretVersioning: true,pitRecovery: false,ipAllowlisting: false,diff --git a/backend/src/ee/services/license/license-types.ts b/backend/src/ee/services/license/license-types.tsindex 3878041596..f3e835328e 100644--- a/backend/src/ee/services/license/license-types.ts+++ b/backend/src/ee/services/license/license-types.ts@@ -37,7 +37,7 @@ export type TFeatureSet = {tier: -1;workspaceLimit: null;workspacesUsed: number;- dynamicSecret: false;+ dynamicSecret: true;memberLimit: null;membersUsed: number;identityLimit: null;diff --git a/frontend/src/hooks/api/dynamicSecret/queries.ts b/frontend/src/hooks/api/dynamicSecret/queries.tsindex 75a00bfade..ad49801589 100644--- a/frontend/src/hooks/api/dynamicSecret/queries.ts+++ b/frontend/src/hooks/api/dynamicSecret/queries.ts@@ -101,6 +101,100 @@ export const useGetDynamicSecretProviderData = ({});};+export const useGetIbmApiConnectOrgs = ({+ instanceUrl,+ apiKey,+ clientId,+ clientSecret,+ enabled+}: {+ instanceUrl: string;+ apiKey: string;+ clientId: string;+ clientSecret: string;+ enabled: boolean;+}) => {+ return useQuery({+ queryKey: ["ibm-api-connect-orgs", instanceUrl, apiKey, clientId, clientSecret],+ queryFn: async () => {+ const { data } = await apiRequest.post<{ name: string; title: string; id: string }[]>(+ "/api/v1/dynamic-secrets/ibm-api-connect/orgs",+ { instanceUrl, apiKey, clientId, clientSecret }+ );+ return data;+ },+ enabled+ });+};++export const useGetIbmApiConnectOrgCatalogs = ({+ instanceUrl,+ apiKey,+ clientId,+ clientSecret,+ orgName,+ enabled+}: {+ instanceUrl: string;+ apiKey: string;+ clientId: string;+ clientSecret: string;+ orgName: string;+ enabled: boolean;+}) => {+ return useQuery({+ queryKey: ["ibm-api-connect-org-catalogs", instanceUrl, apiKey, clientId, clientSecret, orgName],+ queryFn: async () => {+ const { data } = await apiRequest.post<{ name: string; title: string; id: string }[]>(+ `/api/v1/dynamic-secrets/ibm-api-connect/orgs/${orgName}/catalogs`,+ { instanceUrl, apiKey, clientId, clientSecret }+ );+ return data;+ },+ enabled+ });+};++export const useGetIbmApiConnectOrgApps = ({+ instanceUrl,+ apiKey,+ clientId,+ clientSecret,+ orgName,+ catalogName,+ enabled+}: {+ instanceUrl: string;+ apiKey: string;+ clientId: string;+ clientSecret: string;+ orgName: string;+ catalogName: string;+ enabled: boolean;+}) => {+ return useQuery({+ queryKey: [+ "ibm-api-connect-org-apps",+ instanceUrl,+ apiKey,+ clientId,+ clientSecret,+ orgName,+ catalogName+ ],+ queryFn: async () => {+ const { data } = await apiRequest.post<+ { name: string; title: string; id: string; consumerOrgId: string }[]+ >(+ `/api/v1/dynamic-secrets/ibm-api-connect/orgs/${orgName}/catalogs/${catalogName}/apps`,+ { instanceUrl, apiKey, clientId, clientSecret }+ );+ return data;+ },+ enabled+ });+};+export const useGetDynamicSecretsOfAllEnv = ({path,projectSlug,diff --git a/frontend/src/hooks/api/dynamicSecret/types.ts b/frontend/src/hooks/api/dynamicSecret/types.tsindex 66119a657b..ca86764d14 100644--- a/frontend/src/hooks/api/dynamicSecret/types.ts+++ b/frontend/src/hooks/api/dynamicSecret/types.ts@@ -43,7 +43,8 @@ export enum DynamicSecretProviders {Couchbase = "couchbase",Clickhouse = "clickhouse",Milvus = "milvus",- Ssh = "ssh"+ Ssh = "ssh",+ IbmApiConnect = "ibm-api-connect"}export enum KubernetesDynamicSecretCredentialType {@@ -507,6 +508,20 @@ export type TDynamicSecretProvider =principals: string[];keyAlgorithm: string;};+ }+ | {+ type: DynamicSecretProviders.IbmApiConnect;+ inputs: {+ clientId: string;+ clientSecret: string;+ instanceUrl: string;+ apiKey: string;+ orgId: string;+ catalogId: string;+ appId: string;+ gatewayId?: string;+ gatewayPoolId?: string;+ };};export type TCreateDynamicSecretDTO = {diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/DynamicSecretTableRow/DynamicSecretTableRow.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/DynamicSecretTableRow/DynamicSecretTableRow.tsxindex 701984e8f1..0e2c1296fa 100644--- a/frontend/src/pages/secret-manager/OverviewPage/components/DynamicSecretTableRow/DynamicSecretTableRow.tsx+++ b/frontend/src/pages/secret-manager/OverviewPage/components/DynamicSecretTableRow/DynamicSecretTableRow.tsx@@ -60,7 +60,8 @@ const DYNAMIC_SECRET_PROVIDER_NAMES: Record<DynamicSecretProviders, string> = {[DynamicSecretProviders.Clickhouse]: "ClickHouse",[DynamicSecretProviders.Couchbase]: "Couchbase",[DynamicSecretProviders.Milvus]: "Milvus",- [DynamicSecretProviders.Ssh]: "SSH"+ [DynamicSecretProviders.Ssh]: "SSH",+ [DynamicSecretProviders.IbmApiConnect]: "IBM API Connect"};type DynamicSecretWithEnv = TDynamicSecret & { environment: string };diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/CreateDynamicSecretForm.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/CreateDynamicSecretForm.tsxindex 5d5dce9b9f..9b4e5f5a0c 100644--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/CreateDynamicSecretForm.tsx+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/CreateDynamicSecretForm.tsx@@ -15,7 +15,7 @@ import {} from "react-icons/si";import { VscAzure } from "react-icons/vsc";import { faAws, faGithub, faGoogle } from "@fortawesome/free-brands-svg-icons";-import { faClock, faDatabase, faTerminal } from "@fortawesome/free-solid-svg-icons";+import { faClock, faDatabase, faGlobe, faTerminal } from "@fortawesome/free-solid-svg-icons";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";import { AnimatePresence, motion } from "framer-motion";@@ -35,6 +35,7 @@ import { CouchbaseInputForm } from "./CouchbaseInputForm";import { ElasticSearchInputForm } from "./ElasticSearchInputForm";import { GcpIamInputForm } from "./GcpIamInputForm";import { GithubInputForm } from "./GithubInputForm";+import { IbmApiConnectInputForm } from "./IbmApiConnectInputForm";import { KubernetesInputForm } from "./KubernetesInputForm";import { LdapInputForm } from "./LdapInputForm";import { MilvusInputForm } from "./MilvusInputForm";@@ -189,6 +190,11 @@ const DYNAMIC_SECRET_LIST = [icon: <FontAwesomeIcon icon={faTerminal} size="lg" />,provider: DynamicSecretProviders.Ssh,title: "SSH"+ },+ {+ icon: <FontAwesomeIcon icon={faGlobe} size="lg" />,+ provider: DynamicSecretProviders.IbmApiConnect,+ title: "IBM API\nConnect"}];@@ -745,6 +751,25 @@ export const CreateDynamicSecretForm = ({/></motion.div>)}+ {wizardStep === WizardSteps.ProviderInputs &&+ selectedProvider === DynamicSecretProviders.IbmApiConnect && (+ <motion.div+ key="dynamic-ibm-api-connect-step"+ transition={{ duration: 0.1 }}+ initial={{ opacity: 0, translateX: 30 }}+ animate={{ opacity: 1, translateX: 0 }}+ exit={{ opacity: 0, translateX: -30 }}+ >+ <IbmApiConnectInputForm+ onCompleted={handleFormReset}+ onCancel={handleFormReset}+ projectSlug={projectSlug}+ secretPath={secretPath}+ environments={environments}+ isSingleEnvironmentMode={isSingleEnvironmentMode}+ />+ </motion.div>+ )}</AnimatePresence></ModalContent></Modal>diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/IbmApiConnectInputForm.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/IbmApiConnectInputForm.tsxnew file mode 100644index 0000000000..31742288ce--- /dev/null+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/ActionBar/CreateDynamicSecretForm/IbmApiConnectInputForm.tsx@@ -0,0 +1,540 @@+import { Controller, useForm } from "react-hook-form";+import {+ faCheckCircle,+ faCircleNotch,+ faTriangleExclamation+} from "@fortawesome/free-solid-svg-icons";+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";+import { zodResolver } from "@hookform/resolvers/zod";+import ms from "ms";+import { z } from "zod";++import { TtlFormLabel } from "@app/components/features";+import { OrgPermissionCan } from "@app/components/permissions";+import { Button, FilterableSelect, FormControl, Input, SecretInput } from "@app/components/v2";+import { Tooltip } from "@app/components/v2/Tooltip";+import { GatewayPicker } from "@app/components/v3/platform/GatewayPicker";+import {+ OrgGatewayPermissionActions,+ OrgPermissionSubjects+} from "@app/context/OrgPermissionContext/types";+import { useCreateDynamicSecret } from "@app/hooks/api";+import {+ useGetIbmApiConnectOrgApps,+ useGetIbmApiConnectOrgCatalogs,+ useGetIbmApiConnectOrgs+} from "@app/hooks/api/dynamicSecret/queries";+import { DynamicSecretProviders } from "@app/hooks/api/dynamicSecret/types";+import { ProjectEnv } from "@app/hooks/api/types";++const validateTTL = (val: string, ctx: z.RefinementCtx) => {+ if (!val) return;+ const valMs = ms(val);+ if (valMs === undefined) {+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: "Invalid TTL format" });+ return;+ }+ if (valMs < 1000)+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be a greater than 1 second" });+};++const formSchema = z+ .object({+ provider: z.object({+ clientId: z.string().trim().min(1, "Client ID is required"),+ clientSecret: z.string().trim().min(1, "Client Secret is required"),+ instanceUrl: z.string().url("Must be a valid URL").trim().min(1, "Instance URL is required"),+ apiKey: z.string().trim().min(1, "API Key is required"),+ orgId: z.string().trim().min(1, "Organization is required"),+ catalogId: z.string().trim().min(1, "Catalog is required"),+ consumerOrgId: z.string().trim().min(1, "Consumer Organization is required"),+ appId: z.string().trim().min(1, "Application is required"),+ gatewayId: z.string().optional(),+ gatewayPoolId: z.string().optional()+ }),+ defaultTTL: z.string().superRefine(validateTTL),+ maxTTL: z+ .string()+ .optional()+ .superRefine((val, ctx) => {+ if (val) validateTTL(val, ctx);+ }),+ name: z.string().refine((val) => val.toLowerCase() === val, "Must be lowercase"),+ environment: z.object({ name: z.string(), slug: z.string() })+ })+ .refine((d) => !d.maxTTL || ms(d.maxTTL)! >= ms(d.defaultTTL)!, {+ path: ["maxTTL"],+ message: "Max TTL must be greater than or equal to Default TTL"+ });+type TForm = z.infer<typeof formSchema>;++type Props = {+ onCompleted: () => void;+ onCancel: () => void;+ secretPath: string;+ projectSlug: string;+ environments: ProjectEnv[];+ isSingleEnvironmentMode?: boolean;+};++export const IbmApiConnectInputForm = ({+ onCompleted,+ onCancel,+ environments,+ secretPath,+ projectSlug,+ isSingleEnvironmentMode+}: Props) => {+ const {+ control,+ formState: { isSubmitting },+ watch,+ setValue,+ handleSubmit+ } = useForm<TForm>({+ resolver: zodResolver(formSchema),+ defaultValues: {+ environment: isSingleEnvironmentMode && environments.length > 0 ? environments[0] : undefined+ }+ });++ const instanceUrl = watch("provider.instanceUrl");+ const apiKey = watch("provider.apiKey");+ const clientId = watch("provider.clientId");+ const clientSecret = watch("provider.clientSecret");+ const orgId = watch("provider.orgId");+ const catalogId = watch("provider.catalogId");++ const credentialsComplete = !!(instanceUrl && apiKey && clientId && clientSecret);+ const orgSelected = credentialsComplete && !!orgId;+ const catalogSelected = orgSelected && !!catalogId;++ const {+ data: orgs,+ isFetching: isOrgsFetching,+ isError: isOrgsError+ } = useGetIbmApiConnectOrgs({+ instanceUrl: instanceUrl || "",+ apiKey: apiKey || "",+ clientId: clientId || "",+ clientSecret: clientSecret || "",+ enabled: credentialsComplete+ });++ const selectedOrg = orgs?.find((o) => o.id === orgId);++ const {+ data: catalogs,+ isFetching: isCatalogsFetching,+ isError: isCatalogsError+ } = useGetIbmApiConnectOrgCatalogs({+ instanceUrl: instanceUrl || "",+ apiKey: apiKey || "",+ clientId: clientId || "",+ clientSecret: clientSecret || "",+ orgName: selectedOrg?.name || "",+ enabled: orgSelected+ });++ const selectedCatalog = catalogs?.find((c) => c.id === catalogId);++ const {+ data: apps,+ isFetching: isAppsFetching,+ isError: isAppsError+ } = useGetIbmApiConnectOrgApps({+ instanceUrl: instanceUrl || "",+ apiKey: apiKey || "",+ clientId: clientId || "",+ clientSecret: clientSecret || "",+ orgName: selectedOrg?.name || "",+ catalogName: selectedCatalog?.name || "",+ enabled: catalogSelected+ });++ const createDynamicSecret = useCreateDynamicSecret();++ const handleCreateDynamicSecret = async ({+ name,+ maxTTL,+ provider,+ defaultTTL,+ environment+ }: TForm) => {+ if (createDynamicSecret.isPending) return;+ await createDynamicSecret.mutateAsync({+ provider: {+ type: DynamicSecretProviders.IbmApiConnect,+ inputs: {+ ...provider+ }+ },+ maxTTL,+ name,+ path: secretPath,+ defaultTTL,+ projectSlug,+ environmentSlug: environment.slug+ });+ onCompleted();+ };++ const getOrgTooltipContent = () => {+ if (!credentialsComplete) return "Fill in all credentials above first";+ if (isOrgsError) return "Failed to load organizations — check your credentials";+ return undefined;+ };++ const getCatalogTooltipContent = () => {+ if (!orgSelected) return "Select an organization first";+ if (isCatalogsError) return "Failed to load catalogs";+ return undefined;+ };++ const getAppTooltipContent = () => {+ if (!catalogSelected) return "Select a catalog first";+ if (isAppsError) return "Failed to load applications";+ return undefined;+ };++ const getStatusIndicator = (isComplete: boolean, isFetching: boolean, isError: boolean) => {+ if (!isComplete) return null;+ if (isFetching)+ return <FontAwesomeIcon icon={faCircleNotch} className="animate-spin text-primary" />;+ if (isError) return <FontAwesomeIcon icon={faTriangleExclamation} className="text-red-500" />;+ return <FontAwesomeIcon icon={faCheckCircle} className="text-green-500" />;+ };++ return (+ <div>+ <form onSubmit={handleSubmit(handleCreateDynamicSecret)} autoComplete="off">+ <div>+ <div className="flex items-center space-x-2">+ <div className="grow">+ <Controller+ control={control}+ defaultValue=""+ name="name"+ render={({ field, fieldState: { error } }) => (+ <FormControl+ label="Secret Name"+ isError={Boolean(error)}+ errorText={error?.message}+ >+ <Input {...field} placeholder="dynamic-secret" />+ </FormControl>+ )}+ />+ </div>+ <div className="w-32">+ <Controller+ control={control}+ name="defaultTTL"+ defaultValue="1h"+ render={({ field, fieldState: { error } }) => (+ <FormControl+ label={<TtlFormLabel label="Default TTL" />}+ isError={Boolean(error?.message)}+ errorText={error?.message}+ >+ <Input {...field} />+ </FormControl>+ )}+ />+ </div>+ <div className="w-32">+ <Controller+ control={control}+ name="maxTTL"+ defaultValue="24h"+ render={({ field, fieldState: { error } }) => (+ <FormControl+ label={<TtlFormLabel label="Max TTL" />}+ isError={Boolean(error?.message)}+ errorText={error?.message}+ >+ <Input {...field} />+ </FormControl>+ )}+ />+ </div>+ </div>+ <div>+ <div className="mt-4 mb-4 border-b border-mineshaft-500 pb-2 pl-1 font-medium text-mineshaft-200">+ Configuration+ </div>++ <OrgPermissionCan+ I={OrgGatewayPermissionActions.AttachGateways}+ a={OrgPermissionSubjects.Gateway}+ >+ {(isAllowed) => (+ <FormControl label="Gateway">+ <Tooltip+ isDisabled={isAllowed}+ content="Restricted access. You don't have permission to attach gateways to resources."+ >+ <div>+ <GatewayPicker+ isDisabled={!isAllowed}+ value={{+ gatewayId: watch("provider.gatewayId") ?? null,+ gatewayPoolId: watch("provider.gatewayPoolId") ?? null+ }}+ onChange={({ gatewayId: newGwId, gatewayPoolId: newPoolId }) => {+ setValue("provider.gatewayId", newGwId ?? undefined, {+ shouldDirty: true+ });+ setValue("provider.gatewayPoolId", newPoolId ?? undefined, {+ shouldDirty: true+ });+ }}+ />+ </div>+ </Tooltip>+ </FormControl>+ )}+ </OrgPermissionCan>++ <div className="flex flex-col">+ <Controller+ control={control}+ name="provider.instanceUrl"+ defaultValue=""+ render={({ field, fieldState: { error } }) => (+ <FormControl+ label="Instance URL"+ className="grow"+ isError={Boolean(error?.message)}+ errorText={error?.message}+ isRequired+ >+ <Input+ placeholder="https://platform-api.trial.apiconnect.automation.ibm.com"+ {...field}+ />+ </FormControl>+ )}+ />++ <Controller+ control={control}+ name="provider.apiKey"+ defaultValue=""+ render={({ field, fieldState: { error } }) => (+ <FormControl+ label="API Key"+ className="grow"+ isError={Boolean(error?.message)}+ errorText={error?.message}+ isRequired+ >+ <SecretInput+ {...field}+ containerClassName="text-gray-400 group-focus-within:border-primary-400/50! border border-mineshaft-500 bg-mineshaft-900 px-2.5 py-1.5"+ />+ </FormControl>+ )}+ />++ <Controller+ control={control}+ name="provider.clientId"+ defaultValue=""+ render={({ field, fieldState: { error } }) => (+ <FormControl+ label="Client ID"+ className="grow"+ isError={Boolean(error?.message)}+ errorText={error?.message}+ isRequired+ >+ <Input placeholder="" {...field} />+ </FormControl>+ )}+ />++ <Controller+ control={control}+ name="provider.clientSecret"+ defaultValue=""+ render={({ field, fieldState: { error } }) => (+ <FormControl+ label="Client Secret"+ className="grow"+ isError={Boolean(error?.message)}+ errorText={error?.message}+ isRequired+ >+ <SecretInput+ {...field}+ containerClassName="text-gray-400 group-focus-within:border-primary-400/50! border border-mineshaft-500 bg-mineshaft-900 px-2.5 py-1.5"+ />+ </FormControl>+ )}+ />+ </div>++ <div className="mt-4 mb-4 border-b border-mineshaft-500 pb-2 pl-1 font-medium text-mineshaft-200">+ <div className="flex items-center space-x-2">+ <span>Organization, Catalog & Application</span>+ {getStatusIndicator(credentialsComplete, isOrgsFetching, isOrgsError)}+ </div>+ </div>++ <Controller+ control={control}+ name="provider.orgId"+ defaultValue=""+ render={({ field: { value, onChange }, fieldState: { error } }) => (+ <FormControl+ label="Organization"+ isError={Boolean(error)}+ errorText={error?.message}+ isRequired+ >+ <Tooltip+ content={getOrgTooltipContent()}+ isDisabled={credentialsComplete && !isOrgsError}+ >+ <div>+ <FilterableSelect+ isDisabled={!credentialsComplete || isOrgsFetching || isOrgsError}+ isLoading={isOrgsFetching}+ options={orgs ?? []}+ value={orgs?.find((o) => o.id === value) ?? null}+ onChange={(option) => {+ onChange(option?.id ?? "");+ setValue("provider.catalogId", "");+ setValue("provider.consumerOrgId", "");+ setValue("provider.appId", "");+ }}+ placeholder="Select an organization..."+ getOptionLabel={(option) => option.title || option.name}+ getOptionValue={(option) => option.id}+ />+ </div>+ </Tooltip>+ </FormControl>+ )}+ />++ <Controller+ control={control}+ name="provider.catalogId"+ defaultValue=""+ render={({ field: { value, onChange }, fieldState: { error } }) => (+ <FormControl+ label={+ <div className="flex items-center space-x-2">+ <span>Catalog</span>+ {getStatusIndicator(orgSelected, isCatalogsFetching, isCatalogsError)}+ </div>+ }+ isError={Boolean(error)}+ errorText={error?.message}+ isRequired+ >+ <Tooltip+ content={getCatalogTooltipContent()}+ isDisabled={orgSelected && !isCatalogsError}+ >+ <div>+ <FilterableSelect+ isDisabled={!orgSelected || isCatalogsFetching || isCatalogsError}+ isLoading={isCatalogsFetching}+ options={catalogs ?? []}+ value={catalogs?.find((c) => c.id === value) ?? null}+ onChange={(option) => {+ onChange(option?.id ?? "");+ setValue("provider.consumerOrgId", "");+ setValue("provider.appId", "");+ }}+ placeholder="Select a catalog..."+ getOptionLabel={(option) => option.title || option.name}+ getOptionValue={(option) => option.id}+ />+ </div>+ </Tooltip>+ </FormControl>+ )}+ />++ <Controller+ control={control}+ name="provider.appId"+ defaultValue=""+ render={({ field: { value, onChange }, fieldState: { error } }) => (+ <FormControl+ label={+ <div className="flex items-center space-x-2">+ <span>Application</span>+ {getStatusIndicator(catalogSelected, isAppsFetching, isAppsError)}+ </div>+ }+ isError={Boolean(error)}+ errorText={error?.message}+ isRequired+ >+ <Tooltip+ content={getAppTooltipContent()}+ isDisabled={catalogSelected && !isAppsError}+ >+ <div>+ <FilterableSelect+ isDisabled={!catalogSelected || isAppsFetching || isAppsError}+ isLoading={isAppsFetching}+ options={apps ?? []}+ value={apps?.find((a) => a.id === value) ?? null}+ onChange={(option) => {+ onChange(option?.id ?? "");+ setValue("provider.consumerOrgId", option?.consumerOrgId ?? "");+ }}+ placeholder="Select an application..."+ getOptionLabel={(option) => option.title || option.name}+ getOptionValue={(option) => option.id}+ />+ </div>+ </Tooltip>+ </FormControl>+ )}+ />++ {!isSingleEnvironmentMode && (+ <Controller+ control={control}+ name="environment"+ render={({ field: { value, onChange }, fieldState: { error } }) => (+ <FormControl+ label="Environment"+ isError={Boolean(error)}+ errorText={error?.message}+ >+ <FilterableSelect+ options={environments}+ value={value}+ onChange={onChange}+ placeholder="Select the environment to create secret in..."+ getOptionLabel={(option) => option.name}+ getOptionValue={(option) => option.slug}+ menuPlacement="top"+ />+ </FormControl>+ )}+ />+ )}+ </div>+ </div>++ <div className="mt-4 flex items-center space-x-4">+ <Button type="submit" isLoading={isSubmitting}>+ Submit+ </Button>+ <Button variant="outline_bg" onClick={onCancel}>+ Cancel+ </Button>+ </div>+ </form>+ </div>+ );+};diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/CreateDynamicSecretLease.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/CreateDynamicSecretLease.tsxindex c978985ffb..363006963c 100644--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/CreateDynamicSecretLease.tsx+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/CreateDynamicSecretLease.tsx@@ -413,6 +413,24 @@ const renderOutputForm = ();}+ if (provider === DynamicSecretProviders.IbmApiConnect) {+ const { CLIENT_ID, CLIENT_SECRET } = data as {+ CLIENT_ID: string;+ CLIENT_SECRET: string;+ };++ return (+ <div>+ <OutputDisplay label="Client ID" value={CLIENT_ID} />+ <OutputDisplay+ label="Client Secret"+ value={CLIENT_SECRET}+ helperText="Important: Copy these credentials now. You will not be able to see them again after you close the modal."+ />+ </div>+ );+ }+return null;};diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretForm.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretForm.tsxindex b146ffb2c7..b11ab4fb40 100644--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretForm.tsx+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretForm.tsx@@ -15,6 +15,7 @@ import { EditDynamicSecretCouchbaseForm } from "./EditDynamicSecretCouchbaseFormimport { EditDynamicSecretElasticSearchForm } from "./EditDynamicSecretElasticSearchForm";import { EditDynamicSecretGcpIamForm } from "./EditDynamicSecretGcpIamForm";import { EditDynamicSecretGithubForm } from "./EditDynamicSecretGithubForm";+import { EditDynamicSecretIbmApiConnectForm } from "./EditDynamicSecretIbmApiConnectForm";import { EditDynamicSecretKubernetesForm } from "./EditDynamicSecretKubernetesForm";import { EditDynamicSecretLdapForm } from "./EditDynamicSecretLdapForm";import { EditDynamicSecretMilvusForm } from "./EditDynamicSecretMilvusForm";@@ -493,6 +494,23 @@ export const EditDynamicSecretForm = ({/></motion.div>)}+ {dynamicSecretDetails?.type === DynamicSecretProviders.IbmApiConnect && (+ <motion.div+ key="ibm-api-connect-edit"+ transition={{ duration: 0.1 }}+ initial={{ opacity: 0, translateX: 30 }}+ animate={{ opacity: 1, translateX: 0 }}+ exit={{ opacity: 0, translateX: -30 }}+ >+ <EditDynamicSecretIbmApiConnectForm+ onClose={onClose}+ projectSlug={projectSlug}+ secretPath={secretPath}+ dynamicSecret={dynamicSecretDetails}+ environment={environment}+ />+ </motion.div>+ )}</AnimatePresence>);};diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretIbmApiConnectForm.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretIbmApiConnectForm.tsxnew file mode 100644index 0000000000..f50dd4d22a--- /dev/null+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretIbmApiConnectForm.tsx@@ -0,0 +1,503 @@+import { Controller, useForm } from "react-hook-form";+import {+ faCheckCircle,+ faCircleNotch,+ faTriangleExclamation+} from "@fortawesome/free-solid-svg-icons";+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";+import { zodResolver } from "@hookform/resolvers/zod";+import ms from "ms";+import { z } from "zod";++import { TtlFormLabel } from "@app/components/features";+import { createNotification } from "@app/components/notifications";+import { OrgPermissionCan } from "@app/components/permissions";+import { Button, FilterableSelect, FormControl, Input, SecretInput } from "@app/components/v2";+import { Tooltip } from "@app/components/v2/Tooltip";+import { GatewayPicker } from "@app/components/v3/platform/GatewayPicker";+import {+ OrgGatewayPermissionActions,+ OrgPermissionSubjects+} from "@app/context/OrgPermissionContext/types";+import { useUpdateDynamicSecret } from "@app/hooks/api";+import {+ useGetIbmApiConnectOrgApps,+ useGetIbmApiConnectOrgCatalogs,+ useGetIbmApiConnectOrgs+} from "@app/hooks/api/dynamicSecret/queries";+import { TDynamicSecret } from "@app/hooks/api/dynamicSecret/types";++const validateTTL = (val: string, ctx: z.RefinementCtx) => {+ if (!val) return;+ const valMs = ms(val);+ if (valMs === undefined) {+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: "Invalid TTL format" });+ return;+ }+ if (valMs < 1000)+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be a greater than 1 second" });+};++const formSchema = z+ .object({+ inputs: z.object({+ clientId: z.string().trim().min(1, "Client ID is required"),+ clientSecret: z.string().trim().min(1, "Client Secret is required"),+ instanceUrl: z.string().url("Must be a valid URL").trim().min(1, "Instance URL is required"),+ apiKey: z.string().trim().min(1, "API Key is required"),+ orgId: z.string().trim().min(1, "Organization is required"),+ catalogId: z.string().trim().min(1, "Catalog is required"),+ consumerOrgId: z.string().trim().min(1, "Consumer Organization is required"),+ appId: z.string().trim().min(1, "Application is required"),+ gatewayId: z.string().optional().nullable(),+ gatewayPoolId: z.string().optional().nullable()+ }),+ defaultTTL: z.string().superRefine(validateTTL),+ maxTTL: z+ .string()+ .optional()+ .superRefine((val, ctx) => {+ if (val) validateTTL(val, ctx);+ }),+ newName: z.string().refine((val) => val.toLowerCase() === val, "Must be lowercase")+ })+ .refine((d) => !d.maxTTL || ms(d.maxTTL)! >= ms(d.defaultTTL)!, {+ path: ["maxTTL"],+ message: "Max TTL must be greater than or equal to Default TTL"+ });+type TForm = z.infer<typeof formSchema>;++type Props = {+ onClose: () => void;+ dynamicSecret: TDynamicSecret & { inputs: unknown };+ secretPath: string;+ environment: string;+ projectSlug: string;+};++export const EditDynamicSecretIbmApiConnectForm = ({+ onClose,+ dynamicSecret,+ secretPath,+ environment,+ projectSlug+}: Props) => {+ const {+ control,+ formState: { isSubmitting },+ watch,+ setValue,+ handleSubmit+ } = useForm<TForm>({+ resolver: zodResolver(formSchema),+ values: {+ defaultTTL: dynamicSecret.defaultTTL,+ maxTTL: dynamicSecret.maxTTL,+ newName: dynamicSecret.name,+ inputs: {+ ...(dynamicSecret.inputs as TForm["inputs"])+ }+ }+ });++ const instanceUrl = watch("inputs.instanceUrl");+ const apiKey = watch("inputs.apiKey");+ const clientId = watch("inputs.clientId");+ const clientSecret = watch("inputs.clientSecret");+ const orgId = watch("inputs.orgId");+ const catalogId = watch("inputs.catalogId");++ const credentialsComplete = !!(instanceUrl && apiKey && clientId && clientSecret);+ const orgSelected = credentialsComplete && !!orgId;+ const catalogSelected = orgSelected && !!catalogId;++ const {+ data: orgs,+ isFetching: isOrgsFetching,+ isError: isOrgsError+ } = useGetIbmApiConnectOrgs({+ instanceUrl: instanceUrl || "",+ apiKey: apiKey || "",+ clientId: clientId || "",+ clientSecret: clientSecret || "",+ enabled: credentialsComplete+ });++ const selectedOrg = orgs?.find((o) => o.id === orgId);++ const {+ data: catalogs,+ isFetching: isCatalogsFetching,+ isError: isCatalogsError+ } = useGetIbmApiConnectOrgCatalogs({+ instanceUrl: instanceUrl || "",+ apiKey: apiKey || "",+ clientId: clientId || "",+ clientSecret: clientSecret || "",+ orgName: selectedOrg?.name || "",+ enabled: orgSelected+ });++ const selectedCatalog = catalogs?.find((c) => c.id === catalogId);++ const {+ data: apps,+ isFetching: isAppsFetching,+ isError: isAppsError+ } = useGetIbmApiConnectOrgApps({+ instanceUrl: instanceUrl || "",+ apiKey: apiKey || "",+ clientId: clientId || "",+ clientSecret: clientSecret || "",+ orgName: selectedOrg?.name || "",+ catalogName: selectedCatalog?.name || "",+ enabled: catalogSelected+ });++ const updateDynamicSecret = useUpdateDynamicSecret();++ const handleUpdateDynamicSecret = async ({ inputs, maxTTL, defaultTTL, newName }: TForm) => {+ if (updateDynamicSecret.isPending) return;+ await updateDynamicSecret.mutateAsync({+ name: dynamicSecret.name,+ path: secretPath,+ projectSlug,+ environmentSlug: environment,+ data: {+ maxTTL: maxTTL || undefined,+ defaultTTL,+ inputs,+ newName: newName === dynamicSecret.name ? undefined : newName+ }+ });+ onClose();+ createNotification({+ type: "success",+ text: "Successfully updated dynamic secret"+ });+ };++ const getOrgTooltipContent = () => {+ if (!credentialsComplete) return "Fill in all credentials above first";+ if (isOrgsError) return "Failed to load organizations — check your credentials";+ return undefined;+ };++ const getCatalogTooltipContent = () => {+ if (!orgSelected) return "Select an organization first";+ if (isCatalogsError) return "Failed to load catalogs";+ return undefined;+ };++ const getAppTooltipContent = () => {+ if (!catalogSelected) return "Select a catalog first";+ if (isAppsError) return "Failed to load applications";+ return undefined;+ };++ const getStatusIndicator = (isComplete: boolean, isFetching: boolean, isError: boolean) => {+ if (!isComplete) return null;+ if (isFetching)+ return <FontAwesomeIcon icon={faCircleNotch} className="animate-spin text-primary" />;+ if (isError) return <FontAwesomeIcon icon={faTriangleExclamation} className="text-red-500" />;+ return <FontAwesomeIcon icon={faCheckCircle} className="text-green-500" />;+ };++ return (+ <div>+ <form onSubmit={handleSubmit(handleUpdateDynamicSecret)} autoComplete="off">+ <div>+ <div className="flex items-center space-x-2">+ <div className="grow">+ <Controller+ control={control}+ name="newName"+ render={({ field, fieldState: { error } }) => (+ <FormControl+ label="Secret Name"+ isError={Boolean(error)}+ errorText={error?.message}+ >+ <Input {...field} placeholder="dynamic-secret" />+ </FormControl>+ )}+ />+ </div>+ <div className="w-32">+ <Controller+ control={control}+ name="defaultTTL"+ render={({ field, fieldState: { error } }) => (+ <FormControl+ label={<TtlFormLabel label="Default TTL" />}+ isError={Boolean(error?.message)}+ errorText={error?.message}+ >+ <Input {...field} />+ </FormControl>+ )}+ />+ </div>+ <div className="w-32">+ <Controller+ control={control}+ name="maxTTL"+ render={({ field, fieldState: { error } }) => (+ <FormControl+ label={<TtlFormLabel label="Max TTL" />}+ isError={Boolean(error?.message)}+ errorText={error?.message}+ >+ <Input {...field} />+ </FormControl>+ )}+ />+ </div>+ </div>+ <div>+ <div className="mt-4 mb-4 border-b border-mineshaft-500 pb-2 pl-1 font-medium text-mineshaft-200">+ Configuration+ </div>++ <OrgPermissionCan+ I={OrgGatewayPermissionActions.AttachGateways}+ a={OrgPermissionSubjects.Gateway}+ >+ {(isAllowed) => (+ <FormControl label="Gateway">+ <Tooltip+ isDisabled={isAllowed}+ content="Restricted access. You don't have permission to attach gateways to resources."+ >+ <div>+ <GatewayPicker+ isDisabled={!isAllowed}+ value={{+ gatewayId: watch("inputs.gatewayId") ?? null,+ gatewayPoolId: watch("inputs.gatewayPoolId") ?? null+ }}+ onChange={({ gatewayId: newGwId, gatewayPoolId: newPoolId }) => {+ setValue("inputs.gatewayId", newGwId ?? undefined, {+ shouldDirty: true+ });+ setValue("inputs.gatewayPoolId", newPoolId ?? undefined, {+ shouldDirty: true+ });+ }}+ />+ </div>+ </Tooltip>+ </FormControl>+ )}+ </OrgPermissionCan>++ <div className="flex flex-col">+ <Controller+ control={control}+ name="inputs.instanceUrl"+ render={({ field, fieldState: { error } }) => (+ <FormControl+ label="Instance URL"+ className="grow"+ isError={Boolean(error?.message)}+ errorText={error?.message}+ isRequired+ >+ <Input+ placeholder="https://platform-api.trial.apiconnect.automation.ibm.com"+ {...field}+ />+ </FormControl>+ )}+ />++ <Controller+ control={control}+ name="inputs.apiKey"+ render={({ field, fieldState: { error } }) => (+ <FormControl+ label="API Key"+ className="grow"+ isError={Boolean(error?.message)}+ errorText={error?.message}+ isRequired+ >+ <SecretInput+ {...field}+ containerClassName="text-gray-400 group-focus-within:border-primary-400/50! border border-mineshaft-500 bg-mineshaft-900 px-2.5 py-1.5"+ />+ </FormControl>+ )}+ />++ <Controller+ control={control}+ name="inputs.clientId"+ render={({ field, fieldState: { error } }) => (+ <FormControl+ label="Client ID"+ className="grow"+ isError={Boolean(error?.message)}+ errorText={error?.message}+ isRequired+ >+ <Input {...field} />+ </FormControl>+ )}+ />++ <Controller+ control={control}+ name="inputs.clientSecret"+ render={({ field, fieldState: { error } }) => (+ <FormControl+ label="Client Secret"+ className="grow"+ isError={Boolean(error?.message)}+ errorText={error?.message}+ isRequired+ >+ <SecretInput+ {...field}+ containerClassName="text-gray-400 group-focus-within:border-primary-400/50! border border-mineshaft-500 bg-mineshaft-900 px-2.5 py-1.5"+ />+ </FormControl>+ )}+ />+ </div>++ <div className="mt-4 mb-4 border-b border-mineshaft-500 pb-2 pl-1 font-medium text-mineshaft-200">+ <div className="flex items-center space-x-2">+ <span>Organization, Catalog & Application</span>+ {getStatusIndicator(credentialsComplete, isOrgsFetching, isOrgsError)}+ </div>+ </div>++ <Controller+ control={control}+ name="inputs.orgId"+ render={({ field: { value, onChange }, fieldState: { error } }) => (+ <FormControl+ label="Organization"+ isError={Boolean(error)}+ errorText={error?.message}+ isRequired+ >+ <Tooltip+ content={getOrgTooltipContent()}+ isDisabled={credentialsComplete && !isOrgsError}+ >+ <div>+ <FilterableSelect+ isDisabled={!credentialsComplete || isOrgsFetching || isOrgsError}+ isLoading={isOrgsFetching}+ options={orgs ?? []}+ value={orgs?.find((o) => o.id === value) ?? null}+ onChange={(option) => {+ onChange(option?.id ?? "");+ setValue("inputs.catalogId", "");+ setValue("inputs.consumerOrgId", "");+ setValue("inputs.appId", "");+ }}+ placeholder="Select an organization..."+ getOptionLabel={(option) => option.title || option.name}+ getOptionValue={(option) => option.id}+ />+ </div>+ </Tooltip>+ </FormControl>+ )}+ />++ <Controller+ control={control}+ name="inputs.catalogId"+ render={({ field: { value, onChange }, fieldState: { error } }) => (+ <FormControl+ label={+ <div className="flex items-center space-x-2">+ <span>Catalog</span>+ {getStatusIndicator(orgSelected, isCatalogsFetching, isCatalogsError)}+ </div>+ }+ isError={Boolean(error)}+ errorText={error?.message}+ isRequired+ >+ <Tooltip+ content={getCatalogTooltipContent()}+ isDisabled={orgSelected && !isCatalogsError}+ >+ <div>+ <FilterableSelect+ isDisabled={!orgSelected || isCatalogsFetching || isCatalogsError}+ isLoading={isCatalogsFetching}+ options={catalogs ?? []}+ value={catalogs?.find((c) => c.id === value) ?? null}+ onChange={(option) => {+ onChange(option?.id ?? "");+ setValue("inputs.consumerOrgId", "");+ setValue("inputs.appId", "");+ }}+ placeholder="Select a catalog..."+ getOptionLabel={(option) => option.title || option.name}+ getOptionValue={(option) => option.id}+ />+ </div>+ </Tooltip>+ </FormControl>+ )}+ />++ <Controller+ control={control}+ name="inputs.appId"+ render={({ field: { value, onChange }, fieldState: { error } }) => (+ <FormControl+ label={+ <div className="flex items-center space-x-2">+ <span>Application</span>+ {getStatusIndicator(catalogSelected, isAppsFetching, isAppsError)}+ </div>+ }+ isError={Boolean(error)}+ errorText={error?.message}+ isRequired+ >+ <Tooltip+ content={getAppTooltipContent()}+ isDisabled={catalogSelected && !isAppsError}+ >+ <div>+ <FilterableSelect+ isDisabled={!catalogSelected || isAppsFetching || isAppsError}+ isLoading={isAppsFetching}+ options={apps ?? []}+ value={apps?.find((a) => a.id === value) ?? null}+ onChange={(option) => {+ onChange(option?.id ?? "");+ setValue("inputs.consumerOrgId", option?.consumerOrgId ?? "");+ }}+ placeholder="Select an application..."+ getOptionLabel={(option) => option.title || option.name}+ getOptionValue={(option) => option.id}+ />+ </div>+ </Tooltip>+ </FormControl>+ )}+ />+ </div>+ </div>+ <div className="mt-4 flex items-center space-x-4">+ <Button type="submit" isLoading={isSubmitting}>+ Submit+ </Button>+ <Button variant="outline_bg" onClick={onClose}>+ Cancel+ </Button>+ </div>+ </form>+ </div>+ );+};