fix: Add error handling to credential-library creation form
This commit is contained in:
7 files changed
+67
-50
No files matched your search
@@ -6,7 +6,7 @@ import { fragment } from 'ember-data-model-fragments/attributes';
|
||||
* Enum options for credential library.
|
||||
*/
|
||||
export const options = {
|
||||
http_methods: ['GET', 'POST'],
|
||||
http_method: ['GET', 'POST'],
|
||||
};
|
||||
|
||||
export default class CredentialLibraryModel extends GeneratedCredentialLibraryModel {
|
||||
@@ -15,11 +15,7 @@ export default class CredentialLibraryModel extends GeneratedCredentialLibraryMo
|
||||
// See the application adapter's error normalization method for
|
||||
// more information.
|
||||
|
||||
@attr('string', {
|
||||
readOnly: true,
|
||||
defaultValue: options.http_methods[0],
|
||||
})
|
||||
attributes_http_method;
|
||||
@attr('string', { readOnly: true }) attributes_http_method;
|
||||
@attr('string', { readOnly: true }) attributes_http_request_body;
|
||||
@attr('string', { readOnly: true }) attributes_path;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -484,7 +484,6 @@ export default function () {
|
||||
const attrs = this.normalizedRequestAttrs();
|
||||
const credentialStore = credentialStores.find(attrs.credentialStoreId);
|
||||
attrs.scopeId = credentialStore.scope.id;
|
||||
console.log(attrs);
|
||||
return credentialLibraries.create(attrs);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -115,12 +115,3 @@ value:
|
||||
callback_url:
|
||||
label: Callback URL
|
||||
help: The URL to which the third-party provider sends the authentication response. Paste this into the provider configuration.
|
||||
vault_path:
|
||||
label: Vault Path
|
||||
help: The path in Vault to request credentials from.
|
||||
http_method:
|
||||
label: HTTP Method
|
||||
help: The HTTP method the library uses when requesting credentials from Vault.
|
||||
http_request_body:
|
||||
label: HTTP 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.
|
||||
@@ -280,4 +280,17 @@ credential-library:
|
||||
messages:
|
||||
none:
|
||||
title: No Credential Libraries Available
|
||||
description: No Credential Libraries available in this credential store.
|
||||
description: No Credential Libraries available in this credential store.
|
||||
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 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.
|
||||
http_post_method_options:
|
||||
label: HTTP Method POST Options
|
||||
help: The options available for when HTTP method is set to POST.
|
||||
@@ -48,15 +48,15 @@
|
||||
@name='vault_path'
|
||||
@type='text'
|
||||
@value={{@model.attributes.path}}
|
||||
@label={{t 'form.vault_path.label'}}
|
||||
@error={{@model.errors.name}}
|
||||
@helperText={{t 'form.vault_path.help'}}
|
||||
@label={{t 'resources.credential-library.form.vault_path.label'}}
|
||||
@error={{@model.errors.attributes_path}}
|
||||
@helperText={{t 'resources.credential-library.form.vault_path.help'}}
|
||||
readonly={{false}}
|
||||
as |field|
|
||||
>
|
||||
{{#if @model.errors.name}}
|
||||
{{#if @model.errors.attributes_path}}
|
||||
<field.errors as |errors|>
|
||||
{{#each @model.errors.name as |error|}}
|
||||
{{#each @model.errors.attributes_path as |error|}}
|
||||
<errors.message>{{error.message}}</errors.message>
|
||||
{{/each}}
|
||||
</field.errors>
|
||||
@@ -64,8 +64,10 @@
|
||||
</form.input>
|
||||
|
||||
<form.fieldset>
|
||||
<:title>{{t 'form.http_method.label'}}</:title>
|
||||
<:description>{{t 'form.http_method.help'}}</:description>
|
||||
<: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'
|
||||
@@ -74,32 +76,48 @@
|
||||
@inline={{true}}
|
||||
as |radioGroup|
|
||||
>
|
||||
{{#each this.httpMethods as |httpMethod|}}
|
||||
{{#each this.httpMethodOptions as |httpMethod|}}
|
||||
<radioGroup.radio @label={{httpMethod}} @value={{httpMethod}} />
|
||||
{{/each}}
|
||||
</form.radioGroup>
|
||||
</:body>
|
||||
</form.fieldset>
|
||||
|
||||
<form.textarea
|
||||
@name='http_request_body'
|
||||
@type='text'
|
||||
@value={{@model.attributes.http_request_body}}
|
||||
@label={{t 'form.http_request_body.label'}}
|
||||
@error={{@model.errors.description}}
|
||||
@helperText={{t 'form.http_request_body.help'}}
|
||||
@disabled={{this.cannotSaveHttpRequestBody}}
|
||||
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>
|
||||
{{#if this.isHttpRequestBodyAllowed}}
|
||||
<form.fieldset>
|
||||
<:title>{{t
|
||||
'resources.credential-library.form.http_post_method_options.label'
|
||||
}}</:title>
|
||||
<:description>{{t
|
||||
'resources.credential-library.form.http_post_method_options.help'
|
||||
}}</:description>
|
||||
<:body>
|
||||
<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>
|
||||
</:body>
|
||||
</form.fieldset>
|
||||
{{/if}}
|
||||
|
||||
<form.actions
|
||||
@disabled={{if @model.cannotSave @model.cannotSave}}
|
||||
|
||||
@@ -7,16 +7,14 @@ export default class FormCredentialLibraryIndexComponent extends Component {
|
||||
/**
|
||||
* @type {object}
|
||||
*/
|
||||
httpMethods = options.http_methods;
|
||||
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', 'isSaving')
|
||||
get cannotSaveHttpRequestBody() {
|
||||
return (
|
||||
!this.args.model.attributes.http_method?.match(/post/i) || this.isSaving
|
||||
);
|
||||
@computed('args.model.attributes.http_method')
|
||||
get isHttpRequestBodyAllowed() {
|
||||
return this.args.model.attributes.http_method?.match(/post/i);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user