-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
85 changed files
with
9,386 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
# reva | ||
Cloud Storage Sync and Share Interoperability Platform | ||
# REVA | ||
|
||
Cloud Storage Sync & Share Interoperability Platform | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
appproviderv0alphapb "github.com/cernbox/go-cs3apis/cs3/appprovider/v0alpha" | ||
rpcpb "github.com/cernbox/go-cs3apis/cs3/rpc" | ||
) | ||
|
||
func appProviderGetIFrameCommand() *command { | ||
cmd := newCommand("app-provider-get-iframe") | ||
cmd.Description = func() string { | ||
return "find iframe UI provider for filename" | ||
} | ||
cmd.Action = func() error { | ||
if cmd.NArg() < 3 { | ||
fmt.Println(cmd.Usage()) | ||
os.Exit(1) | ||
} | ||
|
||
appProvider := cmd.Args()[0] | ||
fn := cmd.Args()[1] | ||
token := cmd.Args()[2] | ||
req := &appproviderv0alphapb.GetIFrameRequest{ | ||
Filename: fn, | ||
AccessToken: token, | ||
} | ||
|
||
client, err := getAppProviderClient(appProvider) | ||
if err != nil { | ||
return err | ||
} | ||
ctx := context.Background() | ||
res, err := client.GetIFrame(ctx, req) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if res.Status.Code != rpcpb.Code_CODE_OK { | ||
return formatError(res.Status) | ||
} | ||
|
||
fmt.Printf("Load in your browser the following iframe to edit the resource: %s", res.IframeLocation) | ||
return nil | ||
} | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"mime" | ||
"os" | ||
"path" | ||
|
||
appregistryv0alphapb "github.com/cernbox/go-cs3apis/cs3/appregistry/v0alpha" | ||
rpcpb "github.com/cernbox/go-cs3apis/cs3/rpc" | ||
) | ||
|
||
func appRegistryFindCommand() *command { | ||
cmd := newCommand("app-registry-find") | ||
cmd.Description = func() string { | ||
return "find applicaton provider for file extension or mimetype" | ||
} | ||
cmd.Action = func() error { | ||
if cmd.NArg() == 0 { | ||
fmt.Println(cmd.Usage()) | ||
os.Exit(1) | ||
} | ||
|
||
fn := cmd.Args()[0] | ||
ext := path.Ext(fn) | ||
mime := mime.TypeByExtension(ext) | ||
req := &appregistryv0alphapb.FindRequest{ | ||
FilenameExtension: ext, | ||
FilenameMimetype: mime, | ||
} | ||
|
||
client, err := getAppRegistryClient() | ||
if err != nil { | ||
return err | ||
} | ||
ctx := context.Background() | ||
res, err := client.Find(ctx, req) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if res.Status.Code != rpcpb.Code_CODE_OK { | ||
return formatError(res.Status) | ||
} | ||
|
||
fmt.Printf("application provider can be found at %s\n", res.AppProviderInfo.Location) | ||
return nil | ||
} | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
rpcpb "github.com/cernbox/go-cs3apis/cs3/rpc" | ||
storagebrokerv0alphapb "github.com/cernbox/go-cs3apis/cs3/storagebroker/v0alpha" | ||
) | ||
|
||
func brokerFindCommand() *command { | ||
cmd := newCommand("broker-find") | ||
cmd.Description = func() string { | ||
return "find storage provider for path" | ||
} | ||
cmd.Action = func() error { | ||
fn := "/" | ||
if cmd.NArg() >= 1 { | ||
fn = cmd.Args()[0] | ||
} | ||
|
||
req := &storagebrokerv0alphapb.FindRequest{ | ||
Filename: fn, | ||
} | ||
client, err := getStorageBrokerClient() | ||
if err != nil { | ||
return err | ||
} | ||
ctx := context.Background() | ||
res, err := client.Find(ctx, req) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if res.Status.Code != rpcpb.Code_CODE_OK { | ||
return formatError(res.Status) | ||
} | ||
|
||
fmt.Printf("resource can be found at %s\n", res.ProviderInfo.Location) | ||
return nil | ||
} | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
) | ||
|
||
// command is the representation to create commands | ||
type command struct { | ||
*flag.FlagSet | ||
Name string | ||
Action func() error | ||
Usage func() string | ||
Description func() string | ||
} | ||
|
||
// newCommand creates a new command | ||
func newCommand(name string) *command { | ||
fs := flag.NewFlagSet(name, flag.ExitOnError) | ||
cmd := &command{ | ||
Name: name, | ||
Usage: func() string { | ||
return fmt.Sprintf("Usage: %s", name) | ||
}, | ||
Action: func() error { | ||
fmt.Println("Hello REVA") | ||
return nil | ||
}, | ||
Description: func() string { | ||
return "TODO description" | ||
}, | ||
FlagSet: fs, | ||
} | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"encoding/json" | ||
"io/ioutil" | ||
gouser "os/user" | ||
"path" | ||
"strings" | ||
|
||
"golang.org/x/crypto/ssh/terminal" | ||
) | ||
|
||
func getConfigFile() string { | ||
user, err := gouser.Current() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return path.Join(user.HomeDir, ".reva.config") | ||
} | ||
|
||
func getTokenFile() string { | ||
user, err := gouser.Current() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return path.Join(user.HomeDir, ".reva-token") | ||
} | ||
|
||
func writeToken(token string) { | ||
ioutil.WriteFile(getTokenFile(), []byte(token), 0600) | ||
} | ||
|
||
func readToken() (string, error) { | ||
data, err := ioutil.ReadFile(getTokenFile()) | ||
if err != nil { | ||
return "", err | ||
} | ||
return string(data), nil | ||
} | ||
|
||
func readConfig() (*config, error) { | ||
data, err := ioutil.ReadFile(getConfigFile()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
c := &config{} | ||
if err := json.Unmarshal(data, c); err != nil { | ||
return nil, err | ||
} | ||
|
||
return c, nil | ||
} | ||
|
||
func writeConfig(c *config) error { | ||
data, err := json.Marshal(c) | ||
if err != nil { | ||
return err | ||
} | ||
return ioutil.WriteFile(getConfigFile(), data, 0600) | ||
} | ||
|
||
type config struct { | ||
Host string `json:"host"` | ||
} | ||
|
||
func read(r *bufio.Reader) (string, error) { | ||
text, err := r.ReadString('\n') | ||
if err != nil { | ||
return "", err | ||
} | ||
return strings.TrimSpace(text), nil | ||
} | ||
func readPassword(fd int) (string, error) { | ||
bytePassword, err := terminal.ReadPassword(fd) | ||
if err != nil { | ||
return "", err | ||
} | ||
return strings.TrimSpace(string(bytePassword)), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"os" | ||
) | ||
|
||
var configureCommand = func() *command { | ||
cmd := newCommand("configure") | ||
cmd.Description = func() string { return "configure the reva client" } | ||
cmd.Action = func() error { | ||
reader := bufio.NewReader(os.Stdin) | ||
fmt.Print("host: ") | ||
text, err := read(reader) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
c := &config{Host: text} | ||
writeConfig(c) | ||
fmt.Println("config saved in ", getConfigFile()) | ||
return nil | ||
} | ||
return cmd | ||
} |
Oops, something went wrong.