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

Initial implementation of the new OpenInApp API #1723

Merged
merged 1 commit into from
May 28, 2021
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
7 changes: 7 additions & 0 deletions changelog/unreleased/improve-open-in-app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Enhancement: Open in app workflow using the new API

This provides a new `open-in-app` command for the CLI and the implementation
on the appprovider gateway service for the new API, including the option
to specify the appplication to use, thus overriding the preconfigured one.

https://github.com/cs3org/reva/pull/1723
2 changes: 1 addition & 1 deletion cmd/reva/completer.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (c *Completer) argumentCompleter(args ...string) []prompt.Suggest {
return prompt.FilterHasPrefix(c.lsArgumentCompleter(false), args[2], true)
}

case "rm", "stat", "share-create", "ocm-share-create", "public-share-create", "open-file-in-app-provider", "download":
case "rm", "stat", "share-create", "ocm-share-create", "public-share-create", "open-in-app", "open-file-in-app-provider", "download":
if len(args) == 2 {
return prompt.FilterHasPrefix(c.lsArgumentCompleter(false), args[1], true)
}
Expand Down
1 change: 1 addition & 0 deletions cmd/reva/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ var (
shareUpdateCommand(),
shareListReceivedCommand(),
shareUpdateReceivedCommand(),
openInAppCommand(),
openFileInAppProviderCommand(),
transferCreateCommand(),
transferGetStatusCommand(),
Expand Down
4 changes: 2 additions & 2 deletions cmd/reva/open-file-in-app-provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func openFileInAppProviderCommand() *command {
}
path := cmd.Args()[0]

vm := getViewMode(*viewMode)
vm := getViewModeDeprecated(*viewMode)

client, err := getClient()
if err != nil {
Expand Down Expand Up @@ -91,7 +91,7 @@ func openFileInAppProviderCommand() *command {
return cmd
}

func getViewMode(viewMode string) gateway.OpenFileInAppProviderRequest_ViewMode {
func getViewModeDeprecated(viewMode string) gateway.OpenFileInAppProviderRequest_ViewMode {
switch viewMode {
case "view":
return gateway.OpenFileInAppProviderRequest_VIEW_MODE_VIEW_ONLY
Expand Down
107 changes: 107 additions & 0 deletions cmd/reva/open-in-app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Copyright 2018-2021 CERN
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// In applying this license, CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

package main

import (
"fmt"
"io"

gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
typespb "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/pkg/errors"
)

func openInAppCommand() *command {
cmd := newCommand("open-in-app")
cmd.Description = func() string { return "open a reference in an external app provider" }
cmd.Usage = func() string {
return "Usage: open-in-app [-flags] [-viewmode view|read|write] [-app appname] <path>"
}
viewMode := cmd.String("viewmode", "view", "the view permissions, defaults to view")
app := cmd.String("app", "", "the application if the default is to be overridden for the file's mimetype")
insecureFlag := cmd.Bool("insecure", false, "disables grpc transport security")
skipVerifyFlag := cmd.Bool("skip-verify", false, "whether to skip verifying remote reva's certificate chain and host name")

cmd.ResetFlags = func() {
*viewMode = "view"
*app = ""
*insecureFlag = false
*skipVerifyFlag = false
}

cmd.Action = func(w ...io.Writer) error {
ctx := getAuthContext()
if cmd.NArg() < 1 {
return errors.New("Invalid arguments: " + cmd.Usage())
}
path := cmd.Args()[0]

vm := getViewMode(*viewMode)

client, err := getClient()
if err != nil {
return err
}

ref := &provider.Reference{
Spec: &provider.Reference_Path{Path: path},
}

opaqueObj := &typespb.Opaque{
Map: map[string]*typespb.OpaqueEntry{},
}
if *insecureFlag {
opaqueObj.Map["insecure"] = &typespb.OpaqueEntry{}
}
if *skipVerifyFlag {
opaqueObj.Map["skip-verify"] = &typespb.OpaqueEntry{}
}

openRequest := &gateway.OpenInAppRequest{Ref: ref, ViewMode: vm, App: *app, Opaque: opaqueObj}

openRes, err := client.OpenInApp(ctx, openRequest)
if err != nil {
return err
}

if openRes.Status.Code != rpc.Code_CODE_OK {
return formatError(openRes.Status)
}

fmt.Println("App URL: " + openRes.AppUrl)

return nil
}
return cmd
}

func getViewMode(viewMode string) gateway.OpenInAppRequest_ViewMode {
switch viewMode {
case "view":
return gateway.OpenInAppRequest_VIEW_MODE_VIEW_ONLY
case "read":
return gateway.OpenInAppRequest_VIEW_MODE_READ_ONLY
case "write":
return gateway.OpenInAppRequest_VIEW_MODE_READ_WRITE
default:
return gateway.OpenInAppRequest_VIEW_MODE_INVALID
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ description: >
# _struct: config_

{{% dir name="iopsecret" type="string" default="" %}}
The iopsecret used to connect to the wopiserver. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L59)
The iopsecret used to connect to the wopiserver. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L60)
{{< highlight toml >}}
[grpc.services.appprovider]
iopsecret = ""
{{< /highlight >}}
{{% /dir %}}

{{% dir name="wopiurl" type="string" default="" %}}
The wopiserver's URL. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L60)
The wopiserver's URL. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L61)
{{< highlight toml >}}
[grpc.services.appprovider]
wopiurl = ""
{{< /highlight >}}
{{% /dir %}}

{{% dir name="wopibridgeurl" type="string" default="" %}}
The wopibridge's URL. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L61)
The wopibridge's URL. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L62)
{{< highlight toml >}}
[grpc.services.appprovider]
wopibridgeurl = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,47 @@ description: >
# _struct: config_

{{% dir name="insecure" type="bool" default=false %}}
Whether to skip certificate checks when sending requests. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/auth/manager/oidc/oidc.go#L53)
Whether to skip certificate checks when sending requests. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/auth/manager/oidc/oidc.go#L55)
{{< highlight toml >}}
[auth.manager.oidc]
insecure = false
{{< /highlight >}}
{{% /dir %}}

{{% dir name="issuer" type="string" default="" %}}
The issuer of the OIDC token. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/auth/manager/oidc/oidc.go#L54)
The issuer of the OIDC token. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/auth/manager/oidc/oidc.go#L56)
{{< highlight toml >}}
[auth.manager.oidc]
issuer = ""
{{< /highlight >}}
{{% /dir %}}

{{% dir name="id_claim" type="string" default="sub" %}}
The claim containing the ID of the user. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/auth/manager/oidc/oidc.go#L55)
The claim containing the ID of the user. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/auth/manager/oidc/oidc.go#L57)
{{< highlight toml >}}
[auth.manager.oidc]
id_claim = "sub"
{{< /highlight >}}
{{% /dir %}}

{{% dir name="uid_claim" type="string" default="" %}}
The claim containing the UID of the user. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/auth/manager/oidc/oidc.go#L56)
The claim containing the UID of the user. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/auth/manager/oidc/oidc.go#L58)
{{< highlight toml >}}
[auth.manager.oidc]
uid_claim = ""
{{< /highlight >}}
{{% /dir %}}

{{% dir name="gid_claim" type="string" default="" %}}
The claim containing the GID of the user. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/auth/manager/oidc/oidc.go#L57)
The claim containing the GID of the user. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/auth/manager/oidc/oidc.go#L59)
{{< highlight toml >}}
[auth.manager.oidc]
gid_claim = ""
{{< /highlight >}}
{{% /dir %}}

{{% dir name="gatewaysvc" type="string" default="" %}}
The endpoint at which the GRPC gateway is exposed. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/auth/manager/oidc/oidc.go#L58)
The endpoint at which the GRPC gateway is exposed. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/auth/manager/oidc/oidc.go#L60)
{{< highlight toml >}}
[auth.manager.oidc]
gatewaysvc = ""
Expand Down
2 changes: 1 addition & 1 deletion docs/content/en/docs/tutorials/wopi-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ Run according to instructions in the readme ("Run the WOPI server locally", http
## 7. Local changes
To try the connection you could for example go to a new reva terminal window and type
`./cmd/reva/reva -insecure login basic` - use einstein and relativity as log in ccredentials
`./cmd/reva/reva -insecure open-file-in-app-provider /home/example.txt read` - this should print out the app provider url in your terminal.
`./cmd/reva/reva -insecure open-in-app /home/example.txt read` - this should print out the app provider url in your terminal.

## 8. Enjoy your new Reva and wopiserver set up!
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/cheggaaa/pb v1.0.29
github.com/coreos/go-oidc v2.2.1+incompatible
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e
github.com/cs3org/go-cs3apis v0.0.0-20210527092012-82617367e09d
github.com/cs3org/go-cs3apis v0.0.0-20210527092509-2b828e94ed4c
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/eventials/go-tus v0.0.0-20200718001131-45c7ec8f5d59
github.com/gdexlab/go-render v1.0.1
Expand Down
Loading