Skip to content

Commit

Permalink
policy refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
rzrbld committed Jul 1, 2020
1 parent f011652 commit 2102f29
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 60 deletions.
117 changes: 58 additions & 59 deletions src/handlers/buckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,64 @@ import (
policy "github.com/minio/minio-go/v6/pkg/policy"
)

type accessPerms string
func getPolicyWithName(bucketName string) (string, string, error) {
var p policy.BucketAccessPolicy

bp, err := minioClnt.GetBucketPolicyWithContext(context.Background(), bucketName)
policyShort := "none"
if bp != "" {
if err = json.Unmarshal([]byte(bp), &p); err != nil {
fmt.Println("Error Unmarshal policy")
}
pName := string(policy.GetPolicy(p.Statements, bucketName, ""))
if pName == string(policy.BucketPolicyNone) && bp != "" {
pName = "custom"
}
policyShort = policyToString(pName)
}

return policyShort, bp, err
}

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"
}
return name
}

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"
}
return policy
}

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


var BuckList = func(ctx iris.Context) {
lb, err := minioClnt.ListBuckets()
Expand Down Expand Up @@ -273,64 +330,6 @@ var BuckGetPolicy = func(ctx iris.Context) {
}
}

func getPolicyWithName(bucketName string) (string, string, error) {
var p policy.BucketAccessPolicy

bp, err := minioClnt.GetBucketPolicyWithContext(context.Background(), bucketName)
policyShort := "none"
if bp != "" {
if err = json.Unmarshal([]byte(bp), &p); err != nil {
fmt.Println("Error Unmarshal policy")
}
pName := string(policy.GetPolicy(p.Statements, bucketName, ""))
if pName == string(policy.BucketPolicyNone) && bp != "" {
pName = "custom"
}
policyShort = policyToString(pName)
}

return policyShort, bp, err
}

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"
}
return name
}

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"
}
return policy
}

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

var BuckSetPolicy = func(ctx iris.Context) {

var bucket = ctx.FormValue("bucketName")
Expand Down
2 changes: 1 addition & 1 deletion src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func main() {

fmt.Println("\033[31m\r\n ________ ________ _____ ______ ___ ________ ___ ________ \r\n|\\ __ \\ |\\ ___ \\ |\\ _ \\ _ \\ |\\ \\ |\\ ___ \\ |\\ \\ |\\ __ \\ \r\n\\ \\ \\|\\ \\\\ \\ \\_|\\ \\\\ \\ \\\\\\__\\ \\ \\\\ \\ \\\\ \\ \\\\ \\ \\\\ \\ \\\\ \\ \\|\\ \\ \r\n \\ \\ __ \\\\ \\ \\ \\\\ \\\\ \\ \\\\|__| \\ \\\\ \\ \\\\ \\ \\\\ \\ \\\\ \\ \\\\ \\ \\\\\\ \\ \r\n \\ \\ \\ \\ \\\\ \\ \\_\\\\ \\\\ \\ \\ \\ \\ \\\\ \\ \\\\ \\ \\\\ \\ \\\\ \\ \\\\ \\ \\\\\\ \\ \r\n \\ \\__\\ \\__\\\\ \\_______\\\\ \\__\\ \\ \\__\\\\ \\__\\\\ \\__\\\\ \\__\\\\ \\__\\\\ \\_______\\\r\n \\|__|\\|__| \\|_______| \\|__| \\|__| \\|__| \\|__| \\|__| \\|__| \\|_______|\r\n \r\n \r\n \033[m")
fmt.Println("\033[33mAdmin REST API for http://min.io (minio) s3 server")
fmt.Println("Version : 1.0")
fmt.Println("Version : 1.1")
fmt.Println("Authors : rzrbld, 0x003e")
fmt.Println("License : MIT")
fmt.Println("GitHub : https://github.com/rzrbld/adminio-api")
Expand Down

0 comments on commit 2102f29

Please sign in to comment.