console: clean up styles for entry and server code (#9648)

Backports PR #9646

**Commit 1:**
console: clean up styles for entry and server code

Much of the code in console is original from when the project was a
separate plugin and was not updated when it was ported over.  Now, any
code in the root of the project or in the server directory will be
linted based on the global rules in Kibana.

* Original sha: aa82918c40
* Authored by Court Ewing <court@epixa.com> on 2016-12-26T20:02:30Z
This commit is contained in:
jasper 2016-12-26 20:43:55 -05:00 committed by Court Ewing
parent 00c3e1f216
commit 01039f854f
9 changed files with 75 additions and 39 deletions

View file

@ -1,7 +1,7 @@
---
root: true
extends: '../../../.eslintrc'
extends: '../../../../.eslintrc'
rules:
block-scoped-var: off

View file

@ -1,13 +1,14 @@
import Joi from 'joi';
import Boom from 'boom';
import apiServer from './api_server/server';
import { existsSync } from 'fs';
import { resolve, join, sep } from 'path';
import { startsWith, endsWith } from 'lodash';
import { ProxyConfigCollection } from './server/proxy_config_collection';
module.exports = function (kibana) {
let { resolve, join, sep } = require('path');
let Joi = require('joi');
let Boom = require('boom');
let modules = resolve(__dirname, 'public/webpackShims/');
let src = resolve(__dirname, 'public/src/');
let { existsSync } = require('fs');
const { startsWith, endsWith } = require('lodash');
export default function (kibana) {
const modules = resolve(__dirname, 'public/webpackShims/');
const src = resolve(__dirname, 'public/src/');
const apps = [];
@ -88,7 +89,7 @@ module.exports = function (kibana) {
if (!filters.some(re => re.test(uri))) {
const err = Boom.forbidden();
err.output.payload = "Error connecting to '" + uri + "':\n\nUnable to send requests to that url.";
err.output.payload = `Error connecting to '${uri}':\n\nUnable to send requests to that url.`;
err.output.headers['content-type'] = 'text/plain';
reply(err);
} else {
@ -109,19 +110,19 @@ module.exports = function (kibana) {
const filterHeaders = server.plugins.elasticsearch.filterHeaders;
reply.proxy({
mapUri: function (request, done) {
done(null, uri, filterHeaders(request.headers, requestHeadersWhitelist))
done(null, uri, filterHeaders(request.headers, requestHeadersWhitelist));
},
xforward: true,
onResponse(err, res, request, reply, settings, ttl) {
if (err != null) {
reply("Error connecting to '" + uri + "':\n\n" + err.message).type("text/plain").statusCode = 502;
reply(`Error connecting to '${uri}':\n\n${err.message}`).type('text/plain').statusCode = 502;
} else {
reply(null, res);
}
},
...proxyConfigCollection.configForUri(uri)
})
});
}
};
@ -150,14 +151,13 @@ module.exports = function (kibana) {
path: '/api/console/api_server',
method: ['GET', 'POST'],
handler: function (req, reply) {
let server = require('./api_server/server');
let {sense_version, apis} = req.query;
const { sense_version, apis } = req.query;
if (!apis) {
reply(Boom.badRequest('"apis" is a required param.'));
return;
}
return server.resolveApi(sense_version, apis.split(","), reply);
return apiServer.resolveApi(sense_version, apis.split(','), reply);
}
});
@ -190,5 +190,5 @@ module.exports = function (kibana) {
join(src, 'sense_editor/mode/worker.js')
]
}
})
};
});
}

View file

@ -0,0 +1,36 @@
---
root: true
extends: '../../../../.eslintrc'
rules:
block-scoped-var: off
camelcase: off
curly: off
dot-location: off
dot-notation: off
eqeqeq: off
guard-for-in: off
indent: off
max-len: off
new-cap: off
no-caller: off
no-empty: off
no-extend-native: off
no-loop-func: off
no-multi-str: off
no-nested-ternary: off
no-proto: off
no-sequences: off
no-undef: off
no-use-before-define: off
one-var: off
quotes: off
space-before-blocks: off
space-in-parens: off
space-infix-ops: off
semi: off
strict: off
wrap-iife: off
no-var: off
prefer-const: off

View file

@ -6,20 +6,20 @@ import fs from 'fs';
import https, { Agent as HttpsAgent } from 'https';
import { parse as parseUrl } from 'url';
import { ProxyConfig } from '../proxy_config'
import { ProxyConfig } from '../proxy_config';
const matchGoogle = {
protocol: 'https',
host: 'google.com',
path: '/search'
}
};
const parsedGoogle = parseUrl('https://google.com/search');
const parsedLocalEs = parseUrl('https://localhost:5601/search');
describe('ProxyConfig', function () {
beforeEach(function () {
sinon.stub(fs, 'readFileSync', function (path) {
return { path }
return { path };
});
});

View file

@ -5,7 +5,7 @@ import sinon from 'sinon';
import fs from 'fs';
import { Agent as HttpsAgent } from 'https';
import { ProxyConfigCollection } from '../proxy_config_collection'
import { ProxyConfigCollection } from '../proxy_config_collection';
describe('ProxyConfigCollection', function () {
beforeEach(function () {
@ -60,7 +60,7 @@ describe('ProxyConfigCollection', function () {
timeout: 5
}
]
];
function getTimeout(uri) {
const collection = new ProxyConfigCollection(proxyConfigs);
@ -69,7 +69,7 @@ describe('ProxyConfigCollection', function () {
context('http://localhost:5601', function () {
it('defaults to the first matching timeout', function () {
expect(getTimeout('http://localhost:5601')).to.be(3)
expect(getTimeout('http://localhost:5601')).to.be(3);
});
});

View file

@ -1,7 +1,7 @@
/* eslint-env mocha */
import expect from 'expect.js'
import expect from 'expect.js';
import { WildcardMatcher } from '../wildcard_matcher'
import { WildcardMatcher } from '../wildcard_matcher';
function should(candidate, ...constructorArgs) {
if (!new WildcardMatcher(...constructorArgs).match(candidate)) {

View file

@ -1,14 +1,14 @@
import { memoize, values } from 'lodash'
import { format as formatUrl } from 'url'
import { Agent as HttpsAgent } from 'https'
import { readFileSync } from 'fs'
import { memoize, values } from 'lodash';
import { format as formatUrl } from 'url';
import { Agent as HttpsAgent } from 'https';
import { readFileSync } from 'fs';
import { WildcardMatcher } from './wildcard_matcher'
import { WildcardMatcher } from './wildcard_matcher';
const makeHttpsAgent = memoize(
opts => new HttpsAgent(opts),
opts => JSON.stringify(opts)
)
);
export class ProxyConfig {
constructor(config) {

View file

@ -1,12 +1,12 @@
import { defaultsDeep } from 'lodash'
import { defaultsDeep } from 'lodash';
import { ProxyConfig } from './proxy_config'
import { parse as parseUrl } from 'url'
import { ProxyConfig } from './proxy_config';
import { parse as parseUrl } from 'url';
export class ProxyConfigCollection {
constructor(configs = []) {
this.configs = configs.map(settings => new ProxyConfig(settings))
this.configs = configs.map(settings => new ProxyConfig(settings));
}
configForUri(uri) {

View file

@ -1,4 +1,4 @@
import { Minimatch } from 'minimatch'
import { Minimatch } from 'minimatch';
export class WildcardMatcher {
constructor(wildcardPattern, emptyVal) {
@ -10,7 +10,7 @@ export class WildcardMatcher {
nocase: true,
matchBase: true,
nocomment: true
})
});
}
match(candidate) {
@ -19,6 +19,6 @@ export class WildcardMatcher {
return true;
}
return this.matcher.match(candidate || '')
return this.matcher.match(candidate || '');
}
}