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

give util functions a context #4556

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/unreleased/context-for-utils.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Allow tracing requests by giving util functions a context

We deprecated GetServiceUserContext with GetServiceUserContextWithContext and GetUser with GetUserWithContext to allow passing in a trace context.

https://github.com/cs3org/reva/pull/4556
15 changes: 13 additions & 2 deletions pkg/utils/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@ var (
)

// GetServiceUserContext returns an authenticated context of the given service user
// Deprecated: Use GetServiceUserContextWithContext()
func GetServiceUserContext(serviceUserID string, gwc gateway.GatewayAPIClient, serviceUserSecret string) (context.Context, error) {
ctx := context.Background()
return GetServiceUserContextWithContext(context.Background(), gwc, serviceUserID, serviceUserSecret)
}

// GetServiceUserContextWithContext returns an authenticated context of the given service user
func GetServiceUserContextWithContext(ctx context.Context, gwc gateway.GatewayAPIClient, serviceUserID string, serviceUserSecret string) (context.Context, error) {
authRes, err := gwc.Authenticate(ctx, &gateway.AuthenticateRequest{
Type: "serviceaccounts",
ClientId: serviceUserID,
Expand All @@ -57,8 +62,14 @@ func GetServiceUserContext(serviceUserID string, gwc gateway.GatewayAPIClient, s
}

// GetUser gets the specified user
// Deprecated: Use GetUserWithContext()
func GetUser(userID *user.UserId, gwc gateway.GatewayAPIClient) (*user.User, error) {
getUserResponse, err := gwc.GetUser(context.Background(), &user.GetUserRequest{UserId: userID})
return GetUserWithContext(context.Background(), userID, gwc)
}

// GetUserWithContext gets the specified user
func GetUserWithContext(ctx context.Context, userID *user.UserId, gwc gateway.GatewayAPIClient) (*user.User, error) {
getUserResponse, err := gwc.GetUser(ctx, &user.GetUserRequest{UserId: userID})
if err != nil {
return nil, err
}
Expand Down
Loading