diff --git a/lib/logging/addon/components/logging/new-edit/component.js b/lib/logging/addon/components/logging/new-edit/component.js index e6bac7bb8..27e6ed096 100644 --- a/lib/logging/addon/components/logging/new-edit/component.js +++ b/lib/logging/addon/components/logging/new-edit/component.js @@ -107,12 +107,13 @@ export default Component.extend(NewOrEdit, { set(model, 'outputTags', get(model, `${targetType}.outputTags`)); set(model, 'dockerRoot', get(model, `${targetType}.dockerRoot`)); - const formatConfig = get(model, `${targetType}.config`).clone() - if (targetType === 'elasticsearch') { - Object.assign(formatConfig, {endpoint: this.formatUrl(formatConfig.endpoint)}) - } + let formatConfig = get(model, `${targetType}.config`) set(model, `${targetType}Config`, formatConfig); + + if (targetType === 'elasticsearch') { + set(model, `${targetType}Config`, {endpoint: this.formatUrl(formatConfig.endpoint)}) + } this._super(cb); }, }, diff --git a/lib/logging/addon/components/logging/target-elasticsearch/component.js b/lib/logging/addon/components/logging/target-elasticsearch/component.js index f0f5f324a..cf272c524 100644 --- a/lib/logging/addon/components/logging/target-elasticsearch/component.js +++ b/lib/logging/addon/components/logging/target-elasticsearch/component.js @@ -2,12 +2,19 @@ import Component from '@ember/component'; import es from 'logging/mixins/target-elasticsearch'; import { get, computed, setProperties, set } from '@ember/object'; import { alias } from '@ember/object/computed' +import parseUri from 'shared/utils/parse-uri'; + +const endpointText = { + hostError: 'loggingPage.elasticsearch.endpointHostError', + protocolError: 'loggingPage.elasticsearch.endpointProtocolError', +} export default Component.extend(es, { showAdvanced: false, config: alias('model.config'), sslVerify: alias('model.config.sslVerify'), endpointError: false, + endpointErrorText: null, didInsertElement() { this.$('#elasticsearch-endpoint').focus() @@ -39,10 +46,16 @@ export default Component.extend(es, { actions: { alertMessage(value='') { + const urlParser = parseUri(value) || {} + set(this, 'endpointError', true) if (value.startsWith('https://') || value.startsWith('http://')) { - set(this, 'endpointError', false) + if (urlParser.host) { + set(this, 'endpointError', false) + } else { + set(this, 'endpointErrorText', endpointText.hostError) + } } else { - set(this, 'endpointError', true) + set(this, 'endpointErrorText', endpointText.protocolError) } }, }, diff --git a/lib/logging/addon/components/logging/target-elasticsearch/template.hbs b/lib/logging/addon/components/logging/target-elasticsearch/template.hbs index 81993e803..44faeddbd 100644 --- a/lib/logging/addon/components/logging/target-elasticsearch/template.hbs +++ b/lib/logging/addon/components/logging/target-elasticsearch/template.hbs @@ -14,7 +14,7 @@ }} {{#if endpointError}} -
{{t 'loggingPage.elasticsearch.endpointErrorText'}}
+{{t endpointErrorText}}
{{else}}{{t 'loggingPage.elasticsearch.endpointHelpText'}}
{{/if}} diff --git a/lib/logging/translations/en-us.yaml b/lib/logging/translations/en-us.yaml index f6d1859a5..107574f34 100644 --- a/lib/logging/translations/en-us.yaml +++ b/lib/logging/translations/en-us.yaml @@ -85,7 +85,8 @@ loggingPage: elasticsearch: header: Elasticsearch Configuration endpointHelpText: Copy your endpoint from Elastic Cloud, or input the reachable endpoint of your self-hosted Elacticsearch. - endpointErrorText: Endpoint should start with "http://" or "https://" + endpointProtocolError: Endpoint should starts with "http://" or "https://". + endpointHostError: Please enter host name or domain name. xpack: header: X-Pack Security headerOptional: (optional)