예제 #1
0
def start(listen, data_repo, template_repo, config_repo, config_key, debug,
          telegram_bot_token, telegram_chat_id, auto_push, auto_push_interval,
          admin_organization, user_organization, mode, god):
    """
    start the 0-robot daemon.
    this will start the REST API on address and port specified by --listen and block
    """
    level = "INFO"
    if debug:
        level = "DEBUG"

    j.logger.handlers_level_set(level)
    j.logger.loggers_level_set(level)

    # Check if configmanager is configured to zdb backend and has a namespace configured
    if j.core.state.configGetFromDict("myconfig", "backend", "file") == "db":
        namespace = j.core.state.configGetFromDict("myconfig", "namespace",
                                                   "default")
        if namespace:
            j.tools.configmanager.set_namespace(namespace)
        else:
            raise RuntimeError(
                "Working in zdb backend mode and don't have a namespace")

    if (telegram_bot_token
            and not telegram_chat_id) or (telegram_chat_id
                                          and not telegram_bot_token):
        raise ValueError(
            "To enable telegram error logging, you need to specify both the --telegram-bot-token and the --telegram-chat-id options"
        )

    if telegram_bot_token:
        telegram_logger.disabled = False
        telegrambot = j.clients.telegram_bot.get(
            instance='errorbot', data=dict(bot_token_=telegram_bot_token))
        handler = TelegramHandler(telegrambot, telegram_chat_id)
        handler.setFormatter(TelegramFormatter())
        handler.setLevel(logging.ERROR)
        telegram_logger.addHandler(handler)

    robot = Robot()

    config_repo = config_repo or get_db_config_repo()
    config_key = config_key or get_db_config_key()

    robot.set_config_repo(config_repo, config_key)

    robot.set_data_repo(data_repo)

    for url in template_repo:
        robot.add_template_repo(url)

    robot.start(listen=listen,
                auto_push=auto_push,
                auto_push_interval=auto_push_interval,
                admin_organization=admin_organization,
                user_organization=user_organization,
                mode=mode,
                god=god)
예제 #2
0
파일: server.py 프로젝트: albayck/0-robot
def start(listen, data_repo, template_repo, config_repo, config_key, debug,
          telegram_bot_token, telegram_chat_id, auto_push, auto_push_interval,
          admin_organization, user_organization, mode, god):
    """
    start the 0-robot daemon.
    this will start the REST API on address and port specified by --listen and block
    """
    level = "INFO"
    if debug:
        level = "DEBUG"

    j.logger.handlers_level_set(level)
    j.logger.loggers_level_set(level)

    if (telegram_bot_token
            and not telegram_chat_id) or (telegram_chat_id
                                          and not telegram_bot_token):
        raise ValueError(
            "To enable telegram error logging, you need to specify both the --telegram-bot-token and the --telegram-chat-id options"
        )

    if telegram_bot_token:
        telegram_logger.disabled = False
        telegrambot = j.clients.telegram_bot.get(
            instance='errorbot', data=dict(bot_token_=telegram_bot_token))
        handler = TelegramHandler(telegrambot, telegram_chat_id)
        handler.setFormatter(TelegramFormatter())
        handler.setLevel(logging.ERROR)
        telegram_logger.addHandler(handler)

    robot = Robot()

    for url in template_repo:
        robot.add_template_repo(url)

    robot.set_data_repo(data_repo)
    robot.set_config_repo(config_repo, config_key)

    robot.start(listen=listen,
                auto_push=auto_push,
                auto_push_interval=auto_push_interval,
                admin_organization=admin_organization,
                user_organization=user_organization,
                mode=mode,
                god=god)
예제 #3
0
    def start(self):
        """
        start the 0-robot daemon.
        this will start the REST API on address and port specified by --listen and block

        Arguments:
            listen {string} -- listen address (default :6600)
            data_repo {string} -- URL of the git repository or absolute path where to save the data of the zero robot
            template_repo {list} -- list of template repository URL. Use fragment URL to specify a branch: http://github.com/account/repo#branch'
            config_repo {string} -- URL of the configuration repository (https://github.com/Jumpscale/core9/blob/development/docs/config/configmanager.md)
            config_key {string} -- Absolute path to ssh key to secure configuration data, which is committed and pushed (see auto-push) in the configuration repo
            debug {boolean} -- enable debug logging
            telegram_bot_token {string} -- Bot to push template action failures
            telegram_chat_id {string} -- Chat id to push template action failures
            auto_push {boolean} -- enable automatically commit and pushing of data repository
            auto_push_interval {integer} -- interval in minutes of automatic pushing of data repository
            organization {string} -- if specified, enable JWT authentication for each request

        Raises:
            ValueError -- when telegram_bot is enable but no chat id is specified
        """
        data_repo = self.config.data['data_repo']
        listen = self.config.data.get('listen', ':6600')
        template_repo = self.config.data.get('template_repo')
        config_repo = self.config.data.get('config_repo') or None
        config_key = self.config.data.get('config_key') or None
        debug = self.config.data.get('debug', False)
        telegram_bot_token = self.config.data.get('telegram_bot_token') or None
        telegram_chat_id = self.config.data.get('telegram_chat_id') or None
        auto_push = self.config.data.get('auto_push', False)
        auto_push_interval = self.config.data.get('auto_push_interval', False)
        organization = self.config.data.get('organization') or None

        level = "INFO"
        if debug:
            level = "DEBUG"

        j.logger.handlers_level_set(level)
        j.logger.loggers_level_set(level)

        if (telegram_bot_token
                and not telegram_chat_id) or (telegram_chat_id
                                              and not telegram_bot_token):
            raise ValueError(
                "To enable telegram error logging, you need to specify both the --telegram-bot-token and the --telegram-chat-id options"
            )

        if telegram_bot_token:
            telegram_logger.disabled = False
            telegrambot = j.clients.telegram_bot.get(
                instance='errorbot', data=dict(bot_token_=telegram_bot_token))
            handler = TelegramHandler(telegrambot, telegram_chat_id)
            handler.setFormatter(TelegramFormatter())
            handler.setLevel(logging.ERROR)
            telegram_logger.addHandler(handler)

        robot = Robot()

        for url in template_repo or []:
            robot.add_template_repo(url)

        robot.set_data_repo(data_repo)
        robot.set_config_repo(config_repo, config_key)

        robot.start(listen=listen,
                    auto_push=auto_push,
                    auto_push_interval=auto_push_interval,
                    jwt_organization=organization)