Skip to content

Commit

Permalink
appprovider fixes (#2024)
Browse files Browse the repository at this point in the history
  • Loading branch information
wkloucek authored Sep 1, 2021
1 parent 5c0e31a commit b54f42d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
4 changes: 4 additions & 0 deletions changelog/unreleased/appprovider-url-object-fixes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Bugfix: Fixes for http appprovider endpoints

https://github.com/cs3org/reva/pull/2024
https://github.com/cs3org/reva/pull/1968
4 changes: 2 additions & 2 deletions internal/grpc/services/appregistry/appregistry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func Test_ListAppProviders(t *testing.T) {
Providers: []*registrypb.ProviderInfo{
{
Address: "",
MimeTypes: []string{"text/plain"},
MimeTypes: []string{},
},
},
},
Expand All @@ -104,7 +104,7 @@ func Test_ListAppProviders(t *testing.T) {
Providers: []*registrypb.ProviderInfo{
{
Address: "",
MimeTypes: []string{"text/plain"},
MimeTypes: []string{},
},
},
},
Expand Down
24 changes: 24 additions & 0 deletions internal/http/services/appprovider/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ func (s *svc) handleList(w http.ResponseWriter, r *http.Request) {
mimeTypes := listRes.MimeTypes
filterAppsByUserAgent(mimeTypes, r.UserAgent())

filterMimeTypes(mimeTypes)

if mimeTypes == nil {
mimeTypes = make(map[string]*appregistry.AppProviderList) // ensure array empty object instead of null in json
}

js, err := json.Marshal(map[string]interface{}{"mime-types": mimeTypes})
if err != nil {
ocmd.WriteError(w, r, ocmd.APIErrorServerError, "error marshalling JSON response", err)
Expand Down Expand Up @@ -183,6 +189,24 @@ func (s *svc) handleOpen(w http.ResponseWriter, r *http.Request) {
}
}

func filterMimeTypes(mimeTypes map[string]*appregistry.AppProviderList) {
for m, providers := range mimeTypes {
apps := []*appregistry.ProviderInfo{}
for _, p := range providers.AppProviders {
p.Address = "" // address is internal only and not needed in the client
// apps are called by name, so if it has no name you cannot call it. Therefore we should not advertise it.
if p.Name != "" {
apps = append(apps, p)
}
}
if len(apps) > 0 {
mimeTypes[m] = &appregistry.AppProviderList{AppProviders: apps}
} else {
delete(mimeTypes, m)
}
}
}

func filterAppsByUserAgent(mimeTypes map[string]*appregistry.AppProviderList, userAgent string) {
ua := ua.Parse(userAgent)
if ua.Desktop {
Expand Down
3 changes: 2 additions & 1 deletion pkg/app/provider/wopi/wopi.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ func (p *wopiProvider) getAccessTokenTTL(ctx context.Context) (string, error) {
}

if claims, ok := token.Claims.(*jwt.StandardClaims); ok && token.Valid {
return strconv.FormatInt(claims.ExpiresAt, 10), nil
// milliseconds since Jan 1, 1970 UTC as required in https://wopi.readthedocs.io/projects/wopirest/en/latest/concepts.html?highlight=access_token_ttl#term-access-token-ttl
return strconv.FormatInt(claims.ExpiresAt*1000, 10), nil
}

return "", errtypes.InvalidCredentials("wopi: invalid token present in ctx")
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/registry/static/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (c *config) init() {
c.Providers = map[string]*registrypb.ProviderInfo{
sharedconf.GetGatewaySVC(""): {
Address: sharedconf.GetGatewaySVC(""),
MimeTypes: []string{"text/plain"},
MimeTypes: []string{},
},
}
}
Expand Down

0 comments on commit b54f42d

Please sign in to comment.