grafana/public/app/features/api-keys/state/actions.ts
Torkel Ödegaard 1d689888b0
Prettier: Upgrade to 2 (#30387)
* Updated package json but not updated source files

* Update eslint plugin

* updated files
2021-01-20 07:59:48 +01:00

32 lines
1014 B
TypeScript

import { getBackendSrv } from 'app/core/services/backend_srv';
import { ApiKey, ThunkResult } from 'app/types';
import { apiKeysLoaded, setSearchQuery } from './reducers';
export function addApiKey(
apiKey: ApiKey,
openModal: (key: string) => void,
includeExpired: boolean
): ThunkResult<void> {
return async (dispatch) => {
const result = await getBackendSrv().post('/api/auth/keys', apiKey);
dispatch(setSearchQuery(''));
dispatch(loadApiKeys(includeExpired));
openModal(result.key);
};
}
export function loadApiKeys(includeExpired: boolean): ThunkResult<void> {
return async (dispatch) => {
const response = await getBackendSrv().get('/api/auth/keys?includeExpired=' + includeExpired);
dispatch(apiKeysLoaded(response));
};
}
export function deleteApiKey(id: number, includeExpired: boolean): ThunkResult<void> {
return async (dispatch) => {
getBackendSrv()
.delete(`/api/auth/keys/${id}`)
.then(() => dispatch(loadApiKeys(includeExpired)));
};
}