mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 01:53:33 -06:00
* remove state and refactor interface to IsDisabled * update docs and span * Update pkg/services/apikey/apikey.go Co-authored-by: Alexander Zobnin <alexanderzobnin@gmail.com> --------- Co-authored-by: Alexander Zobnin <alexanderzobnin@gmail.com>
50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
import { getBackendSrv } from 'app/core/services/backend_srv';
|
|
import { ThunkResult } from 'app/types';
|
|
|
|
import { apiKeysLoaded, includeExpiredToggled, isFetching } from './reducers';
|
|
|
|
export function loadApiKeys(): ThunkResult<void> {
|
|
return async (dispatch) => {
|
|
dispatch(isFetching());
|
|
const [keys, keysIncludingExpired] = await Promise.all([
|
|
getBackendSrv().get('/api/auth/keys?includeExpired=false&accesscontrol=true'),
|
|
getBackendSrv().get('/api/auth/keys?includeExpired=true&accesscontrol=true'),
|
|
]);
|
|
dispatch(apiKeysLoaded({ keys, keysIncludingExpired }));
|
|
};
|
|
}
|
|
|
|
export function deleteApiKey(id: number): ThunkResult<void> {
|
|
return async (dispatch) => {
|
|
getBackendSrv()
|
|
.delete(`/api/auth/keys/${id}`)
|
|
.then(() => dispatch(loadApiKeys()));
|
|
};
|
|
}
|
|
|
|
export function migrateApiKey(id: number): ThunkResult<void> {
|
|
return async (dispatch) => {
|
|
try {
|
|
await getBackendSrv().post(`/api/serviceaccounts/migrate/${id}`);
|
|
} finally {
|
|
dispatch(loadApiKeys());
|
|
}
|
|
};
|
|
}
|
|
|
|
export function migrateAll(): ThunkResult<void> {
|
|
return async (dispatch) => {
|
|
try {
|
|
await getBackendSrv().post('/api/serviceaccounts/migrate');
|
|
} finally {
|
|
dispatch(loadApiKeys());
|
|
}
|
|
};
|
|
}
|
|
|
|
export function toggleIncludeExpired(): ThunkResult<void> {
|
|
return (dispatch) => {
|
|
dispatch(includeExpiredToggled());
|
|
};
|
|
}
|