예제 #1
0
    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)
    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)
    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,
        )
예제 #4
0
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()
예제 #5
0
def get_token():
    storageURL, authtoken = client.get_auth(authen.auth_url + ':35357/v2.0',
                                            authen.username,
                                            authen.password,
                                            tenant_name=authen.tenant_name,
                                            auth_version=2)
    return storageURL, authtoken
예제 #6
0
    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
예제 #7
0
    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
예제 #8
0
 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)
예제 #9
0
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']
        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)
            request.session['auth_token'] = auth_token
            request.session['storage_url'] = storage_url
            request.session['username'] = 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))
 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)
예제 #11
0
    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)
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"
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'})
예제 #14
0
    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', '')

        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:
                messages.error(args[0], _("Session expired."))
        return {'errors': 'true'}
예제 #15
0
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)
예제 #16
0
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)
예제 #17
0
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()
 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)
예제 #19
0
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"
예제 #20
0
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"
예제 #21
0
    def test_auth_v2_with_tenant_user_in_user(self):
        def read(*args, **kwargs):
            acct_url = 'http://127.0.01/AUTH_FOO'
            body = {
                'access': {
                    'serviceCatalog': [{
                        u'endpoints': [{
                            'publicURL': acct_url
                        }],
                        'type': 'object-store'
                    }],
                    'token': {
                        'id': 'XXXXXXX'
                    }
                }
            }
            return c.json_dumps(body)

        c.http_connection = self.fake_http_connection(200, return_read=read)
        url, token = c.get_auth('http://www.test.com',
                                'foo:bar',
                                'asdf',
                                auth_version="2.0")
        self.assertTrue(url.startswith("http"))
        self.assertTrue(token)
 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)
예제 #23
0
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))
예제 #24
0
def get_token():
    storageURL, authtoken = client.get_auth(authen.auth_url + ':35357/v2.0',
                                              authen.username,
                                              authen.password,
                                              tenant_name = authen.tenant_name,
                                              auth_version = 2
                                             )
    return storageURL, authtoken
예제 #25
0
 def test_auth_v2(self):
     os_options = {'tenant_name': 'asdf'}
     c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(os_options)
     url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf',
                             os_options=os_options,
                             auth_version="2.0")
     self.assertTrue(url.startswith("http"))
     self.assertTrue(token)
예제 #26
0
 def test_auth_v1(self):
     c.http_connection = self.fake_http_connection(200)
     url, token = c.get_auth('http://www.test.com',
                             'asdf',
                             'asdf',
                             auth_version="1.0")
     self.assertEquals(url, None)
     self.assertEquals(token, None)
 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)
예제 #28
0
 def test_auth_v1(self):
     c.http_connection = self.fake_http_connection(200, auth_v1=True)
     url, token = c.get_auth('http://www.test.com',
                             'asdf',
                             'asdf',
                             auth_version="1.0")
     self.assertEqual(url, 'storageURL')
     self.assertEqual(token, 'someauthtoken')
 def test_auth_v2_tenant_name_no_os_options(self):
     tenant_option = {'tenant_name': 'asdf'}
     c.get_auth_keystone = fake_get_auth_keystone(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)
 def test_auth_v2_with_os_region_name(self):
     os_options = {'region_name': 'good-region',
                   'tenant_name': 'asdf'}
     c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(os_options)
     url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf',
                             os_options=os_options,
                             auth_version="2.0")
     self.assertTrue(url.startswith("http"))
     self.assertTrue(token)
예제 #31
0
 def connect(self):
     auth = client.get_auth(self.authurl,
                            self.user_name,
                            self.user_pass,
                            tenant_name=self.tenant,
                            auth_version='2')
     self.storage_url = auth[0]
     self.http_conn = client.http_connection(self.storage_url)
     self.token = auth[1]
예제 #32
0
def get_swift_url_and_token(project_name):
    admin_user = settings.MANAGEMENT_ADMIN_USERNAME
    admin_passwd = settings.MANAGEMENT_ADMIN_PASSWORD
    keystone_url = settings.KEYSTONE_ADMIN_URL

    return swift_client.get_auth(keystone_url,
                                 project_name + ":" + admin_user,
                                 admin_passwd,
                                 auth_version="3")
    def test_auth_v1_insecure(self):
        c.http_connection = self.fake_http_connection(200, auth_v1=True)
        url, token = c.get_auth("http://www.test.com/invalid_cert", "asdf", "asdf", auth_version="1.0", insecure=True)
        self.assertEqual(url, "storageURL")
        self.assertEqual(token, "someauthtoken")

        self.assertRaises(
            c.ClientException, c.get_auth, "http://www.test.com/invalid_cert", "asdf", "asdf", auth_version="1.0"
        )
예제 #34
0
 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)
 def test_auth_v2_with_os_options(self):
     os_options = {'service_type': 'object-store',
                   'endpoint_type': 'internalURL',
                   'tenant_name': 'asdf'}
     c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(os_options)
     url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf',
                             os_options=os_options,
                             auth_version="2.0")
     self.assertTrue(url.startswith("http"))
     self.assertTrue(token)
예제 #36
0
 def test_auth_v2_with_os_region_name(self):
     os_options = {'region_name': 'good-region', 'tenant_name': 'asdf'}
     c.get_auth_keystone = fake_get_auth_keystone(os_options)
     url, token = c.get_auth('http://www.test.com',
                             'asdf',
                             'asdf',
                             os_options=os_options,
                             auth_version="2.0")
     self.assertTrue(url.startswith("http"))
     self.assertTrue(token)
예제 #37
0
 def test_auth_v2_with_os_options(self):
     os_options = {'service_type': 'object-store',
                   'endpoint_type': 'internalURL',
                   'tenant_name': 'asdf'}
     c.get_keystoneclient_2_0 = fake_get_keystoneclient_2_0(os_options)
     url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf',
                             os_options=os_options,
                             auth_version="2.0")
     self.assertTrue(url.startswith("http"))
     self.assertTrue(token)
 def test_auth_v2_with_project_id(self):
     os_options = {'project_id': 'asdf'}
     req_args = {'auth_version': '2.0'}
     c.get_auth_keystone = fake_get_auth_keystone(os_options,
                                                  required_kwargs=req_args)
     url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf',
                             os_options=os_options,
                             auth_version="2.0")
     self.assertTrue(url.startswith("http"))
     self.assertTrue(token)
 def test_auth_v3_with_tenant_name(self):
     # check the correct auth version is passed to get_auth_keystone
     os_options = {'tenant_name': 'asdf'}
     req_args = {'auth_version': '3'}
     c.get_auth_keystone = fake_get_auth_keystone(os_options,
                                                  required_kwargs=req_args)
     url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf',
                             os_options=os_options,
                             auth_version="3")
     self.assertTrue(url.startswith("http"))
     self.assertTrue(token)
def get_tempurl_key():
    (storage_url, auth_token) = client.get_auth(settings.SWIFT_AUTH_URL, settings.SWIFT_USER, settings.SWIFT_PASSWORD)

    meta = client.head_account(storage_url, auth_token)
    key = meta.get("x-account-meta-temp-url-key")
    if not key:
        key = random_key()
        headers = {"x-account-meta-temp-url-key": key}
        client.post_account(storage_url, auth_token, headers)

    return storage_url, key
예제 #41
0
 def test_auth_v2_tenant_name_no_os_options(self):
     tenant_option = {'tenant_name': 'asdf'}
     c.get_auth_keystone = fake_get_auth_keystone(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)
예제 #42
0
파일: rule.py 프로젝트: cy0713/controller
 def _get_admin_token(self):
     """
     Method called to obtain the admin credentials, which we need to deploy
     filters in accounts.
     """
     try:
         _, self.token = c.get_auth(self.admin_keystone_url,
                                    self.admin_project+":"+self.admin_user,
                                    self.admin_pass, auth_version="3")
     except:
         logger.error("Rule, There was an error gettting a token from keystone")
         raise Exception()
예제 #43
0
 def test_auth_v2_with_project_id(self):
     os_options = {'project_id': 'asdf'}
     req_args = {'auth_version': '2.0'}
     c.get_auth_keystone = fake_get_auth_keystone(os_options,
                                                  required_kwargs=req_args)
     url, token = c.get_auth('http://www.test.com',
                             'asdf',
                             'asdf',
                             os_options=os_options,
                             auth_version="2.0")
     self.assertTrue(url.startswith("http"))
     self.assertTrue(token)
예제 #44
0
def _reauthorize(request):
    print "Reauthorizing..."
    print "Old Token: ", request.session[auth_token_key]
    if not request.session.get('username') and not request.session.get(pass_key):
        raise swift_exception.ClientException('Authentication details not set in session.')
    (username, password) = request.session.get('username'), request.session.get(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'] = auth_token, storage_url
    print "New Token: ", request.session[auth_token_key]
    return storage_url, auth_token
예제 #45
0
    def test_auth_v1_insecure(self):
        c.http_connection = self.fake_http_connection(200, auth_v1=True)
        url, token = c.get_auth('http://www.test.com/invalid_cert',
                                'asdf', 'asdf',
                                auth_version='1.0',
                                insecure=True)
        self.assertEqual(url, 'storageURL')
        self.assertEqual(token, 'someauthtoken')

        self.assertRaises(c.ClientException, c.get_auth,
                          'http://www.test.com/invalid_cert',
                          'asdf', 'asdf',
                          auth_version='1.0')
예제 #46
0
 def test_auth_v3_with_tenant_name(self):
     # check the correct auth version is passed to get_auth_keystone
     os_options = {'tenant_name': 'asdf'}
     req_args = {'auth_version': '3'}
     c.get_auth_keystone = fake_get_auth_keystone(os_options,
                                                  required_kwargs=req_args)
     url, token = c.get_auth('http://www.test.com',
                             'asdf',
                             'asdf',
                             os_options=os_options,
                             auth_version="3")
     self.assertTrue(url.startswith("http"))
     self.assertTrue(token)
예제 #47
0
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 ExecDep storlet and dependencies'
    deploy_storlet(url, token)

    print "Invoking ExecDep storlet"
    invoke_storlet(url, token)
예제 #48
0
def swift_login(request, username, password):
    storage_url = auth_token = None

    settings = request.registry.settings
    auth_url = settings.get('swift.auth.url')
    auth_version = int(settings.get('swith.auth.version', 1))
    logger.debug('auth_url = %s', auth_url)

    try:
        (storage_url, auth_token) = client.get_auth(auth_url, username, password, auth_version=auth_version)
    except ClientException:
        raise Exception('swift login failed for user %s' % username)
    return dict(storage_url=storage_url, auth_token=auth_token)
    def test_auth_v1_insecure(self):
        c.http_connection = self.fake_http_connection(200, auth_v1=True)
        url, token = c.get_auth('http://www.test.com/invalid_cert',
                                'asdf', 'asdf',
                                auth_version='1.0',
                                insecure=True)
        self.assertEqual(url, 'storageURL')
        self.assertEqual(token, 'someauthtoken')

        self.assertRaises(c.ClientException, c.get_auth,
                          'http://www.test.com/invalid_cert',
                          'asdf', 'asdf',
                          auth_version='1.0')
 def test_auth_v2(self):
     def read(*args, **kwargs):
         acct_url = 'http://127.0.01/AUTH_FOO'
         body = {'access': {'serviceCatalog':
                                [{u'endpoints': [{'publicURL': acct_url}],
                                  'type': 'object-store'}],
                            'token': {'id': 'XXXXXXX'}}}
         return c.json_dumps(body)
     c.http_connection = self.fake_http_connection(200, return_read=read)
     url, token = c.get_auth('http://www.test.com', 'asdf', 'asdf',
                             tenant_name='asdf', auth_version="2.0")
     self.assertTrue(url.startswith("http"))
     self.assertTrue(token)
예제 #51
0
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 EecDep storlet and dependencies'
    deploy_storlet(url, token)
    
    print "Invoking ExecDep storlet"
    invoke_storlet(url, token)
예제 #52
0
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 Half storlet and dependencies'

    deploy_storlet(url, token)

    print "Invoking Half storlet on GET"
    assert (invoke_storlet(url, token, 'GET') == 'acegikmn')
    print "Invoking Half storlet on GET with byte ranges"
    assert (invoke_storlet(url, token, 'GET', headers={'range':
                                                       'bytes=5-10'}) == 'fhj')
def get_tempurl_key():
    (storage_url, auth_token) = client.get_auth(
        settings.SWIFT_AUTH_URL, settings.SWIFT_USER, settings.SWIFT_PASSWORD)

    try:
        meta = client.head_container(storage_url, auth_token,
                                     settings.SWIFT_CONTAINER)
        key = meta.get('x-container-meta-temp-url-key')
    except client.ClientException:
        client.put_container(storage_url, auth_token, settings.SWIFT_CONTAINER)
        key = None

    if not key:
        key = random_key()
        headers = {'x-container-meta-temp-url-key': key}
        client.post_container(storage_url, auth_token,
                              settings.SWIFT_CONTAINER, headers)

    return storage_url, key
예제 #54
0
    def register(self, filepath, protocol, extra=None):
        ''' Reigster filepath and protocol with the ID service.  If there is
        an interface specified use that.  The interface parameter is useful
        when testing on the same host as the ID service and you want to use
        the VM IP Auth '''

        if protocol == "swift":
            path_parts = filepath.split("/")
            object_name = path_parts.pop()
            url = "%s//%s/%s/%s" % ((path_parts[0], ) + tuple(path_parts[2:5]))
            container = "/".join(path_parts[5:])
            if self.swift_auth_url == self.os_auth_url:
                token = self.auth_token
            else:
                _, token = get_auth(
                    self.swift_auth_url,
                    "%s:%s" % (self.swift_tenant, self.swift_username),
                    self.swift_password)

            size = head_object(url, token, container,
                               object_name)["content-length"]

            swift = {
                "swift": {
                    "url": url,
                    "container": container,
                    "object": object_name,
                    "auth_url": self.swift_auth_url
                },
                "filesize": size
            }
            if extra:
                extra.update(swift)
            else:
                extra = swift

        record = {"filepath": filepath, "protocol": protocol}
        if extra:
            record.update(extra)

        return self.http_post("%s%s" % (self.id_service, self.ID_PATH),
                              json.dumps(record)).text
예제 #55
0
def get_auth(conf, user, passwd):
    """
    Get token string to access to swift

    :param conf: a dict of config parameters
    :returns: (swift endpoint url, token string)
    """
    auth_url = conf.auth_uri
    project = conf.project_name
    os_options = {
        'user_domain_name': conf.domain_name,
        'project_name': conf.project_name,
        'region_name': conf.region
    }
    url, token = client.get_auth(auth_url,
                                 project + ':' + user,
                                 passwd,
                                 os_options=os_options,
                                 auth_version=conf.auth_version)
    return url, token
예제 #56
0
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']
        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)
            request.session['auth_token'] = auth_token
            request.session['storage_url'] = storage_url
            request.session['username'] = username
            return redirect(containerview)

        except client.ClientException:
            traceback.print_exc()
            messages.add_message(request, messages.ERROR, _("Login failed."))

    if 'REMOTE_USER' in request.META.keys():
        try:
            headers = {'REMOTE_USER': request.META.get('REMOTE_USER')}
            auth = requests.get(settings.SWIFT_HTTP_AUTH_URL, headers=headers)
            request.session['auth_token'] = auth.headers['x-auth-token']
            request.session['storage_url'] = auth.headers['x-storage-url']
            request.session['username'] = request.META.get(
                'REMOTE_USER').split('@')[0]
            return redirect(containerview)
        except Exception:
            traceback.print_exc()
            messages.add_message(request, messages.ERROR,
                                 _("Login with REMOTE_USER failed."))

    return render_to_response('login.html', {
        'form': form,
    },
                              context_instance=RequestContext(request))
예제 #57
0
def main():
    init_path_dependant_params()

    print 'Getting token'
    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 myobjects container'
    c.put_container(url, token, 'myobjects')

    print 'Invoking test storlet'
    testTestStorlet(url, token)

    os.system('python execdep_test.py')
    os.system('python identity_storlet_test.py')
    os.system('python half_storlet_test.py')
    os.system('python metadata_storlet_test.py')
    os.system('python SLO_test.py')
예제 #58
0
def get_auth(conf):
    """
    Get token string to access to swift

    :param conf: a dict of config parameters
    :returns: (swift endpoint url, token string)
    """
    auth_url = conf['auth_uri']
    project = conf['project_name']
    os_options = {
        'user_domain_name': conf['domain_name'],
        'project_name': conf['project_name']
    }
    user = conf['user']
    passwd = conf['password']
    url, token = client.get_auth(auth_url,
                                 project + ':' + user,
                                 passwd,
                                 os_options=os_options,
                                 auth_version=conf['auth_version'])
    return url, token
예제 #59
0
def stg_authenticate(account, user, passwd, domain, admin=False):
    '''
    认证函数,如果认证成功,返回存储路径和token值
    :param account:  swift account账号, 在这就是系统编码
    :param user:   系统编码对应的用户
    :param passwd: 系统编码用户的密码
    :param system_env: 系统编码的系统环境
    :param admin (bool): 管理员标志位
    :return:
    '''
    try:
        auth_account = user
        auth_passwd = passwd
        auth_version = config.swift_auth_version or 1
        (storage_url, auth_token) = swclient.get_auth(config.swift_auth_url, auth_account, auth_passwd,
                                                      auth_version=auth_version, os_options={'project_name': account,
                                                                                             'project_domain_name': domain,
                                                                                             'user_domain_name': domain if not admin else "Default"})
        return (storage_url, auth_token)
    except Exception as ex:
        raise RuntimeError('swift authenticate fail ,the reason is %s' % ex)