-
Notifications
You must be signed in to change notification settings - Fork 189
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
fixed the FileInfo.BreadcrumbFolderURL in a collaboration api #10720
Conversation
8e3aead
to
c25ae0b
Compare
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.
I'm pretty sure the coverage.out file shouldn't be there... make sure it's deleted from the repo because it's quite big for something we don't want to keep.
parentFolderURL := &url.URL{} | ||
*parentFolderURL = *ocisURL | ||
parentFolderURL.Path = path.Join(ocisURL.Path, "f", storagespace.FormatResourceID(statRes.GetInfo().GetParentId())) | ||
if publicShare := wopiContext.GetPublicShare(); publicShare != nil && isPublicShare { |
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.
Is the isPublicShare
boolean obsolete now? I mean, you already have the publicShare
variable.
Maybe we can use the publicShare
variable, which has more info, instead of the isPublicShare
@@ -36,6 +38,7 @@ type WopiContext struct { | |||
FileReference *providerv1beta1.Reference | |||
TemplateReference *providerv1beta1.Reference | |||
ViewMode appproviderv1beta1.ViewMode | |||
publicShare *link.PublicShare |
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.
Note that this information will be sent around (encrypted) through the network in the URL. Please, double-check the size of the access token to ensure it doesn't increase by a lot.
We should try to minimize the amount of information we need to move around.
As an alternative, you could parse / decrypt / dismantle the WopiContext.AccessToken
on demand. This might be better for consistency because there is only one source of truth (the access token), so it's impossible to have inconsistencies if the access token says one thing and the public share information says a different thing. It's true that there will be a performance penalty because we need to decrypt the access token twice, but hopefully it's fine.
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.
Why publicShare will be added if it is a private field?
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.
I thought it would be added, but it seems it the json marshaller ignores the private fields, so it should be fine
for k, v := range scope { | ||
if strings.HasPrefix(k, "publicshare:") && v.Resource.Decoder == "json" { | ||
share := &link.PublicShare{} | ||
err := utils.UnmarshalJSONToProtoV1(v.Resource.Value, share) | ||
if err == nil { | ||
claims.WopiContext.publicShare = share | ||
break | ||
} | ||
} | ||
} |
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.
This might need some changes...
Do we need some debug log to know what public shares are we interested in, or how many scopes are detected? In any case, if there is some error unmarshaling the JSON, not only it will be skipped (which might be fine), but we don't know what happen (which is bad). The error needs to be logged at the very least.
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.
added the error logging
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.
Do we need some debug log to know what public shares are we interested in, or how many scopes are detected?
I don't think so. we use the same approach in a publicstorage provider as well https://github.com/cs3org/reva/blob/bddf9f01f7decc0c839a3da26bacbac5a8a05156/internal/grpc/services/publicstorageprovider/publicstorageprovider.go#L525
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 feels weird that the last sentence is an unconditional error log. It seems the goal is to log the error and not filling the publicShare
property.
What about
if strings.HasPrefix(k, "publicshare:") && ..... {
err := utils.UnmarshalJSONToProtoV1(......)
if err != nil {
wopiLogger.Error().Err(err)......
} else {
claims.WopiContext.publicShare = share
}
break
}
Note that the usual pattern is if err != nil { return / break....}
, so changing the pattern makes the code slower to read for a person.
@@ -230,6 +245,13 @@ func GenerateWopiToken(wopiContext WopiContext, cfg *config.Config, st microstor | |||
return accessToken, claims.ExpiresAt.UnixMilli(), err | |||
} | |||
|
|||
func (w *WopiContext) GetPublicShare() *link.PublicShare { |
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.
This is questionable as it is at the moment. Why the publicShare
property isn't public like the rest? That would make this method obsolete. At the moment, this method doesn't add anything of value other than getting the value, so making the property public to keep the consistency with the rest of the data seems fine to me.
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.
So the property needs to be private in order not to include it in the jwt token, and we need a public method to access to the private property.
A couple of additional things:
- If the method is attached to the WopiContext, it's better to have the code as close as possible to the WopiContext definition, so the code should be move upwards. Reading the code should be easier this way.
- This method just returns the private property, but it might not be set or evaluated yet (a bit weird scenario, but it could happen if we prepare a WopiContext outside of the http middleware). In this regard, it might be better to either include a public
EvaluatePublicShare
method that should be called before getting the public share (most of the code is already in the middleware, so it's moving things around), or extract the public share information on demand with theGetPublicShare
method and let the private property act as a cache.
I'd go with theEvaluatePublicShare
in case the access token changes (which shouldn't happen under normal conditions) because it gives us extra flexibility. As long as it's documented that theEvaluatePublicShare
must be called before theGetPublicShare
, it should be fine.
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.
I don't think that EvaluatePublicShare
method will be good because it has some dependencies.
We could change the private field publicShare
to scope
and change the GetPublicShare
to generic GetScope(keyPrefix string, m proto.Message)
method
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.
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 scope is only filled in the middleware, and I don't think it's a good idea. If you check the tests, we create a custom WopiContext, but even if we supply correct data to the public WopiContext properties, the scope won't return anything valuable. This is why a suggested to include the EvaluatePublicShare
method: to fill and adjust the private properties.
Changing the WopiContext, in particular the access token inside, could also have negative consequences because the scope information isn't valid any longer and we can't update the information in any way. This means that the only valid context is the one supplied by the middleware, and changing or adjusting data in the WopiContext is discouraged.
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.
We can try to do it another way, use the context like for the user.
ctx = ctxpkg.ContextSetScopes(ctx, scope)
ocis/services/collaboration/pkg/middleware/wopicontext.go
Lines 123 to 134 in 2237534
user, _, err := tokenManager.DismantleToken(ctx, wopiContextAccessToken) | |
if err != nil { | |
wopiLogger.Error().Err(err).Msg("failed to dismantle reva token manager") | |
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) | |
return | |
} | |
claims.WopiContext.AccessToken = wopiContextAccessToken | |
ctx = context.WithValue(ctx, wopiContextKey, claims.WopiContext) | |
// authentication for the CS3 api | |
ctx = metadata.AppendToOutgoingContext(ctx, ctxpkg.TokenHeader, claims.WopiContext.AccessToken) | |
ctx = ctxpkg.ContextSetUser(ctx, user) |
In this case we can use existing functions ContextSetScopes
, ContextGetScopes
and add some scope extractor function
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.
c07323d
to
eee7a4e
Compare
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.
remember to remove the coverage.out file!
scope map[string]*auth.Scope | ||
} | ||
|
||
// GetScope returns the scope from the WopiContext |
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.
We might need some additional information to say that you need to provide a "message" and the result will be written there.
In general, parameters are treated as read-only, so nobody expects a parameter to change inside the function. The cases where this happens are limited. If the idea is that you just need to pass a placeholder where the result will be written, I think it's better to document it to avoid confusion.
39e42ce
to
9d62fbc
Compare
Quality Gate passedIssues Measures |
fixed the FileInfo.BreadcrumbFolderURL in a collaboration api
We could move the |
Description
Fixed the FileInfo.BreadcrumbFolderURL in a collaboration api"
Related Issue
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: