Skip to content

Commit

Permalink
ui: Partitions Application Layer (#11017)
Browse files Browse the repository at this point in the history
* Add Partition to all our models

* Add partitions into our serializers/fingerprinting

* Make some amends to a few adapters ready for partitions

* Amend blueprints to avoid linting error

* Update all  our repositories to include partitions, also

Remove enabled/disable nspace repo and just use a nspace with
conditionals

* Ensure nspace and parition parameters always return '' no matter what

* Ensure data-sink finds the model properly

This will later be replaced by a @datasink decorator but we are find
kicking that can down the road a little more

* Add all the new partition data layer

* Add a way to set the title of the page from inside the route

and make it accessibile via a route announcer

* Make the Consul Route the default/basic one

* Tweak nspace and partition abilities not to check the length

* Thread partition through all the components that need it

* Some ACL tweaks

* Move the entire app to use partitions

* Delete all the tests we no longer need

* Update some Unit tests to use partition

* Fix up KV title tests

* Fix up a few more acceptance tests

* Fixup and temporarily ignore some acceptance tests

* Stop using ember-cli-page-objects fillable as it doesn't seem to work

* Fix lint error

* Remove old ACL related test

* Add a tick after filling out forms

* Fix token warning modal

* Found some more places where we need a partition var

* Fixup some more acceptance tests

* Tokens still needs a repo service for CRUD

* Remove acceptance tests we no longer need

* Fixup and "FIXME ignore" a few tests

* Remove an s

* Disable blocking queries for KV to revert to previous release for now

* Fixup adapter tests to follow async/function resolving interface

* Fixup all the serializer integration tests

* Fixup service/repo integration tests

* Fixup deleting acceptance test

* Fixup some ent tests

* Make sure nspaces passes the dc through for when thats important

* ...aaaand acceptance nspaces with the extra dc param
  • Loading branch information
johncowen authored Sep 15, 2021
1 parent 0eb4a98 commit fc14a41
Show file tree
Hide file tree
Showing 334 changed files with 3,573 additions and 3,295 deletions.
2 changes: 1 addition & 1 deletion ui/packages/consul-ui/app/abilities/nspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class NspaceAbility extends BaseAbility {
}

get canChoose() {
return this.canUse && (this.nspaces || []).length > 0;
return this.canUse;
}

get canUse() {
Expand Down
2 changes: 1 addition & 1 deletion ui/packages/consul-ui/app/abilities/partition.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class PartitionAbility extends BaseAbility {
}

get canChoose() {
return this.canUse && (this.partitions || []).length > 0;
return this.canUse;
}

get canUse() {
Expand Down
2 changes: 1 addition & 1 deletion ui/packages/consul-ui/app/adapters/binding-rule.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Adapter from './application';

export default class BindingRuleAdapter extends Adapter {
requestForQuery(request, { dc, ns, partition, authmethod, index, id }) {
requestForQuery(request, { dc, ns, partition, authmethod, index }) {
return request`
GET /v1/acl/binding-rules?${{ dc, authmethod }}
Expand Down
1 change: 1 addition & 0 deletions ui/packages/consul-ui/app/adapters/intention.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default class IntentionAdapter extends Adapter {
}
${{
partition: '',
ns: '*',
index,
filter,
Expand Down
8 changes: 5 additions & 3 deletions ui/packages/consul-ui/app/adapters/kv.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { SLUG_KEY } from 'consul-ui/models/kv';
const API_KEYS_KEY = 'keys';

export default class KvAdapter extends Adapter {
requestForQuery(request, { dc, ns, partition, index, id, separator }) {
async requestForQuery(request, { dc, ns, partition, index, id, separator }) {
if (typeof id === 'undefined') {
throw new Error('You must specify an id');
}
return request`
const respond = await request`
GET /v1/kv/${keyToArray(id)}?${{ [API_KEYS_KEY]: null, dc, separator }}
${{
Expand All @@ -20,9 +20,11 @@ export default class KvAdapter extends Adapter {
index,
}}
`;
await respond((headers, body) => delete headers['x-consul-index']);
return respond;
}

requestForQueryRecord(request, { dc, ns, partition, index, id }) {
async requestForQueryRecord(request, { dc, ns, partition, index, id }) {
if (typeof id === 'undefined') {
throw new Error('You must specify an id');
}
Expand Down
1 change: 1 addition & 0 deletions ui/packages/consul-ui/app/adapters/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default class NodeAdapter extends Adapter {
`;
}

// this does not require a partition parameter
requestForQueryLeader(request, { dc, uri }) {
return request`
GET /v1/status/leader?${{ dc }}
Expand Down
11 changes: 7 additions & 4 deletions ui/packages/consul-ui/app/adapters/nspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { SLUG_KEY } from 'consul-ui/models/nspace';

// namespaces aren't categorized by datacenter, therefore no dc
export default class NspaceAdapter extends Adapter {
requestForQuery(request, { partition, index, uri }) {
requestForQuery(request, { dc, partition, index, uri }) {
return request`
GET /v1/namespaces
GET /v1/namespaces?${{ dc }}
X-Request-ID: ${uri}
${{
Expand All @@ -15,12 +15,12 @@ export default class NspaceAdapter extends Adapter {
`;
}

requestForQueryRecord(request, { partition, index, id }) {
requestForQueryRecord(request, { dc, partition, index, id }) {
if (typeof id === 'undefined') {
throw new Error('You must specify an name');
}
return request`
GET /v1/namespace/${id}
GET /v1/namespace/${id}?${{ dc }}
${{
partition,
Expand All @@ -32,6 +32,7 @@ export default class NspaceAdapter extends Adapter {
requestForCreateRecord(request, serialized, data) {
return request`
PUT /v1/namespace/${data[SLUG_KEY]}?${{
dc: data.Datacenter,
partition: data.Partition,
}}
Expand All @@ -49,6 +50,7 @@ export default class NspaceAdapter extends Adapter {
requestForUpdateRecord(request, serialized, data) {
return request`
PUT /v1/namespace/${data[SLUG_KEY]}?${{
dc: data.Datacenter,
partition: data.Partition,
}}
Expand All @@ -65,6 +67,7 @@ export default class NspaceAdapter extends Adapter {
requestForDeleteRecord(request, serialized, data) {
return request`
DELETE /v1/namespace/${data[SLUG_KEY]}?${{
dc: data.Datacenter,
partition: data.Partition,
}}
`;
Expand Down
28 changes: 28 additions & 0 deletions ui/packages/consul-ui/app/adapters/partition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Adapter from './application';

// Blocking query support for partitions is currently disabled
export default class PartitionAdapter extends Adapter {
// FIXME: Check overall hierarchy again
async requestForQuery(request, { ns, dc, index }) {
const respond = await request`
GET /v1/partitions?${{ dc }}
${{ index }}
`;
await respond((headers, body) => delete headers['x-consul-index']);
return respond;
}

async requestForQueryRecord(request, { ns, dc, index, id }) {
if (typeof id === 'undefined') {
throw new Error('You must specify an id');
}
const respond = await request`
GET /v1/partition/${id}?${{ dc }}
${{ index }}
`;
await respond((headers, body) => delete headers['x-consul-index']);
return respond;
}
}
2 changes: 1 addition & 1 deletion ui/packages/consul-ui/app/adapters/permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class PermissionAdapter extends Adapter {
resources = resources.map(item => ({ ...item, Partition: partition }));
}
return request`
POST /v1/internal/acl/authorize?${{ dc, index }}
POST /v1/internal/acl/authorize?${{ dc }}
${resources}
`;
Expand Down
7 changes: 5 additions & 2 deletions ui/packages/consul-ui/app/adapters/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,22 @@ export default class TokenAdapter extends Adapter {
`;
}

requestForQueryRecord(request, { dc, ns, partition, index, id }) {
async requestForQueryRecord(request, { dc, ns, partition, index, id }) {
if (typeof id === 'undefined') {
throw new Error('You must specify an id');
}
return request`
const respond = await request`
GET /v1/acl/token/${id}?${{ dc }}
Cache-Control: no-store
${{
ns,
partition,
index,
}}
`;
respond((headers, body) => delete headers['x-consul-index']);
return respond;
}

requestForCreateRecord(request, serialized, data) {
Expand Down
6 changes: 5 additions & 1 deletion ui/packages/consul-ui/app/components/auth-dialog/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
token=token
) (hash
AuthProfile=(component 'auth-profile' item=token)
AuthForm=(component 'auth-form' dc=dc nspace=nspace onsubmit=(action sink.open value="data"))
AuthForm=(component 'auth-form'
dc=dc
partition=partition
nspace=nspace
onsubmit=(action sink.open value="data"))
) as |api components|}}
<State @matches="authorized">
{{#yield-slot name="authorized"}}
Expand Down
10 changes: 9 additions & 1 deletion ui/packages/consul-ui/app/components/auth-form/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@
{{#if (env 'CONSUL_SSO_ENABLED')}}
{{!-- This `or` can be completely removed post 1.10 as 1.10 has optional params with default values --}}
<DataSource
@src={{concat '/' (or nspace '') '/' dc '/oidc/providers'}}
@src={{uri '/${partition}/${nspace}/${dc}/oidc/providers'
(hash
partition=partition
nspace=(or nspace '')
dc=dc
)
}}
@onchange={{queue (action (mut providers) value="data")}}
@onerror={{queue (action (mut error) value="error.errors.firstObject")}}
@loading="lazy"
Expand All @@ -96,9 +102,11 @@
{{/if}}
</div>
<State @matches="loading">
{{!FIXME: default partition?}}
<TokenSource
@dc={{dc}}
@nspace={{or value.Namespace nspace}}
@partition={{or value.Partition 'default'}}
@type={{if value.Name 'oidc' 'secret'}}
@value={{if value.Name value.Name value}}
@onchange={{queue (action dispatch "RESET") (action onsubmit)}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@
<span><YieldSlot @name="label">{{yield}}</YieldSlot></span>
{{#if isOpen}}
<DataSource
@src={{concat '/' nspace '/' dc '/' (pluralize type)}}
@src={{uri '/${partition}/${nspace}/${dc}/${type}'
(hash
partition=partition
nspace=nspace
dc=dc
type=(pluralize type)
)
}}
@onchange={{action (mut allOptions) value="data"}}
/>
{{/if}}
Expand Down
28 changes: 28 additions & 0 deletions ui/packages/consul-ui/app/components/consul/acl/disabled/index.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<AppView>
<BlockSlot @name="header">
<h1>
Tokens
</h1>
</BlockSlot>
<BlockSlot @name="content">
<EmptyState data-test-acls-disabled>
<BlockSlot @name="header">
<h2>Welcome to ACLs</h2>
</BlockSlot>
<BlockSlot @name="body">
<p>
ACLs are not enabled in this Consul cluster. We strongly encourage the use of ACLs in production environments for the best security practices.
</p>
</BlockSlot>
<BlockSlot @name="actions">
<li class="docs-link">
<a href="{{env 'CONSUL_DOCS_URL'}}/acl/index.html" rel="noopener noreferrer" target="_blank">Read the documentation</a>
</li>
<li class="learn-link">
<a href="{{env 'CONSUL_DOCS_LEARN_URL'}}/consul/security-networking/production-acls" rel="noopener noreferrer" target="_blank">Follow the guide</a>
</li>
</BlockSlot>
</EmptyState>
</BlockSlot>
</AppView>

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A presentational component for rendering HealthChecks.
<figure>
<figcaption>Grab some mock data...</figcaption>
<DataSource @src="/default/dc-1/node/my-node" as |source|>
<DataSource @src="/partition/default/dc-1/node/my-node" as |source|>
<figure>
<figcaption>but only show a max of 2 items for docs purposes</figcaption>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@type="intention"
@dc={{@dc}}
@nspace={{@nspace}}
@partition={{@partition}}
@autofill={{@autofill}}
@item={{@item}}
@src={{@src}}
Expand Down Expand Up @@ -73,15 +74,27 @@ as |api|>
{{/let}}

<DataSource
@src={{concat '/*/' @dc '/services'}}
@src={{uri '/${partition}/*/${dc}/services'
(hash
partition=@partition
dc=@dc
)
}}
@onchange={{action this.createServices item}}
/>
{{#if (env 'CONSUL_NSPACES_ENABLED')}}

{{#if (can 'use nspaces')}}
<DataSource
@src="/*/*/namespaces"
@src={{uri '/${partition}/*/${dc}/namespaces'
(hash
partition=@partition
dc=@dc
)
}}
@onchange={{action this.createNspaces item}}
/>
{{/if}}

{{#if (and api.isCreate this.isManagedByCRDs)}}
<Consul::Intention::Notice::CustomResource @type="warning" />
{{/if}}
Expand Down
5 changes: 3 additions & 2 deletions ui/packages/consul-ui/app/components/consul/kv/form/index.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<DataForm
@dc={{dc}}
@nspace={{nspace}}
@partition={{partition}}
@type="kv"
@label="key"
@autofill={{autofill}}
Expand All @@ -19,11 +20,11 @@
{{#if api.isCreate}}
<label class="type-text{{if api.data.error.Key ' has-error'}}">
<span>Key or folder</span>
<input autofocus="autofocus" type="text" value={{left-trim api.data.Key parent.Key}} name="additional" oninput={{action api.change}} placeholder="Key or folder" />
<input autofocus="autofocus" type="text" value={{left-trim api.data.Key parent}} name="additional" oninput={{action api.change}} placeholder="Key or folder" />
<em>To create a folder, end a key with <code>/</code></em>
</label>
{{/if}}
{{#if (or (eq (left-trim api.data.Key parent.Key) '') (not-eq (last api.data.Key) '/'))}}
{{#if (or (eq (left-trim api.data.Key parent) '') (not-eq (last api.data.Key) '/'))}}
<div>
<div class="type-toggle">
<label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default Component.extend({
set(item, 'Value', this.encoder.execute(target.value));
break;
case 'additional':
parent = get(this, 'parent.Key');
parent = get(this, 'parent');
set(item, 'Key', `${parent !== '/' ? parent : ''}${target.value}`);
break;
case 'json':
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<DataForm
@dc={{dc}}
@nspace={{nspace}}
@partition={{partition}}
@item={{item}}
@type="session"
@onsubmit={{action onsubmit}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class: ember
# Consul::LockSession::List

```hbs preview-template
<DataSource @src="/default/dc-1/sessions/for-node/my-node" as |source|>
<DataSource @src="/partition/default/dc-1/sessions/for-node/my-node" as |source|>
<Consul::LockSession::List
@items={{source.data}}
@onInvalidate={{action (noop)}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ A presentational component for presenting Consul Metadata
The following example shows how to construct the required structure from the Consul API using ember-componsable-helpers' `entries` helper.

```hbs
<DataSource @src="/default/dc-1/service-instance/service-id/node-0/service-0" as |source|>
<DataSource @src="/partition/default/dc-1/service-instance/service-id/node-0/service-0" as |source|>
<Consul::Metadata::List
@items={{entries source.data.firstObject.Meta}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class: ember
## Consul::Nspace::List

```hbs
<DataSource @src="/default/dc-1/namespaces" as |source|>
<DataSource @src="/partition/default/dc-1/namespaces" as |source|>
<Consul::Nspace::List
@items={{source.data}}
@ondelete={{action (noop)}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,15 @@ as |key value|}}
{{#each dcs as |dc|}}
<Option @value={{dc.Name}} @selected={{contains dc.Name @filter.datacenter.value}}>{{dc.Name}}</Option>
{{/each}}
<DataSource @src="/*/*/datacenters" @loading="lazy" @onchange={{action (mut this.dcs) value="data"}} />
<DataSource
@src={{uri "/${partition}/*/*/datacenters"
(hash
partition=@partition
)
}}
@loading="lazy"
@onchange={{action (mut this.dcs) value="data"}}
/>
{{/let}}
</BlockSlot>
</search.Select>
Expand Down
Loading

0 comments on commit fc14a41

Please sign in to comment.