Skip to content

Commit

Permalink
Merge branch 'master' of github.com:academo/kibbe
Browse files Browse the repository at this point in the history
  • Loading branch information
academo committed Jul 14, 2021
2 parents 76ea089 + 411bd65 commit 075517e
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 25 deletions.
13 changes: 13 additions & 0 deletions kibbe-conf-example
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=
13 changes: 7 additions & 6 deletions src/commands/check.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from pathlib import PurePath
import os
import subprocess
from typing import DefaultDict
from pathlib import PurePath

import click
import os
from termcolor import colored
import termcolor

from src.util import find_related_plugin_folder, find_related_test, force_kibana_root, get_modified_files
from click.types import Path
from src.util import (find_related_plugin_folder, find_related_test,
force_kibana_root, get_modified_files)
from termcolor import colored


@click.command(help="""Run quick checks for your modified files. Useful to run before committing""")
Expand Down
68 changes: 68 additions & 0 deletions src/commands/es.py
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())
11 changes: 0 additions & 11 deletions src/commands/functional.py

This file was deleted.

16 changes: 16 additions & 0 deletions src/config.py
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
20 changes: 15 additions & 5 deletions src/main.py
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)
6 changes: 3 additions & 3 deletions src/util.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os
import json
import os
import subprocess
from typing import ValuesView
import click
from pathlib import PurePath

import click


def is_tool(name):
"""Check whether `name` is on PATH and marked as executable."""
Expand Down

0 comments on commit 075517e

Please sign in to comment.