grafana/public/app/features/api-keys/state/actions.ts
Eric Leijonmarck ad4b053231
API keys: Remove state hideAPIkeys and refactor interface to IsDisabled (#64018)
* 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>
2023-03-03 16:12:34 +00:00

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());
};
}