This repository was archived by the owner on Nov 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 356
Emulated vault #4097
Merged
Merged
Emulated vault #4097
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a135a2d
Experimental - a web server emulating the RIAK over a File Sytem and …
66d6574
Emultaed vault PR fixes
04e8ba6
Emulated vault - code review fixes and further improvements.
e9c8bde
Emulated vault pr fixes
79ade28
adaper base and derived
3eb1bef
Emulated vault - happier linter
434588b
storage adapter abstract class
57b144a
emulated vault - further refinment of the APIs
f653e6a
Emulated vault - code review fixes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| <!-- | ||
| Licensed to the Apache Software Foundation (ASF) under one | ||
| or more contributor license agreements. See the NOTICE file | ||
| distributed with this work for additional information | ||
| regarding copyright ownership. The ASF licenses this file | ||
| to you under the Apache License, Version 2.0 (the | ||
| "License"); you may not use this file except in compliance | ||
| with the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, | ||
| software distributed under the License is distributed on an | ||
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| KIND, either express or implied. See the License for the | ||
| specific language governing permissions and limitations | ||
| under the License. | ||
| --> | ||
|
|
||
| # Emulated Vault - Background | ||
|
|
||
| The emulated_vault module supplies a HTTP server mimicking RIAK behavior for usage as traffic-control vault. | ||
| It may be used in order to replace RIAK traffic_vault, as it is much more simple to install. | ||
| The server may use different type of persistent storage (e.g. file-system), using the proper adapter. | ||
| The resiliency of the stored keys is derived from the resiliency of the underlying storage. | ||
|
|
||
| # Installation | ||
|
|
||
| Basic requirements: Centos ver >= 7; Python >= 2.7 | ||
|
|
||
| In order to install the module on a server please: | ||
| 1. Copy the module files to the server's root | ||
| 2. Add the certificate and key to your favorite path | ||
| 3. Adjust /opt/emulated_vault/conf/cfg.json - pointing at your certificate and key | ||
| 4. "systemctl enable" the service | ||
|
|
||
| Logs may be found under /opt/emulated_vault/var/log | ||
|
|
||
| # Developer's Notes | ||
|
|
||
| If you just want to play around with the module, you may of course run the server script on its own. | ||
| Before doing that, you would probably need to adjust the opt/emulated_vault/conf/cfg.json: | ||
| 1. Changing the db-path to one you have access to | ||
| 2. Disable ssl (just to make it easier) | ||
|
|
||
| Additionally, the vault-debug script is also available to work against the DB with command line. | ||
| It is mostly useful when developing a new adapter. | ||
|
|
||
| # Contact | ||
|
|
||
| For additional information, questions or assistance, please approach [Nir B. Sopher](mailto:nir@apache.org) |
29 changes: 29 additions & 0 deletions
29
experimental/emulated_vault/etc/systemd/system/emulated-vault.service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| # | ||
| # | ||
| [Unit] | ||
| Description=Emulated Vault Service | ||
| After=network.target | ||
|
|
||
| [Service] | ||
| Type=simple | ||
| User=root | ||
| ExecStart=/opt/emulated-vault/vault-server | ||
| Restart=on-failure | ||
|
|
||
|
|
||
| [Install] | ||
| WantedBy=multi-user.target |
30 changes: 30 additions & 0 deletions
30
experimental/emulated_vault/opt/emulated-vault/conf/cfg.ini
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| # | ||
| # | ||
|
|
||
| [general] | ||
| storage-adapter-type = fs | ||
| # Optional: log-dir = /var/log/messages/emulated-vault | ||
| [http-server] | ||
| ssl-key-path = path/to/cert/key.pem | ||
| ssl-cert-path = path/to/cert/cert.pem | ||
| # Optional: use-ssl = False | ||
| # Optional: listen-ip = 1.2.3.4 | ||
| # Optional: listen-port = 12345 | ||
|
|
||
| [fs-adapter] | ||
| db-base-os-path = /opt/emulated-vault/db | ||
| ping-os-path = /opt/emulated-vault/ping | ||
16 changes: 16 additions & 0 deletions
16
experimental/emulated_vault/opt/emulated-vault/storage/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| # | ||
| # |
163 changes: 163 additions & 0 deletions
163
experimental/emulated_vault/opt/emulated-vault/storage/adapter_base.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| # | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| # | ||
| # | ||
|
|
||
| import sys | ||
| if sys.version_info >= (3, 0): | ||
| from abc import ABC, abstractmethod | ||
| else: | ||
| ABC = object | ||
| abstractmethod = lambda f: f | ||
|
|
||
|
|
||
|
|
||
| class AdapterBase(ABC): | ||
| """ | ||
| Base adapter class. | ||
| This class implements the API required for storing and retriving the content kept in the vault. | ||
|
|
||
| Methods to be implemented at derived classes: | ||
| :meth:`get_parameter_storage_path` given a url-key of a parameter return the storage path | ||
| :meth:`get_parameter_storage_path_from_url_path` given a storage path of a parameter | ||
| retrun the url-key | ||
| :meth:`init_cfg` given a config-parser object, read the parameters required for | ||
| adapter's operation. Return "success" bool value | ||
| :meth:`init` prepare the adapter - connecting to storgae / setting the conntent for | ||
| "ping" requests etc.. Return "success" bool value | ||
| :meth:`ping` test the 'ping' status with the adapter. | ||
| Return a tuple: "success" bool & "value" kept as ping variable | ||
| :meth:`read_parameter_by_storage_path` given a storage path retrieve the parameter value. | ||
| Return a tuple: "success" bool & "value" kept in the parameter | ||
| :meth:`read_parameters_by_storage_path` given a storage and and a key holding | ||
| filters on the key and values. | ||
| Return "success" bool indicating a sucessful write, and a key->value dictionary | ||
| for the relevant parameters | ||
| :meth:`write_parameter_by_storage_path` given a storage path and a value string, | ||
| keep the parameter value. Return "success" bool indicating a sucessful write | ||
| :meth:`remove_parameter_by_storage_path` given a storage path, delete the parameter | ||
| from the DB. Return "success" bool indicating a sucessful deletion | ||
| """ | ||
|
|
||
| @abstractmethod | ||
| def init_cfg(self, fullConfig):# -> bool: | ||
| """ | ||
| Method to be implemented at derived classes | ||
| Initialize the class basic parameters. Part of Adapter required API. | ||
| :param fullConfig: configuration to operate upon. | ||
| :type fullConfig: configparser.ConfigParser class | ||
| :return: 'True' for successful initialization | ||
| :rtype: bool | ||
| """ | ||
| raise NotImplementedError()#... | ||
|
|
||
| @abstractmethod | ||
| def init(self):# -> bool: | ||
| """ | ||
| Method to be implemented at derived classes | ||
| Initialize the class - e.g. connection to storage & ability to answer for ping. | ||
| :return: 'True' for successful initialization | ||
| :rtype: bool | ||
| """ | ||
| raise NotImplementedError()#... | ||
|
|
||
| @abstractmethod | ||
| def get_parameter_storage_path(self, parameterUrlPath):# -> (bool, str): | ||
| """ | ||
| Method to be implemented at derived classes | ||
| Conversion function - taking a key's path and translate to a file path on the file system | ||
| :param parameterUrlPath: the "url-path" like key of the variable | ||
| :type parameterUrlPath: str | ||
| :return: "success" bool and a file path of where the value is be kept | ||
| :rtype: Tuple[bool, str] | ||
| """ | ||
| raise NotImplementedError()#... | ||
|
|
||
| @abstractmethod | ||
| def get_parameter_url_path_from_storage_path(self, parameterStoragePath):# -> (bool, str): | ||
| """ | ||
| Method to be implemented at derived classes | ||
| Conversion function - taking file path on the file system and translate to key's path | ||
| :param parameterStoragePath: the file name holding a value | ||
| :type parameterUrlPath: str | ||
| :return: "success" bool and the matching variable url-path like key | ||
| :rtype: Tuple[bool, str] | ||
| """ | ||
| raise NotImplementedError()#... | ||
|
|
||
| @abstractmethod | ||
| def ping(self):# -> bool: | ||
| """ | ||
| Method to be implemented at derived classes | ||
| Check ping connection | ||
| :return: 'True' for successful connection with the storage layer | ||
| :rtype: bool | ||
| """ | ||
| raise NotImplementedError()#... | ||
|
|
||
| @abstractmethod | ||
| def read_parameter_by_storage_path(self, parameterStoragePath):# -> (bool, str): | ||
| """ | ||
| Method to be implemented at derived classes | ||
| Reading the value from the provided file name. | ||
| :param parameterStoragePath: the file name | ||
| :type parameterUrlPath: str | ||
| :return: 'True' for successful retrivaland the retrieved value | ||
| :rtype: Tuple[bool, str] | ||
| """ | ||
| raise NotImplementedError()#... | ||
|
|
||
| @abstractmethod | ||
| def read_parameters_by_storage_path(self, parameterStoragePathPrefix, keyFilters):# -> (bool, dict(str,str)): | ||
| """ | ||
| Method to be implemented at derived classes | ||
| Reading the values of the parameters the provided directory. | ||
| :param parameterStoragePathPrefix: the directory to look into | ||
| :type parameterStoragePathPrefix: str | ||
| :param keyFilters: filter-name/filter-func dict, holding functions that get a key as | ||
| input and retunn "true" if key should be included in the result | ||
| :type keyFilters: Dict[str,function[str]] | ||
| :return: 'True' for successful retrival and a dict for key-name/value | ||
| :rtype: Tuple[bool, Dict[str, str]] | ||
| """ | ||
| raise NotImplementedError()#... | ||
|
|
||
|
|
||
| @abstractmethod | ||
| def write_parameter_by_storage_path(self, parameterStoragePath, value):# -> bool: | ||
| """ | ||
| Method to be implemented at derived classes | ||
| Writing the value to the provided file name. | ||
| :param parameterStoragePath: the file name | ||
| :type parameterUrlPath: str | ||
| :param value: value to be writen | ||
| :type parameterUrlPath: str | ||
| :return: 'True' for successful writing | ||
| :rtype: bool | ||
| """ | ||
| raise NotImplementedError()#... | ||
|
|
||
| @abstractmethod | ||
| def remove_parameter_by_storage_path(self, parameterStoragePath):# -> bool: | ||
| """ | ||
| Method to be implemented at derived classes | ||
| Deleting the the provided file. | ||
| :param parameterStoragePath: the file name | ||
| :type parameterUrlPath: str | ||
| :return: 'True' for successful deletion | ||
| :rtype: bool | ||
| """ | ||
| raise NotImplementedError()#... | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.