def auth_request(url, headers=None, body=None): """Perform auth request for token.""" headers = headers or {} body = body or json.dumps({}) if get_authversion() == 'v1.0': # shouldnt need to allow 'stream' return http.get_request(url, headers, None) else: # shouldnt need to allow 'rpath' return http.post_request(url, headers, body=body)
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) LOG.debug('Parsed Auth URL: [ %s ]', a_url) auth_json = auth.parse_reqtype() # remove the prefix for the Authentication URL if Found auth_json_req = json.dumps(auth_json) LOG.debug('Request JSON: [ %s ]', auth_json_req) headers = {'Content-Type': 'application/json'} # Send Request try: auth_resp = http.post_request( url=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: 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 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 _header_poster(self, url, rpath, fheaders): """POST Headers on a specified object in the container. :param url: :param rpath: :param fheaders: """ # perform Object POST request for header update. resp = http.post_request(url=url, rpath=rpath, headers=fheaders) self.resp_exception(resp=resp) report.reporter(msg='STATUS: %s MESSAGE: %s REASON: %s' % (resp.status_code, resp.request, resp.reason), prt=False, lvl='debug') return resp.headers
def _header_poster(self, url, rpath, fheaders): """POST Headers on a specified object in the container. :param url: :param rpath: :param fheaders: """ # perform Object POST request for header update. resp = http.post_request(url=url, rpath=rpath, headers=fheaders) self.resp_exception(resp=resp) report.reporter( msg="STATUS: %s MESSAGE: %s REASON: %s" % (resp.status_code, resp.request, resp.reason), prt=False, lvl="debug", ) return resp.headers
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 try: auth_resp = http.post_request(url=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: 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 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