Пример #1
0
    def get_raw_data(self, job_binary, **kwargs):

        self._validate_job_binary_url(job_binary)

        proxy_configs = kwargs.pop('proxy_configs', None)
        with_context = kwargs.pop('with_context', False)

        if not with_context:
            conn_kwargs = {}
            if proxy_configs:
                conn_kwargs.update(username=proxy_configs.get(
                                   'proxy_username'),
                                   password=key_manager.get_secret(
                                   proxy_configs.get('proxy_password')),
                                   trust_id=proxy_configs.get(
                                   'proxy_trust_id'))
            else:
                conn_kwargs.update(username=job_binary.extra.get('user'),
                                   password=key_manager.get_secret(
                                   job_binary.extra.get('password')))
            conn = sw.client(**conn_kwargs)
        else:
            conn = sw.client_from_token()

        raw = self._get_raw_data(job_binary, conn)
        return raw
Пример #2
0
def get_raw_data(job_binary, proxy_configs=None):
    conn_kwargs = {}
    if proxy_configs:
        conn_kwargs.update(username=proxy_configs.get('proxy_username'),
                           password=proxy_configs.get('proxy_password'),
                           trust_id=proxy_configs.get('proxy_trust_id'))
    else:
        conn_kwargs.update(username=job_binary.extra.get('user'),
                           password=job_binary.extra.get('password'))

    conn = sw.client(**conn_kwargs)
    return _get_raw_data(job_binary, conn)
Пример #3
0
def get_raw_data(job_binary, proxy_configs=None):
    conn_kwargs = {}
    if proxy_configs:
        conn_kwargs.update(
            username=proxy_configs.get("proxy_username"),
            password=proxy_configs.get("proxy_password"),
            trust_id=proxy_configs.get("proxy_trust_id"),
        )
    else:
        conn_kwargs.update(username=job_binary.extra.get("user"), password=job_binary.extra.get("password"))

    conn = sw.client(**conn_kwargs)
    return _get_raw_data(job_binary, conn)
Пример #4
0
def get_raw_data(job_binary, proxy_configs=None):
    conn_kwargs = {}
    if proxy_configs:
        conn_kwargs.update(username=proxy_configs.get('proxy_username'),
                           password=key_manager.get_secret(
                           proxy_configs.get('proxy_password')),
                           trust_id=proxy_configs.get('proxy_trust_id'))
    else:
        conn_kwargs.update(username=job_binary.extra.get('user'),
                           password=key_manager.get_secret(
                           job_binary.extra.get('password')))
    conn = sw.client(**conn_kwargs)
    return _get_raw_data(job_binary, conn)
def get_raw_data(job_binary, proxy_configs=None):
    conn_kwargs = {}
    if proxy_configs:
        conn_kwargs.update(username=proxy_configs.get('proxy_username'),
                           password=proxy_configs.get('proxy_password'),
                           trust_id=proxy_configs.get('proxy_trust_id'))
    else:
        conn_kwargs.update(username=job_binary.extra.get('user'),
                           password=job_binary.extra.get('password'))

    conn = sw.client(**conn_kwargs)

    if not (job_binary.url.startswith(su.SWIFT_INTERNAL_PREFIX)):
        # This should have been guaranteed already,
        # but we'll check just in case.
        raise ex.BadJobBinaryException(
            _("Url for binary in internal swift must start with %s")
            % su.SWIFT_INTERNAL_PREFIX)

    names = job_binary.url[job_binary.url.index("://") + 3:].split("/", 1)
    if len(names) == 1:
        # a container has been requested, this is currently unsupported
        raise ex.BadJobBinaryException(
            _('Url for binary in internal swift must specify an object not '
              'a container'))
    else:
        container, obj = names

        # if container name has '.sahara' suffix we need to strip it
        container = _strip_sahara_suffix(container)

        try:
            # First check the size
            headers = conn.head_object(container, obj)
            total_KB = int(headers.get('content-length', 0)) / 1024.0
            if total_KB > CONF.job_binary_max_KB:
                raise ex.DataTooBigException(
                    round(total_KB, 1), CONF.job_binary_max_KB,
                    _("Size of swift object (%(size)sKB) is greater "
                      "than maximum (%(maximum)sKB)"))

            headers, body = conn.get_object(container, obj)
        except swiftclient.ClientException as e:
            raise ex.SwiftClientException(six.text_type(e))

    return body
Пример #6
0
def get_raw_data(job_binary, proxy_configs=None):
    conn_kwargs = {}
    if proxy_configs:
        conn_kwargs.update(username=proxy_configs.get('proxy_username'),
                           password=proxy_configs.get('proxy_password'),
                           trust_id=proxy_configs.get('proxy_trust_id'))
    else:
        conn_kwargs.update(username=job_binary.extra.get('user'),
                           password=job_binary.extra.get('password'))

    conn = sw.client(**conn_kwargs)

    if not (job_binary.url.startswith(su.SWIFT_INTERNAL_PREFIX)):
        # This should have been guaranteed already,
        # but we'll check just in case.
        raise ex.BadJobBinaryException(
            _("Url for binary in internal swift must start with %s") %
            su.SWIFT_INTERNAL_PREFIX)

    names = job_binary.url[job_binary.url.index("://") + 3:].split("/", 1)
    if len(names) == 1:
        # a container has been requested, this is currently unsupported
        raise ex.BadJobBinaryException(
            _('Url for binary in internal swift must specify an object not '
              'a container'))
    else:
        container, obj = names

        # if container name has '.sahara' suffix we need to strip it
        container = _strip_sahara_suffix(container)

        try:
            # First check the size
            headers = conn.head_object(container, obj)
            total_KB = int(headers.get('content-length', 0)) / 1024.0
            if total_KB > CONF.job_binary_max_KB:
                raise ex.DataTooBigException(
                    round(total_KB, 1), CONF.job_binary_max_KB,
                    _("Size of swift object (%(size)sKB) is greater "
                      "than maximum (%(maximum)sKB)"))

            headers, body = conn.get_object(container, obj)
        except swiftclient.ClientException as e:
            raise ex.SwiftClientException(six.text_type(e))

    return body
Пример #7
0
def get_raw_data(job_binary, proxy_configs=None):
    conn_kwargs = {}
    if proxy_configs:
        key = key_manager.API().get(context.current(),
                                    proxy_configs.get('proxy_password'))
        password = key.get_encoded()
        conn_kwargs.update(username=proxy_configs.get('proxy_username'),
                           password=password,
                           trust_id=proxy_configs.get('proxy_trust_id'))
    else:
        key = key_manager.API().get(context.current(),
                                    job_binary.extra.get('password'))
        password = key.get_encoded()
        conn_kwargs.update(username=job_binary.extra.get('user'),
                           password=password)

    conn = sw.client(**conn_kwargs)
    return _get_raw_data(job_binary, conn)
Пример #8
0
def get_raw_data(job_binary, proxy_configs=None):
    conn_kwargs = {}
    if proxy_configs:
        key = key_manager.API().get(context.current(),
                                    proxy_configs.get('proxy_password'))
        password = key.get_encoded()
        conn_kwargs.update(username=proxy_configs.get('proxy_username'),
                           password=password,
                           trust_id=proxy_configs.get('proxy_trust_id'))
    else:
        key = key_manager.API().get(context.current(),
                                    job_binary.extra.get('password'))
        password = key.get_encoded()
        conn_kwargs.update(username=job_binary.extra.get('user'),
                           password=password)

    conn = sw.client(**conn_kwargs)
    return _get_raw_data(job_binary, conn)
Пример #9
0
 def test_client_with_trust(self, auth_for_proxy, token_from_auth,
                            swift_connection, url_for):
     swift.client('testuser', '12345', 'test_trust')
     self.assertEqual(1, auth_for_proxy.call_count)
     self.assertEqual(1, token_from_auth.call_count)
     self.assertEqual(1, swift_connection.call_count)
Пример #10
0
 def test_client(self, swift_connection, retrieve_auth_url,
                 retrieve_tenant):
     swift.client('testuser', '12345')
     self.assertEqual(1, swift_connection.call_count)
Пример #11
0
 def test_client_with_trust(self, auth_for_proxy, token_from_auth,
                            swift_connection, url_for):
     swift.client('testuser', '12345', 'test_trust')
     self.assertEqual(1, auth_for_proxy.call_count)
     self.assertEqual(1, token_from_auth.call_count)
     self.assertEqual(1, swift_connection.call_count)
Пример #12
0
 def test_client(self, swift_connection, retrieve_auth_url,
                 retrieve_tenant):
     swift.client('testuser', '12345')
     self.assertEqual(1, swift_connection.call_count)