Notify users that Elasticsearch endpoint has to be an URL

https://github.com/rancher/rancher/issues/13943
This commit is contained in:
n313893254 2018-07-02 14:08:55 +08:00
parent 6aee5eb3ea
commit a81a7bc1d9
4 changed files with 23 additions and 8 deletions

View File

@ -107,12 +107,13 @@ export default Component.extend(NewOrEdit, {
set(model, 'outputTags', get(model, `${targetType}.outputTags`)); set(model, 'outputTags', get(model, `${targetType}.outputTags`));
set(model, 'dockerRoot', get(model, `${targetType}.dockerRoot`)); set(model, 'dockerRoot', get(model, `${targetType}.dockerRoot`));
const formatConfig = get(model, `${targetType}.config`).clone() let formatConfig = get(model, `${targetType}.config`)
if (targetType === 'elasticsearch') {
Object.assign(formatConfig, {endpoint: this.formatUrl(formatConfig.endpoint)})
}
set(model, `${targetType}Config`, formatConfig); set(model, `${targetType}Config`, formatConfig);
if (targetType === 'elasticsearch') {
set(model, `${targetType}Config`, {endpoint: this.formatUrl(formatConfig.endpoint)})
}
this._super(cb); this._super(cb);
}, },
}, },

View File

@ -2,12 +2,19 @@ import Component from '@ember/component';
import es from 'logging/mixins/target-elasticsearch'; import es from 'logging/mixins/target-elasticsearch';
import { get, computed, setProperties, set } from '@ember/object'; import { get, computed, setProperties, set } from '@ember/object';
import { alias } from '@ember/object/computed' 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, { export default Component.extend(es, {
showAdvanced: false, showAdvanced: false,
config: alias('model.config'), config: alias('model.config'),
sslVerify: alias('model.config.sslVerify'), sslVerify: alias('model.config.sslVerify'),
endpointError: false, endpointError: false,
endpointErrorText: null,
didInsertElement() { didInsertElement() {
this.$('#elasticsearch-endpoint').focus() this.$('#elasticsearch-endpoint').focus()
@ -39,10 +46,16 @@ export default Component.extend(es, {
actions: { actions: {
alertMessage(value='') { alertMessage(value='') {
const urlParser = parseUri(value) || {}
set(this, 'endpointError', true)
if (value.startsWith('https://') || value.startsWith('http://')) { 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 { } else {
set(this, 'endpointError', true) set(this, 'endpointErrorText', endpointText.protocolError)
} }
}, },
}, },

View File

@ -14,7 +14,7 @@
}} }}
</div> </div>
{{#if endpointError}} {{#if endpointError}}
<p class="text-error text-small">{{t 'loggingPage.elasticsearch.endpointErrorText'}}</p> <p class="text-error text-small">{{t endpointErrorText}}</p>
{{else}} {{else}}
<p class="text-info text-small">{{t 'loggingPage.elasticsearch.endpointHelpText'}}</p> <p class="text-info text-small">{{t 'loggingPage.elasticsearch.endpointHelpText'}}</p>
{{/if}} {{/if}}

View File

@ -85,7 +85,8 @@ loggingPage:
elasticsearch: elasticsearch:
header: Elasticsearch Configuration header: Elasticsearch Configuration
endpointHelpText: Copy your endpoint from Elastic Cloud, or input the reachable endpoint of your self-hosted Elacticsearch. 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: xpack:
header: X-Pack Security header: X-Pack Security
headerOptional: (optional) headerOptional: (optional)