diff --git a/src/handlers/buckets.go b/src/handlers/buckets.go index d9965aa..172308e 100644 --- a/src/handlers/buckets.go +++ b/src/handlers/buckets.go @@ -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() @@ -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") diff --git a/src/main.go b/src/main.go index 59720f9..9df264d 100644 --- a/src/main.go +++ b/src/main.go @@ -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")