Skip to content

Commit

Permalink
Backport of ui: Add ServerExternalAddresses to peer token create form…
Browse files Browse the repository at this point in the history
… into release/1.14.x (#15620)

* backport of commit ea23bac

* backport of commit a4d1535

* backport of commit f782c16

* backport of commit 198eb09

* backport of commit 38c0e32

* backport of commit b388266

Co-authored-by: wenincode <tyler.wendlandt@hashicorp.com>
  • Loading branch information
hc-github-team-consul-core and wenincode authored Nov 30, 2022
1 parent 18dffc5 commit 13836d5
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 130 deletions.
3 changes: 3 additions & 0 deletions .changelog/15555.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:feature
ui: Add field for fallback server addresses to peer token generation form
```
Original file line number Diff line number Diff line change
@@ -1,38 +1,54 @@
<div
class={{class-map
'consul-peer-form-generate-fieldsets'
}}
...attributes
>
<div class={{class-map "consul-peer-form-generate-fieldsets"}} ...attributes>
<StateMachine
@src={{require '/machines/validate.xstate' from="/components/consul/peer/form/generate/fieldsets"}}
as |fsm|>
@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|
}}
<fieldset>
<TextInput
@label="Name of peer"
@label={{t "components.consul.peer.generate.name"}}
@name="Name"
@item={{@item}}
@validations={{Name}}
@chart={{fsm}}
@oninput={{pick 'target.value' (set @item 'Name')}}
@oninput={{pick "target.value" (set @item "Name")}}
/>
{{yield (hash
valid=(not (state-matches fsm.state 'error'))
)}}
{{yield (hash valid=(not (state-matches fsm.state "error")))}}
</fieldset>

{{/let}}

{{#let
(hash help=(t "common.validations.server-external-addresses.help"))
as |ServerExternalAddresses|
}}
<fieldset>
<TextInput
@label={{t "components.consul.peer.generate.addresses"}}
@name="ServerExternalAddresses"
@item={{@item}}
@chart={{fsm}}
@validations={{ServerExternalAddresses}}
@oninput={{pick "target.value" this.onInput}}
/>
{{yield (hash valid=(not (state-matches fsm.state "error")))}}
</fieldset>

{{/let}}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -1,88 +1,81 @@
<div
class={{class-map
'consul-peer-form-generate'
}}
...attributes
>
<div class={{class-map "consul-peer-form-generate"}} ...attributes>
<StateMachine
@src={{require './chart.xstate' from="/components/consul/peer/form/generate"}}
@initial={{if @regenerate 'loading' 'idle'}}
as |fsm|>
@src={{require
"./chart.xstate"
from="/components/consul/peer/form/generate"
}}
@initial={{if @regenerate "loading" "idle"}}
as |fsm|
>

{{#let
(unique-id)
as |id reset|}}
<form
{{on 'submit' (fn fsm.dispatch 'LOAD')}}
id={{id}}
>
{{#let (unique-id) as |id reset|}}
<form {{on "submit" (fn fsm.dispatch "LOAD")}} id={{id}}>

<fsm.State @matches={{array 'idle' 'error'}}>
<fsm.State @matches={{'error'}}>
<Notice
@type="error"
role="alert"
as |notice|>
<notice.Body>
<p>
<strong>Error</strong><br />
{{fsm.state.context.error.message}}
</p>
</notice.Body>
</Notice>
</fsm.State>
{{yield (hash
Fieldsets=(component "consul/peer/form/generate/fieldsets"
item=@item
)
Actions=(component "consul/peer/form/generate/actions"
item=@item
id=id
)
)}}
</fsm.State>

<fsm.State @matches={{'loading'}}>
<DataSource
@src={{uri '/${partition}/${nspace}/${dc}/peering/token-for/${name}'
<fsm.State @matches={{array "idle" "error"}}>
<fsm.State @matches={{"error"}}>
<Notice @type="error" role="alert" as |notice|>
<notice.Body>
<p>
<strong>Error</strong><br />
{{fsm.state.context.error.message}}
</p>
</notice.Body>
</Notice>
</fsm.State>
{{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')
}}
/>
</fsm.State>
</fsm.State>

<fsm.State @matches={{'success'}}>
{{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')
<fsm.State @matches={{"loading"}}>
<DataSource
@src={{uri
"/${partition}/${nspace}/${dc}/peering/token-for/${name}/${externalAddresses}"
(hash
partition=@item.Partition
nspace=""
dc=@item.Datacenter
name=@item.Name
externalAddresses=@item.ServerExternalAddresses
)
}}
@onchange={{queue
@onchange
(pick "data" (fn fsm.dispatch "SUCCESS"))
}}
@onerror={{queue (fn fsm.dispatch "ERROR")}}
/>
</fsm.State>

<fsm.State @matches={{"success"}}>
{{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
)
)}}
</fsm.State>
}}
</fsm.State>

</form>
{{/let}}
</form>
{{/let}}

</StateMachine>
</div>
Original file line number Diff line number Diff line change
@@ -1,63 +1,50 @@
<div
class={{class-map
'consul-peer-form'
}}
...attributes
>
<div class={{class-map "consul-peer-form"}} ...attributes>
<StateMachine
@src={{require './chart.xstate' from='/components/consul/peer/form'}}
as |fsm|>
@src={{require "./chart.xstate" from="/components/consul/peer/form"}}
as |fsm|
>

<TabNav
@items={{array
(hash
label='Generate token'
selected=(state-matches fsm.state 'generate')
label=(t "components.consul.peer.form.generate-label")
selected=(state-matches fsm.state "generate")
state="GENERATE"
)
(hash
label='Establish peering'
selected=(state-matches fsm.state 'initiate')
label=(t "components.consul.peer.form.establish-label")
selected=(state-matches fsm.state "initiate")
state="INITIATE"
)
}}
@onTabClicked={{pick 'state' fsm.dispatch}}
@onTabClicked={{pick "state" fsm.dispatch}}
/>

<fsm.State @matches={{array 'generate'}}>
<fsm.State @matches={{array "generate"}}>

<DataSource
@src={{uri '/${partition}/${nspace}/${dc}/peer-generate/'
@params
@src={{uri "/${partition}/${nspace}/${dc}/peer-generate/" @params}}
as |source|
>
{{yield
(hash Form=(component "consul/peer/form/generate" item=source.data))
}}
as |source|>
{{yield (hash
Form=(component 'consul/peer/form/generate'
item=source.data
)
)
}}
</DataSource>

</fsm.State>

<fsm.State @matches="initiate">

<DataSource
@src={{uri '/${partition}/${nspace}/${dc}/peer-initiate/'
@params
@src={{uri "/${partition}/${nspace}/${dc}/peer-initiate/" @params}}
as |source|
>
{{yield
(hash Form=(component "consul/peer/form/initiate" item=source.data))
}}
as |source|>
{{yield (hash
Form=(component 'consul/peer/form/initiate'
item=source.data
)
)
}}
</DataSource>

</fsm.State>


</StateMachine>
</div>
2 changes: 2 additions & 0 deletions ui/packages/consul-ui/app/models/peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions ui/packages/consul-ui/app/services/repository/peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,19 @@ 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
${{
PeerName: name,
Partition: partition || undefined,
ServerExternalAddresses,
}}
`
)((headers, body, cache) => body);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
Expand All @@ -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"
4 changes: 3 additions & 1 deletion ui/packages/consul-ui/translations/common/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Loading

0 comments on commit 13836d5

Please sign in to comment.