Refactor credential sources to brokered credential sources (#1264)

* chore: 🤖 refactor credential sources to brokered credential source
This commit is contained in:
Dharini Jeeva authored and GitHub committed 2022-08-18 09:11:38 -07:00
1 parent f4f7c0e343
commit 9a8665a314
21 files changed
+136 -110

No files matched your search

+2 -2
View File
@@ -30,14 +30,14 @@ export default class TargetAbility extends ModelAbility {
/**
* @type {boolean}
*/
get canAddCredentialSources() {
get canAddBrokeredCredentialSources() {
return this.hasAuthorizedAction('add-credential-sources');
}
/**
* @type {boolean}
*/
get canRemoveCredentialSources() {
get canRemoveBrokeredCredentialSources() {
return this.hasAuthorizedAction('remove-credential-sources');
}
}
+9 -6
View File
@@ -23,7 +23,7 @@ export default class TargetModel extends GeneratedTargetModel {
/**
* Credential source ids are read only and can be
* persisted via a dedicated call to `addCredentialSources()`.
* persisted via a dedicated call to `addBrokeredCredentialSources()`.
*/
@fragmentArray('fragment-string', {
readOnly: true,
@@ -54,7 +54,7 @@ export default class TargetModel extends GeneratedTargetModel {
* @type {[CredentialLibraryModel, CredentialModel]}
*/
@computed('brokered_credential_source_ids.[]', 'store')
get credentialSources() {
get brokeredCredentialSources() {
return this.brokered_credential_source_ids
.map((source) => {
if (source.value.startsWith('cred')) {
@@ -161,7 +161,10 @@ export default class TargetModel extends GeneratedTargetModel {
* @param {object} options.adapterOptions
* @return {Promise}
*/
addCredentialSources(credentialSourceIDs, options = { adapterOptions: {} }) {
addBrokeredCredentialSources(
credentialSourceIDs,
options = { adapterOptions: {} }
) {
const defaultAdapterOptions = {
method: 'add-credential-sources',
credentialSourceIDs,
@@ -184,7 +187,7 @@ export default class TargetModel extends GeneratedTargetModel {
* @param {object} options.adapterOptions
* @return {Promise}
*/
removeCredentialSources(
removeBrokeredCredentialSources(
credentialSourceIDs,
options = { adapterOptions: {} }
) {
@@ -208,8 +211,8 @@ export default class TargetModel extends GeneratedTargetModel {
* @param {object} options
* @return {Promise}
*/
removeCredentialSource(credentialSourceID, options) {
return this.removeCredentialSources([credentialSourceID], options);
removeBrokeredCredentialSource(credentialSourceID, options) {
return this.removeBrokeredCredentialSources([credentialSourceID], options);
}
/**
+2 -2
View File
@@ -461,7 +461,7 @@ export default function () {
return !attrs.hostSourceIds.includes(id);
});
}
// If adding credential sources, push them into the array
// If adding brokered credential sources, push them into the array
if (method === 'add-credential-sources') {
updatedAttrs.credentialLibraryIds = target.credentialLibraryIds;
updatedAttrs.credentialIds = target.credentialIds;
@@ -478,7 +478,7 @@ export default function () {
}
});
}
// If deleting credential sources, filter them out of the array
// If deleting brokered credential sources, filter them out of the array
if (method === 'remove-credential-sources') {
updatedAttrs.credentialLibraryIds = target.credentialLibraryIds;
updatedAttrs.credentialIds = target.credentialIds;
@@ -43,9 +43,9 @@ module('Unit | Abilities | Target', function (hooks) {
const model = {
authorized_actions: ['add-credential-sources'],
};
assert.ok(service.can('addCredentialSources target', model));
assert.ok(service.can('addBrokeredCredentialSources target', model));
model.authorized_actions = [];
assert.notOk(service.can('addCredentialSources target', model));
assert.notOk(service.can('addBrokeredCredentialSources target', model));
});
test('it reflects when a given target may remove crednetial sources', function (assert) {
@@ -54,8 +54,8 @@ module('Unit | Abilities | Target', function (hooks) {
const model = {
authorized_actions: ['remove-credential-sources'],
};
assert.ok(service.can('removeCredentialSources target', model));
assert.ok(service.can('removeBrokeredCredentialSources target', model));
model.authorized_actions = [];
assert.notOk(service.can('removeCredentialSources target', model));
assert.notOk(service.can('removeBrokeredCredentialSources target', model));
});
});
+9 -9
View File
@@ -231,7 +231,7 @@ module('Unit | Model | target', function (hooks) {
);
});
test('it has a `credentialSources` array of resolved model instances (if those instances are already in the store)', function (assert) {
test('it has a `brokeredCredentialSources` 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({
@@ -250,7 +250,7 @@ module('Unit | Model | target', function (hooks) {
'Target has two entires in brokered_credential_source_ids'
);
assert.strictEqual(
target.credentialSources.length,
target.brokeredCredentialSources.length,
0,
'Target has no resolved credentialSources because they are not loaded yet'
);
@@ -281,13 +281,13 @@ module('Unit | Model | target', function (hooks) {
'Target has two entires in brokered_credential_source_ids'
);
assert.strictEqual(
target.credentialSources.length,
target.brokeredCredentialSources.length,
2,
'Target has two resolved credentialSources'
);
});
test('it has an `addCredentialSources` method that targets a specific POST API endpoint and serialization', async function (assert) {
test('it has an `addBrokeredCredentialSources` method that targets a specific POST API endpoint and serialization', async function (assert) {
assert.expect(1);
this.server.post(
'/v1/targets/123abc:add-credential-sources',
@@ -318,10 +318,10 @@ module('Unit | Model | target', function (hooks) {
},
});
const model = store.peekRecord('target', '123abc');
await model.addCredentialSources(['123_abc', 'foobar']);
await model.addBrokeredCredentialSources(['123_abc', 'foobar']);
});
test('it has a `removeCredentialSources` method that targets a specific POST API endpoint and serialization', async function (assert) {
test('it has a `removeBrokeredCredentialSources` method that targets a specific POST API endpoint and serialization', async function (assert) {
assert.expect(1);
this.server.post(
'/v1/targets/123abc:remove-credential-sources',
@@ -352,10 +352,10 @@ module('Unit | Model | target', function (hooks) {
},
});
const model = store.peekRecord('target', '123abc');
await model.removeCredentialSources(['1', '2']);
await model.removeBrokeredCredentialSources(['1', '2']);
});
test('it has a `removeCredentialSource` method that deletes a single credential library using `removeCredentialSources` method', async function (assert) {
test('it has a `removeBrokeredCredentialSource` method that deletes a single credential library using `removeBrokeredCredentialSources` method', async function (assert) {
assert.expect(1);
this.server.post(
'/v1/targets/123abc:remove-credential-sources',
@@ -386,7 +386,7 @@ module('Unit | Model | target', function (hooks) {
},
});
const model = store.peekRecord('target', '123abc');
await model.removeCredentialSource('2');
await model.removeBrokeredCredentialSource('2');
});
test('it has isSSH property and returns the expected values', function (assert) {