Skip to content

Commit

Permalink
Add delete objects api (#303)
Browse files Browse the repository at this point in the history
Supports single and multiple objects which needs to be defined by recursive flag.
An object to be deleted needs to be defined by a query parameter, path, since it can be
an object or a folder.
  • Loading branch information
cesnietor committed Oct 2, 2020
1 parent a42f1ff commit fcf5d5c
Show file tree
Hide file tree
Showing 17 changed files with 1,129 additions and 48 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ name: Go
on:
pull_request:
branches:
- master
- master
push:
branches:
- master
- master

jobs:
build:
name: Test on Go ${{ matrix.go-version }} and ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
go-version: [1.13.x, 1.14.x]
go-version: [1.14.x]
os: [ubuntu-latest]
steps:
- name: Set up Go ${{ matrix.go-version }} on ${{ matrix.os }}
Expand Down
10 changes: 4 additions & 6 deletions cmd/console/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,19 @@ func newApp(name string) *cli.App {

findClosestCommands := func(command string) []string {
var closestCommands []string
for _, value := range commandsTree.PrefixMatch(command) {
closestCommands = append(closestCommands, value.(string))
}
closestCommands = append(closestCommands, commandsTree.PrefixMatch(command)...)

sort.Strings(closestCommands)
// Suggest other close commands - allow missed, wrongly added and
// even transposed characters
for _, value := range commandsTree.Walk(commandsTree.Root()) {
if sort.SearchStrings(closestCommands, value.(string)) < len(closestCommands) {
if sort.SearchStrings(closestCommands, value) < len(closestCommands) {
continue
}
// 2 is arbitrary and represents the max
// allowed number of typed errors
if words.DamerauLevenshteinDistance(command, value.(string)) < 2 {
closestCommands = append(closestCommands, value.(string))
if words.DamerauLevenshteinDistance(command, value) < 2 {
closestCommands = append(closestCommands, value)
}
}

Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ require (
github.com/jessevdk/go-flags v1.4.0
github.com/minio/cli v1.22.0
github.com/minio/kes v0.11.0
github.com/minio/mc v0.0.0-20200901021141-b55e3e2d2987
github.com/minio/minio v0.0.0-20200901011052-18725679c4f5
github.com/minio/minio-go/v7 v7.0.6-0.20200901014009-5f8d15bbc5fd
github.com/minio/mc v0.0.0-20201001165056-7f2df96e4821
github.com/minio/minio v0.0.0-20200927172404-27d9bd04e544
github.com/minio/minio-go/v7 v7.0.6-0.20200923173112-bc846cb9b089
github.com/minio/operator v0.0.0-20200923155125-e7077234373b
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect
github.com/secure-io/sio-go v0.3.1
github.com/stretchr/testify v1.6.1
github.com/unrolled/secure v1.0.7
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de
golang.org/x/net v0.0.0-20200707034311-ab3426394381
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a
golang.org/x/net v0.0.0-20200904194848-62affa334b73
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
gopkg.in/yaml.v2 v2.3.0
k8s.io/api v0.18.6
Expand Down
44 changes: 33 additions & 11 deletions go.sum

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion restapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ type MCClient interface {
addNotificationConfig(ctx context.Context, arn string, events []string, prefix, suffix string, ignoreExisting bool) *probe.Error
removeNotificationConfig(ctx context.Context, arn string, event string, prefix string, suffix string) *probe.Error
watch(ctx context.Context, options mc.WatchOptions) (*mc.WatchObject, *probe.Error)
remove(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *mc.ClientContent) <-chan *probe.Error
list(ctx context.Context, opts mc.ListOptions) <-chan *mc.ClientContent
}

// Interface implementation
Expand Down Expand Up @@ -151,6 +153,14 @@ func (c mcClient) setReplication(ctx context.Context, cfg *replication.Config, o
return c.client.SetReplication(ctx, cfg, opts)
}

func (c mcClient) remove(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *mc.ClientContent) <-chan *probe.Error {
return c.client.Remove(ctx, isIncomplete, isRemoveBucket, isBypass, contentCh)
}

func (c mcClient) list(ctx context.Context, opts mc.ListOptions) <-chan *mc.ClientContent {
return c.client.List(ctx, opts)
}

// ConsoleCredentials interface with all functions to be implemented
// by mock when testing, it should include all needed consoleCredentials.Login api calls
// that are used within this project.
Expand Down Expand Up @@ -274,14 +284,18 @@ func newMinioClient(claims *models.Principal) (*minio.Client, error) {
}

// newS3BucketClient creates a new mc S3Client to talk to the server based on a bucket
func newS3BucketClient(claims *models.Principal, bucketName string) (*mc.S3Client, error) {
func newS3BucketClient(claims *models.Principal, bucketName string, prefix string) (*mc.S3Client, error) {
endpoint := getMinIOServer()
useTLS := getMinIOEndpointIsSecure()

if strings.TrimSpace(bucketName) != "" {
endpoint += fmt.Sprintf("/%s", bucketName)
}

if strings.TrimSpace(prefix) != "" {
endpoint += fmt.Sprintf("/%s", prefix)
}

if claims == nil {
return nil, fmt.Errorf("the provided credentials are invalid")
}
Expand Down
84 changes: 84 additions & 0 deletions restapi/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions restapi/operations/console_api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

90 changes: 90 additions & 0 deletions restapi/operations/user_api/delete_object.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fcf5d5c

Please sign in to comment.