-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Removing SecretStr from RemoteRepository model #75
Conversation
SecretStr is not JSON serializable and is throwing exceptions for RemoteRepositories that require a password.
Hi @ajrpeggio, A better solution is t create a custom encoder in a
Then in the
with
|
pyartifactory/utils.py
Outdated
from pydantic import SecretStr | ||
from pydantic.json import pydantic_encoder | ||
|
||
|
||
def custom_encoder(obj): | ||
if isinstance(obj, SecretStr): | ||
return obj.get_secret_value() | ||
else: | ||
return pydantic_encoder(obj) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that you haven't run the pre-commits
(Please read the CONTRIBUTING.md file). If you had, you could have seen the following errors:
pyartifactory/utils.py:1:0: C0114: Missing module docstring (missing-module-docstring)
pyartifactory/utils.py:5:0: C0116: Missing function or method docstring (missing-function-docstring)
pyartifactory/utils.py:6:4: R1705: Unnecessary "else" after "return" (no-else-return)
Can be fixed with:
"""
Definition of all utils.
"""
from typing import Any
from pydantic import SecretStr
from pydantic.json import pydantic_encoder
def custom_encoder(obj: Any) -> Any:
"""
Custom encoder function to be passed to the default argument of json.dumps()
:param obj: A pydantic object
:return: An encoded pydantic object
"""
if isinstance(obj, SecretStr):
return obj.get_secret_value()
return pydantic_encoder(obj)
pyartifactory/objects.py
Outdated
f"Repository {repo_name} already exists" | ||
) | ||
except RepositoryNotFoundException: | ||
data= json.dumps(repo, default=custom_encoder) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pre-commits also highlight formatting issue in this line. Indeed data=
should be data =
Also, there are conflicts with the master branch. Indeed, a new release has been merged a few days ago. You will also need to fix the conflicts before merging. We're almost done. A few changes and we are good :) |
Hi @ajrpeggio , |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's go!
Apologies for getting back to this so late. Thank you for fixing these! |
No worries. You're welcome ! |
SecretStr is not JSON serializable and is throwing exceptions for RemoteRepositories that require a password.
Description
I've been using this library to create repositories for my Artifactory Instance. I started adding a RemoteRepository for docker and came upon this error that states: "Object of type SecretStr is not JSON serializable"
To Reproduce
Steps to reproduce the behavior:
Fixes # #74