ui: Add ServerExternalAddresses field to token generation

pull/15555/head
wenincode 2022-11-24 15:06:01 -07:00
parent 941f6da202
commit ea23bac1fb
6 changed files with 50 additions and 3 deletions

View File

@ -36,5 +36,26 @@
</fieldset> </fieldset>
{{/let}} {{/let}}
{{#let
(hash
help=(t 'common.validations.server-external-addresses.help')
)
as |ServerExternalAddresses|}}
<fieldset>
<TextInput
@label="Server address(es)"
@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}}
</StateMachine> </StateMachine>
</div> </div>

View File

@ -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;
}
}

View File

@ -44,12 +44,13 @@
<fsm.State @matches={{'loading'}}> <fsm.State @matches={{'loading'}}>
<DataSource <DataSource
@src={{uri '/${partition}/${nspace}/${dc}/peering/token-for/${name}' @src={{uri '/${partition}/${nspace}/${dc}/peering/token-for/${name}/${externalAddresses}'
(hash (hash
partition=@item.Partition partition=@item.Partition
nspace='' nspace=''
dc=@item.Datacenter dc=@item.Datacenter
name=@item.Name name=@item.Name
externalAddresses=@item.ServerExternalAddresses
) )
}} }}
@onchange={{queue @onchange={{queue

View File

@ -17,6 +17,8 @@ export default class Peer extends Model {
@attr('string') Name; @attr('string') Name;
@attr('string') State; @attr('string') State;
@attr('string') ID; @attr('string') ID;
@attr('string') ServerExternalAddresses;
@nullValue([]) @attr() ServerExternalAddresses;
// only the side that establishes will hold this property // only the side that establishes will hold this property
@attr('string') PeerID; @attr('string') PeerID;

View File

@ -44,8 +44,11 @@ export default class PeerService extends RepositoryService {
}); });
} }
@dataSource('/:partition/:ns/:dc/peering/token-for/:name') @dataSource('/:partition/:ns/:dc/peering/token-for/:name/:externalAddresses')
async fetchToken({ dc, ns, partition, name }, configuration, request) { async fetchToken({ dc, ns, partition, name, externalAddresses }, configuration, request) {
const ServerExternalAddresses =
externalAddresses?.length > 0 ? externalAddresses.split(',') : [];
return ( return (
await request` await request`
POST /v1/peering/token POST /v1/peering/token
@ -53,6 +56,7 @@ export default class PeerService extends RepositoryService {
${{ ${{
PeerName: name, PeerName: name,
Partition: partition || undefined, Partition: partition || undefined,
ServerExternalAddresses,
}} }}
` `
)((headers, body, cache) => body); )((headers, body, cache) => body);

View File

@ -81,4 +81,8 @@ validations:
error: "{name} must be a valid DNS hostname." error: "{name} must be a valid DNS hostname."
immutable: immutable:
help: Once created, this cannot be changed. help: Once created, this cannot be changed.
server-external-addresses:
help: |
Enter a fallback server address for this peer to be used in the event of failed automatic updates. This field is required for HCP-managed clusters.
test: "^$|^[a-zA-Z0-9]([a-zA-Z0-9-]'{0,62}'[a-zA-Z0-9])?$"