From 054881dc4ee26f9dc13bc7a977bad0cce272ce24 Mon Sep 17 00:00:00 2001 From: Zhihe Li Date: Mon, 17 Apr 2023 13:22:32 -0400 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Add=20support=20to=20dis?= =?UTF-8?q?play=20external=20name=20for=20dynamic=20hosts=20(#1664)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 🎸 Add support to display external name for dynamic hosts ✅ Closes: ICU-8795 --- addons/api/addon/models/host.js | 11 ++ addons/api/mirage/factories/host.js | 14 +- addons/api/mirage/generated/factories/host.js | 1 - addons/core/translations/form/en-us.yaml | 8 ++ addons/core/translations/resources/en-us.yaml | 1 + .../app/components/form/host/aws/index.hbs | 133 +++++++++++------- .../app/components/form/host/azure/index.hbs | 112 +++++++++------ .../host-sets/host-set/hosts/index.hbs | 8 +- 8 files changed, 183 insertions(+), 105 deletions(-) diff --git a/addons/api/addon/models/host.js b/addons/api/addon/models/host.js index 93c9632cb..aa6ab14af 100644 --- a/addons/api/addon/models/host.js +++ b/addons/api/addon/models/host.js @@ -29,6 +29,12 @@ export default class HostModel extends GeneratedHostModel { }) external_id; + @attr('string', { + description: 'The external facing name for the plugin based host.', + readOnly: true, + }) + external_name; + // Aws specific @attr({ readOnly: true, @@ -89,4 +95,9 @@ export default class HostModel extends GeneratedHostModel { this.plugin = { name: type }; } } + + // Plugin hosts can support an external name + get displayName() { + return this.name || this.external_name || this.id; + } } diff --git a/addons/api/mirage/factories/host.js b/addons/api/mirage/factories/host.js index 8d07fb4c3..c2abaa1cf 100644 --- a/addons/api/mirage/factories/host.js +++ b/addons/api/mirage/factories/host.js @@ -10,7 +10,9 @@ import generateId from '../helpers/id'; export default factory.extend({ id: () => generateId('h_'), - + name() { + if (this.type === 'static') return faker.random.words(); + }, type() { return this.hostCatalog?.type || factory.attrs.type; }, @@ -34,8 +36,16 @@ export default factory.extend({ } return result; }, + // Return external fields only for plugins external_id() { - return faker.datatype.uuid(); + if (this.type === 'plugin') { + return faker.datatype.uuid(); + } + }, + external_name(i) { + if (this.type === 'plugin') { + return `${this.plugin.name} provided name ${i}`; + } }, // Only aws plugins have dns_names dns_names() { diff --git a/addons/api/mirage/generated/factories/host.js b/addons/api/mirage/generated/factories/host.js index 423a520bd..4b3f64498 100644 --- a/addons/api/mirage/generated/factories/host.js +++ b/addons/api/mirage/generated/factories/host.js @@ -11,7 +11,6 @@ import { faker } from '@faker-js/faker'; */ export default Factory.extend({ type: 'static', - name: () => faker.random.words(), description: () => faker.random.words(), created_time: () => faker.date.recent(), updated_time: () => faker.date.recent(), diff --git a/addons/core/translations/form/en-us.yaml b/addons/core/translations/form/en-us.yaml index 3abfd6419..9d76fa1f4 100644 --- a/addons/core/translations/form/en-us.yaml +++ b/addons/core/translations/form/en-us.yaml @@ -3,9 +3,15 @@ id: label: ID +external_id: + label: External ID + help: A read-only ID given by the plugin host catalog provider name: label: Name help: Name for identification purposes +external_name: + label: External Name + help: A read-only name given by the plugin host catalog provider description: label: Description help: Description for identification purposes @@ -153,10 +159,12 @@ disable_credential_rotation: help: Azure host catalogs do not yet support credential rotation. dns_names: label: Latest DNS Names + help: Read-only DNS names given by the plugin host catalog provider host: label: Host ip_addresses: label: Latest IP Addresses + help: Read-only public and private IP addresses given by the plugin host catalog provider sync-interval: label: Sync Interval help: Optional. Number of seconds between the time Boundary syncs hosts in this set. diff --git a/addons/core/translations/resources/en-us.yaml b/addons/core/translations/resources/en-us.yaml index 68932b448..f9cba0b87 100644 --- a/addons/core/translations/resources/en-us.yaml +++ b/addons/core/translations/resources/en-us.yaml @@ -149,6 +149,7 @@ host-set: host: title: Host title_plural: Hosts + no_name_title: Unnamed Host description: A host is a resource that may be accessed by a Boundary target. messages: welcome: diff --git a/ui/admin/app/components/form/host/aws/index.hbs b/ui/admin/app/components/form/host/aws/index.hbs index 2ca63199f..1b7c4944d 100644 --- a/ui/admin/app/components/form/host/aws/index.hbs +++ b/ui/admin/app/components/form/host/aws/index.hbs @@ -11,51 +11,70 @@ as |form| > - - - - {{#if @model.errors.name}} - - {{#each @model.errors.name as |error|}} - {{error.message}} - {{/each}} - - {{/if}} - + {{t 'form.type.label'}} + - + {{t 'form.external_name.label'}} + {{t 'form.external_name.help'}} + {{#if @model.errors.external_name}} + + {{#each @model.errors.external_name as |error|}} + {{error.message}} + {{/each}} + + {{/if}} + + {{/if}} + + + {{t 'form.external_id.label'}} + {{t 'form.external_id.help'}} + {{#if @model.errors.external_id}} + + {{#each @model.errors.external_id as |error|}} + {{error.message}} + {{/each}} + + {{/if}} + + + + {{t 'form.description.label'}} + {{t 'form.description.help'}} {{#if @model.errors.description}} - + {{#each @model.errors.description as |error|}} - {{error.message}} + {{error.message}} {{/each}} - + {{/if}} - + - - <:title>{{t 'form.ip_addresses.label'}} - <:body> - {{#each @model.ip_addresses as |ip_address|}} - + {{t 'form.ip_addresses.label'}} + {{t 'form.ip_addresses.help'}} + {{#each @model.ip_addresses as |ip_address|}} + + - {{/each}} - - + + {{/each}} + - - <:title>{{t 'form.dns_names.label'}} - <:body> - {{#each @model.dns_names as |dns_name|}} - - {{/each}} - - + + {{t 'form.dns_names.label'}} + {{t 'form.dns_names.help'}} + {{#each @model.dns_names as |dns_name|}} + + + + {{/each}} + {{#if (can 'save model' @model)}} - - - - {{#if @model.errors.name}} - - {{#each @model.errors.name as |error|}} - {{error.message}} - {{/each}} - - {{/if}} - + {{t 'form.type.label'}} + - + {{t 'form.external_name.label'}} + {{t 'form.external_name.help'}} + {{#if @model.errors.external_name}} + + {{#each @model.errors.external_name as |error|}} + {{error.message}} + {{/each}} + + {{/if}} + + {{/if}} + + + {{t 'form.external_id.label'}} + {{t 'form.external_id.help'}} + {{#if @model.errors.external_id}} + + {{#each @model.errors.external_id as |error|}} + {{error.message}} + {{/each}} + + {{/if}} + + + + {{t 'form.description.label'}} + {{t 'form.description.help'}} {{#if @model.errors.description}} - + {{#each @model.errors.description as |error|}} - {{error.message}} + {{error.message}} {{/each}} - + {{/if}} - + - - <:title>{{t 'form.ip_addresses.label'}} - <:body> - {{#each @model.ip_addresses as |ip_address|}} - + {{t 'form.ip_addresses.label'}} + {{t 'form.ip_addresses.help'}} + {{#each @model.ip_addresses as |ip_address|}} + + - {{/each}} - - + + {{/each}} + {{#if (can 'save model' @model)}} - {{t 'form.name.label'}} + {{#if @model.hostSet.isStatic}} + {{t 'form.name.label'}} + {{else}} + {{t 'form.external_name.label'}} + {{/if}} {{t 'form.type.label'}} {{t 'form.id.label'}} - {{#if @model.isStatic}} + {{#if @model.hostSet.isStatic}} {{t 'titles.actions'}} {{/if}}