chore: 🤖 update host source attribute ames

This commit is contained in:
Randall Morey committed 2021-09-22 19:15:09 -04:00
1 parent 4e3a167ef7
commit 94f6316b4a
10 files changed
+39 -37

No files matched your search

+3 -3
View File
@@ -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),
+2 -2
View File
@@ -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,
};
}
+2 -2
View File
@@ -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
+1 -1
View File
@@ -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 };
+14 -14
View File
@@ -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' },
],
@@ -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: {},
@@ -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: {},
@@ -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(
@@ -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,
@@ -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)
)
);