Merge branch 'main' into chore-update-eslint-config-prettier

This commit is contained in:
Carlos Alcaide Corvo authored and GitHub committed 2021-07-23 12:57:57 -07:00
commit 0637d805d3
52 files changed
+911 -32

No files matched your search

@@ -2,6 +2,13 @@ import GeneratedCredentialLibraryModel from '../generated/models/credential-libr
import { attr } from '@ember-data/model';
import { fragment } from 'ember-data-model-fragments/attributes';
/**
* Enum options for credential library.
*/
export const options = {
http_method: ['GET', 'POST'],
};
export default class CredentialLibraryModel extends GeneratedCredentialLibraryModel {
// =error attributes
// These attributes exist solely to capture errors on nested fields.
@@ -1,5 +1,6 @@
import Fragment from 'ember-data-model-fragments/fragment';
import { attr } from '@ember-data/model';
import { options } from './credential-library';
export default class FragmentCredentialLibraryAttributesModel extends Fragment {
//= attributes (vault)
@@ -7,6 +8,7 @@ export default class FragmentCredentialLibraryAttributesModel extends Fragment {
@attr('string', {
description:
'The HTTP method the library uses when requesting credentials from Vault.',
defaultValue: () => options.http_method[0],
})
http_method;
+90
View File
@@ -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);
}
}
+25 -1
View File
@@ -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,
};
}
}
+28 -2
View File
@@ -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);
}
);
@@ -479,7 +497,15 @@ export default function () {
) => credentialLibraries.where({ credentialStoreId })
);
this.get('/credential-libraries/:id');
this.post('/credential-libraries/:id');
this.post(
'/credential-libraries',
function ({ credentialStores, credentialLibraries }) {
const attrs = this.normalizedRequestAttrs();
const credentialStore = credentialStores.find(attrs.credentialStoreId);
attrs.scopeId = credentialStore.scope.id;
return credentialLibraries.create(attrs);
}
);
this.del('/credential-libraries/:id');
this.patch('/credential-libraries/:id');
+15 -5
View File
@@ -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,
});
},
}),
});
+1
View File
@@ -3,4 +3,5 @@ import { Model, belongsTo, hasMany } from 'ember-cli-mirage';
export default Model.extend({
scope: belongsTo(),
hostSets: hasMany(),
credentialLibraries: hasMany(),
});
+1 -1
View File
@@ -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');
});
}
+3
View File
@@ -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;
},
});
+1 -1
View File
@@ -59,7 +59,7 @@
"ember-source-channel-url": "^3.0.0",
"ember-template-lint": "^2.15.0",
"ember-try": "^1.4.0",
"eslint": "^7.17.0",
"eslint": "^7.31.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-ember": "^10.1.1",
"eslint-plugin-node": "^11.1.0",
+158
View File
@@ -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');
});
});
@@ -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: {},
},
@@ -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: {},
},
+1 -1
View File
@@ -53,7 +53,7 @@
"ember-source-channel-url": "^3.0.0",
"ember-template-lint": "^2.15.0",
"ember-try": "^1.4.0",
"eslint": "^7.17.0",
"eslint": "^7.31.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-ember": "^10.1.1",
"eslint-plugin-node": "^11.1.0",
+1 -1
View File
@@ -68,7 +68,7 @@
"ember-source-channel-url": "^3.0.0",
"ember-template-lint": "^2.15.0",
"ember-try": "^1.4.0",
"eslint": "^7.17.0",
"eslint": "^7.31.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-ember": "^10.1.1",
"eslint-plugin-node": "^11.1.0",
+12 -2
View File
@@ -277,9 +277,19 @@ credential-library:
title: Credential Library
title_plural: Credential Libraries
description: A credential library is a resource that provides credentials.
actions:
create: New Credential Library
messages:
none:
title: No Credential Libraries Available
description: No Credential Libraries available in this credential store.
actions:
create: New Credential Library
form:
vault_path:
label: Vault Path
help: The path the library uses when requesting credentials from Vault.
http_method:
label: HTTP Method
help: The HTTP method the library uses when requesting credentials from Vault.
http_request_body:
label: HTTP Method POST Request Body
help: The body of the HTTP request the library sends to Vault when requesting credentials. Only allowed when HTTP method is set to POST.
@@ -20,6 +20,7 @@
input=(component 'rose/form/input' disabled=this.disabled)
select=(component 'rose/form/select' disabled=this.disabled)
textarea=(component 'rose/form/textarea' disabled=this.disabled)
fieldset=(component 'rose/form/fieldset')
actions=(component
(if this.showEditToggleButton
'rose/form/actions/edit-toggle'
+1 -1
View File
@@ -73,7 +73,7 @@
"ember-source-channel-url": "^3.0.0",
"ember-template-lint": "^2.15.0",
"ember-try": "^1.4.0",
"eslint": "^7.17.0",
"eslint": "^7.31.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-ember": "^10.1.1",
"eslint-plugin-node": "^11.1.0",
@@ -0,0 +1,119 @@
<Rose::Form
@onSubmit={{@submit}}
@cancel={{@cancel}}
@disabled={{@model.isSaving}}
@showEditToggle={{if @model.isNew false true}}
as |form|
>
<form.input
@name='name'
@type='name'
@value={{@model.name}}
@label={{t 'form.name.label'}}
@error={{@model.errors.name}}
@helperText={{t 'form.name.help'}}
disabled={{@model.isSaving}}
readonly={{false}}
as |field|
>
{{#if @model.errors.name}}
<field.errors as |errors|>
{{#each @model.errors.name as |error|}}
<errors.message>{{error.message}}</errors.message>
{{/each}}
</field.errors>
{{/if}}
</form.input>
<form.textarea
@name='description'
@type='description'
@value={{@model.description}}
@label={{t 'form.description.label'}}
@error={{@model.errors.description}}
@helperText={{t 'form.description.help'}}
disabled={{@model.isSaving}}
readonly={{false}}
as |field|
>
{{#if @model.errors.description}}
<field.errors as |errors|>
{{#each @model.errors.description as |error|}}
<errors.message>{{error.message}}</errors.message>
{{/each}}
</field.errors>
{{/if}}
</form.textarea>
<form.input
@name='vault_path'
@type='text'
@value={{@model.attributes.path}}
@label={{t 'resources.credential-library.form.vault_path.label'}}
@error={{@model.errors.attributes_path}}
@helperText={{t 'resources.credential-library.form.vault_path.help'}}
disabled={{@model.isSaving}}
readonly={{false}}
as |field|
>
{{#if @model.errors.attributes_path}}
<field.errors as |errors|>
{{#each @model.errors.attributes_path as |error|}}
<errors.message>{{error.message}}</errors.message>
{{/each}}
</field.errors>
{{/if}}
</form.input>
<form.fieldset>
<:title>{{t 'resources.credential-library.form.http_method.label'}}</:title>
<:description>{{t
'resources.credential-library.form.http_method.help'
}}</:description>
<:body>
<form.radioGroup
@name='http_method'
@selectedValue={{@model.attributes.http_method}}
@changed={{fn (mut @model.attributes.http_method)}}
@inline={{true}}
disabled={{@model.isSaving}}
as |radioGroup|
>
{{#each this.httpMethodOptions as |httpMethod|}}
<radioGroup.radio @label={{httpMethod}} @value={{httpMethod}} />
{{/each}}
</form.radioGroup>
</:body>
</form.fieldset>
{{#if this.isHttpRequestBodyAllowed}}
<form.textarea
@name='http_request_body'
@type='text'
@value={{@model.attributes.http_request_body}}
@label={{t 'resources.credential-library.form.http_request_body.label'}}
@error={{@model.errors.attributes_http_request_body}}
@helperText={{t
'resources.credential-library.form.http_request_body.help'
}}
@disabled={{this.cannotSaveHttpRequestBody}}
readonly={{false}}
as |field|
>
{{#if @model.errors.attributes_http_request_body}}
<field.errors as |errors|>
{{#each @model.errors.attributes_http_request_body as |error|}}
<errors.message>{{error.message}}</errors.message>
{{/each}}
</field.errors>
{{/if}}
</form.textarea>
{{/if}}
<form.actions
@disabled={{if @model.cannotSave @model.cannotSave}}
@enableEditText={{t 'actions.edit-form'}}
@submitText={{t 'actions.save'}}
@cancelText={{t 'actions.cancel'}}
/>
</Rose::Form>
@@ -0,0 +1,20 @@
import Component from '@glimmer/component';
import { options } from 'api/models/credential-library';
import { computed } from '@ember/object';
export default class FormCredentialLibraryIndexComponent extends Component {
// =properties
/**
* @type {object}
*/
httpMethodOptions = options.http_method;
/**
* Only allow HTTP request body field if http_method is set to POST.
* @type {boolean}
*/
@computed('args.model.attributes.http_method')
get isHttpRequestBodyAllowed() {
return this.args.model.attributes.http_method?.match(/post/i);
}
}
@@ -0,0 +1,18 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
export default class ScopesScopeCredentialStoresCredentialStoreCredentialLibrariesController extends Controller {
// =services
@service intl;
// =attributes
/**
* Translated credential libraries breadcrumb
* @type {string}
*/
get breadCrumb() {
return this.intl.t('resources.credential-library.title_plural');
}
}
@@ -0,0 +1,18 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
export default class ScopesScopeCredentialStoresCredentialStoreCredentialLibrariesNewController extends Controller {
// =services
@service intl;
// =attributes
/**
* Translated new credential libraries breadcrumb
* @type {string}
*/
get breadCrumb() {
return this.intl.t('titles.new');
}
}
+8 -1
View File
@@ -91,7 +91,14 @@ Router.map(function () {
'credential-store',
{ path: ':credential_store_id' },
function () {
this.route('credential-libraries', function () {});
this.route('credential-libraries', function () {
this.route('new');
this.route(
'credential-library',
{ path: ':credential_library_id' },
function () {}
);
});
}
);
this.route('new');
@@ -1,4 +1,7 @@
import Route from '@ember/routing/route';
import { action } from '@ember/object';
import loading from 'ember-loading/decorator';
import { notifySuccess, notifyError } from 'core/decorators/notify';
export default class ScopesScopeCredentialStoresCredentialStoreCredentialLibrariesRoute extends Route {
// =methods
@@ -13,4 +16,38 @@ export default class ScopesScopeCredentialStoresCredentialStoreCredentialLibrari
);
return this.store.query('credential-library', { credential_store_id });
}
// =actions
/**
* Rollback changes on a credential library.
* @param {CredentialLibraryModel} credentialLibrary
*/
@action
cancel(credentialLibrary) {
const { isNew } = credentialLibrary;
credentialLibrary.rollbackAttributes();
if (isNew)
this.transitionTo(
'scopes.scope.credential-stores.credential-store.credential-libraries'
);
}
/**
* Handle save of a credential library
* @param {CredentialLibraryModel} credentialLibrary
*/
@action
@loading
@notifyError(({ message }) => message)
@notifySuccess(({ isNew }) =>
isNew ? 'notifications.create-success' : 'notifications.save-success'
)
async save(credentialLibrary) {
await credentialLibrary.save();
await this.transitionTo(
'scopes.scope.credential-stores.credential-store.credential-libraries'
);
this.refresh();
}
}
@@ -0,0 +1,49 @@
import Route from '@ember/routing/route';
export default class ScopesScopeCredentialStoresCredentialStoreCredentialLibrariesCredentialLibraryRoute extends Route {
// =methods
/**
* Load a credential-library using current credential store and its parent scope.
* @param {object} params
* @param {string} params.credential_library_id
* @return {CredentialLibraryModel}
*/
async model({ credential_library_id }) {
return this.store.findRecord('credential-library', credential_library_id, {
reload: true,
});
}
/**
* Renders the credential library specific templates for header, navigation, and action page sections.
* @override
*/
renderTemplate() {
super.renderTemplate(...arguments);
this.render(
'scopes/scope/credential-stores/credential-store/credential-libraries/credential-library/-header',
{
into: 'scopes/scope/credential-stores/credential-store',
outlet: 'header',
}
);
this.render(
'scopes/scope/credential-stores/credential-store/credential-libraries/credential-library/-navigation',
{
into: 'scopes/scope/credential-stores/credential-store',
outlet: 'navigation',
}
);
this.render(
'scopes/scope/credential-stores/credential-store/credential-libraries/credential-library/-actions',
{
into: 'scopes/scope/credential-stores/credential-store',
outlet: 'actions',
}
);
}
}
@@ -0,0 +1,3 @@
import Route from '@ember/routing/route';
export default class ScopesScopeCredentialStoresCredentialStoreCredentialLibrariesCredentialLibraryIndexRoute extends Route {}
@@ -0,0 +1,45 @@
import Route from '@ember/routing/route';
export default class ScopesScopeCredentialStoresCredentialStoreCredentialLibrariesNewRoute extends Route {
// =methods
/**
* Creates a new unsaved credential library in current credential store.
* @return {CredentialLibraryModel}
*/
model() {
const { id: credential_store_id } = this.modelFor(
'scopes.scope.credential-stores.credential-store'
);
return this.store.createRecord('credential-library', {
credential_store_id,
});
}
/**
* Renders new credential library specific templates for header, navigation,
* and action page sections.
* @override
*/
renderTemplate() {
super.renderTemplate(...arguments);
this.render(
'scopes/scope/credential-stores/credential-store/credential-libraries/new/-header',
{
into: 'scopes/scope/credential-stores/credential-store',
outlet: 'header',
}
);
this.render('_empty', {
into: 'scopes/scope/credential-stores/credential-store',
outlet: 'navigation',
});
this.render('_empty', {
into: 'scopes/scope/credential-stores/credential-store',
outlet: 'actions',
});
}
}
@@ -3,10 +3,13 @@
@dropdownRight={{true}}
as |dropdown|
>
{{!-- <dropdown.link @route='scopes.scope.credential-stores.new' @model={{@model}}>
<dropdown.link
@route='scopes.scope.credential-stores.credential-store.credential-libraries.new'
@model={{@model}}
>
{{t 'resources.credential-library.actions.create'}}
</dropdown.link>
<dropdown.separator /> --}}
<dropdown.separator />
<dropdown.button
@style='danger'
@disabled={{@model.canSave}}
@@ -0,0 +1,3 @@
{{page-title @model.displayName}}
{{outlet}}
@@ -0,0 +1,9 @@
<h2>{{t 'resources.credential-library.title'}}</h2>
<p>{{t 'resources.credential-library.description'}}</p>
<Copyable
@text={{@model.id}}
@buttonText={{t 'actions.copy-to-clipboard'}}
@acknowledgeText={{t 'states.copied'}}
>
<code>{{@model.id}}</code>
</Copyable>
@@ -0,0 +1,7 @@
<Rose::Nav::Tabs as |nav|>
<nav.link
@route='scopes.scope.credential-stores.credential-store.credential-libraries.credential-library.index'
>
{{t 'titles.details'}}
</nav.link>
</Rose::Nav::Tabs>
@@ -0,0 +1,5 @@
<Form::CredentialLibrary
@model={{@model}}
@submit={{route-action 'save' @model}}
@cancel={{route-action 'cancel' @model}}
/>
@@ -11,7 +11,12 @@
{{#each @model as |credentialLibrary|}}
<body.row as |row|>
<row.headerCell>
{{credentialLibrary.displayName}}
<LinkTo
@route='scopes.scope.credential-stores.credential-store.credential-libraries.credential-library'
@model={{credentialLibrary.id}}
>
{{credentialLibrary.displayName}}
</LinkTo>
<p>{{credentialLibrary.description}}</p>
</row.headerCell>
<row.cell>
@@ -38,6 +43,12 @@
<message.description>
{{t 'resources.credential-library.messages.none.description'}}
</message.description>
<message.link
@route='scopes.scope.credential-stores.credential-store.credential-libraries.new'
>
<Rose::Icon @name='plus-circle-outline' />
{{t 'titles.new'}}
</message.link>
</Rose::Message>
</Rose::Layout::Centered>
@@ -0,0 +1,7 @@
{{page-title (t 'titles.new')}}
<Form::CredentialLibrary
@model={{@model}}
@submit={{route-action 'save' @model}}
@cancel={{route-action 'cancel' @model}}
/>
@@ -0,0 +1,3 @@
<h2>
{{t 'titles.new'}}
</h2>
+1 -1
View File
@@ -77,7 +77,7 @@
"ember-source": "~3.24.0",
"ember-template-lint": "^2.15.0",
"ember-template-lint-plugin-prettier": "^2.0.0",
"eslint": "^7.17.0",
"eslint": "^7.31.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-ember": "^10.1.1",
"eslint-plugin-node": "^11.1.0",
+1 -1
View File
@@ -55,7 +55,7 @@ module('Acceptance | sessions', function (hooks) {
'target',
1,
{ scope: instances.scopes.project },
'withRandomHostSets'
'withAssociations'
);
instances.sessions = this.server.createList(
'session',
@@ -0,0 +1,17 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module(
'Unit | Controller | scopes/scope/credential-stores/credential-store/credential-libraries',
function (hooks) {
setupTest(hooks);
// TODO: Replace this with your real tests.
test('it exists', function (assert) {
let controller = this.owner.lookup(
'controller:scopes/scope/credential-stores/credential-store/credential-libraries'
);
assert.ok(controller);
});
}
);
@@ -0,0 +1,17 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module(
'Unit | Controller | scopes/scope/credential-stores/credential-store/credential-libraries/new',
function (hooks) {
setupTest(hooks);
// TODO: Replace this with your real tests.
test('it exists', function (assert) {
let controller = this.owner.lookup(
'controller:scopes/scope/credential-stores/credential-store/credential-libraries/new'
);
assert.ok(controller);
});
}
);
@@ -0,0 +1,16 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module(
'Unit | Route | scopes/scope/credential-stores/credential-store/credential-libraries/credential-library',
function (hooks) {
setupTest(hooks);
test('it exists', function (assert) {
let route = this.owner.lookup(
'route:scopes/scope/credential-stores/credential-store/credential-libraries/credential-library'
);
assert.ok(route);
});
}
);
@@ -0,0 +1,16 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module(
'Unit | Route | scopes/scope/credential-stores/credential-store/credential-libraries/credential-library/index',
function (hooks) {
setupTest(hooks);
test('it exists', function (assert) {
let route = this.owner.lookup(
'route:scopes/scope/credential-stores/credential-store/credential-libraries/credential-library/index'
);
assert.ok(route);
});
}
);
@@ -0,0 +1,16 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module(
'Unit | Route | scopes/scope/credential-stores/credential-store/credential-libraries/new',
function (hooks) {
setupTest(hooks);
test('it exists', function (assert) {
let route = this.owner.lookup(
'route:scopes/scope/credential-stores/credential-store/credential-libraries/new'
);
assert.ok(route);
});
}
);
+1 -1
View File
@@ -92,7 +92,7 @@
"ember-source": "~3.24.0",
"ember-template-lint": "^2.15.0",
"ember-template-lint-plugin-prettier": "^2.0.0",
"eslint": "^7.17.0",
"eslint": "^7.31.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-ember": "^10.1.1",
"eslint-plugin-node": "^11.1.0",
+1 -1
View File
@@ -97,7 +97,7 @@ module('Acceptance | origin', function (hooks) {
instances.target = this.server.create(
'target',
{ scope: instances.scopes.project },
'withRandomHostSets'
'withAssociations'
);
urls.scopes.global = `/scopes/${instances.scopes.global.id}`;
+1 -1
View File
@@ -92,7 +92,7 @@ module('Acceptance | projects', function (hooks) {
instances.target = this.server.create(
'target',
{ scope: instances.scopes.project },
'withRandomHostSets'
'withAssociations'
);
urls.scopes.global = `/scopes/${instances.scopes.global.id}`;
@@ -97,7 +97,7 @@ module('Acceptance | projects | sessions', function (hooks) {
instances.target = this.server.create(
'target',
{ scope: instances.scopes.project },
'withRandomHostSets'
'withAssociations'
);
instances.session = this.server.create(
'session',
@@ -101,7 +101,7 @@ module('Acceptance | projects | targets', function (hooks) {
instances.target = this.server.create(
'target',
{ scope: instances.scopes.project },
'withRandomHostSets'
'withAssociations'
);
instances.session = this.server.create(
@@ -106,7 +106,7 @@ module('Acceptance | projects | targets | sessions', function (hooks) {
instances.target = this.server.create(
'target',
{ scope: instances.scopes.project },
'withRandomHostSets'
'withAssociations'
);
instances.session = this.server.create(
+1 -1
View File
@@ -110,7 +110,7 @@ module('Acceptance | scopes', function (hooks) {
instances.target = this.server.create(
'target',
{ scope: instances.scopes.project },
'withRandomHostSets'
'withAssociations'
);
instances.session = this.server.create(
+1 -1
View File
@@ -94,7 +94,7 @@ module('Acceptance | targets', function (hooks) {
instances.target = this.server.create(
'target',
{ scope: instances.scopes.project },
'withRandomHostSets'
'withAssociations'
);
urls.scopes.global = `/scopes/${instances.scopes.global.id}`;
+76 -1
View File
@@ -2060,6 +2060,21 @@
minimatch "^3.0.4"
strip-json-comments "^3.1.1"
"@eslint/eslintrc@^0.4.3":
version "0.4.3"
resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-0.4.3.tgz#9e42981ef035beb3dd49add17acb96e8ff6f394c"
integrity sha512-J6KFFz5QCYUJq3pf0mjEcCJVERbzv71PUIDczuh9JkwGEzced6CO5ADLHB1rbf/+oPBtoPfMYNOpGDzCANlbXw==
dependencies:
ajv "^6.12.4"
debug "^4.1.1"
espree "^7.3.0"
globals "^13.9.0"
ignore "^4.0.6"
import-fresh "^3.2.1"
js-yaml "^3.13.1"
minimatch "^3.0.4"
strip-json-comments "^3.1.1"
"@formatjs/ecma402-abstract@1.6.4":
version "1.6.4"
resolved "https://registry.yarnpkg.com/@formatjs/ecma402-abstract/-/ecma402-abstract-1.6.4.tgz#cff5ef03837fb6bae70b16d04940213c17e87884"
@@ -2284,6 +2299,20 @@
resolved "https://registry.yarnpkg.com/@hashicorp/structure-icons/-/structure-icons-1.9.1.tgz#eb294ef28e8192062f6c7c08459382ba31a8b4af"
integrity sha512-uuncAHmehXk/WeNzE3NqS8z0YX/AU3Go8rDEUK2rNFdp1c0T1HiHO6RaBW5byB8KEBAPRdSsFSNqB4RaETarNA==
"@humanwhocodes/config-array@^0.5.0":
version "0.5.0"
resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.5.0.tgz#1407967d4c6eecd7388f83acf1eaf4d0c6e58ef9"
integrity sha512-FagtKFz74XrTl7y6HCzQpwDfXP0yhxe9lHLD1UZxjvZIcbyRz8zTFF/yYNfSfzU414eDwZ1SrO0Qvtyf+wFMQg==
dependencies:
"@humanwhocodes/object-schema" "^1.2.0"
debug "^4.1.1"
minimatch "^3.0.4"
"@humanwhocodes/object-schema@^1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-1.2.0.tgz#87de7af9c231826fdd68ac7258f77c429e0e5fcf"
integrity sha512-wdppn25U8z/2yiaT6YGquE6X8sSv7hNMWSXYSSU1jGv/yd6XqjXgTDJ8KP4NgjTXfJ3GbRjeeb8RTV7a/VpM+w==
"@iarna/cli@^1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@iarna/cli/-/cli-1.2.0.tgz#0f7af5e851afe895104583c4ca07377a8094d641"
@@ -10099,7 +10128,7 @@ eslint@^2.7.0:
text-table "~0.2.0"
user-home "^2.0.0"
eslint@^7.17.0, eslint@^7.27.0:
eslint@^7.27.0:
version "7.28.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.28.0.tgz#435aa17a0b82c13bb2be9d51408b617e49c1e820"
integrity sha512-UMfH0VSjP0G4p3EWirscJEQ/cHqnT/iuH6oNZOB94nBjWbMnhGEPxsZm1eyIW0C/9jLI0Fow4W5DXLjEI7mn1g==
@@ -10144,6 +10173,52 @@ eslint@^7.17.0, eslint@^7.27.0:
text-table "^0.2.0"
v8-compile-cache "^2.0.3"
eslint@^7.31.0:
version "7.31.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.31.0.tgz#f972b539424bf2604907a970860732c5d99d3aca"
integrity sha512-vafgJpSh2ia8tnTkNUkwxGmnumgckLh5aAbLa1xRmIn9+owi8qBNGKL+B881kNKNTy7FFqTEkpNkUvmw0n6PkA==
dependencies:
"@babel/code-frame" "7.12.11"
"@eslint/eslintrc" "^0.4.3"
"@humanwhocodes/config-array" "^0.5.0"
ajv "^6.10.0"
chalk "^4.0.0"
cross-spawn "^7.0.2"
debug "^4.0.1"
doctrine "^3.0.0"
enquirer "^2.3.5"
escape-string-regexp "^4.0.0"
eslint-scope "^5.1.1"
eslint-utils "^2.1.0"
eslint-visitor-keys "^2.0.0"
espree "^7.3.1"
esquery "^1.4.0"
esutils "^2.0.2"
fast-deep-equal "^3.1.3"
file-entry-cache "^6.0.1"
functional-red-black-tree "^1.0.1"
glob-parent "^5.1.2"
globals "^13.6.0"
ignore "^4.0.6"
import-fresh "^3.0.0"
imurmurhash "^0.1.4"
is-glob "^4.0.0"
js-yaml "^3.13.1"
json-stable-stringify-without-jsonify "^1.0.1"
levn "^0.4.1"
lodash.merge "^4.6.2"
minimatch "^3.0.4"
natural-compare "^1.4.0"
optionator "^0.9.1"
progress "^2.0.0"
regexpp "^3.1.0"
semver "^7.2.1"
strip-ansi "^6.0.0"
strip-json-comments "^3.1.0"
table "^6.0.9"
text-table "^0.2.0"
v8-compile-cache "^2.0.3"
esm@^3.2.25, esm@^3.2.4:
version "3.2.25"
resolved "https://registry.yarnpkg.com/esm/-/esm-3.2.25.tgz#342c18c29d56157688ba5ce31f8431fbb795cc10"