Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
cli
Manage
Activity
Members
Labels
Plan
Issues
3
Issue boards
Milestones
Wiki
Code
Merge requests
2
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
funkwhale
cli
Commits
768f2701
Verified
Commit
768f2701
authored
6 years ago
by
Eliot Berriot
Browse files
Options
Downloads
Patches
Plain Diff
Fix
#4
: lazy password evaluation
parent
e9a01d47
No related branches found
No related tags found
1 merge request
!4
Fix #4: lazy password evaluation
Pipeline
#4170
passed with stage
in 38 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
funkwhale_cli/cli.py
+30
-1
30 additions, 1 deletion
funkwhale_cli/cli.py
tests/test_cli.py
+18
-0
18 additions, 0 deletions
tests/test_cli.py
with
48 additions
and
1 deletion
funkwhale_cli/cli.py
+
30
−
1
View file @
768f2701
...
...
@@ -88,6 +88,35 @@ RAW_DECORATOR = click.option(
"
--raw
"
,
is_flag
=
True
,
help
=
"
Directly output JSON returned by the happy
"
)
class
lazy_credential
():
"""
A proxy object to request access to the proxy object at the later possible point,
cf #4
"""
def
__init__
(
self
,
*
args
):
self
.
args
=
args
self
.
_cached_value
=
None
@property
def
value
(
self
):
if
self
.
_cached_value
:
return
self
.
_cached_value
v
=
keyring
.
get_password
(
*
self
.
args
)
self
.
_cached_value
=
v
return
v
def
__str__
(
self
):
return
str
(
self
.
value
)
def
__eq__
(
self
,
other
):
return
self
.
value
==
other
def
__repr__
(
self
):
return
str
(
self
.
value
)
def
__bool__
(
self
):
return
bool
(
self
.
value
)
def
set_server
(
ctx
,
url
,
token
):
ctx
.
ensure_object
(
dict
)
...
...
@@ -96,7 +125,7 @@ def set_server(ctx, url, token):
ctx
.
obj
[
"
SERVER_NETLOC
"
]
=
parsed
.
netloc
ctx
.
obj
[
"
SERVER_PROTOCOL
"
]
=
parsed
.
scheme
try
:
token
=
token
or
keyring
.
get_password
(
url
,
"
_
"
)
token
=
token
or
lazy_credential
(
url
,
"
_
"
)
except
ValueError
as
e
:
raise
click
.
ClickException
(
"
Error while retrieving password from keyring: {}. Your password may be incorrect.
"
.
format
(
e
.
args
[
0
]))
except
Exception
as
e
:
...
...
This diff is collapsed.
Click to expand it.
tests/test_cli.py
+
18
−
0
View file @
768f2701
import
pytest
import
click
import
keyring
from
funkwhale_cli
import
api
from
funkwhale_cli
import
cli
...
...
@@ -61,3 +62,20 @@ def test_delete_command(group, cli_ctx, session, responses):
)
def
test_get_pagination_data
(
input
,
output
):
assert
cli
.
get_pagination_data
(
input
)
==
output
def
test_lazy_credential
(
mocker
):
get_password
=
mocker
.
patch
(
"
keyring.get_password
"
,
return_value
=
"
password
"
)
credential
=
cli
.
lazy_credential
(
"
http://testurl
"
,
"
_
"
)
get_password
.
assert_not_called
()
str
(
credential
)
get_password
.
assert_called_once_with
(
"
http://testurl
"
,
"
_
"
)
assert
credential
==
"
password
"
# result is cached
str
(
credential
)
assert
get_password
.
call_count
==
1
This diff is collapsed.
Click to expand it.
neodarz
@neodarz
mentioned in issue
#7 (closed)
·
6 years ago
mentioned in issue
#7 (closed)
mentioned in issue #7
Toggle commit list
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