# Path: castellan/common/exception.py
# _FATAL_EXCEPTION_FORMAT_ERRORS = False
# class RedirectException(Exception):
# class CastellanException(Exception):
# class Forbidden(CastellanException):
# class KeyManagerError(CastellanException):
# class ManagedObjectNotFoundError(CastellanException):
# class InvalidManagedObjectDictError(CastellanException):
# class UnknownManagedObjectTypeError(CastellanException):
# class AuthTypeInvalidError(CastellanException):
# class InsufficientCredentialDataError(CastellanException):
#     def __init__(self, url):
#     def __init__(self, message_arg=None, *args, **kwargs):
# 
# Path: castellan/key_manager/vault_key_manager.py
# _DEFAULT_VAULT_URL = "http://127.0.0.1:8200"
# _DEFAULT_MOUNTPOINT = "secret"
# _DEFAULT_VERSION = 2
# _VAULT_OPT_GROUP = 'vault'
# _EXCEPTIONS_BY_CODE = [
#     requests.codes['internal_server_error'],
#     requests.codes['service_unavailable'],
#     requests.codes['request_timeout'],
#     requests.codes['gateway_timeout'],
#     requests.codes['precondition_failed'],
# ]
# LOG = logging.getLogger(__name__)
# class VaultKeyManager(key_manager.KeyManager):
#     def __init__(self, configuration):
#     def _get_url(self):
#     def _get_resource_url(self, key_id=None):
#     def _approle_token_id(self):
#     def _set_namespace(self, headers):
#     def _build_auth_headers(self):
#     def _do_http_request(self, method, resource, json=None):
#     def create_key_pair(self, context, algorithm, length,
#                         expiration=None, name=None):
#     def _store_key_value(self, key_id, value):
#     def create_key(self, context, algorithm, length, name=None, **kwargs):
#     def store(self, context, key_value, **kwargs):
#     def get(self, context, key_id, metadata_only=False):
#     def delete(self, context, key_id):
#     def list(self, context, object_type=None, metadata_only=False):
#     def list_options_for_discovery(self):
# 
# Path: castellan/tests/functional/config.py
# TEST_CONF = None
#     TEST_CONF = cfg.ConfigOpts()
# def setup_config(config_file=''):
# def get_config():
# def list_opts():
# 
# Path: castellan/tests/functional/key_manager/test_key_manager.py
# def _get_test_symmetric_key():
# def _get_test_public_key():
# def _get_test_private_key():
# def _get_test_certificate():
# def _get_test_opaque_data():
# def _get_test_passphrase():
#     def _create_key_manager(self):
#     def setUp(self):
#     def _get_valid_object_uuid(self, managed_object):
#     def test_create_key(self):
#     def test_create_key_pair(self):
#     def test_delete(self, managed_object):
#     def test_get(self, managed_object):
#     def test_get_metadata(self, managed_object):
#     def test_store(self, managed_object):
#     def test_list(self, managed_object):
#     def test_list_metadata_only(self, managed_object):
#     def test_list_with_filter(self, object_1, object_2, query_dict):
# class KeyManagerTestCase(object):


import os
import uuid
import requests
from oslo_config import cfg
from oslo_utils import uuidutils
from oslotest import base
from testtools import testcase
from castellan.common import exception
from castellan.key_manager import vault_key_manager
from castellan.tests.functional import config
from castellan.tests.functional.key_manager import test_key_manager
    def test_get_null_object(self):
        self.assertRaises(exception.KeyManagerError,
                          self.key_mgr.get, self.ctxt, None)

    def test_get_unknown_key(self):
        bad_key_uuid = uuidutils.generate_uuid()
        self.assertRaises(exception.ManagedObjectNotFoundError,
                          self.key_mgr.get, self.ctxt, bad_key_uuid)


TEST_POLICY = '''
path "{backend}/*" {{
  capabilities = ["create", "read", "update", "delete", "list"]
}}

path "sys/internal/ui/mounts/{backend}" {{
  capabilities = ["read"]
}}
'''

AUTH_ENDPOINT = 'v1/sys/auth/{auth_type}'
POLICY_ENDPOINT = 'v1/sys/policy/{policy_name}'
APPROLE_ENDPOINT = 'v1/auth/approle/role/{role_name}'


class VaultKeyManagerAppRoleTestCase(VaultKeyManagerTestCase):

    mountpoint = 'secret'

    def _create_key_manager(self):

# Path: castellan/common/exception.py
# _FATAL_EXCEPTION_FORMAT_ERRORS = False
# class RedirectException(Exception):
# class CastellanException(Exception):
# class Forbidden(CastellanException):
# class KeyManagerError(CastellanException):
# class ManagedObjectNotFoundError(CastellanException):
# class InvalidManagedObjectDictError(CastellanException):
# class UnknownManagedObjectTypeError(CastellanException):
# class AuthTypeInvalidError(CastellanException):
# class InsufficientCredentialDataError(CastellanException):
#     def __init__(self, url):
#     def __init__(self, message_arg=None, *args, **kwargs):
# 
# Path: castellan/key_manager/vault_key_manager.py
# _DEFAULT_VAULT_URL = "http://127.0.0.1:8200"
# _DEFAULT_MOUNTPOINT = "secret"
# _DEFAULT_VERSION = 2
# _VAULT_OPT_GROUP = 'vault'
# _EXCEPTIONS_BY_CODE = [
#     requests.codes['internal_server_error'],
#     requests.codes['service_unavailable'],
#     requests.codes['request_timeout'],
#     requests.codes['gateway_timeout'],
#     requests.codes['precondition_failed'],
# ]
# LOG = logging.getLogger(__name__)
# class VaultKeyManager(key_manager.KeyManager):
#     def __init__(self, configuration):
#     def _get_url(self):
#     def _get_resource_url(self, key_id=None):
#     def _approle_token_id(self):
#     def _set_namespace(self, headers):
#     def _build_auth_headers(self):
#     def _do_http_request(self, method, resource, json=None):
#     def create_key_pair(self, context, algorithm, length,
#                         expiration=None, name=None):
#     def _store_key_value(self, key_id, value):
#     def create_key(self, context, algorithm, length, name=None, **kwargs):
#     def store(self, context, key_value, **kwargs):
#     def get(self, context, key_id, metadata_only=False):
#     def delete(self, context, key_id):
#     def list(self, context, object_type=None, metadata_only=False):
#     def list_options_for_discovery(self):
# 
# Path: castellan/tests/functional/config.py
# TEST_CONF = None
#     TEST_CONF = cfg.ConfigOpts()
# def setup_config(config_file=''):
# def get_config():
# def list_opts():
# 
# Path: castellan/tests/functional/key_manager/test_key_manager.py
# def _get_test_symmetric_key():
# def _get_test_public_key():
# def _get_test_private_key():
# def _get_test_certificate():
# def _get_test_opaque_data():
# def _get_test_passphrase():
#     def _create_key_manager(self):
#     def setUp(self):
#     def _get_valid_object_uuid(self, managed_object):
#     def test_create_key(self):
#     def test_create_key_pair(self):
#     def test_delete(self, managed_object):
#     def test_get(self, managed_object):
#     def test_get_metadata(self, managed_object):
#     def test_store(self, managed_object):
#     def test_list(self, managed_object):
#     def test_list_metadata_only(self, managed_object):
#     def test_list_with_filter(self, object_1, object_2, query_dict):
# class KeyManagerTestCase(object):


# Path: castellan/tests/functional/key_manager/test_vault_key_manager.py
import os
import uuid
import requests
from oslo_config import cfg
from oslo_utils import uuidutils
from oslotest import base
from testtools import testcase
from castellan.common import exception
from castellan.key_manager import vault_key_manager
from castellan.tests.functional import config
from castellan.tests.functional.key_manager import test_key_manager

    def test_get_null_object(self):
        self.assertRaises(exception.KeyManagerError,
                          self.key_mgr.get, self.ctxt, None)

    def test_get_unknown_key(self):
        bad_key_uuid = uuidutils.generate_uuid()
        self.assertRaises(exception.ManagedObjectNotFoundError,
                          self.key_mgr.get, self.ctxt, bad_key_uuid)


TEST_POLICY = '''
path "{backend}/*" {{
  capabilities = ["create", "read", "update", "delete", "list"]
}}

path "sys/internal/ui/mounts/{backend}" {{
  capabilities = ["read"]
}}
'''

AUTH_ENDPOINT = 'v1/sys/auth/{auth_type}'
POLICY_ENDPOINT = 'v1/sys/policy/{policy_name}'
APPROLE_ENDPOINT = 'v1/auth/approle/role/{role_name}'


class VaultKeyManagerAppRoleTestCase(VaultKeyManagerTestCase):

    mountpoint = 'secret'

    def _create_key_manager(self):

        key_mgr = vault_key_manager.VaultKeyManager(cfg.CONF)