Skip to content
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

Update WeaviateDocumentStore authentication to use new Secret class #425

Merged
merged 9 commits into from
Feb 15, 2024

Conversation

silvanocerza
Copy link
Contributor

@silvanocerza silvanocerza commented Feb 15, 2024

Fixes #369.

Weaviate supports different manner of authentication via some utility dataclasses.
Cause of this it wasn't feasible to use an init parameterer for each possible secret, so we mirrored a bit their utility classes structures to use the Secret class.

You'll notice that I used a default_factory in all dataclasses fields cause we can't use default as Secret is not a frozen dataclass in the latest beta. When that changes we should be able to use default.

@silvanocerza silvanocerza self-assigned this Feb 15, 2024
@silvanocerza silvanocerza requested a review from a team as a code owner February 15, 2024 14:59
@silvanocerza silvanocerza requested review from davidsbatista and removed request for a team February 15, 2024 14:59
@github-actions github-actions bot added integration:weaviate type:documentation Improvements or additions to documentation labels Feb 15, 2024
@shadeMe shadeMe self-requested a review February 15, 2024 15:09
"""

access_token: Secret = field(default_factory=lambda: Secret.from_env_var(["WEAVIATE_ACCESS_TOKEN"]))
expires_in: Secret = field(default_factory=lambda: Secret.from_env_var(["WEAVIATE_EXPIRES_IN"], strict=False))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look like a secret. Let's just make it a regular int that defaults to 60.

"""


@dataclass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's freeze all dataclasses.

if "type" not in data:
msg = "Missing 'type' in serialization data"
raise DeserializationError(msg)
return _AUTH_CLASSES[data["type"]]._from_dict(data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just move the map into the function.

"""
Converts the object to a dictionary representation for serialization.
"""
# We assume all fields are Secret instances
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check instead of assuming, especially if the expires_in field is going to be an int (see below.)

Comment on lines 29 to 32
return default_to_dict(
self,
**_fields,
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be more comfortable if we used an explicit enum instead of the full type name. That way, it won't break if we move/rename the underlying classes.

@silvanocerza silvanocerza merged commit 5ca05dc into main Feb 15, 2024
9 checks passed
@silvanocerza silvanocerza deleted the weaviate-auth branch February 15, 2024 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration:weaviate type:documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update core integration secret managment - Weaviate
2 participants