def _get_swift_client():
    if RACK_CTX.fs_endpoint:
        try:
            d = json.loads(RACK_CTX.fs_endpoint)
            credentials = {
                "user": d["os_username"],
                "key": d["os_password"],
                "tenant_name": d["os_tenant_name"],
                "authurl": d["os_auth_url"],
                "auth_version": "2"
            }
            return swift_client.Connection(**credentials)
        except (ValueError, KeyError):
            msg = "The format of fs_endpoint is invalid."
            raise exceptions.InvalidFSEndpointError(msg)
    else:
        authurl = "http://%s:%d/auth/v1.0" % (RACK_CTX.proxy_ip, SWIFT_PORT)

    credentials = {
        "user": "rack:admin",
        "key": "admin",
        "authurl": authurl
    }
    swift = swift_client.Connection(**credentials)
    authurl, token = swift.get_auth()

    return swift_client.Connection(preauthurl=authurl, preauthtoken=token)
dataset/ETHPy150Open openstack/python-rackclient/rackclient/lib/syscall/default/file.py/_get_swift_client/original