2022-07-11 16:24:10 +01:00
|
|
|
|
import { getBackendSrv } from 'app/core/services/backend_srv';
|
2023-03-01 15:34:53 +00:00
|
|
|
|
import { ThunkResult } from 'app/types';
|
2022-04-22 14:33:13 +01:00
|
|
|
|
|
2023-03-01 15:34:53 +00:00
|
|
|
|
import { apiKeysLoaded, includeExpiredToggled, isFetching } from './reducers';
|
2018-09-26 13:45:04 +02:00
|
|
|
|
|
2021-12-16 11:46:09 +00:00
|
|
|
|
export function loadApiKeys(): ThunkResult<void> {
|
2021-01-20 07:59:48 +01:00
|
|
|
|
return async (dispatch) => {
|
2021-12-16 11:46:09 +00:00
|
|
|
|
dispatch(isFetching());
|
|
|
|
|
const [keys, keysIncludingExpired] = await Promise.all([
|
2022-04-29 15:30:24 +02:00
|
|
|
|
getBackendSrv().get('/api/auth/keys?includeExpired=false&accesscontrol=true'),
|
|
|
|
|
getBackendSrv().get('/api/auth/keys?includeExpired=true&accesscontrol=true'),
|
2021-12-16 11:46:09 +00:00
|
|
|
|
]);
|
|
|
|
|
dispatch(apiKeysLoaded({ keys, keysIncludingExpired }));
|
2018-09-25 16:23:43 +02:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-16 11:46:09 +00:00
|
|
|
|
export function deleteApiKey(id: number): ThunkResult<void> {
|
2021-01-20 07:59:48 +01:00
|
|
|
|
return async (dispatch) => {
|
2018-09-25 16:23:43 +02:00
|
|
|
|
getBackendSrv()
|
2020-01-21 09:08:07 +00:00
|
|
|
|
.delete(`/api/auth/keys/${id}`)
|
2021-12-16 11:46:09 +00:00
|
|
|
|
.then(() => dispatch(loadApiKeys()));
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-15 15:59:40 +03:00
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-16 11:46:09 +00:00
|
|
|
|
export function toggleIncludeExpired(): ThunkResult<void> {
|
|
|
|
|
return (dispatch) => {
|
|
|
|
|
dispatch(includeExpiredToggled());
|
2018-09-25 16:23:43 +02:00
|
|
|
|
};
|
|
|
|
|
}
|