示例#1
0
文件: agent.py 项目: eavatar/ava.node
    def get_security_keys(self):
        keyfile = os.path.join(environ.conf_dir(), KEYFILE)
        keys = config.load_conf(keyfile)

        self.__secret = keys.get('secret')
        self.user_xid = keys.get('user')
        self.__secret = os.environ.get(AVA_AGENT_SECRET, self.__secret)
        self.user_xid = os.environ.get(AVA_USER_XID, self.user_xid)

        if self.user_xid is None and not settings['debug']:
            logger.error('No User XID is specified!')
            raise SystemExit(2)

        if self.__secret:
            self.__secret = crypto.string_to_secret(self.__secret)
            pk, sk = crypto.generate_keypair(sk=self.__secret)
            self.key = pk
        else:
            logger.debug("No secret key is given, generating one...")
            pk, sk = crypto.generate_keypair()
            self.__secret = sk
            self.key = pk

        self.xid = crypto.key_to_xid(self.key)
        logger.debug("The agent's XID: %s", self.xid)

        if not self.user_xid and settings['debug']:
            logger.debug("User XID not given via environment variable. " +
                         "Generating one...")
            self.user_xid = \
                b'AYPwK3c3VK7ZdBvKfcbV5EmmCZ8zSb9viZ288gKFBFuE92jE'
        logger.debug("The agent's user XID: %s", self.user_xid)
示例#2
0
文件: key.py 项目: eavatar/ava.node
def agent(ctx, force=False):
    """ Generate keys for agent.
    """
    userkeys_path = os.path.join(ctx.obj['app_dir'], 'user-keys.yml')
    if not os.path.exists(userkeys_path):
        click.echo('You should set user keys first.', err=True)
        return

    with open(userkeys_path, 'rb') as userkeys_file:
        userkeys = yaml.load(userkeys_file)
    user_xid = userkeys.get('xid')

    agentkeys_path = os.path.join(environ.conf_dir(), 'ava-keys.yml')
    if os.path.exists(agentkeys_path) and not force:
        click.echo('Agent keys exist!')
        click.confirm('Do you want to overwrite it?', abort=True)

    content = {}
    pk, sk = crypto.generate_keypair()

    content[b'user'] = user_xid
    content[b'secret'] = crypto.secret_to_string(sk)

    with open(agentkeys_path, 'wb') as agentkeys_file:
        yaml.dump(content, agentkeys_file)
示例#3
0
文件: agent.py 项目: eavatar/ava.node
    def get_security_keys(self):
        keyfile = os.path.join(environ.conf_dir(), KEYFILE)
        keys = config.load_conf(keyfile)

        self.__secret = keys.get('secret')
        self.user_xid = keys.get('user')
        self.__secret = os.environ.get(AVA_AGENT_SECRET, self.__secret)
        self.user_xid = os.environ.get(AVA_USER_XID, self.user_xid)

        if self.user_xid is None and not settings['debug']:
            logger.error('No User XID is specified!')
            raise SystemExit(2)

        if self.__secret:
            self.__secret = crypto.string_to_secret(self.__secret)
            pk, sk = crypto.generate_keypair(sk=self.__secret)
            self.key = pk
        else:
            logger.debug("No secret key is given, generating one...")
            pk, sk = crypto.generate_keypair()
            self.__secret = sk
            self.key = pk

        self.xid = crypto.key_to_xid(self.key)
        logger.debug("The agent's XID: %s", self.xid)

        if not self.user_xid and settings['debug']:
            logger.debug("User XID not given via environment variable. " +
                         "Generating one...")
            self.user_xid = \
                b'AYPwK3c3VK7ZdBvKfcbV5EmmCZ8zSb9viZ288gKFBFuE92jE'
        logger.debug("The agent's user XID: %s", self.user_xid)
示例#4
0
文件: agent.py 项目: eavatar/ava.node
    def save_keys(self):
        keyfile = os.path.join(environ.conf_dir(), KEYFILE)
        keys = {
            b'secret': crypto.secret_to_string(self.__secret),
            b'user': self.user_xid,
        }

        config.save_conf(keyfile, keys)
示例#5
0
文件: agent.py 项目: eavatar/ava.node
    def save_keys(self):
        keyfile = os.path.join(environ.conf_dir(), KEYFILE)
        keys = {
            b'secret': crypto.secret_to_string(self.__secret),
            b'user': self.user_xid,
        }

        config.save_conf(keyfile, keys)
示例#6
0
    def _run_https(self):
        logger.debug("Webfront engine(HTTPS) is running...")

        conf_dir = environ.conf_dir()
        keyfile = os.path.join(conf_dir, "ava.key")
        certfile = os.path.join(conf_dir, "ava.crt")

        self._https_listener = pywsgi.WSGIServer(
            (self.listen_addr, self.secure_listen_port), dispatcher, keyfile=keyfile, certfile=certfile
        )

        logger.debug("Webfront engine(HTTPS) is listening on port: %d", self._https_listener.address[1])

        self._https_listener.serve_forever()
示例#7
0
    def _run_https(self):
        logger.debug("Webfront engine(HTTPS) is running...")

        conf_dir = environ.conf_dir()
        keyfile = os.path.join(conf_dir, 'ava.key')
        certfile = os.path.join(conf_dir, 'ava.crt')

        self._https_listener = WSGIServer(
            (self.listen_addr, self.secure_listen_port),
            dispatcher,
            keyfile=keyfile,
            certfile=certfile)

        logger.debug("Webfront engine(HTTPS) is listening on port: %d",
                     self._https_listener.address[1])

        self._https_listener.serve_forever()
示例#8
0
import logging
import logging.config
import os.path
from string import Template

from yaml import load, dump

try:
    from yaml import CLoader as Loader, CDumper as Dumper
except ImportError:
    from yaml import Loader, Dumper

from ava.runtime import environ


AGENT_CONF = os.path.join(environ.conf_dir(), u'ava.yml')

# The default configuration file is located at the base directory.

settings = dict(base_dir=environ.base_dir(),
                conf_dir=environ.conf_dir(),
                data_dir=environ.data_dir(),
                pkgs_dir=environ.pkgs_dir(),
                logs_dir=environ.logs_dir(),
                mods_dir=environ.mods_dir(),
                )


def load_conf(conf_file):
    if not os.path.exists(conf_file):
        return {}
示例#9
0
# -*- coding: utf-8 -*-

"""
Configuration file reading/writing.
"""
from __future__ import absolute_import, division, print_function, unicode_literals

import logging
import logging.config
import os.path
from ConfigParser import SafeConfigParser

from ava.runtime import environ


AGENT_CONF = os.path.join(environ.conf_dir(), b'agent.ini')
LOGGING_CONF = os.path.join(environ.conf_dir(), b'logging.ini')
PACKAGES_CONF = os.path.join(environ.conf_dir(), b'packages.ini')

# The default configuration file is located at the base directory.

_defaults = dict(base_dir=environ.base_dir(),
                 conf_dir=environ.conf_dir(),
                 data_dir=environ.data_dir(),
                 pkgs_dir=environ.pkgs_dir(),
                 logs_dir=environ.logs_dir())


class ConfigFile(SafeConfigParser):
    def __init__(self, filename, defaults=_defaults):
        SafeConfigParser.__init__(self, defaults)