本文整理汇总了Python中swiftclient.client.get_auth函数的典型用法代码示例。如果您正苦于以下问题:Python get_auth函数的具体用法?Python get_auth怎么用?Python get_auth使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_auth函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_auth_v2_insecure
def test_auth_v2_insecure(self):
os_options = {'tenant_name': 'foo'}
c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(
os_options, None)
auth_url_secure = 'https://www.tests.com'
auth_url_insecure = 'https://www.tests.com/invalid-certificate'
url, token = c.get_auth(auth_url_secure, 'asdf', 'asdf',
os_options=os_options, auth_version='2.0')
self.assertTrue(url.startswith("http"))
self.assertTrue(token)
url, token = c.get_auth(auth_url_insecure, 'asdf', 'asdf',
os_options=os_options, auth_version='2.0',
insecure=True)
self.assertTrue(url.startswith("http"))
self.assertTrue(token)
self.assertRaises(c.ClientException, c.get_auth,
auth_url_insecure, 'asdf', 'asdf',
os_options=os_options, auth_version='2.0')
self.assertRaises(c.ClientException, c.get_auth,
auth_url_insecure, 'asdf', 'asdf',
os_options=os_options, auth_version='2.0',
insecure=False)
示例2: test_auth_v2_insecure
def test_auth_v2_insecure(self):
os_options = {"tenant_name": "foo"}
c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(os_options, None)
auth_url_secure = "https://www.tests.com"
auth_url_insecure = "https://www.tests.com/invalid-certificate"
url, token = c.get_auth(auth_url_secure, "asdf", "asdf", os_options=os_options, auth_version="2.0")
self.assertTrue(url.startswith("http"))
self.assertTrue(token)
url, token = c.get_auth(
auth_url_insecure, "asdf", "asdf", os_options=os_options, auth_version="2.0", insecure=True
)
self.assertTrue(url.startswith("http"))
self.assertTrue(token)
self.assertRaises(
c.ClientException, c.get_auth, auth_url_insecure, "asdf", "asdf", os_options=os_options, auth_version="2.0"
)
self.assertRaises(
c.ClientException,
c.get_auth,
auth_url_insecure,
"asdf",
"asdf",
os_options=os_options,
auth_version="2.0",
insecure=False,
)
示例3: wrapper
def wrapper(*args, **kw):
storage_url = args[0].session.get('storage_url', '')
auth_token = args[0].session.get('auth_token', '')
username = args[0].session.get('username', '')
password = args[0].session.get('password', '')
# If the following variables are available, attempt to get an
# auth token
if (storage_url and auth_token and username and password):
try:
client.head_account(storage_url, auth_token)
return fn(*args, **kw)
except:
#Attempt to get a new auth token
try:
auth_version = settings.SWIFT_AUTH_VERSION or 1
(storage_url, auth_token) = client.get_auth(
settings.SWIFT_AUTH_URL, username, password,
auth_version=auth_version)
args[0].session['auth_token'] = auth_token
args[0].session['storage_url'] = storage_url
return fn(*args, **kw)
except:
# Failure to get an auth token, tell the user the session
# has expired.
messages.error(args[0], _("Session expired."))
return redirect(swiftbrowser.views.login)
示例4: test_auth_v2_with_tenant_user_in_user
def test_auth_v2_with_tenant_user_in_user(self):
c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0
url, token = c.get_auth('http://www.test.com', 'foo:bar', 'asdf',
os_options={},
auth_version="2.0")
self.assertTrue(url.startswith("http"))
self.assertTrue(token)
示例5: test_auth_v2
def test_auth_v2(self):
c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0
url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf',
os_options={'tenant_name': 'asdf'},
auth_version="2.0")
self.assertTrue(url.startswith("http"))
self.assertTrue(token)
示例6: main
def main():
os_options = {'tenant_name': ACCOUNT}
url, token = c.get_auth( 'http://' + AUTH_IP + ":"
+ AUTH_PORT + '/v2.0',
ACCOUNT + ':' + USER_NAME,
PASSWORD,
os_options = os_options,
auth_version = '2.0' )
print 'Deploying Identity storlet and dependencies'
deploy_storlet(url, token)
print "Invoking Identity storlet on PUT"
invoke_storlet(url, token,'PUT')
progress_msg("Invoking Identity storlet on 1GB file PUT")
invoke_storlet_on_1GB_file(url, token)
print "Invoking Identity storlet on PUT with execution of dependency"
invoke_storlet(url, token,'PUT', {'execute' : 'true'})
print "Invoking Identity storlet on PUT with double"
invoke_storlet(url, token,'PUT', {'double' : 'true'})
print "Invoking Identity storlet on GET"
invoke_storlet(url, token,'GET')
print "Invoking Identity storlet on GET with double"
invoke_storlet(url, token,'GET', {'double' : 'true'})
print "Invoking Identity storlet on GET with execution of dependency"
invoke_storlet(url, token,'GET',{'execute' : 'true'})
print "Invoking Identity storlet in Task"
示例7: main
def main():
os_options = {'tenant_name': ACCOUNT}
url, token = c.get_auth( 'http://' + AUTH_IP + ":"
+ AUTH_PORT + '/v2.0',
ACCOUNT + ':' + USER_NAME,
PASSWORD,
os_options = os_options,
auth_version = '2.0' )
print 'Deploying ReadHeaders storlet'
deploy_storlet(url, token, 'ReadHeadersStorlet',
'readheadersstorlet-1.0.jar')
print 'Deploying ReadHeaders dependency'
put_storlet_dependency(url, token, 'json-simple-1.1.1.jar',
'../StorletSamples/ReadHeadersStorlet/lib')
print 'Deploying CSS storlet'
deploy_storlet(url, token, 'CssStorlet', 'cssstorlet-1.0.jar')
print "Invoking CSS storlet in PUT mode"
invoke_storlet(url, token, 'CssStorlet', 'cssstorlet-1.0.jar',
'testDataCss', 'PUT')
print "Invoking ReadHeaders storlet in GET mode"
headers, content = invoke_storlet(url, token, 'ReadHeadersStorlet',
'readheadersstorlet-1.0.jar', 'testDataCss', 'GET')
assert '{"Square-Sums":"[2770444.6455999985, 1.9458262030000027E7,' \
+ ' 95.17999999999981]","Lines-Num":"356","Sums":"[27037.0' \
+ '40000000008, 83229.09999999998, 168.39999999999947]"}'\
== content
print "ReadHeaders test finished"
示例8: main
def main():
os_options = {"tenant_name": ACCOUNT}
url, token = c.get_auth(
"http://" + AUTH_IP + ":" + AUTH_PORT + "/v2.0",
ACCOUNT + ":" + USER_NAME,
PASSWORD,
os_options=os_options,
auth_version="2.0",
)
sys.stdout.write("Enter storlet jar name: ")
storlet_jar = sys.stdin.readline().rstrip()
print("Your jar file has the following classes:")
list_classes(storlet_jar)
sys.stdout.write("Please enter storlet main class: ")
storlet_main_class = sys.stdin.readline().rstrip()
print("Please enter dependency jars (leave a blank line when you are " "done):")
dependency_jars = []
dependencies = []
dependency_jar = sys.stdin.readline().rstrip()
while dependency_jar:
dependency_jars.append(dependency_jar)
dependencies.append(os.path.basename(dependency_jar))
dependency_jar = sys.stdin.readline().rstrip()
deploy_storlet(url, token, storlet_jar, storlet_main_class, dependency_jars, dependencies)
示例9: authDomainUser
def authDomainUser(self, _realmname, username, password, environ):
"""Returns True if this username/password pair is valid for the realm,
False otherwise. Used for basic authentication.
"""
try:
username = username.replace(';', ':')
kwargs = {}
if self.auth_version == 2:
tenantname, username = username.split(':')
kwargs = {
'os_options': {
'tenant_name': tenantname}, 'auth_version': 2}
(storage_url, auth_token) = client.get_auth(
self.swift_auth_url, username, password, **kwargs)
print storage_url, auth_token
environ["swift_storage_url"] = storage_url
environ["swift_auth_token"] = auth_token
environ["swift_usernampe"] = username
environ["swift_password"] = password
environ["swift_auth_url"] = self.swift_auth_url
environ["insecure"] = self.insecure
return True
except client.ClientException:
return False
except socket.gaierror:
return False
示例10: test_auth_v2_with_tenant_user_in_user_no_os_options
def test_auth_v2_with_tenant_user_in_user_no_os_options(self):
tenant_option = {'tenant_name': 'foo'}
c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(tenant_option)
url, token = c.get_auth('http://www.test.com', 'foo:bar', 'asdf',
auth_version="2.0")
self.assertTrue(url.startswith("http"))
self.assertTrue(token)
示例11: connect
def connect(self, force=False):
if self.http_conn is not None and not force:
return
swift_url, self.token = swift.get_auth(
auth_url=self.auth_url,
user=self.username,
key=self.password,
auth_version=self.auth_ver,
tenant_name=self.tenant,
)
if self.debug:
print(self.auth_url)
print(self.token)
print(self.swift_url)
print(swift_url)
print
if not swift_url == self.swift_url:
print("Different swift_url returned from swift")
self.http_conn = swift.http_connection(self.swift_url)
if self.debug:
print(self.http_conn)
print
示例12: login
def login(request):
""" Tries to login user and sets session data """
request.session.flush()
form = LoginForm(request.POST or None)
if form.is_valid():
username = form.cleaned_data['username']
password = form.cleaned_data['password']
tenant = settings.SWIFT_TENANT_NAME + ":" + username
try:
auth_version = settings.SWIFT_AUTH_VERSION or 1
(storage_url, auth_token) = client.get_auth(
settings.SWIFT_AUTH_URL, tenant, password,
auth_version=auth_version)
request.session['auth_token'] = auth_token
request.session['storage_url'] = storage_url
request.session['username'] = tenant
request.session['user'] = username
return redirect(containerview)
except client.ClientException:
messages.add_message(request, messages.ERROR, _("Login failed."))
return render_to_response('login.html', {'form': form, },
context_instance=RequestContext(request))
示例13: authenticate
def authenticate(request):
""" Authenticating Swift user. Sets authentication credentials in cookies
:param request: accepts JSON object containing account, user, password
:returns Storage URL, Authentication Token"""
try:
request.session.flush()
auth_data_dict = request.data
(username, password) = auth_data_dict[account_key] + ':' + auth_data_dict[username_key], auth_data_dict[
pass_key]
auth_url = settings.SWIFT_AUTH_URL
(storage_url, auth_token) = client.get_auth(auth_url, username, password)
storage_url = settings.BASE_URL + storage_url.split(':8080')[1]
request.session['auth_token'], request.session['storage_url'], request.session['username'] \
= auth_token, storage_url, username
request.session[pass_key] = password
return Response({'username': username, 'auth_token': auth_token, 'storage_url': storage_url},
status=status.HTTP_200_OK)
except swift_exception.ClientException as e:
print e
return Response(e.message, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
except exceptions.KeyError as e:
print e
return Response('JSON object key error: ' + str(e), status=status.HTTP_400_BAD_REQUEST)
except exceptions.ValueError:
print 'No JSON FOUND'
return Response('No JSON object found', status=status.HTTP_400_BAD_REQUEST)
except Exception as e:
print e
return Response(e, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
示例14: main
def main():
os_options = {'tenant_name': ACCOUNT}
url, token = c.get_auth( 'http://' + AUTH_IP + ":"
+ AUTH_PORT + '/v2.0',
ACCOUNT + ':' + USER_NAME,
PASSWORD,
os_options = os_options,
auth_version = '2.0' )
# print('Creating containers for auxiliary files')
create_container(url, token, 'myobjects')
create_container(url, token, 'container1')
create_container(url, token, 'container2')
create_container(url, token, 'container3')
# print('Creating Auxiliary files')
progress_msg("Creating SLO chunks for upload")
create_local_chunks()
progress_msg("Uploading SLO chunks and assembly")
put_SLO(url, token)
progress_msg("Downloading SLO")
get_SLO(url, token)
progress_msg("Invoking storlet on SLO in GET")
invoke_identity_on_get_SLO(url, token)
# YM comment out 2 lines - temporary only!
progress_msg("Invoking storlet on SLO in GET with double")
invoke_identity_on_get_SLO_double(url, token)
#progress_msg("Invoking storlet on SLO in partial GET")
#invoke_identity_on_partial_get_SLO(url, token)
delete_local_chunks()
示例15: test_auth_v2_tenant_name_no_os_options
def test_auth_v2_tenant_name_no_os_options(self):
tenant_option = {"tenant_name": "asdf"}
c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(tenant_option)
url, token = c.get_auth(
"http://www.test.com", "asdf", "asdf", tenant_name="asdf", os_options={}, auth_version="2.0"
)
self.assertTrue(url.startswith("http"))
self.assertTrue(token)