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
|
|
|
}
|
|
|
|
|
|
|
|
requestForAuthorize(request, { dc, ns, index }) {
|
2019-12-17 18:47:37 +00:00
|
|
|
return request`
|
|
|
|
POST /v1/internal/acl/authorize?${{ dc, ns, index }}
|
|
|
|
|
|
|
|
${[
|
|
|
|
{
|
|
|
|
Resource: 'operator',
|
|
|
|
Access: 'write',
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
`;
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
authorize(store, type, id, snapshot) {
|
2020-07-13 13:23:15 +00:00
|
|
|
return this.rpc(
|
2019-12-17 18:47:37 +00:00
|
|
|
function(adapter, request, serialized, unserialized) {
|
|
|
|
return adapter.requestForAuthorize(request, serialized, unserialized);
|
|
|
|
},
|
|
|
|
function(serializer, respond, serialized, unserialized) {
|
|
|
|
// Completely skip the serializer here
|
|
|
|
return respond(function(headers, body) {
|
|
|
|
return body;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
snapshot,
|
|
|
|
type.modelName
|
|
|
|
);
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
}
|