Skip to content
Snippets Groups Projects
Commit 191bbd18 authored by Vincent Hatakeyama's avatar Vincent Hatakeyama
Browse files

:sparkles: Add option to install store api token in storage

parent 41776ed1
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,11 @@
History
=======
20.12.0
-------
Use SecretStorage to store Orus API token.
20.11.0
-------
......
......@@ -17,6 +17,7 @@
from .config import Config
from .list_modules import list_modules
from .parsing import apply, basic_parser
from .storage import get_orus_api_token
from .toml import load
_logger = logging.getLogger(__name__)
......@@ -52,7 +53,11 @@
class Configuration(Mapping):
def __init__(self, namespace):
super().__init__()
self.orus_api_token = namespace.orus_api_token
self.orus_api_token = (
namespace.orus_api_token
if namespace.orus_api_token
else get_orus_api_token()
)
def __len__(self):
return 1
......
#!/usr/bin/env python3
import sys
from contextlib import closing
from getpass import getpass
from typing import Optional
import secretstorage
__version__ = "1.0.0"
__date__ = "2023-10-23"
__updated__ = "2023-10-23"
__orus_api_token_attributes = {
"application": "odoo_scripts",
"server": "orus.io",
"scheme": "https",
"type": "api_token",
}
def get_orus_api_token() -> Optional[str]:
"""Retrieve Orus API token from secret service.
:return: None if there is no token"""
with closing(secretstorage.dbus_init()) as conn:
collection = secretstorage.get_default_collection(conn)
for item in collection.search_items(__orus_api_token_attributes):
return item.get_secret().decode("UTF-8")
return None
def set_orus_api_token(token: str):
"""Store Orus API token from secret service"""
with closing(secretstorage.dbus_init()) as conn:
collection = secretstorage.get_default_collection(conn)
collection.create_item(
"Orus API Token for Odoo Scripts",
__orus_api_token_attributes,
token.encode("UTF-8"),
True,
)
def main() -> int:
"""Ask for token and set it"""
token = getpass("Type in token value followed by enter:")
set_orus_api_token(token)
return 0
if __name__ == "__main__":
sys.exit(main())
......@@ -41,6 +41,7 @@
"requests_unixsocket",
"requests",
"psycopg2",
"secretstorage >=3.3.1",
]
import_sql = ["psycopg2"]
source_control = [
......@@ -71,6 +72,7 @@
list_modules = "odoo_scripts.list_modules:main"
update_duplicate_sources = "odoo_scripts.update_duplicate_sources:main [source_control]"
docker_redis = "odoo_scripts.docker_redis:main [docker]"
store_orus_api_token = "odoo_scripts.storage:main"
[project.urls]
repository = "https://orus.io/xcg/odoo_scripts"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment