mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-16 08:14:06 +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;
|
||||
};
|
||||
Reference in New Issue
Block a user