当前位置: 首页>>代码示例>>Python>>正文


Python access.create_token函数代码示例

本文整理汇总了Python中st2common.services.access.create_token函数的典型用法代码示例。如果您正苦于以下问题:Python create_token函数的具体用法?Python create_token怎么用?Python create_token使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了create_token函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _create_auth_token

 def _create_auth_token(self, context):
     if not context:
         return None
     user = context.get('user', None)
     if not user:
         return None
     return access.create_token(user)
开发者ID:beryah,项目名称:st2,代码行数:7,代码来源:base.py

示例2: test_delete_token

 def test_delete_token(self):
     token = access.create_token(USERNAME)
     access.delete_token(token.token)
     try:
         token = Token.get(token.token)
         self.assertTrue(False, 'Delete failed was expected to pass.')
     except TokenNotFoundError:
         self.assertTrue(True)
开发者ID:meirwah,项目名称:st2,代码行数:8,代码来源:test_access.py

示例3: test_create_token_ttl_capped

 def test_create_token_ttl_capped(self):
     ttl = cfg.CONF.auth.token_ttl + 10
     expected_expiry = date_utils.get_datetime_utc_now() + datetime.timedelta(seconds=ttl)
     expected_expiry = date_utils.add_utc_tz(expected_expiry)
     token = access.create_token(USERNAME, 10)
     self.assertTrue(token is not None)
     self.assertTrue(token.token is not None)
     self.assertEqual(token.user, USERNAME)
     self.assertLess(isotime.parse(token.expiry), expected_expiry)
开发者ID:meirwah,项目名称:st2,代码行数:9,代码来源:test_access.py

示例4: test_create_token_ttl_ok

 def test_create_token_ttl_ok(self):
     ttl = 10
     token = access.create_token(USERNAME, 10)
     self.assertTrue(token is not None)
     self.assertTrue(token.token is not None)
     self.assertEqual(token.user, USERNAME)
     expected_expiry = datetime.datetime.utcnow() + datetime.timedelta(seconds=ttl)
     expected_expiry = isotime.add_utc_tz(expected_expiry)
     self.assertLess(isotime.parse(token.expiry), expected_expiry)
开发者ID:rgaertner,项目名称:st2,代码行数:9,代码来源:test_access.py

示例5: test_create_token_ttl_capped

 def test_create_token_ttl_capped(self):
     ttl = cfg.CONF.auth.token_ttl + 10
     expected_expiry = datetime.datetime.utcnow() + datetime.timedelta(seconds=ttl)
     expected_expiry = isotime.add_utc_tz(expected_expiry)
     token = access.create_token('manas', 10)
     self.assertTrue(token is not None)
     self.assertTrue(token.token is not None)
     self.assertEqual(token.user, 'manas')
     self.assertLess(isotime.parse(token.expiry), expected_expiry)
开发者ID:BlazeMediaGroup,项目名称:st2,代码行数:9,代码来源:test_access.py

示例6: _get_api_client

    def _get_api_client(self):
        """
        Retrieve API client instance.
        """
        if not self._client:
            ttl = (24 * 60 * 60)
            temporary_token = create_token(username=self._api_username, ttl=ttl)
            api_url = get_full_public_api_url()
            self._client = Client(api_url=api_url, token=temporary_token.token)

        return self._client
开发者ID:AlexeyDeyneko,项目名称:st2,代码行数:11,代码来源:datastore.py

示例7: __init__

 def __init__(self):
     self._action_sensor_enabled = cfg.CONF.action_sensor.enable
     self._trigger_type_endpoint = cfg.CONF.action_sensor.triggers_base_url
     self._retry_wait = cfg.CONF.action_sensor.retry_wait
     self._timeout = cfg.CONF.action_sensor.request_timeout
     self._max_attempts = cfg.CONF.action_sensor.max_attempts
     self._auth_creds = create_token('system.internal_trigger_registrar',
                                     ttl=(1 * 60 * 60))
     self._http_post_headers = {'content-type': 'application/json',
                                'X-Auth-Token': self._auth_creds.token}
     self._http_get_headers = {'X-Auth-Token': self._auth_creds.token}
开发者ID:Kailashkatheth1,项目名称:st2,代码行数:11,代码来源:triggers.py

示例8: test_create_token_service_token_can_use_arbitrary_ttl

    def test_create_token_service_token_can_use_arbitrary_ttl(self):
        ttl = (10000 * 24 * 24)

        # Service token should support arbitrary TTL
        token = access.create_token(USERNAME, ttl=ttl, service=True)
        expected_expiry = date_utils.get_datetime_utc_now() + datetime.timedelta(seconds=ttl)
        expected_expiry = date_utils.add_utc_tz(expected_expiry)

        self.assertTrue(token is not None)
        self.assertEqual(token.user, USERNAME)
        self.assertLess(isotime.parse(token.expiry), expected_expiry)

        # Non service token should throw on TTL which is too large
        self.assertRaises(TTLTooLargeException, access.create_token, USERNAME, ttl=ttl,
                          service=False)
开发者ID:lyandut,项目名称:st2,代码行数:15,代码来源:test_access.py

示例9: _get_api_client

    def _get_api_client(self):
        """
        Retrieve API client instance.
        """
        token_expire = self._token_expire <= get_datetime_utc_now()

        if not self._client or token_expire:
            self._logger.audit('Creating new Client object.')
            ttl = (24 * 60 * 60)
            self._token_expire = get_datetime_utc_now() + timedelta(seconds=ttl)
            temporary_token = create_token(username=self._api_username, ttl=ttl)
            api_url = get_full_public_api_url()
            self._client = Client(api_url=api_url, token=temporary_token.token)

        return self._client
开发者ID:LindsayHill,项目名称:st2,代码行数:15,代码来源:datastore.py

示例10: _create_auth_token

    def _create_auth_token(self, context, action_db, liveaction_db):
        if not context:
            return None

        user = context.get('user', None)
        if not user:
            return None

        metadata = {
            'service': 'actions_container',
            'action_name': action_db.name,
            'live_action_id': str(liveaction_db.id)

        }

        ttl = cfg.CONF.auth.service_token_ttl
        token_db = access.create_token(username=user, ttl=ttl, metadata=metadata, service=True)
        return token_db
开发者ID:nzlosh,项目名称:st2,代码行数:18,代码来源:base.py

示例11: get_api_client

    def get_api_client(self):
        """
        Retrieve API client instance.
        """
        token_expire = self._token_expire <= get_datetime_utc_now()

        if not self._client or token_expire:
            # Note: Late import to avoid high import cost (time wise)
            from st2common.services.access import create_token
            self._logger.debug('Creating new Client object.')

            ttl = cfg.CONF.auth.service_token_ttl
            api_url = get_full_public_api_url()

            temporary_token = create_token(username=self._api_username, ttl=ttl, service=True)
            self._client = Client(api_url=api_url, token=temporary_token.token)
            self._token_expire = get_datetime_utc_now() + timedelta(seconds=ttl)

        return self._client
开发者ID:StackStorm,项目名称:st2,代码行数:19,代码来源:datastore.py

示例12: _spawn_sensor_process

    def _spawn_sensor_process(self, sensor):
        """
        Spawn a new process for the provided sensor.

        New process uses isolated Python binary from a virtual environment
        belonging to the sensor pack.
        """
        sensor_id = self._get_sensor_id(sensor=sensor)
        virtualenv_path = get_sandbox_virtualenv_path(pack=sensor['pack'])
        python_path = get_sandbox_python_binary_path(pack=sensor['pack'])

        if virtualenv_path and not os.path.isdir(virtualenv_path):
            format_values = {'pack': sensor['pack'], 'virtualenv_path': virtualenv_path}
            msg = PACK_VIRTUALENV_DOESNT_EXIST % format_values
            raise Exception(msg)

        trigger_type_refs = sensor['trigger_types'] or []
        trigger_type_refs = ','.join(trigger_type_refs)

        parent_args = json.dumps(sys.argv[1:])

        args = [
            python_path,
            WRAPPER_SCRIPT_PATH,
            '--pack=%s' % (sensor['pack']),
            '--file-path=%s' % (sensor['file_path']),
            '--class-name=%s' % (sensor['class_name']),
            '--trigger-type-refs=%s' % (trigger_type_refs),
            '--parent-args=%s' % (parent_args)
        ]

        if sensor['poll_interval']:
            args.append('--poll-interval=%s' % (sensor['poll_interval']))

        env = os.environ.copy()
        env['PYTHONPATH'] = get_sandbox_python_path(inherit_from_parent=True,
                                                    inherit_parent_virtualenv=True)

        # Include full api URL and API token specific to that sensor
        ttl = (24 * 60 * 60)
        temporary_token = create_token(username='sensors_container', ttl=ttl)

        env[API_URL_ENV_VARIABLE_NAME] = get_full_public_api_url()
        env[AUTH_TOKEN_ENV_VARIABLE_NAME] = temporary_token.token

        # TODO 1: Purge temporary token when service stops or sensor process dies
        # TODO 2: Store metadata (wrapper process id) with the token and delete
        # tokens for old, dead processes on startup
        cmd = ' '.join(args)
        LOG.debug('Running sensor subprocess (cmd="%s")', cmd)

        # TODO: Intercept stdout and stderr for aggregated logging purposes
        try:
            process = subprocess.Popen(args=args, stdin=None, stdout=None,
                                       stderr=None, shell=False, env=env,
                                       preexec_fn=on_parent_exit('SIGTERM'))
        except Exception as e:
            cmd = ' '.join(args)
            message = ('Failed to spawn process for sensor %s ("%s"): %s' %
                       (sensor_id, cmd, str(e)))
            raise Exception(message)

        self._processes[sensor_id] = process
        self._sensors[sensor_id] = sensor
        self._sensor_start_times[sensor_id] = int(time.time())

        self._dispatch_trigger_for_sensor_spawn(sensor=sensor, process=process, cmd=cmd)

        return process
开发者ID:hejin,项目名称:st2,代码行数:69,代码来源:process_container.py

示例13: test_create_token_fail

 def test_create_token_fail(self):
     try:
         access.create_token(None)
         self.assertTrue(False, 'Create succeeded was expected to fail.')
     except ValueError:
         self.assertTrue(True)
开发者ID:meirwah,项目名称:st2,代码行数:6,代码来源:test_access.py

示例14: test_create_token

 def test_create_token(self):
     token = access.create_token(USERNAME)
     self.assertTrue(token is not None)
     self.assertTrue(token.token is not None)
     self.assertEqual(token.user, USERNAME)
开发者ID:meirwah,项目名称:st2,代码行数:5,代码来源:test_access.py

示例15: _create_token_for_user

 def _create_token_for_user(self, username, ttl=None):
     tokendb = create_token(username=username, ttl=ttl)
     return TokenAPI.from_model(tokendb)
开发者ID:rlugojr,项目名称:st2,代码行数:3,代码来源:auth.py


注:本文中的st2common.services.access.create_token函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。