-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UI: Pki key read view #18087
UI: Pki key read view #18087
Conversation
hellobontempo
commented
Nov 22, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Semgrep Scanner found more than 10 potential problems in the proposed changes. Check the Files changed tab for more details.
|
||
export default class PkiKeyModel extends Model { | ||
@attr('string', { readOnly: true }) backend; | ||
@attr('boolean') isDefault; | ||
@attr('string') keyRef; // reference to an existing key: either, vault generate identifier, literal string 'default', or the name assigned to the key. Part of the request URL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the docs refer to key_ref
but this is either the key_name
(which is optional) or the key_id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! I left a few suggestions.
ui/app/adapters/pki/key.js
Outdated
|
||
urlForQuery(backend, id) { | ||
let url = `${this.buildURL()}/${encodePath(backend)}/keys`; | ||
_urlForQuery(backend, id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if changing the name to something like getURL
would be more succinct since you are bypassing the urlForQuery
and urlForQueryRecord
hooks? It seems like this method could handle constructing the url for other methods like createRecord
as well if need be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah! I can do that. I struggled with method naming in this adapter, and wasn't sure if combining the methods into one was okay in the first place
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is. I might have done it slightly different. All you are doing in the queryRecord
override is calling that custom url method. You could instead override urlForQueryRecord
and return the url you need and then not have to override queryRecord
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the adapter instead would just be these three methods?
urlForQuery(backend) {
return `${this.buildURL()}/${encodePath(backend)}/key`;
}
urlForQueryRecord(query) {
const { backend, id } = query;
return `${this.buildURL()}/${encodePath(backend)}/key/${encodePath(id)}`;
}
query(store, type, query) {
const { backend } = query;
return this.ajax(this.urlForQuery(backend), 'GET', { data: { list: true } });
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep that looks good! The way you approached it works too but I personally like to work with the provided hooks when possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I haven't worked much with adapters and couldn't discern a clear pattern that we use. I also didn't realize urlForQueryRecord
was a built in hook!
ui/app/models/pki/key.js
Outdated
_attributeMeta = null; // cache initial result of expandAttributeMeta in getter and return | ||
get formFields() { | ||
if (!this._attributeMeta) { | ||
this._attributeMeta = expandAttributeMeta(this, ['keyId', 'keyName', 'keyType', 'keyBits']); | ||
} | ||
return this._attributeMeta; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the mean time you could move this to the constructor instead which is how formFields
is populated when the decorator is applied.
_attributeMeta = null; // cache initial result of expandAttributeMeta in getter and return | |
get formFields() { | |
if (!this._attributeMeta) { | |
this._attributeMeta = expandAttributeMeta(this, ['keyId', 'keyName', 'keyType', 'keyBits']); | |
} | |
return this._attributeMeta; | |
} | |
constructor() { | |
super(...arguments); | |
this.formFields = expandAttributeMeta(this, ['keyId', 'keyName', 'keyType', 'keyBits']); | |
} |
<nav class="breadcrumb" aria-label="breadcrumbs" data-test-breadcrumbs="key-details"> | ||
<ul> | ||
<li> | ||
<span class="sep">/</span> | ||
<LinkToExternal @route="secrets">secrets</LinkToExternal> | ||
</li> | ||
{{#each this.breadcrumbs as |breadcrumb|}} | ||
<li> | ||
<span class="sep">/</span> | ||
{{#if breadcrumb.path}} | ||
<LinkTo @route={{breadcrumb.path}}> | ||
{{breadcrumb.label}} | ||
</LinkTo> | ||
{{else}} | ||
{{breadcrumb.label}} | ||
{{/if}} | ||
</li> | ||
{{/each}} | ||
</ul> | ||
</nav> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might not be worth it if this exists in HDS but if not could we turn this into a component? This pattern appears to be copied in a lot of places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied this from Chelsea's PR along with her "TODO" - I can ask what her thoughts are
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reminds me that I also wanted to consult @hashishaw about which also includes breadcrumbs and is used elsewhere in the PKI engine. I think some general cleanup could happen with all of these headers and would be a good follow-on ticket to tackle all of the views in one PR
|
||
<div class="box is-fullwidth is-sideless is-paddingless is-marginless"> | ||
{{#each @key.formFields as |attr|}} | ||
{{#let (get @key attr.name) as |value|}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think since value
is only used once you could remove the let
block and use the get helper directly on @value
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you - good catch! I forgot to fix this when I added formFields
to the model!
interface Args { | ||
key: { | ||
backend: string; | ||
keyName: string; | ||
keyId: string; | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
<InfoTableRow | ||
@label={{capitalize (or attr.options.detailsLabel attr.options.label (humanize (dasherize attr.name)))}} | ||
@value={{get @key attr.name}} | ||
/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was the alwaysRender
arg not needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keyBits
is an attribute available when generating a key, but is not currently included in the GET
response for a key. (There's discussion to add it, but it's not looking likely) Since it will always be empty, I opted to remove alwaysRender=true
so it can still appear in the create form, but won't render the row in the details page
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!