Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Odoo scripts
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Container Registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
XCG
Odoo scripts
Commits
191bbd18
Commit
191bbd18
authored
1 year ago
by
Vincent Hatakeyama
Browse files
Options
Downloads
Patches
Plain Diff
Add option to install store api token in storage
parent
41776ed1
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
NEWS.rst
+5
-0
5 additions, 0 deletions
NEWS.rst
odoo_scripts/docker_build_copy.py
+6
-1
6 additions, 1 deletion
odoo_scripts/docker_build_copy.py
odoo_scripts/storage.py
+52
-0
52 additions, 0 deletions
odoo_scripts/storage.py
pyproject.toml
+2
-0
2 additions, 0 deletions
pyproject.toml
with
65 additions
and
1 deletion
NEWS.rst
+
5
−
0
View file @
191bbd18
...
...
@@ -2,6 +2,11 @@
History
=======
20.12.0
-------
Use SecretStorage to store Orus API token.
20.11.0
-------
...
...
This diff is collapsed.
Click to expand it.
odoo_scripts/docker_build_copy.py
+
6
−
1
View file @
191bbd18
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
odoo_scripts/storage.py
0 → 100644
+
52
−
0
View file @
191bbd18
#!/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
())
This diff is collapsed.
Click to expand it.
pyproject.toml
+
2
−
0
View file @
191bbd18
...
...
@@ -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"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment