Add minimum support for static credential stores to admin UI (#1145)

* cred store read ability

* filter out static cred stores and credentials from credential libraries

* chore: 🤖 finish up minimum static cred store support

Co-authored-by: dharini <dharini@hashicorp.com>
This commit is contained in:
Randall Moreyanddharini authored and GitHub committed 2022-06-18 10:56:25 -04:00
1 parent 52904dc639
commit 4ef66fdd29
11 files changed
+50 -22

No files matched your search

@@ -0,0 +1,16 @@
import ModelAbility from './model';
/**
* Provides abilities for credential store.
*/
export default class CredentialStoreAbility extends ModelAbility {
// =permissions
/**
* Only "known" credential store types may be read.
* @type {boolean}
*/
get canRead() {
return !this.model.isStatic && this.hasAuthorizedAction('read');
}
}
@@ -31,4 +31,9 @@ export default class CredentialStoreModel extends GeneratedCredentialStoreModel
* @type {boolean}
*/
@equal('type', 'vault') isVault;
/**
* @type {boolean}
*/
@equal('type', 'static') isStatic;
}
@@ -0,0 +1 @@
export { default } from 'api/abilities/credential-store';
@@ -4,7 +4,7 @@ import { trait } from 'ember-cli-mirage';
import permissions from '../helpers/permissions';
import generateId from '../helpers/id';
const types = ['vault'];
const types = ['vault', 'static'];
export default factory.extend({
authorized_actions: () =>
@@ -318,6 +318,7 @@ credential-store:
delete: Delete Credential Store
types:
vault: Vault
static: Static
form:
address:
label: Address
@@ -60,7 +60,6 @@ export default class OnboardingQuickSetupCreateResourcesRoute extends Route {
try {
await this.createOnboardingResourcesAndRedirect(hostAddress, targetPort);
} catch (e) {
console.log(e);
this.router.replaceWith('scopes.scope', 'global');
throw new Error();
}
@@ -32,9 +32,13 @@ export default class ScopesScopeTargetsTargetAddCredentialSourcesRoute extends R
scope_id,
});
await all(
credentialStores.map(({ id: credential_store_id }) =>
this.store.query('credential-library', { credential_store_id })
)
credentialStores.map(({ id: credential_store_id, isStatic }) => {
//credential libraries don't have a type static so exclude them
if (!isStatic)
return this.store.query('credential-library', {
credential_store_id,
});
})
);
const credentialLibraries = this.store.peekAll('credential-library');
return {
@@ -13,14 +13,17 @@ export default class ScopesScopeTargetsTargetCredentialSourcesRoute extends Rout
* @return {Promise{[CredentialLibraryModel]}}
*/
beforeModel() {
const { application_credential_source_ids: credential_libraries } =
const { application_credential_source_ids: sourceIDFragments } =
this.modelFor('scopes.scope.targets.target');
return all(
credential_libraries.map((credential_library) =>
this.store.findRecord('credential-library', credential_library.value, {
reload: true,
})
)
sourceIDFragments.map(({ value }) => {
const isStoreOrLibrary = !value.includes('cred');
if (isStoreOrLibrary) {
return this.store.findRecord('credential-library', value, {
reload: true,
});
}
})
);
}
+9 -9
View File
@@ -128,15 +128,15 @@
&.loading {
&::after {
animation: gradient 1s linear infinite;
background: repeating-linear-gradient(
to right,
var(--subtle),
var(--subtle),
var(--info),
var(--subtle),
var(--subtle)
);
// animation: gradient 1s linear infinite;
// background: repeating-linear-gradient(
// to right,
// var(--subtle),
// var(--subtle),
// var(--info),
// var(--subtle),
// var(--subtle)
// );
background-position: -100% 0;
background-size: 200% auto;
content: ' ';
@@ -42,7 +42,7 @@
{{#each @model as |credentialStore|}}
<body.row as |row|>
<row.headerCell>
{{#if (can 'read model' credentialStore)}}
{{#if (can 'read credential-store' credentialStore)}}
<LinkTo
@route='scopes.scope.credential-stores.credential-store'
@model={{credentialStore.id}}
@@ -82,7 +82,6 @@ module('Acceptance | credential-libraries | read', function (hooks) {
assert.expect(1);
await visit(urls.unknownCredentialLibrary);
await a11yAudit();
console.debug(find('.rose-message-subtitle'));
assert.ok(find('.rose-message-subtitle').textContent.trim(), 'Error 404');
});
});