2020-03-23 01:15:38 +00:00
|
|
|
import http from '@/api/http';
|
|
|
|
import { ApiKey, rawDataToApiKey } from '@/api/account/getApiKeys';
|
|
|
|
|
|
|
|
export default (description: string, allowedIps: string): Promise<ApiKey & { secretToken: string }> => {
|
|
|
|
return new Promise((resolve, reject) => {
|
2020-07-05 01:30:50 +00:00
|
|
|
http.post('/api/client/account/api-keys', {
|
2020-03-23 01:15:38 +00:00
|
|
|
description,
|
|
|
|
allowed_ips: allowedIps.length > 0 ? allowedIps.split('\n') : [],
|
|
|
|
})
|
2022-06-26 19:13:52 +00:00
|
|
|
.then(({ data }) =>
|
|
|
|
resolve({
|
|
|
|
...rawDataToApiKey(data.attributes),
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
secretToken: data.meta?.secret_token ?? '',
|
2022-11-25 20:25:03 +00:00
|
|
|
}),
|
2022-06-26 19:13:52 +00:00
|
|
|
)
|
2020-03-23 01:15:38 +00:00
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
};
|