Skip to content

Commit

Permalink
console: clean up styles for entry and server code (#9648)
Browse files Browse the repository at this point in the history
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: aa82918
* Authored by Court Ewing <[email protected]> on 2016-12-26T20:02:30Z
  • Loading branch information
elastic-jasper authored and epixa committed Dec 27, 2016
1 parent 00c3e1f commit 01039f8
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---

root: true
extends: '../../../.eslintrc'
extends: '../../../../.eslintrc'

rules:
block-scoped-var: off
Expand Down
34 changes: 17 additions & 17 deletions src/core_plugins/console/index.js
Original file line number Diff line number Diff line change
@@ -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 = [];

Expand Down Expand Up @@ -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 {
Expand All @@ -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)
})
});
}
};

Expand Down Expand Up @@ -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);
}
});

Expand Down Expand Up @@ -190,5 +190,5 @@ module.exports = function (kibana) {
join(src, 'sense_editor/mode/worker.js')
]
}
})
};
});
}
36 changes: 36 additions & 0 deletions src/core_plugins/console/public/.eslintrc
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions src/core_plugins/console/server/__tests__/proxy_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -60,7 +60,7 @@ describe('ProxyConfigCollection', function () {

timeout: 5
}
]
];

function getTimeout(uri) {
const collection = new ProxyConfigCollection(proxyConfigs);
Expand All @@ -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);
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/core_plugins/console/server/__tests__/wildcard_matcher.js
Original file line number Diff line number Diff line change
@@ -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)) {
Expand Down
12 changes: 6 additions & 6 deletions src/core_plugins/console/server/proxy_config.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions src/core_plugins/console/server/proxy_config_collection.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/core_plugins/console/server/wildcard_matcher.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Minimatch } from 'minimatch'
import { Minimatch } from 'minimatch';

export class WildcardMatcher {
constructor(wildcardPattern, emptyVal) {
Expand All @@ -10,7 +10,7 @@ export class WildcardMatcher {
nocase: true,
matchBase: true,
nocomment: true
})
});
}

match(candidate) {
Expand All @@ -19,6 +19,6 @@ export class WildcardMatcher {
return true;
}

return this.matcher.match(candidate || '')
return this.matcher.match(candidate || '');
}
}

0 comments on commit 01039f8

Please sign in to comment.