Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
silkaj
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
python
silkaj
Commits
2ee05f74
Commit
2ee05f74
authored
2 months ago
by
Moul
Browse files
Options
Downloads
Patches
Plain Diff
Implement AccountStorage class (
#477
)
Define tools.click_fail() (
#501
)
parent
deb6152b
No related branches found
No related tags found
1 merge request
!277
Account storage support: authentication, revocation (#477)
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
silkaj/account_storage.py
+54
-0
54 additions, 0 deletions
silkaj/account_storage.py
silkaj/tools.py
+5
-0
5 additions, 0 deletions
silkaj/tools.py
tests/unit/test_account_storage.py
+49
-0
49 additions, 0 deletions
tests/unit/test_account_storage.py
with
108 additions
and
0 deletions
silkaj/account_storage.py
0 → 100644
+
54
−
0
View file @
2ee05f74
# Copyright 2016-2025 Maël Azimi <m.a@moul.re>
#
# Silkaj is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Silkaj is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Silkaj. If not, see <https://www.gnu.org/licenses/>.
from
pathlib
import
Path
from
silkaj
import
tools
from
silkaj.blockchain
import
tools
as
bc_tools
class
AccountStorage
:
xdg_data_home
=
"
.local/share
"
program_name
=
"
silkaj
"
revocation_file_name
=
"
revocation.txt
"
authentication_v1_file_name
=
"
authentication_file_ed25519.dewif
"
authentication_v2_file_name
=
"
authentication_file_sr25519.json
"
def
__init__
(
self
)
->
None
:
self
.
account_name
=
tools
.
has_account_defined
()
self
.
path
=
Path
.
home
().
joinpath
(
self
.
xdg_data_home
,
self
.
program_name
,
bc_tools
.
get_currency
(),
self
.
account_name
,
)
self
.
path
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
def
authentication_file_path
(
self
,
check_exist
:
bool
=
True
)
->
Path
:
auth_file_path
=
self
.
path
.
joinpath
(
self
.
authentication_v1_file_name
)
if
check_exist
and
not
auth_file_path
.
is_file
():
tools
.
click_fail
(
f
"
{
auth_file_path
}
not found for account name:
{
self
.
account_name
}
"
,
)
return
auth_file_path
def
revocation_path
(
self
,
check_exist
:
bool
=
True
)
->
Path
:
revocation_path
=
self
.
path
.
joinpath
(
self
.
revocation_file_name
)
if
check_exist
and
not
revocation_path
.
is_file
():
tools
.
click_fail
(
f
"
{
revocation_path
}
not found for account name:
{
self
.
account_name
}
"
,
)
return
revocation_path
This diff is collapsed.
Click to expand it.
silkaj/tools.py
+
5
−
0
View file @
2ee05f74
...
...
@@ -36,6 +36,11 @@ def message_exit(message: str) -> None:
sys
.
exit
(
FAILURE_EXIT_STATUS
)
@click.pass_context
def
click_fail
(
context
:
click
.
Context
,
message
:
str
)
->
None
:
context
.
fail
(
message
)
class
MutuallyExclusiveOption
(
click
.
Option
):
def
__init__
(
self
,
*
args
:
Any
,
**
kwargs
:
Any
)
->
None
:
self
.
mutually_exclusive
=
set
(
kwargs
.
pop
(
"
mutually_exclusive
"
,
[]))
...
...
This diff is collapsed.
Click to expand it.
tests/unit/test_account_storage.py
0 → 100644
+
49
−
0
View file @
2ee05f74
# Copyright 2016-2025 Maël Azimi <m.a@moul.re>
#
# Silkaj is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Silkaj is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Silkaj. If not, see <https://www.gnu.org/licenses/>.
from
pathlib
import
Path
from
unittest.mock
import
Mock
import
pytest
from
silkaj.account_storage
import
AccountStorage
from
silkaj.blockchain
import
tools
from
tests
import
helpers
@pytest.mark.parametrize
(
(
"
account_name
"
,
"
currency
"
),
[
(
"
test
"
,
"
g1
"
),
(
"
toto
"
,
"
g1-test
"
),
],
)
def
test_account_storage_account
(
account_name
,
currency
,
monkeypatch
):
def
patched_get_currency
():
return
currency
helpers
.
define_click_context
(
account_name
=
account_name
)
patched_pathlib_mkdir
=
Mock
()
monkeypatch
.
setattr
(
Path
,
"
mkdir
"
,
patched_pathlib_mkdir
)
monkeypatch
.
setattr
(
tools
,
"
get_currency
"
,
patched_get_currency
)
account_storage
=
AccountStorage
()
assert
account_storage
.
path
==
Path
.
home
().
joinpath
(
account_storage
.
xdg_data_home
,
account_storage
.
program_name
,
currency
,
account_name
,
)
patched_pathlib_mkdir
.
assert_called_once
()
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