forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions.ts
31 lines (28 loc) · 1008 Bytes
/
actions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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)));
};
}