mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-31 00:16:47 +01:00
67 lines
1.7 KiB
TypeScript
67 lines
1.7 KiB
TypeScript
|
import useAPI from '../useApi/useApi';
|
||
|
|
||
|
export interface IServiceAccountPayload {
|
||
|
name: string;
|
||
|
username: string;
|
||
|
rootRole: number;
|
||
|
}
|
||
|
|
||
|
export const useServiceAccountsApi = () => {
|
||
|
const { loading, makeRequest, createRequest, errors } = useAPI({
|
||
|
propagateErrors: true,
|
||
|
});
|
||
|
|
||
|
const addServiceAccount = async (
|
||
|
serviceAccount: IServiceAccountPayload
|
||
|
) => {
|
||
|
const requestId = 'addServiceAccount';
|
||
|
const req = createRequest(
|
||
|
'api/admin/service-account',
|
||
|
{
|
||
|
method: 'POST',
|
||
|
body: JSON.stringify(serviceAccount),
|
||
|
},
|
||
|
requestId
|
||
|
);
|
||
|
|
||
|
const response = await makeRequest(req.caller, req.id);
|
||
|
return await response.json();
|
||
|
};
|
||
|
|
||
|
const removeServiceAccount = async (serviceAccountId: number) => {
|
||
|
const requestId = 'removeServiceAccount';
|
||
|
const req = createRequest(
|
||
|
`api/admin/service-account/${serviceAccountId}`,
|
||
|
{ method: 'DELETE' },
|
||
|
requestId
|
||
|
);
|
||
|
|
||
|
await makeRequest(req.caller, req.id);
|
||
|
};
|
||
|
|
||
|
const updateServiceAccount = async (
|
||
|
serviceAccountId: number,
|
||
|
serviceAccount: IServiceAccountPayload
|
||
|
) => {
|
||
|
const requestId = 'updateServiceAccount';
|
||
|
const req = createRequest(
|
||
|
`api/admin/service-account/${serviceAccountId}`,
|
||
|
{
|
||
|
method: 'PUT',
|
||
|
body: JSON.stringify(serviceAccount),
|
||
|
},
|
||
|
requestId
|
||
|
);
|
||
|
|
||
|
await makeRequest(req.caller, req.id);
|
||
|
};
|
||
|
|
||
|
return {
|
||
|
addServiceAccount,
|
||
|
updateServiceAccount,
|
||
|
removeServiceAccount,
|
||
|
errors,
|
||
|
loading,
|
||
|
};
|
||
|
};
|