Skip to content

Commit

Permalink
merged
Browse files Browse the repository at this point in the history
  • Loading branch information
2403905 committed Dec 12, 2023
2 parents d9b5969 + 32c08b8 commit 4a44097
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 28 deletions.
2 changes: 1 addition & 1 deletion services/gateway/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type Debug struct {
}

type GRPCConfig struct {
Addr string `yaml:"addr" env:"GATEWAY_GRPC_ADDR" desc:"The bind address of the GRPC service."`
Addr string `yaml:"addr" env:"OCIS_GATEWAY_GRPC_ADDR;GATEWAY_GRPC_ADDR" desc:"The bind address of the GRPC service."`
TLS *shared.GRPCServiceTLS `yaml:"tls"`
Namespace string `yaml:"-"`
Protocol string `yaml:"protocol" env:"GATEWAY_GRPC_PROTOCOL" desc:"The transport protocol of the GRPC service."`
Expand Down
18 changes: 10 additions & 8 deletions services/storage-users/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Cleaned uploads:

<!-- referencing: https://github.com/owncloud/ocis/pull/5500 -->

This command is about overview, restore trash-bin items and purging old trash-bin items of `project` spaces (spaces that have been created manually) and `personal` spaces.
This command is about the trash-bin to get an overview of items, restore items and purging old items of `project` spaces (spaces that have been created manually) and `personal` spaces.

```bash
ocis storage-users trash-bin <command>
Expand All @@ -100,15 +100,17 @@ The configuration for the `purge-expired` command is done by using the following

#### List and Restore Trash-Bins Items

To authenticate the cli command use `OCIS_MACHINE_AUTH_API_KEY=<some-ocis-machine-auth-api-key>`
To authenticate the cli command use `OCIS_MACHINE_AUTH_API_KEY=<some-ocis-machine-auth-api-key>`. The `storage-users` cli tool uses the default address to establish the connection to the `gateway` service. If the connection is failed check your custom `gateway`
service `GATEWAY_GRPC_ADDR` configuration and set the same address to `storage-users` variable `OCIS_GATEWAY_GRPC_ADDR` or `STORAGE_USERS_GATEWAY_GRPC_ADDR`.

The ID sources:
- 'userID' in a `https://{host}/graph/v1.0/me`
- personal 'spaceID' in a `https://{host}/graph/v1.0/me/drives?$filter=driveType+eq+personal`
- project 'spaceID' in a `https://{host}/graph/v1.0/me/drives?$filter=driveType+eq+project`
- 'userID' in a `https://{host}/graph/v1.0/me`
- personal 'spaceID' in a `https://{host}/graph/v1.0/me/drives?$filter=driveType+eq+personal`
- project 'spaceID' in a `https://{host}/graph/v1.0/me/drives?$filter=driveType+eq+project`

```bash
NAME:
ocis storage-users trash-bin list - Print a list of all trash-bin items in a space.
ocis storage-users trash-bin list - Print a list of all trash-bin items for a space.

USAGE:
ocis storage-users trash-bin list command [command options] ['userID' required] ['spaceID' required]
Expand All @@ -125,7 +127,7 @@ COMMANDS:
help, h Shows a list of commands or help for one command

OPTIONS:
--option value, -o value The restore option defines the behavior for a file to be restored, where the file name already already exists in the target space. Expected values [skip] [replace] [keep-both] (default: The default value is [skip] restoring an existing file.)
--option value, -o value The restore option defines the behavior for a file to be restored, where the file name already already exists in the target space. Supported values are: 'skip', 'replace' and 'keep-both'. The default value is 'skip' overwriting an existing file.
```
```bash
Expand All @@ -139,7 +141,7 @@ COMMANDS:
help, h Shows a list of commands or help for one command

OPTIONS:
--option value, -o value The restore option defines the behavior for a file to be restored, where the file name already already exists in the target space. Expected values [skip] [replace] [keep-both] (default: The default value is [skip] restoring an existing file.)
--option value, -o value The restore option defines the behavior for a file to be restored, where the file name already already exists in the target space. Supported values are: 'skip', 'replace' and 'keep-both'. The default value is 'skip' overwriting an existing file.
```
## Caching
Expand Down
36 changes: 18 additions & 18 deletions services/storage-users/pkg/command/trash_bin.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ var optionFlagTmpl = cli.StringFlag{
Name: "option",
Value: "skip",
Aliases: []string{"o"},
Usage: "The restore option defines the behavior for a file to be restored, where the file name already already exists in the target space. Expected values [skip] [replace] [keep-both]",
DefaultText: "The default value is [skip] restoring an existing file.",
Usage: "The restore option defines the behavior for a file to be restored, where the file name already already exists in the target space. Supported values are: 'skip', 'replace' and 'keep-both'.",
DefaultText: "The default value is 'skip' overwriting an existing file",
}

// TrashBin wraps trash-bin related sub-commands.
Expand Down Expand Up @@ -119,7 +119,7 @@ func listTrashBinItems(cfg *config.Config) *cli.Command {
_ = cli.ShowSubcommandHelp(c)
return fmt.Errorf("spaceID is requered")
}
fmt.Printf("Getting trash-bin items for spaceID:%s ...\n", spaceID)
fmt.Printf("Getting trash-bin items for spaceID: '%s' ...\n", spaceID)

ref, err := storagespace.ParseReference(spaceID)
if err != nil {
Expand Down Expand Up @@ -161,8 +161,8 @@ func listTrashBinItems(cfg *config.Config) *cli.Command {
fmt.Println("The list is empty.")
}

for k, item := range res.GetRecycleItems() {
fmt.Printf("%d: itemID:%s, path:%s, type:%s, delited at:%s\n", k+1, item.GetKey(), item.GetRef().GetPath(), itemType(item.GetType()), utils.TSToTime(item.GetDeletionTime()).UTC().Format(time.RFC3339))
for _, item := range res.GetRecycleItems() {
fmt.Printf("itemID: '%s', path: '%s', type: '%s', delited at :%s\n", item.GetKey(), item.GetRef().GetPath(), itemType(item.GetType()), utils.TSToTime(item.GetDeletionTime()).UTC().Format(time.RFC3339))
}
return nil
},
Expand Down Expand Up @@ -215,7 +215,7 @@ func restoreAllTrashBinItems(cfg *config.Config) *cli.Command {
_ = cli.ShowSubcommandHelp(c)
return cli.Exit("The option flag is invalid", 1)
}
fmt.Printf("Restoring trash-bin items for spaceID:%s ...\n", spaceID)
fmt.Printf("Restoring trash-bin items for spaceID: '%s' ...\n", spaceID)
ref, err := storagespace.ParseReference(spaceID)
if err != nil {
return err
Expand Down Expand Up @@ -267,20 +267,20 @@ func restoreAllTrashBinItems(cfg *config.Config) *cli.Command {
} else if strings.ToLower(i) == "n" {
return nil
} else if strings.ToLower(i) == "s" {
for k, item := range res.GetRecycleItems() {
fmt.Printf("%d: itemID:%s, path:%s, type:%s, delited at:%s\n", k+1, item.GetKey(), item.GetRef().GetPath(), itemType(item.GetType()), utils.TSToTime(item.GetDeletionTime()).UTC().Format(time.RFC3339))
for _, item := range res.GetRecycleItems() {
fmt.Printf("itemID: '%s', path: '%s', type: '%s', delited at: %s\n", item.GetKey(), item.GetRef().GetPath(), itemType(item.GetType()), utils.TSToTime(item.GetDeletionTime()).UTC().Format(time.RFC3339))
}
}
}

fmt.Printf("\nRun restoring-all with option=%s\n", optionFlagVal)
for k, item := range res.GetRecycleItems() {
fmt.Printf("%d: restoring itemID:%s, path:%s, type:%s\n", k+1, item.GetKey(), item.GetRef().GetPath(), itemType(item.GetType()))
for _, item := range res.GetRecycleItems() {
fmt.Printf("restoring itemID: '%s', path: '%s', type: '%s'\n", item.GetKey(), item.GetRef().GetPath(), itemType(item.GetType()))
dstRes, err := restore(ctx, client, ref, item, overwriteOption)
if err != nil {
return err
}
fmt.Printf("itemID:%s, path:%s, restored as %s\n", item.GetKey(), item.GetRef().GetPath(), dstRes.GetPath())
fmt.Printf("itemID: '%s', path: '%s', restored as '%s'\n", item.GetKey(), item.GetRef().GetPath(), dstRes.GetPath())
}
return nil
},
Expand Down Expand Up @@ -385,15 +385,15 @@ func restoreTrashBindItem(cfg *config.Config) *cli.Command {
}
}
if !found {
return fmt.Errorf("itemID %s not found", itemID)
return fmt.Errorf("itemID '%s' not found", itemID)
}
fmt.Printf("\nRun restoring with option=%s\n", optionFlagVal)
fmt.Printf("restoring itemID:%s, path:%s, type:%s\n", itemRef.GetKey(), itemRef.GetRef().GetPath(), itemType(itemRef.GetType()))
fmt.Printf("restoring itemID: '%s', path: '%s', type: '%s'\n", itemRef.GetKey(), itemRef.GetRef().GetPath(), itemType(itemRef.GetType()))
dstRes, err := restore(ctx, client, ref, itemRef, overwriteOption)
if err != nil {
return err
}
fmt.Printf("itemID:%s, path:%s, restored as %s\n", itemRef.GetKey(), itemRef.GetRef().GetPath(), dstRes.GetPath())
fmt.Printf("itemID: '%s', path: '%s', restored as '%s'\n", itemRef.GetKey(), itemRef.GetRef().GetPath(), dstRes.GetPath())
return nil
},
}
Expand All @@ -415,7 +415,7 @@ func restore(ctx context.Context, client gateway.GatewayAPIClient, ref provider.
}

if exists {
fmt.Printf("destination %s %s exists.\n", dstStatRes.GetInfo().GetId(), dstStatRes.GetInfo().GetPath())
fmt.Printf("destination '%s' exists.\n", dstStatRes.GetInfo().GetPath())
switch overwriteOption {
case SKIP:
return &dst, nil
Expand All @@ -441,12 +441,12 @@ func restore(ctx context.Context, client gateway.GatewayAPIClient, ref provider.
res, err := client.RestoreRecycleItem(ctx, req)
if err != nil {
log.Error().Err(err).Msg("trash-bin item restoring error")
return &dst, err
return req.RestoreRef, err
}
if res.Status.Code != rpc.Code_CODE_OK {
return &dst, fmt.Errorf("trash-bin item restoring error %s", res.Status.Code)
return req.RestoreRef, fmt.Errorf("trash-bin item restoring error %s", res.Status.Code)
}
return &dst, nil
return req.RestoreRef, nil
}

func resolveDestination(ctx context.Context, client gateway.GatewayAPIClient, dstRef provider.Reference) (*provider.Reference, error) {
Expand Down
2 changes: 1 addition & 1 deletion services/storage-users/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Config struct {

TokenManager *TokenManager `yaml:"token_manager"`
Reva *shared.Reva `yaml:"reva"`
RevaGatewayGRPCAddr string `yaml:"gateway_addr" env:"GATEWAY_GRPC_ADDR" desc:"The REVA gateway GRPC address."`
RevaGatewayGRPCAddr string `yaml:"gateway_addr" env:"OCIS_GATEWAY_GRPC_ADDR;STORAGE_USERS_GATEWAY_GRPC_ADDR" desc:"The bind address of the gateway GRPC address."`
MachineAuthAPIKey string `yaml:"machine_auth_api_key" env:"OCIS_MACHINE_AUTH_API_KEY" desc:"Machine auth API key used to validate internal requests necessary for the access to resources from other services."`

SkipUserGroupsInToken bool `yaml:"skip_user_groups_in_token" env:"STORAGE_USERS_SKIP_USER_GROUPS_IN_TOKEN" desc:"Disables the loading of user's group memberships from the reva access token."`
Expand Down

0 comments on commit 4a44097

Please sign in to comment.