2019-12-17 18:47:37 +00:00
|
|
|
import Adapter from './application';
|
|
|
|
import { SLUG_KEY } from 'consul-ui/models/nspace';
|
|
|
|
|
|
|
|
// namespaces aren't categorized by datacenter, therefore no dc
|
2020-11-09 17:29:12 +00:00
|
|
|
export default class NspaceAdapter extends Adapter {
|
|
|
|
requestForQuery(request, { index, uri }) {
|
2019-12-17 18:47:37 +00:00
|
|
|
return request`
|
|
|
|
GET /v1/namespaces
|
2020-07-17 13:42:45 +00:00
|
|
|
X-Request-ID: ${uri}
|
2019-12-17 18:47:37 +00:00
|
|
|
|
|
|
|
${{ index }}
|
|
|
|
`;
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
requestForQueryRecord(request, { index, id }) {
|
2019-12-17 18:47:37 +00:00
|
|
|
if (typeof id === 'undefined') {
|
|
|
|
throw new Error('You must specify an name');
|
|
|
|
}
|
|
|
|
return request`
|
|
|
|
GET /v1/namespace/${id}
|
|
|
|
|
|
|
|
${{ index }}
|
|
|
|
`;
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
requestForCreateRecord(request, serialized, data) {
|
2019-12-17 18:47:37 +00:00
|
|
|
return request`
|
|
|
|
PUT /v1/namespace/${data[SLUG_KEY]}
|
|
|
|
|
|
|
|
${{
|
|
|
|
Name: serialized.Name,
|
|
|
|
Description: serialized.Description,
|
|
|
|
ACLs: {
|
|
|
|
PolicyDefaults: serialized.ACLs.PolicyDefaults.map(item => ({ ID: item.ID })),
|
|
|
|
RoleDefaults: serialized.ACLs.RoleDefaults.map(item => ({ ID: item.ID })),
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
`;
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
requestForUpdateRecord(request, serialized, data) {
|
2019-12-17 18:47:37 +00:00
|
|
|
return request`
|
|
|
|
PUT /v1/namespace/${data[SLUG_KEY]}
|
|
|
|
|
|
|
|
${{
|
|
|
|
Description: serialized.Description,
|
|
|
|
ACLs: {
|
|
|
|
PolicyDefaults: serialized.ACLs.PolicyDefaults.map(item => ({ ID: item.ID })),
|
|
|
|
RoleDefaults: serialized.ACLs.RoleDefaults.map(item => ({ ID: item.ID })),
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
`;
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
requestForDeleteRecord(request, serialized, data) {
|
2019-12-17 18:47:37 +00:00
|
|
|
return request`
|
|
|
|
DELETE /v1/namespace/${data[SLUG_KEY]}
|
|
|
|
`;
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
}
|