Skip to content

Commit

Permalink
add trashbin commands to reva cli (#240)
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
  • Loading branch information
butonic authored and labkode committed Sep 6, 2019
1 parent bfa62ca commit ab07bd7
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/reva/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ func main() {
appProviderGetIFrameCommand(),
preferencesCommand(),
genCommand(),
recycleListCommand(),
recycleRestoreCommand(),
recyclePurgeCommand(),
shareCreateCommand(),
shareListCommand(),
shareRemoveCommand(),
Expand Down
64 changes: 64 additions & 0 deletions cmd/reva/recycle-list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright 2018-2019 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"
"os"

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

func recycleListCommand() *command {
cmd := newCommand("recycle-list")
cmd.Description = func() string { return "list a recycle bin" }
cmd.Usage = func() string { return "Usage: recycle-list [-flags] " }

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

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

req := &storageproviderv0alphapb.ListRecycleRequest{}

ctx := getAuthContext()
res, err := client.ListRecycle(ctx, req)
if err != nil {
return err
}

if res.Status.Code != rpcpb.Code_CODE_OK {
return formatError(res.Status)
}

items := res.RecycleItems
for _, item := range items {
fmt.Printf("%+v\n", item)
}
return nil
}
return cmd
}
60 changes: 60 additions & 0 deletions cmd/reva/recycle-purge.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2018-2019 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"
"os"

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

func recyclePurgeCommand() *command {
cmd := newCommand("recycle-purge")
cmd.Description = func() string { return "purge a recycle bin" }
cmd.Usage = func() string { return "Usage: recycle-purge [-flags] " }

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

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

req := &storageproviderv0alphapb.PurgeRecycleRequest{}

ctx := getAuthContext()
res, err := client.PurgeRecycle(ctx, req)
if err != nil {
return err
}

if res.Status.Code != rpcpb.Code_CODE_OK {
return formatError(res.Status)
}

return nil
}
return cmd
}
64 changes: 64 additions & 0 deletions cmd/reva/recycle-restore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright 2018-2019 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"
"os"

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

func recycleRestoreCommand() *command {
cmd := newCommand("recycle-restore")
cmd.Description = func() string { return "restore a recycle bin item" }
cmd.Usage = func() string { return "Usage: recycle-restore [-flags] key" }

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

key := cmd.Args()[0]

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

req := &storageproviderv0alphapb.RestoreRecycleItemRequest{
Key: key,
}

ctx := getAuthContext()
res, err := client.RestoreRecycleItem(ctx, req)
if err != nil {
return err
}

if res.Status.Code != rpcpb.Code_CODE_OK {
return formatError(res.Status)
}

return nil
}
return cmd
}

0 comments on commit ab07bd7

Please sign in to comment.