mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-16 02:16:34 +00:00
feature: secret sync base + aws parameter store & github
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
export * from "./queries";
|
||||
export * from "./types";
|
||||
@@ -0,0 +1,105 @@
|
||||
import { useQuery, UseQueryOptions } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
import { appConnectionKeys } from "@app/hooks/api/appConnections";
|
||||
|
||||
import {
|
||||
TGitHubConnectionEnvironment,
|
||||
TGitHubConnectionListEnvironmentsResponse,
|
||||
TGitHubConnectionListOrganizationsResponse,
|
||||
TGitHubConnectionListRepositoriesResponse,
|
||||
TGitHubConnectionOrganization,
|
||||
TGitHubConnectionRepository,
|
||||
TListGitHubConnectionEnvironments
|
||||
} from "./types";
|
||||
|
||||
const githubConnectionKeys = {
|
||||
all: [...appConnectionKeys.all, "github"] as const,
|
||||
listRepositories: (connectionId: string) =>
|
||||
[...githubConnectionKeys.all, "repositories", connectionId] as const,
|
||||
listOrganizations: (connectionId: string) =>
|
||||
[...githubConnectionKeys.all, "organizations", connectionId] as const,
|
||||
listEnvironments: ({ connectionId, repo, owner }: TListGitHubConnectionEnvironments) =>
|
||||
[...githubConnectionKeys.all, "environments", connectionId, repo, owner] as const
|
||||
};
|
||||
|
||||
export const useGitHubConnectionListRepositories = (
|
||||
connectionId: string,
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
TGitHubConnectionRepository[],
|
||||
unknown,
|
||||
TGitHubConnectionRepository[],
|
||||
ReturnType<typeof githubConnectionKeys.listRepositories>
|
||||
>,
|
||||
"queryKey" | "queryFn"
|
||||
>
|
||||
) => {
|
||||
return useQuery({
|
||||
queryKey: githubConnectionKeys.listRepositories(connectionId),
|
||||
queryFn: async () => {
|
||||
const { data } = await apiRequest.get<TGitHubConnectionListRepositoriesResponse>(
|
||||
`/api/v1/app-connections/github/${connectionId}/repositories`
|
||||
);
|
||||
|
||||
return data.repositories;
|
||||
},
|
||||
...options
|
||||
});
|
||||
};
|
||||
|
||||
export const useGitHubConnectionListOrganizations = (
|
||||
connectionId: string,
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
TGitHubConnectionOrganization[],
|
||||
unknown,
|
||||
TGitHubConnectionOrganization[],
|
||||
ReturnType<typeof githubConnectionKeys.listOrganizations>
|
||||
>,
|
||||
"queryKey" | "queryFn"
|
||||
>
|
||||
) => {
|
||||
return useQuery({
|
||||
queryKey: githubConnectionKeys.listOrganizations(connectionId),
|
||||
queryFn: async () => {
|
||||
const { data } = await apiRequest.get<TGitHubConnectionListOrganizationsResponse>(
|
||||
`/api/v1/app-connections/github/${connectionId}/organizations`
|
||||
);
|
||||
|
||||
return data.organizations;
|
||||
},
|
||||
...options
|
||||
});
|
||||
};
|
||||
|
||||
export const useGitHubConnectionListEnvironments = (
|
||||
{ connectionId, repo, owner }: TListGitHubConnectionEnvironments,
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
TGitHubConnectionEnvironment[],
|
||||
unknown,
|
||||
TGitHubConnectionEnvironment[],
|
||||
ReturnType<typeof githubConnectionKeys.listEnvironments>
|
||||
>,
|
||||
"queryKey" | "queryFn"
|
||||
>
|
||||
) => {
|
||||
return useQuery({
|
||||
queryKey: githubConnectionKeys.listEnvironments({ connectionId, repo, owner }),
|
||||
queryFn: async () => {
|
||||
const { data } = await apiRequest.get<TGitHubConnectionListEnvironmentsResponse>(
|
||||
`/api/v1/app-connections/github/${connectionId}/environments`,
|
||||
{
|
||||
params: {
|
||||
repo,
|
||||
owner
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return data.environments;
|
||||
},
|
||||
...options
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
export type TGitHubConnectionOrganization = {
|
||||
login: string;
|
||||
id: number;
|
||||
};
|
||||
|
||||
export type TGitHubConnectionRepository = {
|
||||
id: number;
|
||||
name: string;
|
||||
owner: TGitHubConnectionOrganization;
|
||||
};
|
||||
|
||||
export type TGitHubConnectionEnvironment = {
|
||||
id: number;
|
||||
name: string;
|
||||
};
|
||||
|
||||
export type TGitHubConnectionListRepositoriesResponse = {
|
||||
repositories: TGitHubConnectionRepository[];
|
||||
};
|
||||
|
||||
export type TGitHubConnectionListOrganizationsResponse = {
|
||||
organizations: TGitHubConnectionOrganization[];
|
||||
};
|
||||
|
||||
export type TGitHubConnectionListEnvironmentsResponse = {
|
||||
environments: TGitHubConnectionEnvironment[];
|
||||
};
|
||||
|
||||
export type TListGitHubConnectionEnvironments = {
|
||||
connectionId: string;
|
||||
repo: string;
|
||||
owner: string;
|
||||
};
|
||||
@@ -7,6 +7,8 @@ import {
|
||||
TAppConnection,
|
||||
TAppConnectionMap,
|
||||
TAppConnectionOptions,
|
||||
TAvailableAppConnection,
|
||||
TAvailableAppConnectionsResponse,
|
||||
TGetAppConnection,
|
||||
TListAppConnections
|
||||
} from "@app/hooks/api/appConnections/types";
|
||||
@@ -19,9 +21,10 @@ export const appConnectionKeys = {
|
||||
all: ["app-connection"] as const,
|
||||
options: () => [...appConnectionKeys.all, "options"] as const,
|
||||
list: () => [...appConnectionKeys.all, "list"] as const,
|
||||
listAvailable: (app: AppConnection) => [...appConnectionKeys.all, app, "list-available"] as const,
|
||||
listByApp: (app: AppConnection) => [...appConnectionKeys.list(), app],
|
||||
byId: (app: AppConnection, templateId: string) =>
|
||||
[...appConnectionKeys.all, app, "by-id", templateId] as const
|
||||
byId: (app: AppConnection, connectionId: string) =>
|
||||
[...appConnectionKeys.all, app, "by-id", connectionId] as const
|
||||
};
|
||||
|
||||
export const useAppConnectionOptions = (
|
||||
@@ -83,6 +86,31 @@ export const useListAppConnections = (
|
||||
});
|
||||
};
|
||||
|
||||
export const useListAvailableAppConnections = (
|
||||
app: AppConnection,
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
TAvailableAppConnection[],
|
||||
unknown,
|
||||
TAvailableAppConnection[],
|
||||
ReturnType<typeof appConnectionKeys.listAvailable>
|
||||
>,
|
||||
"queryKey" | "queryFn"
|
||||
>
|
||||
) => {
|
||||
return useQuery({
|
||||
queryKey: appConnectionKeys.listAvailable(app),
|
||||
queryFn: async () => {
|
||||
const { data } = await apiRequest.get<TAvailableAppConnectionsResponse>(
|
||||
`/api/v1/app-connections/${app}/available`
|
||||
);
|
||||
|
||||
return data.appConnections;
|
||||
},
|
||||
...options
|
||||
});
|
||||
};
|
||||
|
||||
export const useListAppConnectionsByApp = <T extends AppConnection>(
|
||||
app: T,
|
||||
options?: Omit<
|
||||
|
||||
@@ -8,10 +8,13 @@ export * from "./github-connection";
|
||||
|
||||
export type TAppConnection = TAwsConnection | TGitHubConnection;
|
||||
|
||||
export type TAvailableAppConnection = Pick<TAppConnection, "name" | "app" | "id">;
|
||||
|
||||
export type TListAppConnections<T extends TAppConnection> = { appConnections: T[] };
|
||||
export type TGetAppConnection<T extends TAppConnection> = { appConnection: T };
|
||||
export type TAppConnectionOptions = { appConnectionOptions: TAppConnectionOption[] };
|
||||
export type TAppConnectionResponse = { appConnection: TAppConnection };
|
||||
export type TAvailableAppConnectionsResponse = { appConnections: TAvailableAppConnection[] };
|
||||
|
||||
export type TCreateAppConnectionDTO = Pick<
|
||||
TAppConnection,
|
||||
|
||||
Reference in New Issue
Block a user