Esempio n. 1
0
def client(username, password, trust_id=None):
    '''return a Swift client

    This will return a Swift client for the specified username scoped to the
    current context project, unless a trust identifier is specified.

    If a trust identifier is present then the Swift client will be created
    based on a preauthorized token generated by the username scoped to the
    trust identifier.

    :param username: The username for the Swift client
    :param password: The password associated with the username
    :param trust_id: A trust identifier for scoping the username (optional)
    :returns: A Swift client object

    '''
    if trust_id:
        proxyauth = k.auth_for_proxy(username, password, trust_id)
        return client_from_token(k.token_from_auth(proxyauth))
    else:
        return swiftclient.Connection(
            auth_version='2.0',
            cacert=CONF.swift.ca_file,
            insecure=CONF.swift.api_insecure,
            authurl=su.retrieve_auth_url(),
            user=username,
            key=password,
            tenant_name=sh.retrieve_tenant(),
            retries=CONF.retries.retries_number,
            retry_on_ratelimit=True,
            starting_backoff=CONF.retries.retry_after,
            max_backoff=CONF.retries.retry_after)
Esempio n. 2
0
def client(username, password, trust_id=None):
    '''return a Swift client

    This will return a Swift client for the specified username scoped to the
    current context project, unless a trust identifier is specified.

    If a trust identifier is present then the Swift client will be created
    based on a preauthorized token generated by the username scoped to the
    trust identifier.

    :param username: The username for the Swift client
    :param password: The password associated with the username
    :param trust_id: A trust identifier for scoping the username (optional)
    :returns: A Swift client object

    '''
    if trust_id:
        proxyauth = k.auth_for_proxy(username, password, trust_id)
        return client_from_token(k.token_from_auth(proxyauth))
    else:
        return swiftclient.Connection(
            auth_version='2.0',
            cacert=CONF.swift.ca_file,
            insecure=CONF.swift.api_insecure,
            authurl=su.retrieve_auth_url(CONF.keystone.endpoint_type),
            user=username,
            key=password,
            tenant_name=sh.retrieve_tenant(),
            retries=CONF.retries.retries_number,
            retry_on_ratelimit=True,
            starting_backoff=CONF.retries.retry_after,
            max_backoff=CONF.retries.retry_after)
Esempio n. 3
0
def client(username, password, trust_id=None):
    '''return a Swift client

    This will return a Swift client for the specified username scoped to the
    current context project, unless a trust identifier is specified.

    If a trust identifier is present then the Swift client will be created
    based on a preauthorized token generated by the username scoped to the
    trust identifier.

    :param username: The username for the Swift client
    :param password: The password associated with the username
    :param trust_id: A trust identifier for scoping the username (optional)
    :returns: A Swift client object

    '''
    client_kwargs = dict(auth_version='2.0')
    if trust_id:
        proxyclient = k.client_for_proxy_user(username, password, trust_id)
        client_kwargs.update(preauthurl=su.retrieve_preauth_url(),
                             preauthtoken=proxyclient.auth_token)
    else:
        client_kwargs.update(authurl=su.retrieve_auth_url(),
                             user=username,
                             key=password,
                             tenant_name=sh.retrieve_tenant())

    return swiftclient.Connection(**client_kwargs)
Esempio n. 4
0
def client(username, password, trust_id=None):
    '''return a Swift client

    This will return a Swift client for the specified username scoped to the
    current context project, unless a trust identifier is specified.

    If a trust identifier is present then the Swift client will be created
    based on a preauthorized token generated by the username scoped to the
    trust identifier.

    :param username: The username for the Swift client
    :param password: The password associated with the username
    :param trust_id: A trust identifier for scoping the username (optional)
    :returns: A Swift client object

    '''
    if trust_id:
        proxyclient = k.client_for_proxy_user(username, password, trust_id)
        return client_from_token(proxyclient.auth_token)
    else:
        return swiftclient.Connection(auth_version='2.0',
                                      cacert=CONF.swift.ca_file,
                                      insecure=CONF.swift.api_insecure,
                                      authurl=su.retrieve_auth_url(),
                                      user=username,
                                      key=password,
                                      tenant_name=sh.retrieve_tenant())
Esempio n. 5
0
def get_swift_configs():
    configs = x.load_hadoop_xml_defaults('swift/resources/conf-template.xml')
    for conf in configs:
        if conf['name'] == HADOOP_SWIFT_AUTH_URL:
            conf['value'] = su.retrieve_auth_url() + "tokens/"
        if conf['name'] == HADOOP_SWIFT_TENANT:
            conf['value'] = retrieve_tenant()

    result = [cfg for cfg in configs if cfg['value']]
    LOG.info("Swift would be integrated with the following "
             "params: %s", result)
    return result
Esempio n. 6
0
def get_swift_configs():
    configs = x.load_hadoop_xml_defaults("swift/resources/conf-template.xml")
    for conf in configs:
        if conf["name"] == HADOOP_SWIFT_AUTH_URL:
            conf["value"] = su.retrieve_auth_url() + "tokens/"
        if conf["name"] == HADOOP_SWIFT_TENANT:
            conf["value"] = retrieve_tenant()
        if CONF.os_region_name and conf["name"] == HADOOP_SWIFT_REGION:
            conf["value"] = CONF.os_region_name

    result = [cfg for cfg in configs if cfg["value"]]
    LOG.info(_LI("Swift would be integrated with the following " "params: {result}").format(result=result))
    return result
Esempio n. 7
0
def get_swift_configs():
    configs = x.load_hadoop_xml_defaults('swift/resources/conf-template.xml')
    for conf in configs:
        if conf['name'] == HADOOP_SWIFT_AUTH_URL:
            conf['value'] = su.retrieve_auth_url() + "auth/tokens/"
        if conf['name'] == HADOOP_SWIFT_TENANT:
            conf['value'] = retrieve_tenant()
        if CONF.os_region_name and conf['name'] == HADOOP_SWIFT_REGION:
            conf['value'] = CONF.os_region_name

    result = [cfg for cfg in configs if cfg['value']]
    LOG.info("Swift would be integrated with the following "
             "params: {result}".format(result=result))
    return result
Esempio n. 8
0
def get_swift_configs():
    configs = x.load_hadoop_xml_defaults('swift/resources/conf-template.xml')
    for conf in configs:
        if conf['name'] == HADOOP_SWIFT_AUTH_URL:
            conf['value'] = su.retrieve_auth_url() + "auth/tokens/"
        if conf['name'] == HADOOP_SWIFT_TENANT:
            conf['value'] = retrieve_tenant()
        if CONF.os_region_name and conf['name'] == HADOOP_SWIFT_REGION:
            conf['value'] = CONF.os_region_name
        if conf['name'] == HADOOP_SWIFT_DOMAIN_NAME:
            # NOTE(jfreud): Don't be deceived here... Even though there is an
            # attribute provided by context called domain_name, it is used for
            # domain scope, and hadoop-swiftfs always authenticates using
            # project scope. The purpose of the setting below is to override
            # the default value for project domain and user domain, domain id
            # as 'default', which may not always be correct.
            # TODO(jfreud): When hadoop-swiftfs allows it, stop hoping that
            # project_domain_name is always equal to user_domain_name.
            conf['value'] = context.current().project_domain_name

    result = [cfg for cfg in configs if cfg['value']]
    LOG.info("Swift would be integrated with the following "
             "params: {result}".format(result=result))
    return result
Esempio n. 9
0
def _get_conn(user, password):
    return swiftclient.Connection(su.retrieve_auth_url(),
                                  user,
                                  password,
                                  tenant_name=swift_helper.retrieve_tenant(),
                                  auth_version="2.0")
Esempio n. 10
0
def _get_conn(user, password):
    return swiftclient.Connection(su.retrieve_auth_url(),
                                  user,
                                  password,
                                  tenant_name=CONF.os_admin_tenant_name,
                                  auth_version="2.0")
Esempio n. 11
0
 def _assert(uri):
     self.setup_context(auth_uri=uri)
     self.assertEqual(correct, utils.retrieve_auth_url())
Esempio n. 12
0
 def _assert(uri):
     url_for_mock.return_value = uri
     self.assertEqual(correct, utils.retrieve_auth_url())
Esempio n. 13
0
 def _assert(uri):
     url_for_mock.return_value = uri
     self.assertEqual(correct, utils.retrieve_auth_url())
Esempio n. 14
0
def retrieve_auth_url(endpoint_type="publicURL", **kwargs):
    return utils.retrieve_auth_url(endpoint_type)
Esempio n. 15
0
 def _assert(uri):
     self.setup_context(auth_uri=uri)
     self.assertEqual(correct, utils.retrieve_auth_url())
Esempio n. 16
0
def _get_conn(user, password):
    return swiftclient.Connection(su.retrieve_auth_url(),
                                  user,
                                  password,
                                  tenant_name=swift_helper.retrieve_tenant(),
                                  auth_version="2.0")
Esempio n. 17
0
def _get_conn(user, password):
    return swiftclient.Connection(su.retrieve_auth_url(),
                                  user,
                                  password,
                                  tenant_name=CONF.os_admin_tenant_name,
                                  auth_version="2.0")