diff --git a/addons/api/addon/models/target.js b/addons/api/addon/models/target.js index 15cd3e678..9cfd4dd2d 100644 --- a/addons/api/addon/models/target.js +++ b/addons/api/addon/models/target.js @@ -18,7 +18,7 @@ export default class TargetModel extends GeneratedTargetModel { readOnly: true, emptyArrayIfMissing: true, }) - host_sets; + host_sources; /** * Credential library ids are read only and can be @@ -36,9 +36,9 @@ export default class TargetModel extends GeneratedTargetModel { * instances). Unresolvable instances are excluded from the array. * @type {[{model: HostSetModel, hostCatalog: HostCatalogModel}]} */ - @computed('host_sets.[]', 'store') + @computed('host_sources.[]', 'store') get hostSets() { - return this.host_sets + return this.host_sources .map(({ host_source_id, host_catalog_id }) => ({ model: this.store.peekRecord('host-set', host_source_id), hostCatalog: this.store.peekRecord('host-catalog', host_catalog_id), diff --git a/addons/api/addon/serializers/target.js b/addons/api/addon/serializers/target.js index a5e434b86..a6ac73f73 100644 --- a/addons/api/addon/serializers/target.js +++ b/addons/api/addon/serializers/target.js @@ -31,7 +31,7 @@ export default class TargetSerializer extends ApplicationSerializer { } /** - * Returns a payload containing only the host_set_ids array using IDs + * Returns a payload containing only the host_source_ids array using IDs * passed into the function (rather than existing host sets on the model). * @param {Snapshot} snapshot * @param {[string]} hostSetIDs @@ -40,7 +40,7 @@ export default class TargetSerializer extends ApplicationSerializer { serializeWithHostSources(snapshot, hostSourceIDs) { return { version: snapshot.attr('version'), - host_set_ids: hostSourceIDs, + host_source_ids: hostSourceIDs, }; } diff --git a/addons/api/mirage/config.js b/addons/api/mirage/config.js index c697bb6c5..a6817e634 100644 --- a/addons/api/mirage/config.js +++ b/addons/api/mirage/config.js @@ -370,7 +370,7 @@ export default function () { // If adding host sets, push them into the array if (method === 'add-host-sources') { updatedAttrs.hostSetIds = target.hostSetIds; - attrs.hostSetIds.forEach((id) => { + attrs.hostSourceIds.forEach((id) => { if (!updatedAttrs.hostSetIds.includes(id)) { updatedAttrs.hostSetIds.push(id); } @@ -380,7 +380,7 @@ export default function () { if (method === 'remove-host-sources') { updatedAttrs.hostSetIds = target.hostSetIds; updatedAttrs.hostSetIds = updatedAttrs.hostSetIds.filter((id) => { - return !attrs.hostSetIds.includes(id); + return !attrs.hostSourceIds.includes(id); }); } // If adding credential libraries, push them into the array diff --git a/addons/api/mirage/serializers/target.js b/addons/api/mirage/serializers/target.js index 1697ab0e2..00249f164 100644 --- a/addons/api/mirage/serializers/target.js +++ b/addons/api/mirage/serializers/target.js @@ -17,7 +17,7 @@ export default ApplicationSerializer.extend({ ); const { hostSets } = this.schema; if (model.hostSetIds?.length) { - json.host_sets = model.hostSetIds.map((host_set_id) => { + json.host_sources = model.hostSetIds.map((host_set_id) => { const hostSet = hostSets.find(host_set_id); const host_catalog_id = hostSet?.hostCatalog?.id; return { id: host_set_id, host_catalog_id }; diff --git a/addons/api/tests/unit/models/target-test.js b/addons/api/tests/unit/models/target-test.js index dc458a879..e182ccf9f 100644 --- a/addons/api/tests/unit/models/target-test.js +++ b/addons/api/tests/unit/models/target-test.js @@ -14,7 +14,7 @@ module('Unit | Model | target', function (hooks) { id: '123abc', type: 'target', attributes: { - host_sets: [ + host_sources: [ { host_source_id: '1', host_catalog_id: '2' }, { host_source_id: '3', host_catalog_id: '2' }, ], @@ -23,9 +23,9 @@ module('Unit | Model | target', function (hooks) { }); const target = store.peekRecord('target', '123abc'); assert.equal( - target.host_sets.length, + target.host_sources.length, 2, - 'Target has two entires in host_sets' + 'Target has two entires in host_sources' ); assert.equal( target.hostSets.length, @@ -46,14 +46,14 @@ module('Unit | Model | target', function (hooks) { attributes: {}, }, }); - // Since `hostSets` is computed on `host_sets`, not the store itself, + // Since `hostSets` is computed on `host_sources`, not the store itself, // it's necessary to do this assignment to kick-off the computed update. // eslint-disable-next-line no-self-assign - target.host_sets = target.host_sets; + target.host_sources = target.host_sources; assert.equal( - target.host_sets.length, + target.host_sources.length, 2, - 'Target has two entires in host_sets' + 'Target has two entires in host_sources' ); assert.equal(target.hostSets.length, 2, 'Target has two resolved hostSets'); assert.notOk( @@ -68,7 +68,7 @@ module('Unit | Model | target', function (hooks) { }, }); // eslint-disable-next-line no-self-assign - target.host_sets = target.host_sets; + target.host_sources = target.host_sources; assert.ok(target.hostSets[0].hostCatalog, 'Host catalog is resolved'); }); @@ -79,7 +79,7 @@ module('Unit | Model | target', function (hooks) { (schema, request) => { const body = JSON.parse(request.requestBody); assert.deepEqual(body, { - host_set_ids: ['123_abc', 'foobar'], + host_source_ids: ['123_abc', 'foobar'], version: 1, }); return { id: '123abc' }; @@ -93,7 +93,7 @@ module('Unit | Model | target', function (hooks) { attributes: { name: 'Target', description: 'Description', - host_sets: [ + host_sources: [ { host_source_id: '1', host_catalog_id: '2' }, { host_source_id: '3', host_catalog_id: '4' }, ], @@ -116,7 +116,7 @@ module('Unit | Model | target', function (hooks) { (schema, request) => { const body = JSON.parse(request.requestBody); assert.deepEqual(body, { - host_set_ids: ['1', '3'], + host_source_ids: ['1', '3'], version: 1, }); return { id: '123abc' }; @@ -130,7 +130,7 @@ module('Unit | Model | target', function (hooks) { attributes: { name: 'Target', description: 'Description', - host_sets: [ + host_sources: [ { host_source_id: '1', host_catalog_id: '2' }, { host_source_id: '3', host_catalog_id: '4' }, ], @@ -153,7 +153,7 @@ module('Unit | Model | target', function (hooks) { (schema, request) => { const body = JSON.parse(request.requestBody); assert.deepEqual(body, { - host_set_ids: ['3'], + host_source_ids: ['3'], version: 1, }); return { id: '123abc' }; @@ -167,7 +167,7 @@ module('Unit | Model | target', function (hooks) { attributes: { name: 'Target', description: 'Description', - host_sets: [ + host_sources: [ { host_source_id: '1', host_catalog_id: '2' }, { host_source_id: '3', host_catalog_id: '4' }, ], diff --git a/addons/api/tests/unit/serializers/application-test.js b/addons/api/tests/unit/serializers/application-test.js index eed4c205a..e1488127f 100644 --- a/addons/api/tests/unit/serializers/application-test.js +++ b/addons/api/tests/unit/serializers/application-test.js @@ -204,7 +204,7 @@ module('Unit | Serializer | application', function (hooks) { authorized_actions: [], name: 'Target 1', scope: { scope_id: 'o_123' }, - host_sets: [], + host_sources: [], application_credential_source_ids: [], }, relationships: {}, diff --git a/addons/api/tests/unit/serializers/target-test.js b/addons/api/tests/unit/serializers/target-test.js index 5254b5ab2..8f9c980c1 100644 --- a/addons/api/tests/unit/serializers/target-test.js +++ b/addons/api/tests/unit/serializers/target-test.js @@ -11,7 +11,7 @@ module('Unit | Serializer | target', function (hooks) { const record = store.createRecord('target', { name: 'User', description: 'Description', - host_sets: [ + host_sources: [ { host_source_id: '1', host_catalog_id: '2' }, { host_source_id: '3', host_catalog_id: '4' }, ], @@ -40,14 +40,14 @@ module('Unit | Serializer | target', function (hooks) { }); }); - test('it serializes only host sets and version when an `adapterOptions.hostSetIDs` array is passed', function (assert) { + test('it serializes only host sources and version when an `adapterOptions.hostSetIDs` array is passed', function (assert) { assert.expect(1); const store = this.owner.lookup('service:store'); const serializer = store.serializerFor('target'); const record = store.createRecord('target', { name: 'User', description: 'Description', - host_sets: [ + host_sources: [ { host_source_id: '1', host_catalog_id: '2' }, { host_source_id: '3', host_catalog_id: '4' }, ], @@ -59,12 +59,12 @@ module('Unit | Serializer | target', function (hooks) { }; const serializedRecord = serializer.serialize(snapshot); assert.deepEqual(serializedRecord, { - host_set_ids: ['4', '5'], + host_source_ids: ['4', '5'], version: 1, }); }); - test('it serializes only credential libraries and version when an `adapterOptions.credentialLibraryIDs` array is passed', function (assert) { + test('it serializes only credential sources and version when an `adapterOptions.credentialLibraryIDs` array is passed', function (assert) { assert.expect(1); const store = this.owner.lookup('service:store'); const serializer = store.serializerFor('target'); @@ -93,7 +93,7 @@ module('Unit | Serializer | target', function (hooks) { const payload = { id: '1', name: 'Target 1', - host_sets: [ + host_sources: [ { host_source_id: '1', host_catalog_id: '2' }, { host_source_id: '3', host_catalog_id: '4' }, ], @@ -112,7 +112,7 @@ module('Unit | Serializer | target', function (hooks) { attributes: { authorized_actions: [], name: 'Target 1', - host_sets: [ + host_sources: [ { host_source_id: '1', host_catalog_id: '2' }, { host_source_id: '3', host_catalog_id: '4' }, ], @@ -123,7 +123,7 @@ module('Unit | Serializer | target', function (hooks) { }); }); - test('it normalizes missing host_sets and credential libraries to empty array', function (assert) { + test('it normalizes missing host_sources and credential libraries to empty array', function (assert) { assert.expect(1); const store = this.owner.lookup('service:store'); const serializer = store.serializerFor('target'); @@ -147,7 +147,7 @@ module('Unit | Serializer | target', function (hooks) { authorized_actions: [], name: 'Target 1', scope: { scope_id: 'o_123' }, - host_sets: [], + host_sources: [], application_credential_source_ids: [], }, relationships: {}, diff --git a/ui/admin/app/components/form/target/add-host-sets/index.js b/ui/admin/app/components/form/target/add-host-sets/index.js index eb0f5e246..edb1cab73 100644 --- a/ui/admin/app/components/form/target/add-host-sets/index.js +++ b/ui/admin/app/components/form/target/add-host-sets/index.js @@ -25,10 +25,10 @@ export default class FormTargetAddHostSetsComponent extends Component { * Host sets not already added to the target. * @type {[HostSetModel]} */ - @computed('args.{hostSets.[],model.host_sets.[]}') + @computed('args.{hostSets.[],model.host_sources.[]}') get filteredHostSets() { // Get IDs for host sets already added to the current target - const alreadyAddedHostSetIDs = this.args.model.host_sets.map( + const alreadyAddedHostSetIDs = this.args.model.host_sources.map( ({ host_source_id }) => host_source_id ); const notAddedHostSets = this.args.hostSets.filter( diff --git a/ui/admin/app/routes/scopes/scope/targets/target/host-sources.js b/ui/admin/app/routes/scopes/scope/targets/target/host-sources.js index 2f0296764..39d1d313a 100644 --- a/ui/admin/app/routes/scopes/scope/targets/target/host-sources.js +++ b/ui/admin/app/routes/scopes/scope/targets/target/host-sources.js @@ -20,8 +20,10 @@ export default class ScopesScopeTargetsTargetHostSourcesRoute extends Route { * @return {Promise{[HostSetModel, HostCatalogModel]}} */ beforeModel() { - const { scopeID, host_sets } = this.modelFor('scopes.scope.targets.target'); - const promises = host_sets.map( + const { scopeID, host_sources } = this.modelFor( + 'scopes.scope.targets.target' + ); + const promises = host_sources.map( ({ host_source_id, host_catalog_id: hostCatalogID }) => hash({ // TODO: multiple host sets may belong to the same catalog, diff --git a/ui/desktop/app/routes/scopes/scope/projects/targets/target/hosts.js b/ui/desktop/app/routes/scopes/scope/projects/targets/target/hosts.js index b155f20c6..435901a2e 100644 --- a/ui/desktop/app/routes/scopes/scope/projects/targets/target/hosts.js +++ b/ui/desktop/app/routes/scopes/scope/projects/targets/target/hosts.js @@ -21,7 +21,7 @@ export default class ScopesScopeProjectsTargetsTargetHostsRoute extends Route { const target = this.modelFor('scopes.scope.projects.targets.target'); // Load all host-sets const hostSets = await all( - target.host_sets.map(({ host_source_id }) => + target.host_sources.map(({ host_source_id }) => this.store.findRecord('host-set', host_source_id) ) );