예제 #1
0
def init():
    """Initializes all required variable for the tracer."""
    global jrds_client, jrds_cert_path, jrds_key_path, jrds_base_uri, subscription_id, \
        account_id, machine_id, hybrid_worker_group_name, worker_version, activity_id, sandbox_id

    # Create the http client
    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)

    # Populate global configuration values
    jrds_cert_path = configuration.get_jrds_cert_path()
    jrds_key_path = configuration.get_jrds_key_path()
    jrds_base_uri = configuration.get_jrds_base_uri()
    subscription_id = "00000000-0000-0000-0000-000000000000"  # temporary place holder
    account_id = configuration.get_account_id()
    machine_id = configuration.get_machine_id()
    hybrid_worker_group_name = configuration.get_hybrid_worker_name()
    worker_version = configuration.get_worker_version()

    sandbox_id = None
    try:
        sandbox_id = os.environ["sandbox_id"]
    except KeyError:
        pass

    # initialize the loggers for for all components except runbook
    if configuration.get_component() != "runbook":
        init_logger()
예제 #2
0
def init():
    """Initializes all required variable for the tracer."""
    global jrds_client, jrds_cert_path, jrds_key_path, jrds_base_uri, subscription_id, \
        account_id, machine_id, hybrid_worker_group_name, worker_version, sandbox_id

    # Create the http client
    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)

    # Populate global configuration values
    jrds_cert_path = configuration.get_jrds_cert_path()
    jrds_key_path = configuration.get_jrds_key_path()
    jrds_base_uri = configuration.get_jrds_base_uri()
    subscription_id = "00000000-0000-0000-0000-000000000000"  # temporary place holder
    account_id = configuration.get_account_id()
    machine_id = configuration.get_machine_id()
    hybrid_worker_group_name = configuration.get_hybrid_worker_name()
    worker_version = configuration.get_worker_version()

    sandbox_id = None
    try:
        sandbox_id = os.environ["sandbox_id"]
    except KeyError:
        pass

    # initialize the loggers for for all components except runbook
    if configuration.get_component() != "runbook":
        locallogger.init_logger()
예제 #3
0
 def __init__(self):
     self.sandbox_id = os.environ["sandbox_id"]
     tracer.log_sandbox_starting(self.sandbox_id, os.getpid())
     http_client_factory = HttpClientFactory(
         configuration.get_jrds_cert_path(),
         configuration.get_jrds_key_path())
     http_client = http_client_factory.create_http_client(
         sys.version_info, configuration.get_verify_certificates())
     self.jrds_client = JRDSClient(http_client)
예제 #4
0
 def __init__(self):
     tracer.log_worker_starting(configuration.get_worker_version())
     http_client_factory = HttpClientFactory(
         configuration.get_jrds_cert_path(),
         configuration.get_jrds_key_path())
     http_client = http_client_factory.create_http_client(
         sys.version_info, configuration.get_verify_certificates())
     self.jrds_client = JRDSClient(http_client)
     self.running_sandboxes = {}
예제 #5
0
    def __init__(self):
        self.sandbox_id = os.environ["sandbox_id"]
        tracer.log_sandbox_starting(sandbox_id=self.sandbox_id, pid=os.getpid(),
                                    worker_type=configuration.get_worker_type())
        tracer.log_sandbox_configuration(sandbox_id=self.sandbox_id,
                                         enforce_runbook_signature_validation=configuration.get_enforce_runbook_signature_validation(),
                                         gpg_public_keyring_paths=configuration.get_gpg_public_keyrings_path(),
                                         working_directory=os.getcwd())

        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)
        self.jrds_client = JRDSClient(http_client)
예제 #6
0
def init():
    """Initializes all required variable for the tracer."""
    global default_logger, sandbox_stdout, jrds_client, jrds_cert_path, jrds_key_path, jrds_base_uri, subscription_id, \
        account_id, machine_id, hybrid_worker_group_name, worker_version, activity_id, sandbox_id

    # Create the http client
    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)

    # Populate global configuration values
    jrds_cert_path = configuration.get_jrds_cert_path()
    jrds_key_path = configuration.get_jrds_key_path()
    jrds_base_uri = configuration.get_jrds_base_uri()
    subscription_id = "00000000-0000-0000-0000-000000000000"  # temporary place holder
    account_id = configuration.get_account_id()
    machine_id = configuration.get_machine_id()
    hybrid_worker_group_name = configuration.get_hybrid_worker_name()
    worker_version = configuration.get_worker_version()

    sandbox_id = None
    try:
        sandbox_id = os.environ["sandbox_id"]
    except KeyError:
        pass

    if sandbox_id is not None:
        log_file_name = configuration.get_component() + sandbox_id
    else:
        log_file_name = configuration.get_component()

    file_name = os.path.join(configuration.get_working_directory_path(),
                             log_file_name + '.log')
    logging.Formatter.converter = time.gmtime

    # Default logger
    default_logger = logging.getLogger("default_logger")
    default_logger.setLevel(logging.INFO)

    # Logger for the sandbox traces coming back to worker
    sandbox_stdout = logging.getLogger("sandbox_stdout_logger")
    sandbox_stdout.setLevel(logging.INFO)

    # Default rotating file handler write traces with the specified format to disk.
    default_rf_handler = logging.handlers.RotatingFileHandler(
        file_name, maxBytes=10485760, backupCount=5)
    formatter = logging.Formatter('%(asctime)s (' + str(os.getpid()) + ')' +
                                  configuration.get_component() +
                                  ' : %(message)s',
                                  datefmt="%Y-%m-%d %H:%M:%S")
    default_rf_handler.setFormatter(formatter)
    default_logger.addHandler(default_rf_handler)

    # Traces coming from sandbox child process and collected by the worker are already formatted, hence no formatter
    # needed.
    worker_sandbox_rf_handler = logging.handlers.RotatingFileHandler(
        file_name, maxBytes=10485760, backupCount=5)
    sandbox_stdout.addHandler(worker_sandbox_rf_handler)

    # Stdout handler (Worker traces have to be formatted).
    log_stream = logging.StreamHandler(sys.stdout)
    log_stream.setFormatter(formatter)
    default_logger.addHandler(log_stream)

    # Stdout handler (traces coming from child process are already formatted).
    sandbox_log_stream = logging.StreamHandler(sys.stdout)
    sandbox_stdout.addHandler(sandbox_log_stream)
예제 #7
0
 def __init__(self):
     tracer.log_worker_starting(configuration.get_worker_version())
     http_client_factory = HttpClientFactory(configuration.get_jrds_cert_path(), configuration.get_jrds_key_path())
     http_client = http_client_factory.create_http_client(sys.version_info, configuration.get_verify_certificates())
     self.jrds_client = JRDSClient(http_client)
     self.running_sandboxes = {}
    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)
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)
예제 #10
0
 def __init__(self):
     self.sandbox_id = os.environ["sandbox_id"]
     tracer.log_sandbox_starting(self.sandbox_id, os.getpid())
     http_client_factory = HttpClientFactory(configuration.get_jrds_cert_path(), configuration.get_jrds_key_path())
     http_client = http_client_factory.create_http_client(sys.version_info, configuration.get_verify_certificates())
     self.jrds_client = JRDSClient(http_client)
예제 #11
0
def init():
    """Initializes all required variable for the tracer."""
    global default_logger, sandbox_stdout, jrds_client, jrds_cert_path, jrds_key_path, jrds_base_uri, subscription_id,\
        account_id, machine_id, hybrid_worker_group_name, worker_version, activity_id

    # Create the http client
    http_client_factory = HttpClientFactory(configuration.get_jrds_cert_path(), configuration.get_jrds_key_path())
    http_client = http_client_factory.create_http_client(sys.version_info, configuration.get_verify_certificates())
    jrds_client = JRDSClient(http_client)

    # Populate global configuration values
    jrds_cert_path = configuration.get_jrds_cert_path()
    jrds_key_path = configuration.get_jrds_key_path()
    jrds_base_uri = configuration.get_jrds_base_uri()
    subscription_id = "00000000-0000-0000-0000-000000000000" # temporary place holder
    account_id = configuration.get_account_id()
    machine_id = configuration.get_machine_id()
    hybrid_worker_group_name = configuration.get_hybrid_worker_name()
    worker_version = configuration.get_worker_version()
    activity_id = generate_activity_id()

    sandbox_id = None
    try:
        sandbox_id = os.environ["sandbox_id"]
    except KeyError:
        pass

    if sandbox_id is not None:
        log_file_name = configuration.get_component() + sandbox_id
    else:
        log_file_name = configuration.get_component()

    file_name = os.path.join(configuration.get_working_directory_path(), log_file_name + '.log')
    logging.Formatter.converter = time.gmtime

    # Default logger
    default_logger = logging.getLogger("default_logger")
    default_logger.setLevel(logging.INFO)

    # Logger for the sandbox traces coming back to worker
    sandbox_stdout = logging.getLogger("sandbox_stdout_logger")
    sandbox_stdout.setLevel(logging.INFO)

    # Default rotating file handler write traces with the specified format to disk.
    default_rf_handler = logging.handlers.RotatingFileHandler(file_name, maxBytes=10485760, backupCount=5)
    formatter = logging.Formatter('%(asctime)s (' + str(os.getpid()) + ')' + configuration.get_component() +
                                  ' : %(message)s', datefmt="%Y-%m-%d %H:%M:%S")
    default_rf_handler.setFormatter(formatter)
    default_logger.addHandler(default_rf_handler)

    # Traces coming from sandbox child process and collected by the worker are already formatted, hence no formatter
    # needed.
    worker_sandbox_rf_handler = logging.handlers.RotatingFileHandler(file_name, maxBytes=10485760, backupCount=5)
    sandbox_stdout.addHandler(worker_sandbox_rf_handler)

    # Stdout handler (Worker traces have to be formatted).
    log_stream = logging.StreamHandler(sys.stdout)
    log_stream.setFormatter(formatter)
    default_logger.addHandler(log_stream)

    # Stdout handler (traces coming from child process are already formatted).
    sandbox_log_stream = logging.StreamHandler(sys.stdout)
    sandbox_stdout.addHandler(sandbox_log_stream)