Esempio n. 1
0
 def _setup_app(self):
     self.log('Invoking setup_app')
     path = os.getcwd()
     if path not in sys.path:
         sys.path.insert(0, path)
     set_config(self.config.getvalue('config_file'))
     py.test.wsgi_app = self._load_app(conf)
Esempio n. 2
0
def main():
    if len(sys.argv) < 2:
        exit_on_error("Invalid configuration file path (absolute path is required).")
    configuration_path = sys.argv[1]

    if not os.path.isfile(configuration_path):
        exit_on_error("Invalid configuration file path (absolute path is required).")

    # configuration has to be read first thing
    try:
        # remove the test_mode env_var value (mainly for Windows)
        # this value is set in test
        del os.environ["test_mode"]
    except KeyError:
        pass
    worker_dir = os.path.dirname(os.path.realpath(__file__))
    config_path = os.path.join(worker_dir, configuration_path)
    configuration.read_and_set_configuration(config_path)
    configuration.set_config({configuration.COMPONENT: "worker"})
    validate_and_setup_path()
    # do not trace anything before this point

    generate_state_file()
    worker = Worker()
    worker.routine()
Esempio n. 3
0
def main():
    if len(sys.argv) < 2:
        exit_on_error(
            "Invalid configuration file path (absolute path is required).")
    configuration_path = sys.argv[1]

    if not os.path.isfile(configuration_path):
        exit_on_error(
            "Invalid configuration file path (absolute path is required).")

    # configuration has to be read first thing
    try:
        # remove the test_mode env_var value (mainly for Windows)
        # this value is set in test
        del os.environ["test_mode"]
    except KeyError:
        pass
    worker_dir = os.path.dirname(os.path.realpath(__file__))
    config_path = os.path.join(worker_dir, configuration_path)
    configuration.read_and_set_configuration(config_path)
    configuration.set_config({configuration.COMPONENT: "worker"})
    validate_and_setup_path()
    # do not trace anything before this point

    generate_state_file()
    worker = Worker()
    worker.routine()
Esempio n. 4
0
def main():
    if len(sys.argv) < 2:
        exit_on_error(
            "Invalid configuration file path (absolute path is required).")
    configuration_path = str(sys.argv[1])

    if not os.path.isfile(configuration_path):
        exit_on_error(
            "Invalid configuration file path or empty configuration file (absolute path is required)."
        )

    # configuration has to be read first thing
    try:
        # remove the test_mode env_var value (mainly for Windows)
        # this value is set in test
        del os.environ["test_mode"]
    except KeyError:
        pass

    configuration.read_and_set_configuration(configuration_path)
    configuration.set_config({
        configuration.COMPONENT: "sandbox",
        configuration.WORKING_DIRECTORY_PATH: os.getcwd()
    })
    # do not trace anything before this point

    sandbox = Sandbox()
    sandbox.routine()
def main():
    # configuration has to be read first thing
    configuration.set_config({configuration.COMPONENT: "sandbox"})
    configuration.set_config({configuration.WORKING_DIRECTORY_PATH: os.getcwd()})
    # do not trace anything before this point

    sandbox = Sandbox()
    sandbox.routine()
Esempio n. 6
0
def main():
    # configuration has to be read first thing
    configuration.set_config({configuration.COMPONENT: "sandbox"})
    configuration.set_config(
        {configuration.WORKING_DIRECTORY_PATH: os.getcwd()})
    # do not trace anything before this point

    sandbox = Sandbox()
    sandbox.routine()
Esempio n. 7
0
def deploy(config_module_or_path):
    set_config(config_module_or_path)
    for module in getattr(conf.app, 'modules'):
        try:
            module_app = import_module('%s.app' % module.__name__)
            if hasattr(module_app, 'setup_app'):
                return module_app.setup_app(conf)
        except ImportError:
            continue

    raise Exception, 'No app.setup_app found in any of the configured app.modules'
Esempio n. 8
0
def _file_listener_config():
    config = configuration()
    req_path, res_path = None, None
    if config:
        req_path, res_path = config.req_path, config.res_path
    if not config or not req_path.is_dir() or not res_path.is_dir():
        # Search for possible configurations
        new_req_path, new_res_path = _communication_directories()
        cfg.set_config(cfg.Configuration(new_req_path, new_res_path))
        return _file_listener_config()
    return req_path, res_path
Esempio n. 9
0
def load_app(config):
    '''
    Used to load a ``Pecan`` application and its environment based on passed
    configuration.

    :param config: Can be a dictionary containing configuration, a string which
                    represents a (relative) configuration filename

    returns a pecan.Pecan object
    '''
    from configuration import _runtime_conf, set_config
    set_config(config, overwrite=True)

    for package_name in getattr(_runtime_conf.app, 'modules', []):
        module = __import__(package_name, fromlist=['app'])
        if hasattr(module, 'app') and hasattr(module.app, 'setup_app'):
            app = module.app.setup_app(_runtime_conf)
            app.config = _runtime_conf
            return app
    raise RuntimeError(
        'No app.setup_app found in any of the configured app.modules'
    )
def main():
    if len(sys.argv) < 2:
        exit_on_error("Invalid configuration file path (absolute path is required).")
    configuration_path = str(sys.argv[1])

    if not os.path.isfile(configuration_path):
        exit_on_error("Invalid configuration file path or empty configuration file (absolute path is required).")

    # configuration has to be read first thing
    try:
        # remove the test_mode env_var value (mainly for Windows)
        # this value is set in test
        del os.environ["test_mode"]
    except KeyError:
        pass

    configuration.read_and_set_configuration(configuration_path)
    configuration.set_config({configuration.COMPONENT: "sandbox",
                              configuration.WORKING_DIRECTORY_PATH: os.getcwd()})
    # do not trace anything before this point

    sandbox = Sandbox()
    sandbox.routine()
    return json.loads(variable[KEY_VALUE])


def set_automation_variable(name, value):
    jrds_client.set_variable_asset(name, json.dumps(value), False)


def get_automation_credential(name):
    credential = jrds_client.get_credential_asset(name)
    return CredentialModelV1(credential[KEY_USERNAME], credential[KEY_VALUE])


def get_automation_connection(name):
    connection = jrds_client.get_connection_asset(name)
    return connection[KEY_CONNECTION_FIELDS]


class CredentialModelV1:
    def __init__(self, username, password):
        self.username = username
        self.password = password


configuration.set_config({configuration.COMPONENT: "assets"})
json = serializerfactory.get_serializer(sys.version_info)
http_client_factory = HttpClientFactory(
    configuration.get_jrds_cert_path(), configuration.get_jrds_key_path(),
    configuration.get_verify_certificates())
http_client = http_client_factory.create_http_client(sys.version_info)
jrds_client = JRDSClient(http_client)
Esempio n. 12
0
                    choices=["INFO", "DEBUG"],
                    help="log level")

args = parser.parse_args()
if args.logLevel == "INFO":
    print(args)

configuration.init_config(args)
inmemorydb.initilize_db()
protocol = args.protocol
serverIp = args.ip
serverPort = args.port
baseAddress = protocol + "://" + serverIp + ":" + serverPort + "/"
signupAddress = baseAddress + "signup"
loginAddress = baseAddress + "login"
configuration.set_config("signupAddress", signupAddress, overrite=True)
configuration.set_config("loginAddress", loginAddress, overrite=True)
returnData = namedtuple('returnData', 'message, backToUrl, caption')
app = Flask(__name__, static_url_path='/static')


@app.route('/', methods=["POST", "GET"])
def index():
    return render_template("login.html",
                           signupURL=signupAddress,
                           loginURL=loginAddress)


@app.route('/login', methods=["POST", "GET"])
def login():
    if request.method == "POST":
def get_automation_variable(name):
    variable = jrds_client.get_variable_asset(name)
    return json.loads(variable[KEY_VALUE])


def set_automation_variable(name, value):
    jrds_client.set_variable_asset(name, json.dumps(value), False)


def get_automation_credential(name):
    credential = jrds_client.get_credential_asset(name)
    return {"username": credential[KEY_USERNAME], "password": credential[KEY_VALUE]}


def get_automation_connection(name):
    connection = jrds_client.get_connection_asset(name)
    return connection[KEY_CONNECTION_FIELDS]


def get_automation_certificate(name):
    certificate = jrds_client.get_certificate_asset(name)
    return binascii.a2b_base64(certificate[KEY_VALUE])


configuration.set_config({configuration.COMPONENT: "assets"})
json = serializerfactory.get_serializer(sys.version_info)
http_client_factory = HttpClientFactory(configuration.get_jrds_cert_path(), configuration.get_jrds_key_path(),
                                        configuration.get_verify_certificates())
http_client = http_client_factory.create_http_client(sys.version_info)
jrds_client = JRDSClient(http_client)
Esempio n. 14
0
from optparse import OptionParser
import sys
import os
import pwd
import grp
import subprocess

import configuration
import serializerfactory

json = serializerfactory.get_serializer(sys.version_info)
configuration.clear_config()
configuration.set_config({
    configuration.PROXY_CONFIGURATION_PATH:
    "/etc/opt/microsoft/omsagent/proxy.conf",
    configuration.WORKER_VERSION: "OMSUtil",
    configuration.WORKING_DIRECTORY_PATH: "/tmp"
})

USERNAME_NXAUTOMATION = "nxautomation"
GROUPNAME_NXAUTOMATION = "nxautomation"
GROUPNAME_OMSAGENT = "omsagent"


def initialize():
    """Initializes the OMS environment. Meant to be executed everytime the resource's set method is invoked.
    Steps:
        - Sets omsagent group to nxautomation user (if needed).
        - Sets group read permission to MSFT keyring.gpg
        - Sets group read and execute to the OMS certificate folder.
Esempio n. 15
0
def main():
    if len(sys.argv) < 2:
        exit_on_error(
            "Invalid configuration file path (absolute path is required).")
    configuration_path = str(sys.argv[1])

    if not os.path.isfile(configuration_path):
        exit_on_error(
            "Invalid configuration file path or empty configuration file (absolute path is required)."
        )

    # configuration has to be read first thing
    try:
        # remove the test_mode env_var value (mainly for Windows)
        # this value is set in test
        del os.environ["test_mode"]
    except KeyError:
        pass

    # fix for nxautomation OMS integration
    # add the nxautomation user to omsagent (omsagent-1.2.0-75.universal.x64.sh and older create the cert under omsagent:omsagent)
    if os.name.lower() != "nt":
        import pwd
        import grp
        nxautomation_username = "******"
        omsagent_group_name = "omsagent"
        try:
            nxautomation_uid = int(pwd.getpwnam(nxautomation_username).pw_uid)
            if os.getuid() == nxautomation_uid:
                omsagent_group = grp.getgrnam(omsagent_group_name)
                if nxautomation_username not in omsagent_group.gr_mem:
                    proc = subprocess.Popen([
                        "sudo", "/usr/sbin/usermod", "-g", "nxautomation",
                        "-a", "-G", "omsagent,omiusers", "nxautomation"
                    ],
                                            stdout=subprocess.PIPE,
                                            stderr=subprocess.PIPE)
                    output, error = proc.communicate()

                    if proc.returncode != 0:
                        exit_on_error(str(error))

                    # exiting to reflect group permission, proper permission will reflect for the process on the next execution
                    sys.exit(3)

                #change permissions for the keyring.gpg
                proc = subprocess.Popen([
                    "sudo", "chmod", "g+r",
                    "/etc/opt/omi/conf/omsconfig/keyring.gpg"
                ],
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.PIPE)
                output, error = proc.communicate()

                if proc.returncode != 0:
                    exit_on_error(str(error))

        except SystemExit:
            raise
        except:
            pass

    configuration.read_and_set_configuration(configuration_path)
    configuration.set_config({configuration.COMPONENT: "worker"})
    validate_and_setup_path()
    # do not trace anything before this point

    generate_state_file()
    worker = Worker()
    worker.telemetry_routine()
    worker.routine()
#!/usr/bin/env python2
#
# Copyright (C) Microsoft Corporation, All rights reserved.

import os

import configuration
import tracer

configuration.set_config({configuration.COMPONENT: "runbook"})


def get_activity_id():
    try:
        return os.environ["AUTOMATION_ACTIVITY_ID"]
    except KeyError:
        return None


def log(trace, activity_id=get_activity_id()):
    tracer.log_runbook_runtime_trace(trace, activity_id=activity_id)