Skip to content

Commit

Permalink
ui: Use of header default ACL policy (hashicorp#11192)
Browse files Browse the repository at this point in the history
* Use of header default ACL policy

* Update test for dc serializer
  • Loading branch information
kaxcode authored Sep 30, 2021
1 parent 35a92e8 commit 5e7ef18
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions ui/packages/consul-ui/app/models/dc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default class Datacenter extends Model {
@attr('string') uid;
@attr('string') Name;
@attr('boolean') Local;
@attr('string') DefaultACLPolicy;

@attr('boolean', { defaultValue: () => true }) MeshEnabled;
}
8 changes: 6 additions & 2 deletions ui/packages/consul-ui/app/serializers/dc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@ export default class DcSerializer extends Serializer {

respondForQuery(respond, query) {
return respond(function(headers, body) {
return body;
return {
body,
headers,
};
});
}

normalizePayload(payload, id, requestType) {
switch (requestType) {
case 'query':
return payload.map(item => {
return payload.body.map(item => {
return {
Local: this.env.var('CONSUL_DATACENTER_LOCAL') === item,
[this.primaryKey]: item,
DefaultACLPolicy: payload.headers['x-consul-default-acl-policy'],
};
});
}
Expand Down
7 changes: 7 additions & 0 deletions ui/packages/consul-ui/mock-api/v1/catalog/.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"*":
GET:
"*":
headers:
response:
X-Consul-Default-Acl-Policy: ${fake.helpers.randomize(['allow', 'deny'])}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ module('Integration | Serializer | dc', function(hooks) {
url: `/v1/catalog/datacenters`,
};
return get(request.url).then(function(payload) {
const expected = payload;
const expected = {
body: payload,
headers: {},
};
const actual = serializer.respondForQuery(function(cb) {
const headers = {};
const body = payload;
Expand Down

0 comments on commit 5e7ef18

Please sign in to comment.