fix: 🐛 minor UI changes, ent flag for worker filter (#2517)

This commit is contained in:
Dharini Jeeva authored and GitHub committed 2024-10-10 12:44:12 -07:00
1 parent 857bf01596
commit 0ff91f9182
6 files changed
+97 -44

No files matched your search

+7 -1
View File
@@ -7,6 +7,7 @@ import ApplicationSerializer from './application';
import { import {
TYPE_HOST_CATALOG_PLUGIN_AWS, TYPE_HOST_CATALOG_PLUGIN_AWS,
TYPE_HOST_CATALOG_PLUGIN_AZURE, TYPE_HOST_CATALOG_PLUGIN_AZURE,
TYPE_CREDENTIAL_DYNAMIC,
} from '../models/host-catalog'; } from '../models/host-catalog';
// These fields are Azure specific // These fields are Azure specific
@@ -41,7 +42,7 @@ const AWSfieldsWithCredentialType = {
export default class HostCatalogSerializer extends ApplicationSerializer { export default class HostCatalogSerializer extends ApplicationSerializer {
serialize(snapshot) { serialize(snapshot) {
const { compositeType } = snapshot.record; const { compositeType, credentialType } = snapshot.record;
const serialized = super.serialize(...arguments); const serialized = super.serialize(...arguments);
// This is a hack to remove the worker_filter field from the serialized data if the compositeType is not AWS // This is a hack to remove the worker_filter field from the serialized data if the compositeType is not AWS
@@ -50,6 +51,11 @@ export default class HostCatalogSerializer extends ApplicationSerializer {
delete serialized.worker_filter; delete serialized.worker_filter;
} }
// By default, disable credential rotation for dynamic credentials
if (credentialType === TYPE_CREDENTIAL_DYNAMIC) {
serialized.attributes.disable_credential_rotation = true;
}
switch (compositeType) { switch (compositeType) {
case 'static': case 'static':
return this.serializeStatic(...arguments); return this.serializeStatic(...arguments);
@@ -212,6 +212,8 @@ host-catalog:
help: help:
static: Provide a list of hosts and host sets with static addresses static: Provide a list of hosts and host sets with static addresses
plugin: Automate discovery of target hosts and services on Azure or AWS plugin: Automate discovery of target hosts and services on Azure or AWS
role_arn: The ARN (Amazon Resource Name) used by this instance.
disable_credential_rotation: Credential rotation is automatically disabled when you use dynamic credentials.
types: types:
static: Static static: Static
unknown: Plugin unknown: Plugin
@@ -228,7 +230,7 @@ host-catalog:
dynamic-credential: dynamic-credential:
edit: Dynamic Credentials edit: Dynamic Credentials
label: Use Assume Role (Dynamic Credentials) label: Use Assume Role (Dynamic Credentials)
help: Specify an Assume Role used to generate credentials to use with this AWS Host Catalog. help: Specify a role used to generate credentials to use with this AWS Host Catalog.
form: form:
aws_region: aws_region:
label: AWS Region label: AWS Region
@@ -479,7 +481,7 @@ storage-bucket:
help: The base path where session recordings will be stored. help: The base path where session recordings will be stored.
role_arn: role_arn:
label: Role ARN label: Role ARN
help: The ARN (Assume Role Name) used by this instance that the worker runs on. help: The ARN (Amazon Resource Name) used by this instance that the worker runs on.
role_external_id: role_external_id:
label: Role external ID label: Role external ID
help: Used to provide access to this account if you have this configured. help: Used to provide access to this account if you have this configured.
@@ -145,7 +145,12 @@
</Hds::Form::TextInput::Field> </Hds::Form::TextInput::Field>
{{#if @model.isNew}} {{#if @model.isNew}}
<Hds::Form::Radio::Group @layout='vertical' @name='credential_type' as |G|> <Hds::Form::Radio::Group
class='dynamic-credential-selection'
@layout='vertical'
@name='credential_type'
as |G|
>
<G.Legend> <G.Legend>
{{t 'resources.host-catalog.types.credential.label'}} {{t 'resources.host-catalog.types.credential.label'}}
</G.Legend> </G.Legend>
@@ -217,7 +222,7 @@
{{t 'resources.storage-bucket.form.role_arn.label'}} {{t 'resources.storage-bucket.form.role_arn.label'}}
</F.Label> </F.Label>
<F.HelperText> <F.HelperText>
{{t 'resources.storage-bucket.form.role_arn.help'}} {{t 'resources.host-catalog.help.role_arn'}}
</F.HelperText> </F.HelperText>
{{#if @model.errors.role_arn}} {{#if @model.errors.role_arn}}
<F.Error as |E|> <F.Error as |E|>
@@ -364,46 +369,64 @@
</Hds::Form::TextInput::Field> </Hds::Form::TextInput::Field>
{{/if}} {{/if}}
<Hds::Form::Textarea::Field {{#if (feature-flag 'dynamic-credentials-worker-filter')}}
name='worker_filter' <Hds::Form::Textarea::Field
@value={{@model.worker_filter}} data-test-dynamic-credential-worker-filter
@isOptional={{true}} name='worker_filter'
@isInvalid={{@model.errors.worker_filter}} @value={{@model.worker_filter}}
disabled={{form.disabled}} @isOptional={{true}}
as |F| @isInvalid={{@model.errors.worker_filter}}
> disabled={{form.disabled}}
<F.Label> as |F|
{{t 'resources.host-catalog.form.worker_filter.label'}} >
</F.Label> <F.Label>
<F.HelperText> {{t 'resources.host-catalog.form.worker_filter.label'}}
{{t 'resources.host-catalog.form.worker_filter.help'}} </F.Label>
<Hds::Link::Inline @href={{doc-url 'worker.create-tags'}}> <F.HelperText>
{{t 'actions.learn-more'}} {{t 'resources.host-catalog.form.worker_filter.help'}}
</Hds::Link::Inline> <Hds::Link::Inline @href={{doc-url 'worker.create-tags'}}>
</F.HelperText> {{t 'actions.learn-more'}}
{{#if @model.errors.worker_filter}} </Hds::Link::Inline>
<F.Error as |E|> </F.HelperText>
{{#each @model.errors.worker_filter as |error|}} {{#if @model.errors.worker_filter}}
<E.Message> <F.Error as |E|>
{{error.message}} {{#each @model.errors.worker_filter as |error|}}
</E.Message> <E.Message>
{{/each}} {{error.message}}
</F.Error> </E.Message>
{{/if}} {{/each}}
</Hds::Form::Textarea::Field> </F.Error>
{{/if}}
<Hds::Form::Checkbox::Field </Hds::Form::Textarea::Field>
name='disable_credential_rotation' {{/if}}
checked={{@model.disable_credential_rotation}}
disabled={{form.disabled}}
{{on 'change' (fn this.toggleDisableCredentialRotation @model)}}
as |F|
>
<F.Label>
{{t 'form.disable_credential_rotation.label'}}
</F.Label>
</Hds::Form::Checkbox::Field>
{{#if this.showDynamicCredentials}}
<Hds::Form::Checkbox::Field
name='disable_credential_rotation'
checked={{true}}
disabled={{true}}
as |F|
>
<F.Label>
{{t 'form.disable_credential_rotation.label'}}
</F.Label>
<F.HelperText>
{{t 'resources.host-catalog.help.disable_credential_rotation'}}
</F.HelperText>
</Hds::Form::Checkbox::Field>
{{else}}
<Hds::Form::Checkbox::Field
name='disable_credential_rotation'
checked={{@model.disable_credential_rotation}}
disabled={{form.disabled}}
{{on 'change' (fn this.toggleDisableCredentialRotation @model)}}
as |F|
>
<F.Label>
{{t 'form.disable_credential_rotation.label'}}
</F.Label>
</Hds::Form::Checkbox::Field>
{{/if}}
&nbsp; &nbsp;
{{#if (can 'save model' @model)}} {{#if (can 'save model' @model)}}
+6
View File
@@ -1073,3 +1073,9 @@
gap: 1.5rem; gap: 1.5rem;
} }
} }
.dynamic-credential-selection {
.hds-form-group__control-field {
margin-bottom: 0;
}
}
+2
View File
@@ -28,6 +28,7 @@ const baseEdition = {
'target-network-address': false, 'target-network-address': false,
'vault-worker-filter': false, 'vault-worker-filter': false,
'ldap-auth-methods': false, 'ldap-auth-methods': false,
'dynamic-credentials-worker-filter': false,
}; };
// Editions maps edition keys to their associated featuresets. // Editions maps edition keys to their associated featuresets.
const featureEditions = {}; const featureEditions = {};
@@ -43,6 +44,7 @@ featureEditions.enterprise = {
...featureEditions.oss, ...featureEditions.oss,
'target-worker-filters-v2-ingress': true, 'target-worker-filters-v2-ingress': true,
'vault-worker-filter': true, 'vault-worker-filter': true,
'dynamic-credentials-worker-filter': true,
}; };
featureEditions.hcp = { featureEditions.hcp = {
...featureEditions.enterprise, ...featureEditions.enterprise,
@@ -21,6 +21,7 @@ module('Acceptance | host-catalogs | create', function (hooks) {
setupMirage(hooks); setupMirage(hooks);
setupIndexedDb(hooks); setupIndexedDb(hooks);
let featuresService;
let getHostCatalogCount; let getHostCatalogCount;
const NAME_INPUT_SELECTOR = '[name="name"]'; const NAME_INPUT_SELECTOR = '[name="name"]';
@@ -84,6 +85,8 @@ module('Acceptance | host-catalogs | create', function (hooks) {
urls.newStaticHostCatalog = `${urls.newHostCatalog}?type=static`; urls.newStaticHostCatalog = `${urls.newHostCatalog}?type=static`;
urls.newAWSDynamicHostCatalog = `${urls.newHostCatalog}?type=aws`; urls.newAWSDynamicHostCatalog = `${urls.newHostCatalog}?type=aws`;
urls.newAzureDynamicHostCatalog = `${urls.newHostCatalog}?type=azure`; urls.newAzureDynamicHostCatalog = `${urls.newHostCatalog}?type=azure`;
featuresService = this.owner.lookup('service:features');
// Generate resource counter // Generate resource counter
getHostCatalogCount = () => getHostCatalogCount = () =>
this.server.schema.hostCatalogs.all().models.length; this.server.schema.hostCatalogs.all().models.length;
@@ -196,6 +199,17 @@ module('Acceptance | host-catalogs | create', function (hooks) {
assert.dom('[data-test-error-message-name]').hasText('Name is required.'); assert.dom('[data-test-error-message-name]').hasText('Name is required.');
}); });
test('users should not see worker filter field in community edition', async function (assert) {
await visit(urls.newAWSDynamicHostCatalog);
assert.dom('[data-test-dynamic-credential-worker-filter]').doesNotExist();
});
test('users should see worker filter field in enterprise edition', async function (assert) {
featuresService.enable('dynamic-credentials-worker-filter');
await visit(urls.newAWSDynamicHostCatalog);
assert.dom('[data-test-dynamic-credential-worker-filter]').exists();
});
test('users cannot directly navigate to new host catalog route without proper authorization', async function (assert) { test('users cannot directly navigate to new host catalog route without proper authorization', async function (assert) {
instances.scopes.project.authorized_collection_actions['host-catalogs'] = instances.scopes.project.authorized_collection_actions['host-catalogs'] =
instances.scopes.project.authorized_collection_actions[ instances.scopes.project.authorized_collection_actions[