Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

console: clean up styles for entry and server code #9646

Merged
merged 1 commit into from
Dec 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When will we remove these linting rules and defer to the ones in the root?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just like the console-root eslintrc that is deleted in this PR, we can delete the specific lint configs once we've updated the code in those directories (public and api_server).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Can we track these tasks in a linting meta-issue? Unless you're planning to move on them immediately, I'm afraid that we'll lose sight of them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The linked issue is the issue for tracking this, but I've added the meta label to it and added four todo items, two of which are tackled here.

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 || '');
}
}