本文整理汇总了Python中app.util.secret.Secret类的典型用法代码示例。如果您正苦于以下问题:Python Secret类的具体用法?Python Secret怎么用?Python Secret使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Secret类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_matching_digests_should_return_true
def test_matching_digests_should_return_true(self):
secret = 'secrettoken'
message = 'message blah blah horse battery staple'
Secret.set(secret)
digest_received = Secret._get_hex_digest(message, secret)
self.assertTrue(Secret.digest_is_valid(digest_received, message))
示例2: test_unspecified_digest_should_return_false
def test_unspecified_digest_should_return_false(self):
secret = 'secrettoken'
message = 'message blah blah horse battery staple'
Secret.set(secret)
digest_received = None
self.assertFalse(Secret.digest_is_valid(digest_received, message))
示例3: test_non_matching_digests_should_return_false
def test_non_matching_digests_should_return_false(self):
secret = 'secrettoken'
message = 'message blah blah horse battery staple'
Secret.set(secret)
digest_received = Secret._get_hex_digest('not the original message', secret)
self.assertFalse(Secret.digest_is_valid(digest_received, message))
示例4: setUp
def setUp(self):
# Configure logging to go to stdout. This makes debugging easier by allowing us to see logs for failed tests.
log.configure_logging('DEBUG')
Secret.set('testsecret')
self.cluster = FunctionalTestCluster(verbose=self._get_test_verbosity())
示例5: _set_secret
def _set_secret(config_filename):
if 'secret' in Configuration and Configuration['secret'] is not None:
secret = Configuration['secret']
else: # No secret found, generate one and persist it
secret = hashlib.sha512().hexdigest()
conf_file = ConfigFile(config_filename)
conf_file.write_value('secret', secret, BASE_CONFIG_FILE_SECTION)
Secret.set(secret)
示例6: _set_secret
def _set_secret(config_filename):
if 'secret' in Configuration and Configuration['secret'] is not None:
secret = Configuration['secret']
else: # No secret found, generate one and persist it
secret_length = 128
chars = string.ascii_lowercase + string.digits
secret = ''.join(random.SystemRandom().choice(chars) for _ in range(secret_length))
conf_file = ConfigFile(config_filename)
conf_file.write_value('secret', secret, BASE_CONFIG_FILE_SECTION)
Secret.set(secret)
示例7: setUp
def setUp(self):
# Configure logging to go to stdout. This makes debugging easier by allowing us to see logs for failed tests.
log.configure_logging('DEBUG')
self._reset_config()
Secret.set('testsecret')
SlaveRegistry.reset_singleton()
self.cluster = FunctionalTestCluster(verbose=self._get_test_verbosity())
self._network = Network()
示例8: setUp
def setUp(self):
# Configure logging to go to stdout. This makes debugging easier by allowing us to see logs for failed tests.
log.configure_logging('DEBUG')
Secret.set('testsecret')
self.test_app_base_dir = tempfile.TemporaryDirectory()
self.test_conf_file_path = self._create_test_config_file({
'secret': Secret.get(),
'base_directory': self.test_app_base_dir.name,
})
self.cluster = FunctionalTestCluster(
conf_file_path=self.test_conf_file_path,
verbose=self._get_test_verbosity(),
)
示例9: kill
def kill(self):
"""
Instructs the slave process to kill itself.
"""
kill_url = self._slave_api.url('kill')
self._network.post_with_digest(kill_url, {}, Secret.get())
self.mark_dead()
示例10: _create_test_config_file
def _create_test_config_file(self, base_dir_sys_path):
"""
Create a temporary conf file just for this test.
:param base_dir_sys_path: Sys path of the base app dir
:type base_dir_sys_path: unicode
:return: The path to the conf file
:rtype: str
"""
# Copy default conf file to tmp location
self._conf_template_path = join(self._clusterrunner_repo_dir, 'conf', 'default_clusterrunner.conf')
# Create the conf file inside base dir so we can clean up the test at the end just by removing the base dir
test_conf_file_path = tempfile.NamedTemporaryFile(dir=base_dir_sys_path).name
shutil.copy(self._conf_template_path, test_conf_file_path)
os.chmod(test_conf_file_path, ConfigFile.CONFIG_FILE_MODE)
conf_file = ConfigFile(test_conf_file_path)
# Set custom conf file values for this test
conf_values_to_set = {
'secret': Secret.get(),
'base_directory': base_dir_sys_path,
'max_log_file_size': 1024 * 5,
}
for conf_key, conf_value in conf_values_to_set.items():
conf_file.write_value(conf_key, conf_value, BASE_CONFIG_FILE_SECTION)
return test_conf_file_path
示例11: test_git_project_params_are_modified_for_slave
def test_git_project_params_are_modified_for_slave(self):
slave = self._create_slave()
slave._network.post_with_digest = Mock()
build_request = BuildRequest({
'type': 'git',
'url': 'http://original-user-specified-url',
})
mock_git = Mock(slave_param_overrides=Mock(return_value={
'url': 'ssh://new-url-for-clusterrunner-master',
'extra': 'something_extra',
}))
mock_build = MagicMock(spec=Build, build_request=build_request,
build_id=Mock(return_value=888), project_type=mock_git)
slave.setup(mock_build, executor_start_index=777)
slave._network.post_with_digest.assert_called_with(
'http://{}/v1/build/888/setup'.format(self._FAKE_SLAVE_URL),
{
'build_executor_start_index': 777,
'project_type_params': {
'type': 'git',
'url': 'ssh://new-url-for-clusterrunner-master',
'extra': 'something_extra'}
},
Secret.get()
)
示例12: setup
def setup(self, build: Build, executor_start_index: int) -> bool:
"""
Execute a setup command on the slave for the specified build. The setup process executes asynchronously on the
slave and the slave will alert the master when setup is complete and it is ready to start working on subjobs.
:param build: The build to set up this slave to work on
:param executor_start_index: The index the slave should number its executors from for this build
:return: Whether or not the call to start setup on the slave was successful
"""
slave_project_type_params = build.build_request.build_parameters().copy()
slave_project_type_params.update(build.project_type.slave_param_overrides())
setup_url = self._slave_api.url('build', build.build_id(), 'setup')
post_data = {
'project_type_params': slave_project_type_params,
'build_executor_start_index': executor_start_index,
}
self.current_build_id = build.build_id()
try:
self._network.post_with_digest(setup_url, post_data, Secret.get())
except (requests.ConnectionError, requests.Timeout) as ex:
self._logger.warning('Setup call to {} failed with {}: {}.', self, ex.__class__.__name__, str(ex))
self.mark_dead()
return False
return True
示例13: setUp
def setUp(self):
# Configure logging to go to stdout. This makes debugging easier by allowing us to see logs for failed tests.
log.configure_logging('DEBUG')
Secret.set('testsecret')
self.test_app_base_dir = tempfile.TemporaryDirectory()
self.test_conf_file_path = self._create_test_config_file({
'secret': Secret.get(),
'base_directory': self.test_app_base_dir.name,
# Set the max log file size to a low value so that we cause at least one rollover during the test.
'max_log_file_size': 1024 * 5,
})
self.cluster = FunctionalTestCluster(
conf_file_path=self.test_conf_file_path,
verbose=self._get_test_verbosity(),
)
示例14: _notify_master_of_state_change
def _notify_master_of_state_change(self, new_state):
"""
Send a state notification to the master. This is used to notify the master of events occurring on the slave
related to build execution progress.
:type new_state: SlaveState
"""
state_url = self._master_api.url('slave', self._slave_id)
self._network.put_with_digest(state_url, request_params={'slave': {'state': new_state}},
secret=Secret.get(), error_on_failure=True)
示例15: _async_start_subjob
def _async_start_subjob(self, subjob):
"""
:type subjob: Subjob
"""
execution_url = self._slave_api.url('build', subjob.build_id(), 'subjob', subjob.subjob_id())
post_data = {'atomic_commands': subjob.atomic_commands()}
response = self._network.post_with_digest(execution_url, post_data, Secret.get(), error_on_failure=True)
subjob_executor_id = response.json().get('executor_id')
analytics.record_event(analytics.MASTER_TRIGGERED_SUBJOB, executor_id=subjob_executor_id,
build_id=subjob.build_id(), subjob_id=subjob.subjob_id(), slave_id=self.id)