Return the configured tokens (keystone token-get)

    CLI Example:

    .. code-block:: bash

        salt '*' keystone.token_get c965f79c4f864eaaa9c3b41904e67082
338938
def token_get(profile=None, **connection_args):
    '''
    
    '''
    kstone = auth(profile, **connection_args)
    token = kstone.service_catalog.get_token()
    return {'id': token['id'],
            'expires': token['expires'],
            'user_id': token['user_id'],
            'tenant_id': token['tenant_id']}
1080836
def _get_token_and_url_from_master():
    '''
    
    '''
    minion_id = __grains__['id']
    pki_dir = __opts__['pki_dir']

    # When rendering pillars, the module executes on the master, but the token
    # should be issued for the minion, so that the correct policies are applied
    if __opts__.get('__role', 'minion') == 'minion':
        private_key = '{0}/minion.pem'.format(pki_dir)
        log.debug('Running on minion, signing token request with key %s',
                  private_key)
        signature = base64.b64encode(salt.crypt.sign_message(
            private_key,
            minion_id
        ))
        result = __salt__['publish.runner'](
            'vault.generate_token',
            arg=[minion_id, signature]
        )
    else:
        private_key = '{0}/master.pem'.format(pki_dir)
        log.debug('Running on master, signing token request for %s with key %s',
                  minion_id, private_key)
        signature = base64.b64encode(salt.crypt.sign_message(
            private_key,
            minion_id
        ))
        result = __salt__['saltutil.runner'](
            'vault.generate_token',
            minion_id=minion_id,
            signature=signature,
            impersonated_by_master=True
        )

    if not result:
        log.error('Failed to get token from master! No result returned - '
                  'is the peer publish configuration correct?')
        raise salt.exceptions.CommandExecutionError(result)
    if not isinstance(result, dict):
        log.error('Failed to get token from master! '
                  'Response is not a dict: %s', result)
        raise salt.exceptions.CommandExecutionError(result)
    if 'error' in result:
        log.error('Failed to get token from master! '
                  'An error was returned: %s', result['error'])
        raise salt.exceptions.CommandExecutionError(result)
    return {
        'url': result['url'],
        'token': result['token'],
        'verify': result.get('verify', None),
    }
35188
def _auth(profile=None):
    '''
    
    '''
    if profile:
        credentials = __salt__['config.option'](profile)
        user = credentials['keystone.user']
        password = credentials.get('keystone.password', None)
        tenant = credentials['keystone.tenant']
        auth_url = credentials['keystone.auth_url']
        auth_version = credentials.get('keystone.auth_version', 2)
        region_name = credentials.get('keystone.region_name', None)
        api_key = credentials.get('keystone.api_key', None)
        os_auth_system = credentials.get('keystone.os_auth_system', None)
    else:
        user = __salt__['config.option']('keystone.user')
        password = __salt__['config.option']('keystone.password', None)
        tenant = __salt__['config.option']('keystone.tenant')
        auth_url = __salt__['config.option']('keystone.auth_url')
        auth_version = __salt__['config.option']('keystone.auth_version', 2)
        region_name = __salt__['config.option']('keystone.region_name')
        api_key = __salt__['config.option']('keystone.api_key')
        os_auth_system = __salt__['config.option']('keystone.os_auth_system')
    kwargs = {
        'user': user,
        'password': password,
        'key': api_key,
        'tenant_name': tenant,
        'auth_url': auth_url,
        'auth_version': auth_version,
        'region_name': region_name
    }

    return suos.SaltSwift(**kwargs)
29242
def fetch_token(self, **kwargs):
        
        if 'client_secret' not in kwargs:
            kwargs.update(client_secret=self.client_secret)
        return self.session.fetch_token(token_url, **kwargs)
584802
def get_token(url_base, tenant_id, user, password):
    
    url = 'http://' + url_base + '/v2.0/tokens'
    headers = {'Content-Type': 'application/json'}
    payload = '{"auth":{"tenantId":"' + tenant_id +\
              '","passwordCredentials":{"username":"'\
              + user + '","password":"' + password + '"}}}'
    response = requests.post(url, headers=headers, data=payload)
    if response.status_code != 200:
        print 'error to obtain the token ' + str(response.status_code)
        exit(1)
    response_json = response.json()
    token = response_json['access']['token']['id']
    return token
883908
def get_token(self):
    
    if self.__token is not None:
      return self.__token

    url = "https://api.neur.io/v1/oauth2/token"

    creds = b64encode(":".join([self.__key,self.__secret]).encode()).decode()

    headers = {
      "Authorization": " ".join(["Basic", creds]),
    }
    payload = {
      "grant_type": "client_credentials"
    }

    r = requests.post(url, data=payload, headers=headers)

    self.__token = r.json()["access_token"]

    return self.__token
433929
def token_getter(provider, token=None):
        
        session_key = provider + '_token'
        if token is None:
            token = session.get(session_key)
        return token
718406
def get_token(self, url):
        
        # A hack to avoid url-encoding the url, since the authorization service
        # doesn't work with correctly encoded urls

        parsed_url = urlparse.urlsplit(url)
        parsed_url = parsed_url._replace(path='/authorization/api')
        self.url = urlparse.urlunsplit(parsed_url)

        response = self.request(method='GET', url='/v1/token?url=' + url)
        return response.result.text
835241
def _get_pillar_cfg(pillar_key,
                    pillarenv=None,
                    saltenv=None):
    '''
    
    '''
    pillar_cfg = __salt__['pillar.get'](pillar_key,
                                        pillarenv=pillarenv,
                                        saltenv=saltenv)
    return pillar_cfg
668233
def retrieve_token(self, token):
        
        headers = self.client._get_private_headers()
        endpoint = '/tokens/{}'.format(token)
        return self.client._get(self.client.URL_BASE + endpoint, headers=headers)
1155010
def get_config():
    
    global token
    config = configparser.ConfigParser()
    config.read(os.path.join(os.path.expanduser('~'), '.config/scdl/scdl.cfg'))
    try:
        token = config['scdl']['auth_token']
        path = config['scdl']['path']
    except:
        logger.error('Are you sure scdl.cfg is in $HOME/.config/scdl/ ?')
        logger.error('Are both "auth_token" and "path" defined there?')
        sys.exit()
    if os.path.exists(path):
        os.chdir(path)
    else:
        logger.error('Invalid path in scdl.cfg...')
        sys.exit()
355785
def _auth(profile=None, **kwargs):
    '''
    
    '''
    keystone_api_args = None
    if kwargs is not None:
        if kwargs.get('keystone_api_args') is not None:
            keystone_api_args = kwargs['keystone_api_args']

    if profile:
        credentials = __salt__['config.option'](profile)
        user = credentials['keystone.user']
        password = credentials['keystone.password']
        tenant = credentials['keystone.tenant']
        auth_url = credentials['keystone.auth_url']
        region_name = credentials.get('keystone.region_name', None)
        api_key = credentials.get('keystone.api_key', None)
        os_auth_system = credentials.get('keystone.os_auth_system', None)
        use_keystoneauth = credentials.get('keystone.use_keystoneauth', False)
    else:
        user = __salt__['config.option']('keystone.user')
        password = __salt__['config.option']('keystone.password')
        tenant = __salt__['config.option']('keystone.tenant')
        auth_url = __salt__['config.option']('keystone.auth_url')
        region_name = __salt__['config.option']('keystone.region_name')
        api_key = __salt__['config.option']('keystone.api_key')
        os_auth_system = __salt__['config.option']('keystone.os_auth_system')
        use_keystoneauth = __salt__['config.option']('keystone.use_keystoneauth')

    # Override pillar settings with settings provided by module argument
    if keystone_api_args:
        user = keystone_api_args.get('user', user)
        password = keystone_api_args.get('password', password)
        tenant = keystone_api_args.get('tenant', tenant)
        auth_url = keystone_api_args.get('auth_url', auth_url)
        region_name = keystone_api_args.get('region_name', region_name)
        api_key = keystone_api_args.get('api_key', api_key)
        os_auth_system = keystone_api_args.get('os_auth_system', os_auth_system)
        use_keystoneauth = keystone_api_args.get('use_keystoneauth', use_keystoneauth)

    if use_keystoneauth is True:
        if profile:
            credentials = __salt__['config.option'](profile)
            project_id = credentials.get('keystone.project_id', None)
            project_name = credentials.get('keystone.project_name', None)
            user_domain_name = credentials.get('keystone.user_domain_name', None)
            project_domain_name = credentials.get('keystone.project_domain_name', None)
            verify = credentials.get('keystone.verify', None)
        else:
            project_id = __salt__['config.option']('keystone.project_id')
            project_name = __salt__['config.option']('keystone.project_name')
            user_domain_name = __salt__['config.option']('keystone.user_domain_name')
            project_domain_name = __salt__['config.option']('keystone.project_domain_name')
            verify = __salt__['config.option']('keystone.verify')

        # Override pillar settings with settings provided by module argument
        if keystone_api_args:
            project_id = keystone_api_args.get('project_id', project_id)
            project_name = keystone_api_args.get('project_name', project_name)
            user_domain_name = keystone_api_args.get('user_domain_name', user_domain_name)
            project_domain_name = keystone_api_args.get('project_domain_name', project_domain_name)
            verify = keystone_api_args.get('verify', verify)

        send_kwargs = {
            'username': user,
            'password': password,
            'project_id': project_id,
            'auth_url': auth_url,
            'region_name': region_name,
            'use_keystoneauth': use_keystoneauth,
            'verify': verify,
            'project_name': project_name,
            'project_domain_name': project_domain_name,
            'user_domain_name': user_domain_name
        }
    else:
        send_kwargs = {
            'username': user,
            'password': password,
            'api_key': api_key,
            'project_id': tenant,
            'auth_url': auth_url,
            'region_name': region_name,
            'os_auth_plugin': os_auth_system
        }
    log.debug('SEND_KWARGS: %s', send_kwargs)
    return suon.SaltNova(**send_kwargs)
1288764
def get(key, service=None, profile=None):  # pylint: disable=W0613
    '''
    
    '''

    if not profile.get('url') or not profile.get('token'):
        raise SaltConfigurationError("url and/or token missing from the tism sdb profile")

    request = {"token": profile['token'], "encsecret": key}

    result = http.query(
        profile['url'],
        method='POST',
        data=salt.utils.json.dumps(request),
    )

    decrypted = result.get('body')

    if not decrypted:
        log.warning(
            'tism.get sdb decryption request failed with error %s',
            result.get('error', 'unknown')
        )
        return 'ERROR' + six.text_type(result.get('status', 'unknown'))

    return decrypted
742395
def get_user_token(self):
        
        headers = { 'User-Agent': self.user_agent(),
                'Host': self.domain(),
                'Accept': '*/*',
        }
        headers.update(self.headers())
        r = requests.get(   self.portals_url()+'/users/_this/token',
                            headers=headers,
                            auth=self.auth())
        if HTTP_STATUS.OK == r.status_code:
            return r.text
        else:
            print("get_user_token: Something went wrong: <{0}>: {1}".format(
                        r.status_code, r.reason))
            r.raise_for_status()
1109198
def get(self, token):
        '''
        
        '''
        log.debug('In the websocket get method')

        self.token = token
        # close the connection, if not authenticated
        if not self.application.auth.get_tok(token):
            log.debug('Refusing websocket connection, bad token!')
            self.send_error(401)
            return
        super(AllEventsHandler, self).get(token)
568636
def list_tokens(opts):
    '''
    
    '''
    ret = []
    for (dirpath, dirnames, filenames) in salt.utils.path.os_walk(opts['token_dir']):
        for token in filenames:
            ret.append(token)
    return ret
1018030
def client_tokens(self):
        
        client_id, client_secret = self.get_auth_basic()
        if not client_id and not client_secret:
            client_id = self.query_kwargs.get('client_id', '')
            client_secret = self.query_kwargs.get('client_secret', '')
            if not client_id and not client_secret:
                client_id = self.body_kwargs.get('client_id', '')
                client_secret = self.body_kwargs.get('client_secret', '')

        return client_id, client_secret