From 4a7fe5625a462be328589931744c72c95d44ea79 Mon Sep 17 00:00:00 2001 From: Tyler Wendlandt Date: Wed, 30 Nov 2022 11:42:36 -0700 Subject: [PATCH] ui: Add ServerExternalAddresses to peer token create form (#15555) * ui: Add ServerExternalAddresses field to token generation * Add test for ServerExternalAddresses on peer token create * Add changelog entry * Update translations * Format hbs files * Update translations --- .changelog/15555.txt | 3 + .../peer/form/generate/fieldsets/index.hbs | 52 ++++--- .../peer/form/generate/fieldsets/index.js | 15 ++ .../consul/peer/form/generate/index.hbs | 145 +++++++++--------- .../app/components/consul/peer/form/index.hbs | 53 +++---- ui/packages/consul-ui/app/models/peer.js | 2 + .../consul-ui/app/services/repository/peer.js | 8 +- .../tests/acceptance/dc/peers/create.feature | 3 + .../consul-ui/translations/common/en-us.yaml | 4 +- .../translations/components/consul/en-us.yaml | 6 + 10 files changed, 161 insertions(+), 130 deletions(-) create mode 100644 .changelog/15555.txt create mode 100644 ui/packages/consul-peerings/app/components/consul/peer/form/generate/fieldsets/index.js diff --git a/.changelog/15555.txt b/.changelog/15555.txt new file mode 100644 index 000000000..c6bec6288 --- /dev/null +++ b/.changelog/15555.txt @@ -0,0 +1,3 @@ +```release-note:feature +ui: Add field for fallback server addresses to peer token generation form +``` diff --git a/ui/packages/consul-peerings/app/components/consul/peer/form/generate/fieldsets/index.hbs b/ui/packages/consul-peerings/app/components/consul/peer/form/generate/fieldsets/index.hbs index f6fd4fcbc..e9ba548c9 100644 --- a/ui/packages/consul-peerings/app/components/consul/peer/form/generate/fieldsets/index.hbs +++ b/ui/packages/consul-peerings/app/components/consul/peer/form/generate/fieldsets/index.hbs @@ -1,38 +1,54 @@ -
+
+ @src={{require + "/machines/validate.xstate" + from="/components/consul/peer/form/generate/fieldsets" + }} + as |fsm| + > {{#let (hash help=(concat - (t 'common.validations.dns-hostname.help') - (t 'common.validations.immutable.help') + (t "common.validations.dns-hostname.help") + (t "common.validations.immutable.help") ) Name=(array (hash - test=(t 'common.validations.dns-hostname.test') - error=(t 'common.validations.dns-hostname.error' name="Name") + test=(t "common.validations.dns-hostname.test") + error=(t "common.validations.dns-hostname.error" name="Name") ) ) ) - as |Name|}} + as |Name| + }}
- {{yield (hash - valid=(not (state-matches fsm.state 'error')) - )}} + {{yield (hash valid=(not (state-matches fsm.state "error")))}} +
+ + {{/let}} + + {{#let + (hash help=(t "common.validations.server-external-addresses.help")) + as |ServerExternalAddresses| + }} +
+ + {{yield (hash valid=(not (state-matches fsm.state "error")))}}
{{/let}} diff --git a/ui/packages/consul-peerings/app/components/consul/peer/form/generate/fieldsets/index.js b/ui/packages/consul-peerings/app/components/consul/peer/form/generate/fieldsets/index.js new file mode 100644 index 000000000..ea90d9406 --- /dev/null +++ b/ui/packages/consul-peerings/app/components/consul/peer/form/generate/fieldsets/index.js @@ -0,0 +1,15 @@ +import Component from '@glimmer/component'; +import { action } from '@ember/object'; + +export default class PeerGenerateFieldSets extends Component { + @action + onInput(addresses) { + if (addresses) { + addresses = addresses.split(',').map(address => address.trim()); + } else { + addresses = []; + } + + this.args.item.ServerExternalAddresses = addresses; + } +} diff --git a/ui/packages/consul-peerings/app/components/consul/peer/form/generate/index.hbs b/ui/packages/consul-peerings/app/components/consul/peer/form/generate/index.hbs index 0e4e63a65..de818b1b5 100644 --- a/ui/packages/consul-peerings/app/components/consul/peer/form/generate/index.hbs +++ b/ui/packages/consul-peerings/app/components/consul/peer/form/generate/index.hbs @@ -1,88 +1,81 @@ -
+
+ @src={{require + "./chart.xstate" + from="/components/consul/peer/form/generate" + }} + @initial={{if @regenerate "loading" "idle"}} + as |fsm| + > - {{#let - (unique-id) - as |id reset|}} -
+ {{#let (unique-id) as |id reset|}} + - - - - -

- Error
- {{fsm.state.context.error.message}} -

-
-
-
- {{yield (hash - Fieldsets=(component "consul/peer/form/generate/fieldsets" - item=@item - ) - Actions=(component "consul/peer/form/generate/actions" - item=@item - id=id - ) - )}} -
- - - + + + +

+ Error
+ {{fsm.state.context.error.message}} +

+
+
+
+ {{yield (hash - partition=@item.Partition - nspace='' - dc=@item.Datacenter - name=@item.Name + Fieldsets=(component + "consul/peer/form/generate/fieldsets" item=@item + ) + Actions=(component + "consul/peer/form/generate/actions" item=@item id=id + ) ) }} - @onchange={{queue - @onchange - (pick 'data' (fn fsm.dispatch 'SUCCESS')) - }} - @onerror={{queue - (fn fsm.dispatch 'ERROR') - }} - /> -
+ - - {{yield (hash - Fieldsets=(component "consul/peer/form/token/fieldsets" - item=@item - token=fsm.state.context.PeeringToken - regenerate=@regenerate - onclick=(queue - (set @item 'Name' '') - (fn fsm.dispatch 'RESET') + + + + + + {{yield + (hash + Fieldsets=(component + "consul/peer/form/token/fieldsets" + item=@item + token=fsm.state.context.PeeringToken + regenerate=@regenerate + onclick=(queue (set @item "Name" "") (fn fsm.dispatch "RESET")) + ) + Actions=(component + "consul/peer/form/token/actions" + token=fsm.state.context.PeeringToken + item=@item + id=id + ) ) - ) - Actions=(component "consul/peer/form/token/actions" - token=fsm.state.context.PeeringToken - item=@item - id=id - ) - )}} - + }} + -
- {{/let}} + + {{/let}}
diff --git a/ui/packages/consul-peerings/app/components/consul/peer/form/index.hbs b/ui/packages/consul-peerings/app/components/consul/peer/form/index.hbs index b8d09b8c8..8f56517f9 100644 --- a/ui/packages/consul-peerings/app/components/consul/peer/form/index.hbs +++ b/ui/packages/consul-peerings/app/components/consul/peer/form/index.hbs @@ -1,42 +1,34 @@ -
+
+ @src={{require "./chart.xstate" from="/components/consul/peer/form"}} + as |fsm| + > - + + {{yield + (hash Form=(component "consul/peer/form/generate" item=source.data)) }} - as |source|> - {{yield (hash - Form=(component 'consul/peer/form/generate' - item=source.data - ) - ) - }} @@ -44,20 +36,15 @@ + {{yield + (hash Form=(component "consul/peer/form/initiate" item=source.data)) }} - as |source|> - {{yield (hash - Form=(component 'consul/peer/form/initiate' - item=source.data - ) - ) - }} -
diff --git a/ui/packages/consul-ui/app/models/peer.js b/ui/packages/consul-ui/app/models/peer.js index 6695253d8..0e03544b9 100644 --- a/ui/packages/consul-ui/app/models/peer.js +++ b/ui/packages/consul-ui/app/models/peer.js @@ -17,6 +17,8 @@ export default class Peer extends Model { @attr('string') Name; @attr('string') State; @attr('string') ID; + @attr('string') ServerExternalAddresses; + @nullValue([]) @attr() ServerExternalAddresses; // only the side that establishes will hold this property @attr('string') PeerID; diff --git a/ui/packages/consul-ui/app/services/repository/peer.js b/ui/packages/consul-ui/app/services/repository/peer.js index c39accbb5..63f65e38a 100644 --- a/ui/packages/consul-ui/app/services/repository/peer.js +++ b/ui/packages/consul-ui/app/services/repository/peer.js @@ -44,8 +44,11 @@ export default class PeerService extends RepositoryService { }); } - @dataSource('/:partition/:ns/:dc/peering/token-for/:name') - async fetchToken({ dc, ns, partition, name }, configuration, request) { + @dataSource('/:partition/:ns/:dc/peering/token-for/:name/:externalAddresses') + async fetchToken({ dc, ns, partition, name, externalAddresses }, configuration, request) { + const ServerExternalAddresses = + externalAddresses?.length > 0 ? externalAddresses.split(',') : []; + return ( await request` POST /v1/peering/token @@ -53,6 +56,7 @@ export default class PeerService extends RepositoryService { ${{ PeerName: name, Partition: partition || undefined, + ServerExternalAddresses, }} ` )((headers, body, cache) => body); diff --git a/ui/packages/consul-ui/tests/acceptance/dc/peers/create.feature b/ui/packages/consul-ui/tests/acceptance/dc/peers/create.feature index 4cfe29db7..271361390 100644 --- a/ui/packages/consul-ui/tests/acceptance/dc/peers/create.feature +++ b/ui/packages/consul-ui/tests/acceptance/dc/peers/create.feature @@ -22,6 +22,7 @@ Feature: dc / peers / create: Peer Create Token --- body: PeerName: new-peer + ServerExternalAddresses: [] --- Then I see the text "an-encoded-token" in ".consul-peer-form-generate code" When I click ".consul-peer-form-generate button[type=reset]" @@ -33,11 +34,13 @@ Feature: dc / peers / create: Peer Create Token Then I fill in with yaml --- Name: another-new-peer + ServerExternalAddresses: "1.1.1.1:123,1.2.3.4:3202" --- When I click ".peer-create-modal .modal-dialog-footer button" Then a POST request was made to "/v1/peering/token" from yaml --- body: PeerName: another-new-peer + ServerExternalAddresses: ["1.1.1.1:123","1.2.3.4:3202"] --- Then I see the text "another-encoded-token" in ".consul-peer-form-generate code" diff --git a/ui/packages/consul-ui/translations/common/en-us.yaml b/ui/packages/consul-ui/translations/common/en-us.yaml index 8fce90430..5c584540e 100644 --- a/ui/packages/consul-ui/translations/common/en-us.yaml +++ b/ui/packages/consul-ui/translations/common/en-us.yaml @@ -81,4 +81,6 @@ validations: error: "{name} must be a valid DNS hostname." immutable: help: Once created, this cannot be changed. - + server-external-addresses: + help: | + Enter a comma separated list of this peer's fallback server address(es) to be used in the event of failed automatic updates. This field is required for HCP-managed clusters. diff --git a/ui/packages/consul-ui/translations/components/consul/en-us.yaml b/ui/packages/consul-ui/translations/components/consul/en-us.yaml index 0809332f4..b8ee183e3 100644 --- a/ui/packages/consul-ui/translations/components/consul/en-us.yaml +++ b/ui/packages/consul-ui/translations/components/consul/en-us.yaml @@ -14,6 +14,12 @@ peer: name: Status asc: Pending to Deleting desc: Deleting to Pending + form: + generate-label: Generate token + establish-label: Establish peering + generate: + name: 'Name of peer' + addresses: 'Server address(es)' service: search-bar: kind: Service Type