def item_to_secret(namespace, msp_path, username, item, verbose=False): """Save a single MSP crypto-material file as a K8S secret. Args: namespace (str): Namespace where secret will live. msp_path (str): Path to the Membership Service Provider crypto-material. username (str): Username for identity. item (CryptoInfo): Item containing cryptographic material information. verbose (bool) Verbosity. False by default. """ # Item in form CryptoInfo(name, subfolder, key, required) secret_name = "hlf--{user}-{type}".format(user=username, type=item.secret_type) file_path = join(msp_path, item.subfolder) try: crypto_secret(secret_name, namespace, file_path=file_path, key=item.key, verbose=verbose) except Exception as error: if item.required: raise Exception(error) else: print('No {} found, so secret "{}" was not created'.format( file_path, secret_name))
def test_crypto_secret_fail(self, mock_glob, mock_secret_from_file): mock_glob.side_effect = [[]] with pytest.raises(Exception): crypto_secret("a-secret", "a-namespace", "./a_dir", "some_file.txt") mock_glob.assert_called_once_with("./a_dir/*") mock_secret_from_file.assert_not_called()
def test_crypto_secret_fail(self, mock_glob, mock_secret_from_file): mock_glob.side_effect = [[]] with pytest.raises(Exception): crypto_secret('a-secret', 'a-namespace', './a_dir', 'some_file.txt') mock_glob.assert_called_once_with('./a_dir/*') mock_secret_from_file.assert_not_called()
def test_crypto_secret(self, mock_glob, mock_secret_from_files): mock_glob.side_effect = [["./a_path/a_file.txt"]] crypto_secret("a-secret", "a-namespace", "./a_dir", "some_file.txt") mock_glob.assert_called_once_with("./a_dir/*") mock_secret_from_files.assert_called_once_with( secret="a-secret", namespace="a-namespace", keys_files_path={"some_file.txt": "./a_path/a_file.txt"}, )
def test_crypto_secret(self, mock_glob, mock_secret_from_file): mock_glob.side_effect = [['./a_path/a_file.txt']] crypto_secret('a-secret', 'a-namespace', './a_dir', 'some_file.txt') mock_glob.assert_called_once_with('./a_dir/*') mock_secret_from_file.assert_called_once_with( secret='a-secret', namespace='a-namespace', key='some_file.txt', filename='./a_path/a_file.txt', verbose=False)
def test_crypto_secret(self, mock_glob, mock_secret_from_file): mock_glob.side_effect = [["./a_path/a_file.txt"]] crypto_secret("a-secret", "a-namespace", "./a_dir", "some_file.txt") mock_glob.assert_called_once_with("./a_dir/*") mock_secret_from_file.assert_called_once_with( secret="a-secret", namespace="a-namespace", key="some_file.txt", filename="./a_path/a_file.txt", verbose=False, )
def item_to_secret(namespace, msp_path, user, item, verbose=False): # Item in form CryptoInfo(name, subfolder, key, required) secret_name = 'hlf--{user}-{type}'.format(user=user, type=item.secret_type) file_path = path.join(msp_path, item.subfolder) try: crypto_secret(secret_name, namespace, file_path=file_path, key=item.key, verbose=verbose) except Exception as error: if item.required: raise Exception(error) else: print('No {} found, so secret "{}" was not created'.format( file_path, secret_name))
def item_to_secret(namespace, msp_path, username, item): """Save a single MSP crypto-material file as a K8S secret. Args: namespace (str): Namespace where secret will live. msp_path (str): Path to the Membership Service Provider crypto-material. username (str): Username for identity. item (CryptoInfo): Item containing cryptographic material information. """ # Item in form CryptoInfo(name, subfolder, key, required) secret_name = f"hlf--{username}-{item.secret_type}" file_path = join(msp_path, item.subfolder) try: crypto_secret(secret_name, namespace, file_path=file_path, key=item.key) except Exception as error: if item.required: raise Exception(error) else: logging.warning( f'No {file_path} found, so secret "{secret_name}" was not created' )