2023-03-14 13:18:55 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-03-14 13:18:55 +00:00
|
|
|
*/
|
|
|
|
|
2022-03-09 09:03:15 +00:00
|
|
|
import RepositoryService from 'consul-ui/services/repository';
|
|
|
|
import dataSource from 'consul-ui/decorators/data-source';
|
|
|
|
|
|
|
|
const MODEL_NAME = 'license';
|
|
|
|
|
2022-09-15 08:43:17 +00:00
|
|
|
const bucket = function (item, { dc, ns = 'default', partition = 'default' }) {
|
2022-03-09 09:03:15 +00:00
|
|
|
return {
|
|
|
|
...item,
|
|
|
|
Datacenter: dc,
|
|
|
|
Namespace: typeof item.Namespace === 'undefined' ? ns : item.Namespace,
|
|
|
|
Partition: typeof item.Partition === 'undefined' ? partition : item.Partition,
|
|
|
|
};
|
2022-09-15 08:43:17 +00:00
|
|
|
};
|
2022-03-09 09:03:15 +00:00
|
|
|
|
|
|
|
const SECONDS = 1000;
|
|
|
|
|
|
|
|
export default class LicenseService extends RepositoryService {
|
|
|
|
@dataSource('/:partition/:ns/:dc/license')
|
2022-09-15 08:43:17 +00:00
|
|
|
async find({ partition, ns, dc }, { uri }, request) {
|
|
|
|
return (
|
|
|
|
await request`
|
2022-03-09 09:03:15 +00:00
|
|
|
GET /v1/operator/license?${{ dc }}
|
|
|
|
X-Request-ID: ${uri}
|
2022-09-15 08:43:17 +00:00
|
|
|
`
|
|
|
|
)((headers, body, cache) => ({
|
|
|
|
meta: {
|
|
|
|
version: 2,
|
|
|
|
uri: uri,
|
|
|
|
interval: 30 * SECONDS,
|
|
|
|
},
|
|
|
|
body: cache(
|
|
|
|
bucket(body, { dc }),
|
|
|
|
(uri) => uri`${MODEL_NAME}:///${partition}/${ns}/${dc}/license/${body.License.license_id}`
|
|
|
|
),
|
|
|
|
}));
|
2022-03-09 09:03:15 +00:00
|
|
|
}
|
|
|
|
}
|