-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:academo/kibbe
- Loading branch information
Showing
7 changed files
with
122 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# This is kibbe configuration file example | ||
|
||
# Each parameter here will be passed to elastic search as an `-E` parameter. | ||
# Note that parameters without value still require an equal sign `=` at the end | ||
# the sign will be ignored when invoking | ||
[elastic.params] | ||
xpack.security.authc.api_key.enabled=true | ||
|
||
# Each parameter here will be passed to kibana when run | ||
# Note that parameters without value still require an equal sign `=` at the end | ||
# the sign will be ignored when invoking | ||
[kibana.params] | ||
--no-base-path= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import re | ||
import subprocess | ||
|
||
from termcolor import colored | ||
from src.config import get_config | ||
import click | ||
import tempfile | ||
from pathlib import Path | ||
|
||
pathDataRe = re.compile(r"path\.data\s?=", re.IGNORECASE) | ||
|
||
|
||
@click.command(help="Runs elastic search from the current kibana clone. It will use parameters from the ~/.kibbe [elastic.params] section.") | ||
@click.option('--data-dir', '-d', type=click.STRING, default="esdata", help="Path where this elastic search will store its data (path.data)") | ||
@click.option('--no-persist', '-n', default=False, is_flag=True, help="If passed will use a disposable data dir. This option will overwrite other options related to data dir.") | ||
@click.option('-E', multiple=True, help="Additional options to pass to elastic search. `path.data` will be ignored") | ||
def es(data_dir, no_persist, e): | ||
|
||
params = process_params(data_dir, no_persist) | ||
|
||
# additional -E params | ||
for item in e: | ||
item = item.strip() | ||
# ignore path.data | ||
if pathDataRe.match(item): | ||
continue | ||
params.append(item) | ||
|
||
command = get_command(params) | ||
click.echo("Will run elastic search as: " + colored(' '.join(command), 'yellow')) | ||
subprocess.run(command) | ||
|
||
|
||
def get_command(params): | ||
final_params = [] | ||
for param in params: | ||
final_params.append('-E') | ||
final_params.append(param) | ||
|
||
return ['node', 'scripts/es', 'snapshot'] + final_params | ||
|
||
|
||
def process_params(data_dir, no_persist): | ||
CONFIG_KEY = 'elastic.params' | ||
config = get_config() | ||
params = [] | ||
if CONFIG_KEY in config: | ||
for (key, value) in config.items(CONFIG_KEY, raw=True): | ||
# ignore path.data if this command overwrites it | ||
if key == 'path.data': | ||
if len(data_dir) > 0: | ||
value = get_data_dir(data_dir, no_persist) | ||
else: | ||
value = get_data_dir(value, no_persist) | ||
|
||
if len(value) > 0: | ||
params.append(str(key) + '=' + str(value)) | ||
else: | ||
params.append(str(key)) | ||
|
||
return params | ||
|
||
|
||
def get_data_dir(data_dir, no_persist): | ||
if no_persist or len(data_dir) == 0: | ||
return tempfile.mkdtemp(suffix='kibbe') | ||
|
||
return str(Path(data_dir).resolve()) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from pathlib import Path, PurePath | ||
import configparser | ||
from termcolor import colored | ||
|
||
import click | ||
|
||
|
||
def get_config(): | ||
config = configparser.ConfigParser() | ||
try: | ||
config_file_path = PurePath(Path.home()).joinpath('.kibbe') | ||
config.read(config_file_path) | ||
except ValueError: | ||
click.echo(colored('Error reading your configuration file.', 'red')) | ||
pass | ||
return config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,25 @@ | ||
from src.util import force_kibana_root | ||
import click | ||
from src.commands.setlicense import setlicense | ||
from src.commands.functional import functional | ||
|
||
from src.commands.check import check | ||
from src.commands.es import es | ||
from src.commands.setlicense import setlicense | ||
from src.util import force_kibana_root | ||
|
||
|
||
@click.group() | ||
@click.group(help=""" | ||
Kibbe is a tool that help with common tasks when developing kibana plugins. | ||
Some subcommands allow you to define a configuration to persist arguments for some | ||
specific tasks such as running kibana or elasticsearch. This configuration file will | ||
persis those arguments among all kibana clones and branches. | ||
You can create a configuration file in your home ~/.kibbe and follow the configuration | ||
example in the kibbe repository | ||
""") | ||
def cli(): | ||
force_kibana_root() | ||
|
||
|
||
cli.add_command(setlicense) | ||
cli.add_command(functional) | ||
cli.add_command(check) | ||
cli.add_command(es) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters