Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
Merge pull request elastic#66 from spalger/lockdown
Browse files Browse the repository at this point in the history
Lockdown
  • Loading branch information
spalger committed Oct 27, 2015
2 parents 582b75d + 9bfa6ef commit 8ae62f2
Show file tree
Hide file tree
Showing 11 changed files with 314 additions and 54 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
webpackShims
public/src/sense_editor/mode/worker.js
56 changes: 56 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---

root: true
extends: airbnb

env:
node: true
amd: true

rules:
no-undef: [1]

func-names: [0]
quotes: [0]
space-before-function-paren: [0]
vars-on-top: [0]
no-cond-assign: [0]
no-param-reassign: [0]
comma-dangle: [0]
no-var: [0]
one-var: [0]
id-length: [0]
eol-last: [0]
consistent-return: [0]
no-use-before-define: [0]
no-nested-ternary: [0]
new-cap: [0]
wrap-iife: [0]
eqeqeq: [0]
no-use-before-define: [0]
no-else-return: [0]
indent: [0]
spaced-comment: [0]
key-spacing: [0]
space-infix-ops: [0]
prefer-const: [0]
camelcase: [0]
no-unused-vars: [0]
padded-blocks: [0]
no-shadow: [0]
semi: [0]
no-console: [0]
brace-style: [0]
no-empty: [0]
strict: [0]
no-redeclare: [0]
curly: [0]
default-case: [0]
dot-notation: [0]
no-multi-spaces: [0]
guard-for-in: [0]
yoda: [0]
no-new: [0]
no-throw-literal: [0]
no-unreachable: [0]
no-multi-str: [0]
17 changes: 3 additions & 14 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
/work
.idea
/agent/logs
/agent/data
/agent/target
/agent/.project
/agent/.classpath
/agent/.settings
/agent/config
/agent/lib
/agent/.local-execution-hints.log
.DS_Store
*.iml
/kibana/kibana
/node_modules
/build
/.aws-config.json
node_modules
build
.aws-config.json
html_docs
target
32 changes: 24 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ Follow the instruction described on the [Kibana Contributing Guide](https://gith

Once Kibana is setup, make sure your have the 4.2 branch checkout:

```
$ git checkout 4.2
```sh
git checkout 4.2
```

Next, clone your Sense fork into it's `installedPlugin` folder:

```
$ git clone [email protected]:YOUR_GITHUB_HANDLE/sense.git installedPlugins/sense
```sh
git clone [email protected]:YOUR_GITHUB_HANDLE/sense.git installedPlugins/sense
```

Create a file named `config/kibana.dev.yml` (under the Kibana *root folder*), with the following content:

```
```yaml
kibana.enabled: false # do not load the Discover, Visualize and Dashboard tabs of Kibana. This saves time
elasticsearch.enabled: false # do not require an active Elasticsearch instance to run
optimize:
Expand All @@ -65,13 +65,30 @@ optimize:
last, run Kibana in development mode:
```
$ ./bin/kibana --dev
```sh
./bin/kibana --dev
```

Congratulations, you should have Sense up and running now.
You can check that by pointing your browser at http://localhost:5601/app/sense/

### Linting your code

Sense uses the fantastic [eslint](http://eslint.org) tool to detect common programming errors and to enforce a uniform code style. To check your code with the linter simply run the lint script in your terminal:

```sh
npm run lint
```

Eslint also has plugins for most text editors and IDEs so that you can get linting results as you work. Here are some hints for getting eslint setup in your favorite editor:

| Editor | Plugin |
| --- | --- | --- |
| Sublime | [SublimeLinter-eslint](https://github.com/roadhump/SublimeLinter-eslint#installation) |
| Atom | [linter-eslint](https://github.com/AtomLinter/linter-eslint#installation) |
| IntelliJ | Settings » Languages & Frameworks » JavaScript » Code Quality Tools » ESLint |
| vi | [scrooloose/syntastic](https://github.com/scrooloose/syntastic) |

### Submitting your changes

Once your changes and tests are ready to submit for review:
Expand Down Expand Up @@ -99,4 +116,3 @@ Once your changes and tests are ready to submit for review:

Then sit back and wait. There will probably be discussion about the pull request and, if any changes are needed,
we would love to work with you to get your pull request merged into Sense.

98 changes: 98 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
module.exports = function (grunt) {
require('jit-grunt')(grunt, {
s3: 'grunt-aws',
eslint: 'gruntify-eslint'
});

const srcFiles = [
{
expand: true,
src: [
'public/**',
'!public/tests/**',
'api_server/**',
'index.js',
'LICENSE.md',
'package.json',
'README.md',
],
dest: 'build/sense-<%= pkg.version %>'
}
];

grunt.initConfig({
pkg: require('./package.json'),

clean: {
build: { src: 'build' },
target: { src: 'target' },
},

compress: {
build: {
options: {
mode: 'tgz',
archive: 'target/sense-<%= pkg.version %>.tar.gz'
},
files: [
{
expand: true,
cwd: 'build/',
src: ['**'],
dest: ''
},
]
}
},

copy: {
build: {
files: srcFiles
}
},

s3: {
release: {
options: {
bucket: 'download.elasticsearch.org',
access: 'private',
gzip: false
},
files: [
{
src: 'target/sense-<%= pkg.version %>.tar.gz',
dest: 'elasticsearch/sense/sense-<%= pkg.version %>.tar.gz'
}
]
}
},

eslint: {
source: {
src: [
'public/**/*.js',
'!**/webpackShims/**'
]
}
},

gitinfo: {},

replace: {
build: {
options: {
patterns: [
{
match: 'SENSE_REVISION',
replacement: '<%= gitinfo.local.branch.current.SHA %>'
}
]
},
files: srcFiles
}
}
});

require('./tasks/build')(grunt);
require('./tasks/release')(grunt);
};
64 changes: 47 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,47 @@ module.exports = function (kibana) {
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');

const apps = [
{
title: 'Sense',
description: 'JSON aware developer\'s interface to ElasticSearch',
icon: 'plugins/sense/bonsai.png',
main: 'plugins/sense/sense',
autoload: kibana.autoload.styles,
injectVars: function (server, options) {
return options;
}
}
];

if (existsSync(resolve(__dirname, 'public/tests'))) {
apps.push({
title: 'Sense Tests',
id: 'sense-tests',
main: 'plugins/sense/tests',
autoload: kibana.autoload.styles,
hidden: true
//listed: false // uncomment after https://github.com/elastic/kibana/pull/4755
});
}

return new kibana.Plugin({
id: 'sense',

config: function (Joi) {
return Joi.object({
enabled: Joi.boolean().default(true),
defaultServerUrl: Joi.string().default('http://localhost:9200'),
proxyFilter: Joi.array().items(Joi.string()).single().default(['.*']),
}).default();
},

init: function (server, options) {
const filters = options.proxyFilter.map(str => new RegExp(str));

// http://hapijs.com/api/8.8.1#route-configuration
server.route({
path: '/api/sense/proxy',
Expand All @@ -20,10 +56,18 @@ module.exports = function (kibana) {
let { uri } = req.query;
if (!uri) {
cb(Boom.badRequest('URI is a required param.'));
return;
}
else {
cb(null, uri);

if (!filters.some(re => re.test(uri))) {
const err = Boom.forbidden();
err.output.payload = 'Unable to send requests to that url';
err.output.headers['content-type'] = 'text/plain';
cb(err);
return;
}

cb(null, uri);
},
passThrough: true,
xforward: true,
Expand Down Expand Up @@ -64,21 +108,7 @@ module.exports = function (kibana) {
},

uiExports: {
apps: [{
title: 'Sense',
description: 'JSON aware developer\'s interface to ElasticSearch',
icon: 'plugins/sense/bonsai.png',
main: 'plugins/sense/sense',
autoload: kibana.autoload.styles
},
{
title: 'Sense Tests',
id: 'sense-tests',
main: 'plugins/sense/tests',
autoload: kibana.autoload.styles,
hidden: true
//listed: false // uncomment after https://github.com/elastic/kibana/pull/4755
}],
apps: apps,

noParse: [
join(modules, 'ace' + sep),
Expand Down
26 changes: 23 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,31 @@
"Spencer Alger <[email protected]>"
],
"name": "Sense",
"version": "2.0.0-SNAPSHOT",
"version": "2.0.0-snapshot",
"repository": {
"type": "git",
"url": "http://github.com/elastic/sense.git"
},
"license": "SEE LICENSE IN LICENSE.MD",
"dependencies": {}
"scripts": {
"build": "grunt build",
"release": "grunt release",
"lint": "grunt eslint:source"
},
"devDependencies": {
"eslint": "^1.7.3",
"eslint-config-airbnb": "^0.1.0",
"eslint-plugin-react": "^3.6.3",
"grunt": "^0.4.5",
"grunt-aws": "^0.6.1",
"grunt-cli": "^0.1.13",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-compress": "^0.14.0",
"grunt-contrib-copy": "^0.8.2",
"grunt-gitinfo": "^0.1.7",
"grunt-replace": "^0.11.0",
"gruntify-eslint": "^1.2.0",
"jit-grunt": "^0.9.1"
},
"dependencies": {},
"license": "Apache-2.0"
}
Loading

0 comments on commit 8ae62f2

Please sign in to comment.