def authenticate(): """Authentication For Openstack API. Pulls the full Openstack Service Catalog Credentials are the Users API Username and Key/Password "osauth" has a Built in Rackspace Method for Authentication Set a DC Endpoint and Authentication URL for the OpenStack environment """ # Setup the request variables url = auth.parse_region() a_url = http.parse_url(url=url, auth=True) auth_json = auth.parse_reqtype() # remove the prefix for the Authentication URL if Found LOG.debug("POST == REQUEST DICT > JSON DUMP %s", auth_json) auth_json_req = json.dumps(auth_json) headers = {"Content-Type": "application/json"} # Send Request request = ("POST", a_url.path, auth_json_req, headers) resp_read = auth.request_process(aurl=a_url, req=request) LOG.debug("POST Authentication Response %s", resp_read) try: auth_resp = json.loads(resp_read) except ValueError as exp: LOG.error("Authentication Failure %s\n%s", exp, traceback.format_exc()) raise turbo.SystemProblem("JSON Decode Failure. ERROR: %s - RESP %s" % (exp, resp_read)) else: auth_info = auth.parse_auth_response(auth_resp) token, tenant, user, inet, enet, cnet, acfep = auth_info report.reporter(msg=("API Access Granted. TenantID: %s Username: %s" % (tenant, user)), prt=False, log=True) return token, tenant, user, inet, enet, cnet, a_url, acfep
def test_parse_reqtype_token(self, mock_log): args = {'os_user': '******', 'os_token': 'TEST-TOKEN'} expected_return = {'auth': {'token': {'id': 'TEST-TOKEN'}}} with mock.patch('turbolift.utils.auth_utils.ARGS', args): ab = auth_utils.parse_reqtype() self.assertEqual(ab, expected_return) self.assertTrue(mock_log.debug.called)
def authenticate(): """Authentication For Openstack API. Pulls the full Openstack Service Catalog Credentials are the Users API Username and Key/Password "osauth" has a Built in Rackspace Method for Authentication Set a DC Endpoint and Authentication URL for the OpenStack environment """ # Setup the request variables a_url = "https://zebra.zerovm.org/auth/v1.0" #a_url = http.parse_url(url=url, auth=True) auth_json = auth.parse_reqtype() print auth_json # remove the prefix for the Authentication URL if Found # LOG.debug('POST == REQUEST DICT > JSON DUMP %s', auth_json) # auth_json_req = json.dumps(auth_json) headers = { 'Content-Type': 'application/json', "X-Auth-User": auth_json['auth']['passwordCredentials']['username'], "X-Auth-Key": auth_json['auth']['passwordCredentials']['password']} # Send Request try: auth_resp = requests.get( url=a_url, headers=headers ) if auth_resp.status_code >= 300: raise SystemExit( 'Authentication Failure, %s %s' % (auth_resp.status_code, auth_resp.reason) ) except ValueError as exp: LOG.error('Authentication Failure %s\n%s', exp, traceback.format_exc()) raise turbo.SystemProblem('JSON Decode Failure. ERROR: %s' % exp) else: LOG.debug('POST Authentication Response %s', auth_resp.json()) #auth_info = auth.parse_auth_response(auth_resp.json()) #token, tenant, user, inet, enet, cnet, acfep = auth_info token = auth_resp.headers['x-auth-token'] tenant, user = auth_json['auth']['passwordCredentials']['username'].split(":") inet = urlparse.urlparse(auth_resp.headers['x-storage-url']) enet = inet cnet = None acfep = inet report.reporter( msg=('API Access Granted. TenantID: %s Username: %s' % (tenant, user)), prt=False, log=True ) return token, tenant, user, inet, enet, cnet, urlparse.urlparse(a_url), acfep
def test_parse_reqtype_password(self, mock_log): args = {'os_user': '******', 'os_password': '******'} expected_return = { 'auth': { 'passwordCredentials': { 'username': '******', 'password': '******' } } } with mock.patch('turbolift.utils.auth_utils.ARGS', args): ab = auth_utils.parse_reqtype() self.assertEqual(ab, expected_return) self.assertTrue(mock_log.debug.called)
def test_parse_reqtype_apikey(self, mock_log): args = {'os_user': '******', 'os_apikey': 'TEST-APIKEY'} expected_return = { 'auth': { 'RAX-KSKEY:apiKeyCredentials': { 'username': '******', 'apiKey': 'TEST-APIKEY' } } } with mock.patch('turbolift.utils.auth_utils.ARGS', args): ab = auth_utils.parse_reqtype() self.assertEqual(ab, expected_return) self.assertTrue(mock_log.debug.called)
def authenticate(): """Authentication For Openstack API. Pulls the full Openstack Service Catalog Credentials are the Users API Username and Key/Password "osauth" has a Built in Rackspace Method for Authentication Set a DC Endpoint and Authentication URL for the OpenStack environment """ # Setup the request variables a_url = "https://zebra.zerovm.org/auth/v1.0" #a_url = http.parse_url(url=url, auth=True) auth_json = auth.parse_reqtype() print auth_json # remove the prefix for the Authentication URL if Found # LOG.debug('POST == REQUEST DICT > JSON DUMP %s', auth_json) # auth_json_req = json.dumps(auth_json) headers = { 'Content-Type': 'application/json', "X-Auth-User": auth_json['auth']['passwordCredentials']['username'], "X-Auth-Key": auth_json['auth']['passwordCredentials']['password'] } # Send Request try: auth_resp = requests.get(url=a_url, headers=headers) if auth_resp.status_code >= 300: raise SystemExit('Authentication Failure, %s %s' % (auth_resp.status_code, auth_resp.reason)) except ValueError as exp: LOG.error('Authentication Failure %s\n%s', exp, traceback.format_exc()) raise turbo.SystemProblem('JSON Decode Failure. ERROR: %s' % exp) else: LOG.debug('POST Authentication Response %s', auth_resp.json()) #auth_info = auth.parse_auth_response(auth_resp.json()) #token, tenant, user, inet, enet, cnet, acfep = auth_info token = auth_resp.headers['x-auth-token'] tenant, user = auth_json['auth']['passwordCredentials'][ 'username'].split(":") inet = urlparse.urlparse(auth_resp.headers['x-storage-url']) enet = inet cnet = None acfep = inet report.reporter(msg=('API Access Granted. TenantID: %s Username: %s' % (tenant, user)), prt=False, log=True) return token, tenant, user, inet, enet, cnet, urlparse.urlparse( a_url), acfep
def authenticate(): """Authentication For Openstack API. Pulls the full Openstack Service Catalog Credentials are the Users API Username and Key/Password "osauth" has a Built in Rackspace Method for Authentication Set a DC Endpoint and Authentication URL for the OpenStack environment """ # Setup the request variables url = auth.parse_region() LOG.debug('Raw Auth URL: [ %s ]', url) a_url = http.parse_url(url=url, auth=True) headers = { 'Content-Type': 'application/json', 'Accept': 'application/json' } headers.update(auth.get_headers() or {}) auth_json = auth.parse_reqtype() or {} LOG.debug('Parsed Auth URL: [ %s ]', a_url) # remove the prefix for the Authentication URL if Found auth_json_req = json.dumps(auth_json) LOG.debug('Request JSON: [ %s ]', auth_json_req) LOG.debug('Request Headers: [ %s ]', headers) # Send Request try: auth_resp = auth.auth_request(a_url, headers=headers, body=auth_json_req) if auth_resp.status_code >= 300: raise SystemExit( 'Authentication Failure, %s %s' % (auth_resp.status_code, auth_resp.reason) ) except ValueError as exp: LOG.error('Authentication Failure %s\n%s', exp, traceback.format_exc()) raise turbo.SystemProblem('JSON Decode Failure. ERROR: %s' % exp) else: auth_info = auth.parse_auth_response(auth_resp) token, tenant, user, inet, enet, cnet, acfep = auth_info report.reporter( msg=('API Access Granted. TenantID: %s Username: %s' % (tenant, user)), prt=False, log=True ) return token, tenant, user, inet, enet, cnet, a_url, acfep
def test_parse_reqtype_token(self, mock_log): args = { 'os_user': '******', 'os_token': 'TEST-TOKEN' } expected_return = { 'auth': { 'token': { 'id': 'TEST-TOKEN' } } } with mock.patch('turbolift.utils.auth_utils.ARGS', args): ab = auth_utils.parse_reqtype() self.assertEqual(ab, expected_return) self.assertTrue(mock_log.debug.called)
def test_parse_reqtype_apikey(self, mock_log): args = { 'os_user': '******', 'os_apikey': 'TEST-APIKEY' } expected_return = { 'auth': { 'RAX-KSKEY:apiKeyCredentials': { 'username': '******', 'apiKey': 'TEST-APIKEY' } } } with mock.patch('turbolift.utils.auth_utils.ARGS', args): ab = auth_utils.parse_reqtype() self.assertEqual(ab, expected_return) self.assertTrue(mock_log.debug.called)
def test_parse_reqtype_password(self, mock_log): args = { 'os_user': '******', 'os_password': '******' } expected_return = { 'auth': { 'passwordCredentials': { 'username': '******', 'password': '******' } } } with mock.patch('turbolift.utils.auth_utils.ARGS', args): ab = auth_utils.parse_reqtype() self.assertEqual(ab, expected_return) self.assertTrue(mock_log.debug.called)
def authenticate(): """Authentication For Openstack API. Pulls the full Openstack Service Catalog Credentials are the Users API Username and Key/Password "osauth" has a Built in Rackspace Method for Authentication Set a DC Endpoint and Authentication URL for the OpenStack environment """ # Setup the request variables url = auth.parse_region() LOG.debug('Raw Auth URL: [ %s ]', url) a_url = http.parse_url(url=url, auth=True) headers = { 'Content-Type': 'application/json', 'Accept': 'application/json' } headers.update(auth.get_headers() or {}) auth_json = auth.parse_reqtype() or {} LOG.debug('Parsed Auth URL: [ %s ]', a_url) # remove the prefix for the Authentication URL if Found auth_json_req = json.dumps(auth_json) LOG.debug('Request JSON: [ %s ]', auth_json_req) LOG.debug('Request Headers: [ %s ]', headers) # Send Request try: auth_resp = auth.auth_request(a_url, headers=headers, body=auth_json_req) if auth_resp.status_code >= 300: raise SystemExit('Authentication Failure, %s %s' % (auth_resp.status_code, auth_resp.reason)) except ValueError as exp: LOG.error('Authentication Failure %s\n%s', exp, traceback.format_exc()) raise turbo.SystemProblem('JSON Decode Failure. ERROR: %s' % exp) else: auth_info = auth.parse_auth_response(auth_resp) token, tenant, user, inet, enet, cnet, acfep = auth_info report.reporter(msg=('API Access Granted. TenantID: %s Username: %s' % (tenant, user)), prt=False, log=True) return token, tenant, user, inet, enet, cnet, a_url, acfep
def authenticate(): """Authentication For Openstack API. Pulls the full Openstack Service Catalog Credentials are the Users API Username and Key/Password "osauth" has a Built in Rackspace Method for Authentication Set a DC Endpoint and Authentication URL for the OpenStack environment :param auth_dict: required parameters are auth_url """ # Setup the request variables url, rax = auth.parse_region() a_url = http.parse_url(url=url, auth=True) auth_json = auth.parse_reqtype() # remove the prefix for the Authentication URL if Found LOG.debug('POST == REQUEST DICT > JSON DUMP %s', auth_json) auth_json_req = json.dumps(auth_json) headers = {'Content-Type': 'application/json'} # Send Request request = ('POST', a_url.path, auth_json_req, headers) resp_read = auth.request_process(aurl=a_url, req=request) LOG.debug('POST Authentication Response %s', resp_read) try: auth_resp = json.loads(resp_read) except ValueError as exp: LOG.error('Authentication Failure %s\n%s', exp, traceback.format_exc()) raise turbo.SystemProblem('JSON Decode Failure. ERROR: %s - RESP %s' % (exp, resp_read)) else: auth_info = auth.parse_auth_response(auth_resp) token, tenant, user, inet, enet, cnet, acfep = auth_info report.reporter(msg=('API Access Granted. TenantID: %s Username: %s' % (tenant, user)), prt=False, log=True) return token, tenant, user, inet, enet, cnet, a_url, acfep