def auth(): url = "https://identity.api.rackspacecloud.com/v2.0/tokens" username = raw_input("Please enter your username: "******"Please enter your API Key: ") jsonreq = { "auth": { "RAX-KSKEY:apiKeyCredentials": { "username": username, "apiKey": apikey } } } auth_headers = {'content-type': 'application/json'} pyrax.set_setting("identity_type", "rackspace") try: r = requests.post(url, data=json.dumps(jsonreq), headers=auth_headers) jsonresp = json.loads(r.text) token = str(jsonresp['access']['token']['id']) tenant = str(jsonresp['access']['token']['tenant']['id']) pyrax.auth_with_token(token, tenant) except: print "Bad name or password!" sys.exit() return token, jsonresp
def is_authenticated(self): """ We do cache the authentication token, which is get by exchanging API credentials. If the cache exists and is still valid, no authentication is made. :return: """ if not os.path.isfile(self.token_file): # No data in cache --> no token --> not authenticated return False data = json.load(open(self.token_file)) token = data['access']['token']['id'] tenant_id = data['access']['token']['tenant']['id'] tenant_name = data['access']['token']['tenant']['name'] pyrax.settings._settings['default'][ "identity_class"] = pyrax.rax_identity.RaxIdentity try: pyrax.auth_with_token(token, tenant_id=tenant_id, tenant_name=tenant_name) except pyrax.exceptions.AuthenticationFailed: return False return True
def test_auth_with_token(self): pyrax.authenticated = False tok = utils.random_unicode() tname = utils.random_unicode() pyrax.auth_with_token(tok, tenant_name=tname) self.assertTrue(pyrax.identity.authenticated) self.assertEqual(pyrax.identity.token, tok) self.assertEqual(pyrax.identity.tenant_name, tname)
def authenticate_token(self, token, tenantId, region, identity_type='rackspace'): '''authenticate with Rackspace Cloud using existing token tenantId: see top-right --> NAME (#XXX) ''' logging.debug('setting identity_type=%s' % identity_type) pyrax.set_setting("identity_type", identity_type) logging.debug('authenticating with token:%s, tenantId:%s, region:%s ' % (token, tenantId, region)) pyrax.auth_with_token(token, tenantId, region=region)
def __authenticate(self): # current implemenation shown below authenticates using # username and password. Need make it work with auth-token if not self._authenticated: pyrax.set_setting("identity_type", "keystone") pyrax.set_setting("auth_endpoint", self.context.auth_url) pyrax.set_setting("tenant_id", self.context.tenant) logger.info("Authenticating with username:%s" % self.context.username) pyrax.auth_with_token(self.context.auth_token, tenant_id=self.context.tenant_id, tenant_name=self.context.tenant) logger.info("User %s authenticated successfully." % self.context.username) self._authenticated = True
def authenticate_token(self): """ This authenticate with Rackspace cloud using existing token. :returns: True or False (Boolean) """ logger = logging.getLogger(__name__) pyrax.set_setting('identity_type', self._identity_type) try: pyrax.auth_with_token(self._token, self._tenant_id, region=self._region) logging.info('authenticated with token:%s, tenant_id:%s, region:%s', self._token, self._tenant_id, self._region) return True except AuthenticationFailed: logging.info('cannot authenticate with token:%s, tenant_id:%s, region:%s', self._token, self._tenant_id, self._region) logger.debug(traceback.format_exc()) return False
def authenticate_token(self, token, tenantId, region, identity_type='rackspace'): '''authenticate with Rackspace Cloud using existing token tenantId: see top-right --> NAME (#XXX) ''' logging.debug('setting identity_type=%s' % identity_type) pyrax.set_setting("identity_type", identity_type) logging.debug('authenticating with token:%s, tenantId:%s, region:%s ' % (token, tenantId, region)) try: pyrax.auth_with_token(token, tenantId, region=region) except: tb = traceback.format_exc() self.r(1, tb, ERROR)
def authenticate_token(self): """This authenticate with Rackspace cloud using existing token. :returns: True or False (Boolean) """ logger = logging.getLogger(__name__) pyrax.set_setting('identity_type', self._identity_type) try: pyrax.auth_with_token(self._token, self._tenant_id, region=self._region) logging.info('authenticated with ' 'token:%s, tenant_id:%s, region:%s' % (self._token, self._tenant_id, self._region)) return True except: logging.info('cannot authenticate with ' 'token:%s, tenant_id:%s, region:%s' % (self._token, self._tenant_id, self._region)) logger.debug(traceback.format_exc()) return False
def __authenticate(self): pyrax.set_setting("identity_type", "keystone") pyrax.set_setting("auth_endpoint", self.context.auth_url) LOG.info(_("Authenticating username:%s") % self.context.username) self.pyrax = pyrax.auth_with_token(self.context.auth_token, tenant_id=self.context.tenant_id, tenant_name=self.context.tenant, region=(cfg.CONF.region_name or None)) if not self.pyrax: raise exception.AuthorizationFailure("No services available.") LOG.info(_("User %s authenticated successfully.") % self.context.username)
def __authenticate(self): pyrax.set_setting("identity_type", "keystone") pyrax.set_setting("auth_endpoint", self.context.auth_url) logger.info(_("Authenticating username:%s") % self.context.username) self.pyrax = pyrax.auth_with_token(self.context.auth_token, tenant_id=self.context.tenant_id, tenant_name=self.context.tenant, region=(cfg.CONF.region_name or None)) if not self.pyrax: raise exception.AuthorizationFailure("No services available.") logger.info( _("User %s authenticated successfully.") % self.context.username)
def auth(): url = "https://identity.api.rackspacecloud.com/v2.0/tokens" username = raw_input("Please enter your username: "******"Please enter your API Key: ") jsonreq = {"auth": {"RAX-KSKEY:apiKeyCredentials": { "username": username, "apiKey": apikey }}} auth_headers = {'content-type': 'application/json'} pyrax.set_setting("identity_type", "rackspace") try: r = requests.post(url, data=json.dumps(jsonreq), headers=auth_headers) jsonresp = json.loads(r.text) token = str(jsonresp['access']['token']['id']) tenant = str(jsonresp['access']['token']['tenant']['id']) pyrax.auth_with_token(token, tenant) except: print "Bad name or password!" sys.exit() return token, jsonresp
def __authenticate(self): # current implemenation shown below authenticates using # username and password. Need make it work with auth-token pyrax.set_setting("identity_type", "keystone") pyrax.set_setting("auth_endpoint", self.context.auth_url) logger.info("Authenticating with username:%s" % self.context.username) self.pyrax = pyrax.auth_with_token(self.context.auth_token, tenant_id=self.context.tenant_id, tenant_name=self.context.tenant, region=(cfg.CONF.region_name or None)) if not self.pyrax: raise exception.AuthorizationFailure("No services available.") logger.info("User %s authenticated successfully." % self.context.username)
import os import sys import pyrax import pyrax.exceptions as exc pyrax.auth_with_token(sys.argv[2], tenant_name=sys.argv[1]) with open(os.path.expanduser("~/.tsung/existingqueue.csv")) as names: for name in names: try: queue = pyrax.queues.create(name.rstrip()) except exc.DuplicateQueue: pass