open-consul/ui-v2/app/adapters/nspace.js
John Cowen 8cb402eae7
ui: Move routes to use data-sources (#8321)
* Add uri identifiers to all data source things and make them the same

1. Add uri identitifer to data-source service
2. Make <EventSource /> and <DataSource /> as close as possible
3. Add extra `.closed` method to get a list of inactive/closed/closing
data-sources from elsewhere

* Make the connections cleanup the least worst connection when required

* Pass the uri/request id through all the things

* Better user erroring

* Make event sources close on error

* Allow <DataLoader /> data slot to be configurable

* Allow the <DataWriter /> removed state to be configurable

* Don't error if meta is undefined

* Stitch together all the repositories into the data-source/sink

* Use data.source over repositories

* Add missing  <EventSource /> components

* Fix up the views/templates

* Disable all the old route based blocking query things

* We still need the repo for the mixin for the moment

* Don't default to default, default != ''
2020-07-17 14:42:45 +01:00

84 lines
2.2 KiB
JavaScript

import Adapter from './application';
import { SLUG_KEY } from 'consul-ui/models/nspace';
// namespaces aren't categorized by datacenter, therefore no dc
export default Adapter.extend({
requestForQuery: function(request, { index, uri }) {
return request`
GET /v1/namespaces
X-Request-ID: ${uri}
${{ index }}
`;
},
requestForQueryRecord: function(request, { index, id }) {
if (typeof id === 'undefined') {
throw new Error('You must specify an name');
}
return request`
GET /v1/namespace/${id}
${{ index }}
`;
},
requestForCreateRecord: function(request, serialized, data) {
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 })),
},
}}
`;
},
requestForUpdateRecord: function(request, serialized, data) {
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 })),
},
}}
`;
},
requestForDeleteRecord: function(request, serialized, data) {
return request`
DELETE /v1/namespace/${data[SLUG_KEY]}
`;
},
requestForAuthorize: function(request, { dc, ns, index }) {
return request`
POST /v1/internal/acl/authorize?${{ dc, ns, index }}
${[
{
Resource: 'operator',
Access: 'write',
},
]}
`;
},
authorize: function(store, type, id, snapshot) {
return this.rpc(
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
);
},
});