Example #1
0
File: run.py Project: herojan/clin
def apply(
    env: str,
    token: Optional[str],
    execute: bool,
    verbose: bool,
    show_diff: bool,
    show_payload: bool,
    file: str,
):
    """Create or update Nakadi resource from single yaml manifest file\n
     Values to fill {{VARIABLES}} are taken from system environment"""
    configure_logging(verbose)

    try:
        config = load_config()
        kind, spec = load_manifest(Path(file), DEFAULT_YAML_LOADER, os.environ)
        processor = Processor(config, token, execute, show_diff, show_payload)
        processor.apply(env, kind, spec)

    except (ProcessingError, NakadiError, ConfigurationError, YamlError) as ex:
        logging.error(ex)
        exit(-1)

    except Exception as ex:
        logging.exception(ex)
        exit(-1)
Example #2
0
File: run.py Project: herojan/clin
def dump(env: str, token: Optional[str], output: str, verbose: bool,
         event_type: str):
    """Print manifest of existing Nakadi event type"""
    configure_logging(verbose)

    try:
        config = load_config()
        if env not in config.environments:
            logging.error(f"Environment not found in configuration: {env}")
            exit(-1)

        nakadi = Nakadi(config.environments[env].nakadi_url, token)
        et = nakadi.get_event_type(event_type)
        if not et:
            logging.error("Event type not found in Nakadi %s: %s", env,
                          event_type)
            exit(-1)

        if output.lower() == "yaml":
            logging.info(pretty_yaml(et.to_spec()))
        elif output.lower() == "json":
            logging.info(pretty_json(et.to_spec()))
        else:
            logging.error("Invalid output format: %s", output)
            exit(-1)

    except (NakadiError, ConfigurationError) as ex:
        logging.error(ex)
        exit(-1)

    except Exception as ex:
        logging.exception(ex)
        exit(-1)
Example #3
0
def dump(
    token: Optional[str],
    verbose: bool,
    env: str,
    output: str,
    include_envelope: bool,
    event_type: str,
):
    """Print manifest of existing Nakadi event type"""
    configure_logging(verbose)

    try:
        config = load_config()
        if env not in config.environments:
            logging.error(f"Environment not found in configuration: {env}")
            exit(-1)

        nakadi = Nakadi(config.environments[env].nakadi_url, token)
        entity = nakadi.get_event_type(event_type)

        if entity and config.environments[env].nakadi_sql_url:
            nakadi_sql = NakadiSql(config.environments[env].nakadi_sql_url,
                                   token)
            entity = nakadi_sql.get_sql_query(entity) or entity

        if entity is None:
            logging.error("Event type not found in Nakadi %s: %s", env,
                          event_type)
            exit(-1)

        payload = (entity.to_envelope().to_manifest()
                   if include_envelope else entity.to_spec())

        if output.lower() == "yaml":
            logging.info(pretty_yaml(payload))
        elif output.lower() == "json":
            logging.info(pretty_json(payload))
        else:
            logging.error("Invalid output format: %s", output)
            exit(-1)

    except (NakadiError, ConfigurationError) as ex:
        logging.error(ex)
        exit(-1)

    except Exception as ex:
        logging.exception(ex)
        exit(-1)
Example #4
0
def process(
    token: Optional[str],
    verbose: bool,
    execute: bool,
    show_diff: bool,
    show_payload: bool,
    id: Tuple[str],
    env: Tuple[str],
    file: str,
):
    """Create or update multiple Nakadi resources from a clin file"""
    configure_logging(verbose)

    try:
        config = load_config()
        processor = Processor(config, token, execute, show_diff, show_payload)
        file_path: Path = Path(file)
        master = load_yaml(file_path, DEFAULT_YAML_LOADER, os.environ)

        scope = calculate_scope(master, file_path.parent, DEFAULT_YAML_LOADER,
                                id, env)

        for task in (scope[Kind.EVENT_TYPE] + scope[Kind.SQL_QUERY] +
                     scope[Kind.SUBSCRIPTION]):
            logging.debug(
                "[%s] applying file %s to %s environment",
                task.id,
                task.path,
                task.target,
            )
            processor.apply(task.target, task.envelope)

    except (ProcessingError, ConfigurationError, YamlError) as ex:
        logging.error(ex)
        exit(-1)

    except Exception as ex:
        logging.exception(ex)
        exit(-1)
Example #5
0
File: run.py Project: herojan/clin
def process(
    token: Optional[str],
    execute: bool,
    verbose: bool,
    show_diff: bool,
    show_payload: bool,
    file: str,
):
    """Create or update multiple Nakadi resources from clin file"""
    configure_logging(verbose)

    try:
        config = load_config()
        processor = Processor(config, token, execute, show_diff, show_payload)
        file_path: Path = Path(file)
        master = load_yaml(file_path, DEFAULT_YAML_LOADER, os.environ)
        scope = calculate_scope(master, file_path.parent, DEFAULT_YAML_LOADER)
        event_types = [et for et in scope if et.kind == "event-type"]
        subscriptions = [sub for sub in scope if sub.kind == "subscription"]

        for task in event_types + subscriptions:
            logging.debug(
                "[%s] applying file %s to %s environment",
                task.id,
                task.path,
                task.target,
            )
            processor.apply(task.target, task.kind, task.spec)

    except (ProcessingError, ConfigurationError, YamlError) as ex:
        logging.error(ex)
        exit(-1)

    except Exception as ex:
        logging.exception(ex)
        exit(-1)