mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* feat: add serviceaccountDTO * WIP * feat: listing number of tokens for a given service account * nit: removed fmt * Update pkg/services/serviceaccounts/database/database.go * Update public/app/features/serviceaccounts/ServiceAccountsListPage.tsx * fixes * align DTOProfile data to the frontend * reviewed myself fixes * fix: tests fix
61 lines
1.8 KiB
TypeScript
61 lines
1.8 KiB
TypeScript
import { ThunkResult } from '../../../types';
|
|
import { getBackendSrv } from '@grafana/runtime';
|
|
import { serviceAccountLoaded, serviceAccountsLoaded, serviceAccountTokensLoaded } from './reducers';
|
|
|
|
const BASE_URL = `/api/serviceaccounts`;
|
|
|
|
export function loadServiceAccount(saID: number): ThunkResult<void> {
|
|
return async (dispatch) => {
|
|
try {
|
|
const response = await getBackendSrv().get(`${BASE_URL}/${saID}`);
|
|
dispatch(serviceAccountLoaded(response));
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
};
|
|
}
|
|
|
|
export function deleteServiceAccountToken(saID: number, id: number): ThunkResult<void> {
|
|
return async (dispatch) => {
|
|
await getBackendSrv().delete(`${BASE_URL}/${saID}/tokens/${id}`);
|
|
dispatch(loadServiceAccountTokens(saID));
|
|
};
|
|
}
|
|
|
|
export function loadServiceAccountTokens(saID: number): ThunkResult<void> {
|
|
return async (dispatch) => {
|
|
try {
|
|
const response = await getBackendSrv().get(`${BASE_URL}/${saID}/tokens`);
|
|
dispatch(serviceAccountTokensLoaded(response));
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
};
|
|
}
|
|
|
|
export function loadServiceAccounts(): ThunkResult<void> {
|
|
return async (dispatch) => {
|
|
try {
|
|
const response = await getBackendSrv().get(BASE_URL);
|
|
dispatch(serviceAccountsLoaded(response));
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
};
|
|
}
|
|
|
|
export function updateServiceAccount(saID: number): ThunkResult<void> {
|
|
return async (dispatch) => {
|
|
// TODO: implement on backend
|
|
await getBackendSrv().patch(`${BASE_URL}/${saID}`, {});
|
|
dispatch(loadServiceAccounts());
|
|
};
|
|
}
|
|
|
|
export function removeServiceAccount(serviceAccountId: number): ThunkResult<void> {
|
|
return async (dispatch) => {
|
|
await getBackendSrv().delete(`${BASE_URL}/${serviceAccountId}`);
|
|
dispatch(loadServiceAccounts());
|
|
};
|
|
}
|