diff --git a/addons/api/addon/models/target.js b/addons/api/addon/models/target.js
index a00c3b182..d60596465 100644
--- a/addons/api/addon/models/target.js
+++ b/addons/api/addon/models/target.js
@@ -20,6 +20,16 @@ export default class TargetModel extends GeneratedTargetModel {
})
host_sets;
+ /**
+ * Credential library ids are read only and can be
+ * persisted via a dedicated call to `addCredentialLibraries()`.
+ */
+ @fragmentArray('fragment-string', {
+ readOnly: true,
+ emptyArrayIfMissing: true,
+ })
+ application_credential_library_ids;
+
/**
* An array of resolved host set and host catalog instances. Model instances
* must already be loaded into the store (this method will not load unloaded
@@ -36,6 +46,24 @@ export default class TargetModel extends GeneratedTargetModel {
.filter((hostSetRef) => hostSetRef.model !== null);
}
+ /**
+ * An array of resolved credential library instances. Model instances
+ * must already be loaded into the store (this method will not load unloaded
+ * instances). Unresolvable instances are excluded from the array.
+ * @type {[CredentialLibraryModel]}
+ */
+ @computed('application_credential_library_ids.[]', 'store')
+ get credentialLibraries() {
+ return this.application_credential_library_ids
+ .map((credential_library_fragment) =>
+ this.store.peekRecord(
+ 'credential-library',
+ credential_library_fragment.value
+ )
+ )
+ .filter(Boolean);
+ }
+
/**
* Sessions associated with this target (but only already loaded sessions).
* @type {SessionModel[]}
@@ -122,4 +150,66 @@ export default class TargetModel extends GeneratedTargetModel {
removeHostSet(hostSetID, options) {
return this.removeHostSets([hostSetID], options);
}
+
+ /**
+ * Adds credential libraries via the `add-credential-libraries` method.
+ * See serializer and adapter for more information.
+ * @param {[string]} credentialLibraryIDs
+ * @param {object} options
+ * @param {object} options.adapterOptions
+ * @return {Promise}
+ */
+ addCredentialLibraries(
+ credentialLibraryIDs,
+ options = { adapterOptions: {} }
+ ) {
+ const defaultAdapterOptions = {
+ method: 'add-credential-libraries',
+ credentialLibraryIDs,
+ };
+ // There is no "deep merge" in ES.
+ return this.save({
+ ...options,
+ adapterOptions: {
+ ...defaultAdapterOptions,
+ ...options.adapterOptions,
+ },
+ });
+ }
+
+ /**
+ * Delete credential libraries via the `remove-credential-libraries` method.
+ * See serializer and adapter for more information.
+ * @param {[string]} credentialLibraryIDs
+ * @param {object} options
+ * @param {object} options.adapterOptions
+ * @return {Promise}
+ */
+ removeCredentialLibraries(
+ credentialLibraryIDs,
+ options = { adapterOptions: {} }
+ ) {
+ const defaultAdapterOptions = {
+ method: 'remove-credential-libraries',
+ credentialLibraryIDs,
+ };
+ // There is no "deep merge" in ES.
+ return this.save({
+ ...options,
+ adapterOptions: {
+ ...defaultAdapterOptions,
+ ...options.adapterOptions,
+ },
+ });
+ }
+
+ /**
+ * Delete a single credential library set via the `remove-credential-libraries` method.
+ * @param {number} credentialLibraryID
+ * @param {object} options
+ * @return {Promise}
+ */
+ removeCredentialLibrary(credentialLibraryID, options) {
+ return this.removeCredentialLibraries([credentialLibraryID], options);
+ }
}
diff --git a/addons/api/addon/serializers/target.js b/addons/api/addon/serializers/target.js
index 4c6745b89..c287aca46 100644
--- a/addons/api/addon/serializers/target.js
+++ b/addons/api/addon/serializers/target.js
@@ -6,7 +6,11 @@ export default class TargetSerializer extends ApplicationSerializer {
/**
* If `adapterOptions.hostSets` is set to an array of host set models,
* the resulting target serialization should include **only host sets**
- * and the version. Normally, host sets are not serialized.
+ * and the version.
+ * If `adapterOptions.credentialLibraries` is set to an array of
+ * credential library models, the resulting target serialization should
+ * include **only credential libraries** and the version.
+ * Normally, neither host sets or credential libraries are not serialized.
* @override
* @param {Snapshot} snapshot
* @return {object}
@@ -16,6 +20,12 @@ export default class TargetSerializer extends ApplicationSerializer {
const hostSetIDs = snapshot?.adapterOptions?.hostSetIDs;
if (hostSetIDs)
serialized = this.serializeWithHostSets(snapshot, hostSetIDs);
+ const credentialLibraryIDs = snapshot?.adapterOptions?.credentialLibraryIDs;
+ if (credentialLibraryIDs)
+ serialized = this.serializeWithCredentialLibraries(
+ snapshot,
+ credentialLibraryIDs
+ );
return serialized;
}
@@ -32,4 +42,18 @@ export default class TargetSerializer extends ApplicationSerializer {
host_set_ids: hostSetIDs,
};
}
+
+ /**
+ * Returns a payload containing only the credential_library_ids array using IDs
+ * passed into the function (rather than existing credential libraries on the model).
+ * @param {Snapshot} snapshot
+ * @param {[string]} credentialLibraryIDs
+ * @return {object}
+ */
+ serializeWithCredentialLibraries(snapshot, credentialLibraryIDs) {
+ return {
+ version: snapshot.attr('version'),
+ application_credential_library_ids: credentialLibraryIDs,
+ };
+ }
}
diff --git a/addons/api/mirage/config.js b/addons/api/mirage/config.js
index 9a1fccb8e..c1b535a41 100644
--- a/addons/api/mirage/config.js
+++ b/addons/api/mirage/config.js
@@ -366,10 +366,10 @@ export default function () {
const target = targets.find(id);
const updatedAttrs = {
version: attrs.version,
- hostSetIds: target.hostSetIds,
};
// If adding host sets, push them into the array
if (method === 'add-host-sets') {
+ updatedAttrs.hostSetIds = target.hostSetIds;
attrs.hostSetIds.forEach((id) => {
if (!updatedAttrs.hostSetIds.includes(id)) {
updatedAttrs.hostSetIds.push(id);
@@ -378,10 +378,28 @@ export default function () {
}
// If deleting host sets, filter them out of the array
if (method === 'remove-host-sets') {
+ updatedAttrs.hostSetIds = target.hostSetIds;
updatedAttrs.hostSetIds = updatedAttrs.hostSetIds.filter((id) => {
return !attrs.hostSetIds.includes(id);
});
}
+ // If adding credential libraries, push them into the array
+ if (method === 'add-credential-libraries') {
+ updatedAttrs.credentialLibraryIds = target.credentialLibraryIds;
+ attrs.applicationCredentialLibraryIds.forEach((id) => {
+ if (!updatedAttrs.credentialLibraryIds.includes(id)) {
+ updatedAttrs.credentialLibraryIds.push(id);
+ }
+ });
+ }
+ // If deleting credential libraries, filter them out of the array
+ if (method === 'remove-credential-libraries') {
+ updatedAttrs.credentialLibraryIds = target.credentialLibraryIds;
+ updatedAttrs.credentialLibraryIds =
+ updatedAttrs.credentialLibraryIds.filter((id) => {
+ return !attrs.applicationCredentialLibraryIds.includes(id);
+ });
+ }
return target.update(updatedAttrs);
}
);
diff --git a/addons/api/mirage/factories/target.js b/addons/api/mirage/factories/target.js
index dc1c97d00..e40df6abf 100644
--- a/addons/api/mirage/factories/target.js
+++ b/addons/api/mirage/factories/target.js
@@ -7,7 +7,7 @@ const hostSetChance = 0.3;
export default factory.extend({
/**
- * -1 means "unlimited" and we want to generate these on occassion.
+ * -1 means "unlimited" and we want to generate these on occasion.
*/
session_connection_limit: () => random.arrayElement([-1, datatype.number()]),
@@ -25,11 +25,11 @@ export default factory.extend({
},
/**
- * Randomly selects existing host sets to assign to target.
+ * Randomly selects existing host sets and credential libraries to assign to target.
*/
- withRandomHostSets: trait({
+ withAssociations: trait({
afterCreate(target, server) {
- let randomlySelectedHostSets;
+ let randomlySelectedHostSets, randomlySelectedCredentialLibraries;
randomlySelectedHostSets = server.schema.hostSets
// BLERG: fun fact, for no reason at all, the element passed
// into a where function is not a full model instance, as you might
@@ -38,7 +38,17 @@ export default factory.extend({
// the result set of `where` _is a collection of model instances_.
.where((hostSet) => hostSet.scopeId === target.scope.id)
.models.filter(() => randomBoolean(hostSetChance));
- target.update({ hostSets: randomlySelectedHostSets });
+
+ randomlySelectedCredentialLibraries = server.schema.credentialLibraries
+ .where(
+ (credentialLibrary) => credentialLibrary.scopeId === target.scope.id
+ )
+ .models.filter(() => randomBoolean());
+
+ target.update({
+ hostSets: randomlySelectedHostSets,
+ credentialLibraries: randomlySelectedCredentialLibraries,
+ });
},
}),
});
diff --git a/addons/api/mirage/models/target.js b/addons/api/mirage/models/target.js
index 0f03cb6ef..389e255d2 100644
--- a/addons/api/mirage/models/target.js
+++ b/addons/api/mirage/models/target.js
@@ -3,4 +3,5 @@ import { Model, belongsTo, hasMany } from 'ember-cli-mirage';
export default Model.extend({
scope: belongsTo(),
hostSets: hasMany(),
+ credentialLibraries: hasMany(),
});
diff --git a/addons/api/mirage/scenarios/default.js b/addons/api/mirage/scenarios/default.js
index fc5931908..d448a443b 100644
--- a/addons/api/mirage/scenarios/default.js
+++ b/addons/api/mirage/scenarios/default.js
@@ -47,8 +47,8 @@ export default function (server) {
// Other resources
server.schema.scopes.where({ type: 'project' }).models.forEach((scope) => {
server.createList('host-catalog', 2, { scope }, 'withChildren');
- server.createList('target', 2, { scope }, 'withRandomHostSets');
server.createList('session', 4, { scope }, 'withAssociations');
server.createList('credential-store', 3, { scope }, 'withAssociations');
+ server.createList('target', 2, { scope }, 'withAssociations');
});
}
diff --git a/addons/api/mirage/serializers/target.js b/addons/api/mirage/serializers/target.js
index 006388773..b970f4853 100644
--- a/addons/api/mirage/serializers/target.js
+++ b/addons/api/mirage/serializers/target.js
@@ -23,6 +23,9 @@ export default ApplicationSerializer.extend({
return { id: host_set_id, host_catalog_id };
});
}
+ if (model.credentialLibraryIds?.length) {
+ json.application_credential_library_ids = model.credentialLibraryIds;
+ }
return json;
},
});
diff --git a/addons/api/package.json b/addons/api/package.json
index 1bf61697c..2dfeaf358 100644
--- a/addons/api/package.json
+++ b/addons/api/package.json
@@ -59,8 +59,8 @@
"ember-source-channel-url": "^3.0.0",
"ember-template-lint": "^2.15.0",
"ember-try": "^1.4.0",
- "eslint": "^7.17.0",
- "eslint-config-prettier": "^7.1.0",
+ "eslint": "^7.31.0",
+ "eslint-config-prettier": "^8.3.0",
"eslint-plugin-ember": "^10.1.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.3.1",
diff --git a/addons/api/tests/unit/models/target-test.js b/addons/api/tests/unit/models/target-test.js
index 18be834bd..1c6fa2b22 100644
--- a/addons/api/tests/unit/models/target-test.js
+++ b/addons/api/tests/unit/models/target-test.js
@@ -223,4 +223,162 @@ module('Unit | Model | target', function (hooks) {
'Target has two associated sessions loaded in the store'
);
});
+
+ test('it has a `credentialLibraries` array of resolved model instances (if those instances are already in the store)', function (assert) {
+ assert.expect(4);
+ const store = this.owner.lookup('service:store');
+ store.push({
+ data: {
+ id: '123abc',
+ type: 'target',
+ attributes: {
+ application_credential_library_ids: [{ value: '1' }, { value: '2' }],
+ },
+ },
+ });
+ const target = store.peekRecord('target', '123abc');
+ assert.equal(
+ target.application_credential_library_ids.length,
+ 2,
+ 'Target has two entires in application_credential_library_ids'
+ );
+ assert.equal(
+ target.credentialLibraries.length,
+ 0,
+ 'Target has no resolved credentialLibraries because they are not loaded yet'
+ );
+ store.push({
+ data: {
+ id: '1',
+ type: 'credential-library',
+ attributes: {},
+ },
+ });
+ store.push({
+ data: {
+ id: '2',
+ type: 'credential-library',
+ attributes: {},
+ },
+ });
+ // Since `credentialLibraries` is computed on `application_credential_library_ids`,
+ // not the store itself, it's necessary to do this assignment to kick-off the
+ // computed update.
+ /* eslint-disable no-self-assign */
+ target.application_credential_library_ids =
+ target.application_credential_library_ids;
+ /* eslint-enable no-self-assign */
+ assert.equal(
+ target.application_credential_library_ids.length,
+ 2,
+ 'Target has two entires in application_credential_library_ids'
+ );
+ assert.equal(
+ target.credentialLibraries.length,
+ 2,
+ 'Target has two resolved credentialLibraries'
+ );
+ });
+
+ test('it has an `addCredentialLibraries` method that targets a specific POST API endpoint and serialization', async function (assert) {
+ assert.expect(1);
+ this.server.post(
+ '/v1/targets/123abc:add-credential-libraries',
+ (schema, request) => {
+ const body = JSON.parse(request.requestBody);
+ assert.deepEqual(body, {
+ application_credential_library_ids: ['123_abc', 'foobar'],
+ version: 1,
+ });
+ return { id: '123abc' };
+ }
+ );
+ const store = this.owner.lookup('service:store');
+ store.push({
+ data: {
+ id: '123abc',
+ type: 'target',
+ attributes: {
+ name: 'Target',
+ description: 'Description',
+ application_credential_library_ids: [{ value: '1' }, { value: '2' }],
+ version: 1,
+ scope: {
+ scope_id: 'o_1',
+ type: 'scope',
+ },
+ },
+ },
+ });
+ const model = store.peekRecord('target', '123abc');
+ await model.addCredentialLibraries(['123_abc', 'foobar']);
+ });
+
+ test('it has a `removeCredentialLibraries` method that targets a specific POST API endpoint and serialization', async function (assert) {
+ assert.expect(1);
+ this.server.post(
+ '/v1/targets/123abc:remove-credential-libraries',
+ (schema, request) => {
+ const body = JSON.parse(request.requestBody);
+ assert.deepEqual(body, {
+ application_credential_library_ids: ['1', '2'],
+ version: 1,
+ });
+ return { id: '123abc' };
+ }
+ );
+ const store = this.owner.lookup('service:store');
+ store.push({
+ data: {
+ id: '123abc',
+ type: 'target',
+ attributes: {
+ name: 'Target',
+ description: 'Description',
+ application_credential_library_ids: [{ value: '1' }, { value: '2' }],
+ version: 1,
+ scope: {
+ scope_id: 'o_1',
+ type: 'scope',
+ },
+ },
+ },
+ });
+ const model = store.peekRecord('target', '123abc');
+ await model.removeCredentialLibraries(['1', '2']);
+ });
+
+ test('it has a `removeCredentialLibrary` method that deletes a single credential library using `removeCredentialLibraries` method', async function (assert) {
+ assert.expect(1);
+ this.server.post(
+ '/v1/targets/123abc:remove-credential-libraries',
+ (schema, request) => {
+ const body = JSON.parse(request.requestBody);
+ assert.deepEqual(body, {
+ application_credential_library_ids: ['2'],
+ version: 1,
+ });
+ return { id: '123abc' };
+ }
+ );
+ const store = this.owner.lookup('service:store');
+ store.push({
+ data: {
+ id: '123abc',
+ type: 'target',
+ attributes: {
+ name: 'Target',
+ description: 'Description',
+ application_credential_library_ids: [{ value: '1' }, { value: '2' }],
+ version: 1,
+ scope: {
+ scope_id: 'o_1',
+ type: 'scope',
+ },
+ },
+ },
+ });
+ const model = store.peekRecord('target', '123abc');
+ await model.removeCredentialLibrary('2');
+ });
});
diff --git a/addons/api/tests/unit/serializers/application-test.js b/addons/api/tests/unit/serializers/application-test.js
index a7040e876..c2fe164c9 100644
--- a/addons/api/tests/unit/serializers/application-test.js
+++ b/addons/api/tests/unit/serializers/application-test.js
@@ -203,6 +203,7 @@ module('Unit | Serializer | application', function (hooks) {
name: 'Target 1',
scope: { scope_id: 'o_123' },
host_sets: [],
+ application_credential_library_ids: [],
},
relationships: {},
},
diff --git a/addons/api/tests/unit/serializers/target-test.js b/addons/api/tests/unit/serializers/target-test.js
index 255faa9ac..12dcacd4b 100644
--- a/addons/api/tests/unit/serializers/target-test.js
+++ b/addons/api/tests/unit/serializers/target-test.js
@@ -4,7 +4,7 @@ import { setupTest } from 'ember-qunit';
module('Unit | Serializer | target', function (hooks) {
setupTest(hooks);
- test('it serializes targets normally, without host sets', function (assert) {
+ test('it serializes targets normally, without host sets or credential libraries', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('target');
@@ -15,6 +15,7 @@ module('Unit | Serializer | target', function (hooks) {
{ host_set_id: '1', host_catalog_id: '2' },
{ host_set_id: '3', host_catalog_id: '4' },
],
+ application_credential_library_ids: [{ value: '1' }, { value: '2' }],
scope: {
scope_id: 'org_1',
type: 'org',
@@ -63,6 +64,27 @@ module('Unit | Serializer | target', function (hooks) {
});
});
+ test('it serializes only credential libraries 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');
+ const record = store.createRecord('target', {
+ name: 'User',
+ description: 'Description',
+ application_credential_library_ids: [{ value: '1' }, { value: '2' }],
+ version: 1,
+ });
+ const snapshot = record._createSnapshot();
+ snapshot.adapterOptions = {
+ credentialLibraryIDs: ['4', '5'],
+ };
+ const serializedRecord = serializer.serialize(snapshot);
+ assert.deepEqual(serializedRecord, {
+ application_credential_library_ids: ['4', '5'],
+ version: 1,
+ });
+ });
+
test('it normalizes records with array fields', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
@@ -75,6 +97,7 @@ module('Unit | Serializer | target', function (hooks) {
{ host_set_id: '1', host_catalog_id: '2' },
{ host_set_id: '3', host_catalog_id: '4' },
],
+ application_credential_library_ids: ['1'],
};
const normalized = serializer.normalizeSingleResponse(
store,
@@ -92,13 +115,14 @@ module('Unit | Serializer | target', function (hooks) {
{ host_set_id: '1', host_catalog_id: '2' },
{ host_set_id: '3', host_catalog_id: '4' },
],
+ application_credential_library_ids: [{ value: '1' }],
},
relationships: {},
},
});
});
- test('it normalizes missing host_sets to empty array', function (assert) {
+ test('it normalizes missing host_sets and credential libraries to empty array', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('target');
@@ -122,6 +146,7 @@ module('Unit | Serializer | target', function (hooks) {
name: 'Target 1',
scope: { scope_id: 'o_123' },
host_sets: [],
+ application_credential_library_ids: [],
},
relationships: {},
},
diff --git a/addons/auth/package.json b/addons/auth/package.json
index 9d27bee7c..f656717be 100644
--- a/addons/auth/package.json
+++ b/addons/auth/package.json
@@ -53,8 +53,8 @@
"ember-source-channel-url": "^3.0.0",
"ember-template-lint": "^2.15.0",
"ember-try": "^1.4.0",
- "eslint": "^7.17.0",
- "eslint-config-prettier": "^7.1.0",
+ "eslint": "^7.31.0",
+ "eslint-config-prettier": "^8.3.0",
"eslint-plugin-ember": "^10.1.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.3.1",
diff --git a/addons/core/package.json b/addons/core/package.json
index 1e3f3ef9a..4ede3ce38 100644
--- a/addons/core/package.json
+++ b/addons/core/package.json
@@ -68,8 +68,8 @@
"ember-source-channel-url": "^3.0.0",
"ember-template-lint": "^2.15.0",
"ember-try": "^1.4.0",
- "eslint": "^7.17.0",
- "eslint-config-prettier": "^7.1.0",
+ "eslint": "^7.31.0",
+ "eslint-config-prettier": "^8.3.0",
"eslint-plugin-ember": "^10.1.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.3.1",
diff --git a/addons/core/translations/resources/en-us.yaml b/addons/core/translations/resources/en-us.yaml
index 16d2cde4f..727a34a5a 100644
--- a/addons/core/translations/resources/en-us.yaml
+++ b/addons/core/translations/resources/en-us.yaml
@@ -270,7 +270,10 @@ target:
credential-store:
title: Credential Store
title_plural: Credential Stores
- description: A credential stores is a collection of credentials and credential libraries.
+ description: A credential store is a collection of credentials and credential libraries.
+ messages:
+ welcome:
+ title: Welcome to Credential Stores
actions:
delete: Delete Credential Store
credential-library:
diff --git a/addons/rose/package.json b/addons/rose/package.json
index dad7f51cb..dde5784b5 100644
--- a/addons/rose/package.json
+++ b/addons/rose/package.json
@@ -73,8 +73,8 @@
"ember-source-channel-url": "^3.0.0",
"ember-template-lint": "^2.15.0",
"ember-try": "^1.4.0",
- "eslint": "^7.17.0",
- "eslint-config-prettier": "^7.1.0",
+ "eslint": "^7.31.0",
+ "eslint-config-prettier": "^8.3.0",
"eslint-plugin-ember": "^10.1.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.3.1",
diff --git a/ui/admin/app/templates/scopes/scope/credential-stores/index.hbs b/ui/admin/app/templates/scopes/scope/credential-stores/index.hbs
index c8ff3b098..7b6e88c9e 100644
--- a/ui/admin/app/templates/scopes/scope/credential-stores/index.hbs
+++ b/ui/admin/app/templates/scopes/scope/credential-stores/index.hbs
@@ -8,7 +8,9 @@
{{t 'resources.credential-store.title_plural'}}
{{t 'resources.credential-store.description'}}
+ {{#if @model}} +{{t 'resources.credential-store.description'}}
+ {{/if}}