Skip to content

Commit

Permalink
go get -u && go fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
rzrbld committed Jul 1, 2020
1 parent 0742853 commit c868d9d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 58 deletions.
4 changes: 2 additions & 2 deletions src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ require (
github.com/microcosm-cc/bluemonday v1.0.3 // indirect
github.com/minio/hdfs/v3 v3.0.1 // indirect
github.com/minio/lsync v1.0.1 // indirect
github.com/minio/minio v0.0.0-20200628185605-8c5f0597c059
github.com/minio/minio v0.0.0-20200630183019-d2d1ebe0849b
github.com/minio/minio-go/v6 v6.0.58-0.20200612001654-a57fec8037ec
github.com/montanaflynn/stats v0.6.3 // indirect
github.com/moul/http2curl v1.0.0 // indirect
Expand All @@ -40,7 +40,7 @@ require (
github.com/rzrbld/goth-provider-wso2 v0.0.0-20200321130802-e588ec0a9128
github.com/secure-io/sio-go v0.3.1 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/shirou/gopsutil v2.20.5+incompatible // indirect
github.com/shirou/gopsutil v2.20.6+incompatible // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/smartystreets/assertions v1.1.1 // indirect
github.com/smartystreets/goconvey v1.6.4 // indirect
Expand Down
4 changes: 4 additions & 0 deletions src/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ github.com/minio/minio v0.0.0-20200614184039-41a793874879 h1:E32j1mqi6//QDIlf6Oo
github.com/minio/minio v0.0.0-20200614184039-41a793874879/go.mod h1:JLeFiP5xG3ILwLY/A+v1zRA9Z25BCC900jt0VnEbYcc=
github.com/minio/minio v0.0.0-20200628185605-8c5f0597c059 h1:gtJc+gt4c015m0+pHHQBxtrN77KLzKCNg2NDtyBpi5U=
github.com/minio/minio v0.0.0-20200628185605-8c5f0597c059/go.mod h1:ctbP/g2mJMMBab+326+uNrSdm7Ucs0qfLDpGww43duw=
github.com/minio/minio v0.0.0-20200630183019-d2d1ebe0849b h1:YNrNFSdUD7FGfkHeLSzx1Uop1ad1ct1UGIAiBPQnOSw=
github.com/minio/minio v0.0.0-20200630183019-d2d1ebe0849b/go.mod h1:ctbP/g2mJMMBab+326+uNrSdm7Ucs0qfLDpGww43duw=
github.com/minio/minio-go/v6 v6.0.53 h1:8jzpwiOzZ5Iz7/goFWqNZRICbyWYShbb5rARjrnSCNI=
github.com/minio/minio-go/v6 v6.0.53/go.mod h1:DIvC/IApeHX8q1BAMVCXSXwpmrmM+I+iBvhvztQorfI=
github.com/minio/minio-go/v6 v6.0.55-0.20200425081427-89eebdef2af0/go.mod h1:KQMM+/44DSlSGSQWSfRrAZ12FVMmpWNuX37i2AX0jfI=
Expand Down Expand Up @@ -563,6 +565,8 @@ github.com/shirou/gopsutil v2.20.4+incompatible h1:cMT4rxS55zx9NVUnCkrmXCsEB/RNf
github.com/shirou/gopsutil v2.20.4+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shirou/gopsutil v2.20.5+incompatible h1:tYH07UPoQt0OCQdgWWMgYHy3/a9bcxNpBIysykNIP7I=
github.com/shirou/gopsutil v2.20.5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shirou/gopsutil v2.20.6+incompatible h1:P37G9YH8M4vqkKcwBosp+URN5O8Tay67D2MbR361ioY=
github.com/shirou/gopsutil v2.20.6+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
Expand Down
111 changes: 55 additions & 56 deletions src/handlers/buckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ package handlers

import (
"context"
"encoding/json"
"fmt"
log "log"
"strconv"
"strings"
"encoding/json"
"sync"

iris "github.com/kataras/iris/v12"
minio "github.com/minio/minio-go/v6"
policy "github.com/minio/minio-go/v6/pkg/policy"
"github.com/minio/minio-go/v6/pkg/tags"
madmin "github.com/minio/minio/pkg/madmin"
cnf "github.com/rzrbld/adminio-api/config"
resph "github.com/rzrbld/adminio-api/response"
policy "github.com/minio/minio-go/v6/pkg/policy"
)

func getPolicyWithName(bucketName string) (string, string, error) {
Expand All @@ -41,15 +41,15 @@ func policyToString(policyName string) string {
name := ""
switch policyName {
case "none":
name = "none"
case "readonly":
name = "download"
case "writeonly":
name = "upload"
case "readwrite":
name = "public"
case "custom":
name = "custom"
name = "none"
case "readonly":
name = "download"
case "writeonly":
name = "upload"
case "readwrite":
name = "public"
case "custom":
name = "custom"
}
return name
}
Expand All @@ -58,65 +58,64 @@ func stringToPolicy(strPolicy string) string {
policy := ""
switch strPolicy {
case "none":
policy = "none"
case "download":
policy = "readonly"
case "upload":
policy = "writeonly"
case "public":
policy = "readwrite"
case "custom":
policy = "custom"
policy = "none"
case "download":
policy = "readonly"
case "upload":
policy = "writeonly"
case "public":
policy = "readwrite"
case "custom":
policy = "custom"
}
return policy
}

func isJSON(s string) bool {
var js map[string]interface{}
return json.Unmarshal([]byte(s), &js) == nil
var js map[string]interface{}
return json.Unmarshal([]byte(s), &js) == nil
}


var BuckList = func(ctx iris.Context) {
lb, err := minioClnt.ListBuckets()
var res = resph.BodyResHandler(ctx, err, lb)
ctx.JSON(res)
}

var BuckListExtended = func(ctx iris.Context) {
var BuckListExtended = func(ctx iris.Context) {

var wg sync.WaitGroup

lb, err := minioClnt.ListBuckets()
allBuckets := make([]iris.Map, len(lb))

wg.Add(len(lb))
for i := 0; i < len(lb); i++ {
go func(i int) {
bucket := lb[i]
bn, err := minioClnt.GetBucketNotification(bucket.Name)
if err != nil {
log.Print("Error while getting bucket notification", err)
}
bq, _ := madmClnt.GetBucketQuota(context.Background(), bucket.Name)
bt, bterr := minioClnt.GetBucketTaggingWithContext(context.Background(), bucket.Name)

pName, _, _ := getPolicyWithName(bucket.Name)

btMap := map[string]string{}

if bterr == nil {
btMap = bt.ToMap()
}

br := iris.Map{"name": bucket.Name, "info": bucket, "events": bn, "quota": bq, "tags": btMap, "policy": pName}
allBuckets[i] = br
wg.Done()
}(i)
}
wg.Wait()
var res = resph.BodyResHandler(ctx, err, allBuckets)
ctx.JSON(res)
lb, err := minioClnt.ListBuckets()
allBuckets := make([]iris.Map, len(lb))

wg.Add(len(lb))
for i := 0; i < len(lb); i++ {
go func(i int) {
bucket := lb[i]
bn, err := minioClnt.GetBucketNotification(bucket.Name)
if err != nil {
log.Print("Error while getting bucket notification", err)
}
bq, _ := madmClnt.GetBucketQuota(context.Background(), bucket.Name)
bt, bterr := minioClnt.GetBucketTaggingWithContext(context.Background(), bucket.Name)

pName, _, _ := getPolicyWithName(bucket.Name)

btMap := map[string]string{}

if bterr == nil {
btMap = bt.ToMap()
}

br := iris.Map{"name": bucket.Name, "info": bucket, "events": bn, "quota": bq, "tags": btMap, "policy": pName}
allBuckets[i] = br
wg.Done()
}(i)
}
wg.Wait()
var res = resph.BodyResHandler(ctx, err, allBuckets)
ctx.JSON(res)
}

var BuckSetTags = func(ctx iris.Context) {
Expand Down Expand Up @@ -331,7 +330,7 @@ var BuckGetPolicy = func(ctx iris.Context) {
if resph.CheckAuthBeforeRequest(ctx) != false {
pName, bp, err := getPolicyWithName(bucketName)

respBp := iris.Map{"policy":bp, "name":pName}
respBp := iris.Map{"policy": bp, "name": pName}
var res = resph.BodyResHandler(ctx, err, respBp)
ctx.JSON(res)
} else {
Expand All @@ -344,7 +343,7 @@ var BuckSetPolicy = func(ctx iris.Context) {
var bucket = ctx.FormValue("bucketName")
var policyStr = ctx.FormValue("bucketPolicy")

if !isJSON(policyStr){
if !isJSON(policyStr) {
if policyStr == "none" {
policyStr = ""
} else {
Expand Down

0 comments on commit c868d9d

Please sign in to comment.