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

WIP: tracing + refactor + gateway service. #165

Merged
merged 34 commits into from
Aug 14, 2019
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
83a4554
refactor
labkode Jul 29, 2019
235e7ab
refactor
labkode Jul 23, 2019
09eb717
refactor
labkode Jul 23, 2019
c0c3fe0
refactor
labkode Jul 25, 2019
4c18cff
refactor
labkode Jul 26, 2019
3167b51
refactor
labkode Jul 29, 2019
f02356e
refactor
labkode Jul 29, 2019
a8f1e44
refactor
labkode Jul 30, 2019
a03606f
use gateway services
labkode Jul 30, 2019
a4a3421
ignore pid files
labkode Jul 30, 2019
a9948fd
refactor
labkode Jul 31, 2019
20e3a4d
refactor
labkode Jul 31, 2019
50017ea
clean fmt.Pritnln calls
labkode Jul 31, 2019
7e12e0b
clean
labkode Jul 31, 2019
138560f
add more services to gateway
labkode Jul 31, 2019
52b0609
refactor
labkode Jul 31, 2019
15d9706
use common package for errors
labkode Aug 8, 2019
1c6eed4
fix errtypes import
labkode Aug 8, 2019
b0ae5f6
add in memory implementation for received shares
labkode Aug 8, 2019
442261f
implement share manager
labkode Aug 8, 2019
73ea020
sync to cs3apis
labkode Aug 8, 2019
602be88
fix ocssvc
labkode Aug 8, 2019
db6f888
add share commands
labkode Aug 12, 2019
a79993f
refactor: use status package
labkode Aug 12, 2019
675ecdb
refactor auth
labkode Aug 12, 2019
7e3850f
add share-update command
labkode Aug 12, 2019
5444364
add pretty print
labkode Aug 12, 2019
77b7f19
finish sharing api
labkode Aug 12, 2019
992947f
always craete working folders
labkode Aug 12, 2019
bcfd3ba
polish
labkode Aug 12, 2019
79ba671
add more services to gatewaysvc
labkode Aug 12, 2019
15be4d3
include ocdavsvc in gateway
labkode Aug 12, 2019
5b5ff45
fix linters
labkode Aug 13, 2019
fff604e
Merge branch 'master' into tracing
labkode Aug 13, 2019
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
19 changes: 7 additions & 12 deletions cmd/reva/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,27 @@ import (
"io"
"net/http"
"os"
"time"

"github.com/cheggaaa/pb"
rpcpb "github.com/cs3org/go-cs3apis/cs3/rpc"
storageproviderv0alphapb "github.com/cs3org/go-cs3apis/cs3/storageprovider/v0alpha"
"github.com/cs3org/reva/cmd/revad/svcs/httpsvcs/utils"
)

func downloadCommand() *command {
cmd := newCommand("download")
cmd.Description = func() string { return "download a remote file into the local filesystem" }
cmd.Usage = func() string { return "Usage: download [-flags] <remote_file> <local_file>" }
cmd.Action = func() error {
if cmd.NArg() < 3 {
if cmd.NArg() < 2 {
fmt.Println(cmd.Usage())
os.Exit(1)
}

provider := cmd.Args()[0]
remote := cmd.Args()[1]
local := cmd.Args()[2]
remote := cmd.Args()[0]
local := cmd.Args()[1]

client, err := getStorageProviderClient(provider)
client, err := getStorageProviderClient()
if err != nil {
return err
}
Expand Down Expand Up @@ -85,16 +84,12 @@ func downloadCommand() *command {

dataServerURL := res.DownloadEndpoint
// TODO(labkode): do a protocol switch
httpReq, err := http.NewRequest("GET", dataServerURL, nil)
httpReq, err := utils.NewRequest(ctx, "GET", dataServerURL, nil)
if err != nil {
return err
}

// TODO(labkode): harden http client
// https://medium.com/@nate510/don-t-use-go-s-default-http-client-4804cb19f779
httpClient := &http.Client{
Timeout: time.Second * 10,
}
httpClient := utils.GetHTTPClient(ctx)

httpRes, err := httpClient.Do(httpReq)
if err != nil {
Expand Down
26 changes: 12 additions & 14 deletions cmd/reva/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ import (
"fmt"
"log"

"google.golang.org/grpc/metadata"

"github.com/pkg/errors"

appproviderv0alphapb "github.com/cs3org/go-cs3apis/cs3/appprovider/v0alpha"
appregistryv0alphapb "github.com/cs3org/go-cs3apis/cs3/appregistry/v0alpha"
authv0alphapb "github.com/cs3org/go-cs3apis/cs3/auth/v0alpha"
Expand All @@ -35,10 +31,15 @@ import (
storageproviderv0alphapb "github.com/cs3org/go-cs3apis/cs3/storageprovider/v0alpha"
storageregistryv0alphapb "github.com/cs3org/go-cs3apis/cs3/storageregistry/v0alpha"
usershareproviderv0alphapb "github.com/cs3org/go-cs3apis/cs3/usershareprovider/v0alpha"

"github.com/cs3org/reva/cmd/revad/svcs/grpcsvcs/pool"
"github.com/cs3org/reva/pkg/token"
"github.com/pkg/errors"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
)

const defaultHeader = "x-access-token"

func getAuthContext() context.Context {
ctx := context.Background()
// read token from file
Expand All @@ -47,7 +48,8 @@ func getAuthContext() context.Context {
log.Println(err)
return ctx
}
ctx = metadata.AppendToOutgoingContext(ctx, "x-access-token", t)
ctx = token.ContextSetToken(ctx, t)
ctx = metadata.AppendToOutgoingContext(ctx, defaultHeader, t)
return ctx
}

Expand All @@ -74,20 +76,16 @@ func getAppRegistryClient() (appregistryv0alphapb.AppRegistryServiceClient, erro
return appregistryv0alphapb.NewAppRegistryServiceClient(conn), nil
}

func getUserShareProviderClient(host string) (usershareproviderv0alphapb.UserShareProviderServiceClient, error) {
conn, err := getConnToHost(host)
func getUserShareProviderClient() (usershareproviderv0alphapb.UserShareProviderServiceClient, error) {
conn, err := getConn()
if err != nil {
return nil, err
}
return usershareproviderv0alphapb.NewUserShareProviderServiceClient(conn), nil
}

func getStorageProviderClient(host string) (storageproviderv0alphapb.StorageProviderServiceClient, error) {
conn, err := getConnToHost(host)
if err != nil {
return nil, err
}
return storageproviderv0alphapb.NewStorageProviderServiceClient(conn), nil
func getStorageProviderClient() (storageproviderv0alphapb.StorageProviderServiceClient, error) {
return pool.GetStorageProviderServiceClient(conf.Host)
}

func getAuthClient() (authv0alphapb.AuthServiceClient, error) {
Expand Down
11 changes: 5 additions & 6 deletions cmd/reva/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,19 @@ import (
func importCommand() *command {
cmd := newCommand("import")
cmd.Description = func() string { return "import metadata" }
cmd.Usage = func() string { return "Usage: import [-flags] <provider> <user export folder>" }
cmd.Usage = func() string { return "Usage: import [-flags] <user export folder>" }
cmd.Action = func() error {
if cmd.NArg() < 2 {
if cmd.NArg() < 1 {
fmt.Println(cmd.Usage())
os.Exit(1)
}
provider := cmd.Args()[0]
f := cmd.Args()[1]
f := cmd.Args()[0]

sClient, err := getStorageProviderClient(provider)
sClient, err := getStorageProviderClient()
if err != nil {
return err
}
uClient, err := getUserShareProviderClient(provider)
uClient, err := getUserShareProviderClient()
if err != nil {
return err
}
Expand Down
23 changes: 15 additions & 8 deletions cmd/reva/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,26 @@ package main
import (
"fmt"
"os"
"path"

storageproviderv0alphapb "github.com/cs3org/go-cs3apis/cs3/storageprovider/v0alpha"
)

func lsCommand() *command {
cmd := newCommand("ls")
cmd.Description = func() string { return "list a folder contents" }
cmd.Usage = func() string { return "Usage: ls [-flags] <provider> <folder_name>" }
cmd.Description = func() string { return "list a container contents" }
cmd.Usage = func() string { return "Usage: ls [-flags] <container_name>" }
longFlag := cmd.Bool("l", false, "long listing")
fullFlag := cmd.Bool("f", false, "shows full path")

cmd.Action = func() error {
if cmd.NArg() < 2 {
if cmd.NArg() < 1 {
fmt.Println(cmd.Usage())
os.Exit(1)
}

provider := cmd.Args()[0]
fn := cmd.Args()[1]
client, err := getStorageProviderClient(provider)
fn := cmd.Args()[0]
client, err := getStorageProviderClient()
if err != nil {
return err
}
Expand All @@ -56,10 +58,15 @@ func lsCommand() *command {

infos := res.Infos
for _, info := range infos {
p := info.Path
if !*fullFlag {
p = path.Base(info.Path)
}

if *longFlag {
fmt.Printf("%+v %d %d %v %s\n", info.PermissionSet, info.Mtime, info.Size, info.Id, info.Path)
fmt.Printf("%+v %d %d %v %s\n", info.PermissionSet, info.Mtime, info.Size, info.Id, p)
} else {
fmt.Println(info.Path)
fmt.Println(p)
}
}
return nil
Expand Down
9 changes: 4 additions & 5 deletions cmd/reva/mkdir.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,18 @@ import (

func mkdirCommand() *command {
cmd := newCommand("mkdir")
cmd.Description = func() string { return "creates a folder" }
cmd.Usage = func() string { return "Usage: mkdir <folder_name> [-flags]" }
cmd.Description = func() string { return "creates a container" }
cmd.Usage = func() string { return "Usage: mkdir [-flags] <container_name>" }
cmd.Action = func() error {
if cmd.NArg() < 2 {
if cmd.NArg() < 1 {
fmt.Println(cmd.Usage())
os.Exit(1)
}

fn := cmd.Args()[0]
provider := cmd.Args()[1]

ctx := getAuthContext()
client, err := getStorageProviderClient(provider)
client, err := getStorageProviderClient()
if err != nil {
return err
}
Expand Down
9 changes: 4 additions & 5 deletions cmd/reva/mv.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,16 @@ func moveCommand() *command {
cmd.Description = func() string { return "moves/rename a file/folder" }
cmd.Usage = func() string { return "Usage: mv [-flags] <source> <destination>" }
cmd.Action = func() error {
if cmd.NArg() < 3 {
if cmd.NArg() < 2 {
fmt.Println(cmd.Usage())
os.Exit(1)
}

provider := cmd.Args()[0]
src := cmd.Args()[1]
dst := cmd.Args()[2]
src := cmd.Args()[0]
dst := cmd.Args()[1]

ctx := getAuthContext()
client, err := getStorageProviderClient(provider)
client, err := getStorageProviderClient()
if err != nil {
return err
}
Expand Down
7 changes: 3 additions & 4 deletions cmd/reva/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@ func rmCommand() *command {
cmd.Description = func() string { return "removes a file or folder" }
cmd.Usage = func() string { return "Usage: rm [-flags] <file_name>" }
cmd.Action = func() error {
if cmd.NArg() < 2 {
if cmd.NArg() < 1 {
fmt.Println(cmd.Usage())
os.Exit(1)
}

provider := cmd.Args()[0]
fn := cmd.Args()[1]
fn := cmd.Args()[0]
ctx := getAuthContext()
client, err := getStorageProviderClient(provider)
client, err := getStorageProviderClient()
if err != nil {
return err
}
Expand Down
7 changes: 3 additions & 4 deletions cmd/reva/stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,15 @@ func statCommand() *command {
cmd.Description = func() string { return "get the metadata for a file or folder" }
cmd.Usage = func() string { return "Usage: stat [-flags] <file_name>" }
cmd.Action = func() error {
if cmd.NArg() < 2 {
if cmd.NArg() < 1 {
fmt.Println(cmd.Usage())
os.Exit(1)
}

provider := cmd.Args()[0]
fn := cmd.Args()[1]
fn := cmd.Args()[0]

ctx := getAuthContext()
client, err := getStorageProviderClient(provider)
client, err := getStorageProviderClient()
if err != nil {
return err
}
Expand Down
30 changes: 12 additions & 18 deletions cmd/reva/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ import (
"math"
"net/http"
"os"
"time"

"github.com/cs3org/reva/cmd/revad/svcs/grpcsvcs/storageprovidersvc"

"github.com/cs3org/reva/pkg/crypto"

"github.com/cheggaaa/pb"
rpcpb "github.com/cs3org/go-cs3apis/cs3/rpc"
storageproviderv0alphapb "github.com/cs3org/go-cs3apis/cs3/storageprovider/v0alpha"
"github.com/cs3org/reva/cmd/revad/svcs/grpcsvcs/storageprovidersvc"
"github.com/cs3org/reva/cmd/revad/svcs/httpsvcs/utils"
"github.com/cs3org/reva/pkg/crypto"
)

func uploadCommand() *command {
Expand All @@ -41,14 +39,15 @@ func uploadCommand() *command {
cmd.Usage = func() string { return "Usage: upload [-flags] <file_name> <remote_target>" }
xsFlag := cmd.String("xs", "negotiate", "compute checksum")
cmd.Action = func() error {
if cmd.NArg() < 3 {
ctx := getAuthContext()

if cmd.NArg() < 2 {
fmt.Println(cmd.Usage())
os.Exit(1)
}

provider := cmd.Args()[0]
fn := cmd.Args()[1]
target := cmd.Args()[2]
fn := cmd.Args()[0]
target := cmd.Args()[1]

fd, err := os.Open(fn)
if err != nil {
Expand All @@ -64,8 +63,7 @@ func uploadCommand() *command {

fmt.Printf("Local file size: %d bytes\n", md.Size())

ctx := getAuthContext()
client, err := getStorageProviderClient(provider)
client, err := getStorageProviderClient()
if err != nil {
return err
}
Expand Down Expand Up @@ -113,8 +111,7 @@ func uploadCommand() *command {
bar.Start()
reader := bar.NewProxyReader(fd)

// TODO(labkode): do a protocol switch
httpReq, err := http.NewRequest("PUT", dataServerURL, reader)
httpReq, err := utils.NewRequest(ctx, "PUT", dataServerURL, reader)
if err != nil {
return err
}
Expand All @@ -124,11 +121,7 @@ func uploadCommand() *command {
q.Add("xs_type", storageprovidersvc.GRPC2PKGXS(xsType).String())
httpReq.URL.RawQuery = q.Encode()

// TODO(labkode): harden http client
// https://medium.com/@nate510/don-t-use-go-s-default-http-client-4804cb19f779
httpClient := &http.Client{
Timeout: time.Second * 10,
}
httpClient := utils.GetHTTPClient(ctx)

httpRes, err := httpClient.Do(httpReq)
if err != nil {
Expand Down Expand Up @@ -160,6 +153,7 @@ func uploadCommand() *command {
info := res2.Info

fmt.Printf("File uploaded: %s:%s %d %s\n", info.Id.StorageId, info.Id.OpaqueId, info.Size, info.Path)

return nil
}
return cmd
Expand Down
19 changes: 19 additions & 0 deletions cmd/revad/gateway.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[core]
log_file = "stderr"
log_mode = "dev"
max_cpus = "100%"
tracing_enabled = true
disable_http = true

[log]
level = "debug"
mode = "console"

[grpc]
network = "tcp"
address = "0.0.0.0:10000"
enabled_services = ["gatewaysvc"]

[grpc.services.gatewaysvc]
storageregistrysvc = "localhost:9999"
authsvc = "localhost:9999"
Loading