From 3bd9c4257479b2b114a3edbf92b094edd1498828 Mon Sep 17 00:00:00 2001 From: yangpeng Date: Thu, 6 Jul 2023 11:11:00 +0800 Subject: [PATCH] add access point command --- lib/bucket_access_point.go | 630 ++++++++++++++++++++++ lib/bucket_access_point_test.go | 901 ++++++++++++++++++++++++++++++++ lib/command.go | 1 + 3 files changed, 1532 insertions(+) create mode 100644 lib/bucket_access_point.go create mode 100644 lib/bucket_access_point_test.go diff --git a/lib/bucket_access_point.go b/lib/bucket_access_point.go new file mode 100644 index 00000000..220dab6e --- /dev/null +++ b/lib/bucket_access_point.go @@ -0,0 +1,630 @@ +package lib + +import ( + "bytes" + "encoding/json" + "fmt" + "io/ioutil" + "os" + "strings" +) + +var specChineseBucketAccessPoint = SpecText{ + synopsisText: "设置、查询bucket的access point配置", + paramText: "bucket_url|ap-alias local_xml_file [options]", + + syntaxText: ` + ossutil access-point --method put oss://bucket local_xml_file [local_xml_result] [options] + ossutil access-point --method get oss://bucket ap-name [local_xml_file] [options] + ossutil access-point --method list oss://bucket [local_xml_file] [options] + ossutil access-point --method delete oss://bucket ap-name [options] + ossutil access-point --method put --item policy oss://bucket local_json_file [options] + ossutil access-point --method put --item policy oss://ap-alias local_json_file [options] + ossutil access-point --method get --item policy oss://bucket ap-name [local_json_file] [options] + ossutil access-point --method get --item policy oss://ap-alias ap-name [local_json_file] [options] + ossutil access-point --method delete --item policy oss://bucket ap-name [options] + ossutil access-point --method delete --item policy oss://ap-alias ap-name [options] +`, + detailHelpText: ` + access-point命令通过设置method选项值为put、get、list和delete,可以设置、查询、列举和删除bucket的access point配置 + +用法: + 该命令有七种用法: + + 1) ossutil access-point --method put oss://bucket local_xml_file [local_xml_result] [options] + 这个命令从配置文件local_xml_file中读取access point配置,然后设置bucket的access point规则 + 如果输入参数local_xml_result,执行结果将输出到该文件,否则输出到屏幕上 + 配置文件是一个xml格式的文件,下面是一个例子 + + + + ap-01 + vpc + + vpc-t4nlw426y44rd3iq4**** + + + + 或 + + + + ap-01 + internet + + + 2) ossutil access-point --method get oss://bucket ap-name [local_xml_file] [options] + 这个命令查询bucket的access point名字为ap-name的配置 + 如果输入参数local_xml_file,access point配置将输出到该文件,否则输出到屏幕上 + + 3) ossutil access-point --method list oss://bucket [local_xml_file] [options] + 这个命令列举bucket的access point的配置 + 如果输入参数local_xml_file,access point配置将输出到该文件,否则输出到屏幕上 + + 4) ossutil access-point --method delete oss://bucket ap-name [options] + 这个命令删除bucket的access point名字为ap-name的配置 + + 5) ossutil access-point --method put --item policy oss://bucket ap-name local_json_file [options] + 这个命令从配置文件local_json_file中读取policy配置,然后设置bucket的access point名字为ap-name的policy规则 + 配置文件是一个json格式的文件,举例如下: + + { + "Version": "1", + "Statement": [{ + "Effect": "Deny", + "Action": [ + "oss:PutObject", + "oss:GetObject" + ], + "Principal": [ + "123456" + ], + "Resource": [ + "acs:oss:oss-cn-hangzhou:123456:accesspoint/ap-name", + "acs:oss:oss-cn-hangzhou:123456:accesspoint/ap-name/object/*" + ] + }] + } + + 6) ossutil access-point --method get --item policy oss://bucket ap-name [local_json_file] [options] + 这个命令获取access point名字为ap-name的bucket的policy规则 + 如果输入参数local_json_file,access point配置将输出到该文件,否则输出到屏幕上 + + 7) ossutil access-point --method get --item policy oss://bucket ap-name [options] + 这个命令删除access point名字为ap-name的bucket的policy规则 +`, + sampleText: ` + 1) 设置bucket的access point配置,结果输出到标准输出 + ossutil access-point --method put oss://bucket local_xml_file + + 2) 设置bucket的access point配置,结果输出到本地文件 + ossutil access-point --method put oss://bucket local_xml_file local_xml_result + + 3) 查询bucket的access point名字为ap-name配置,结果输出到标准输出 + ossutil access-point --method get oss://bucket ap-name + + 4) 查询bucket的access point名字为ap-name配置,结果输出到本地文件 + ossutil access-point --method get oss://bucket ap-name local_xml_file + + 5) 列举bucket的access point配置,结果输出到标准输出 + ossutil access-point --method list oss://bucket + + 6) 列举bucket的access point配置,结果输出到本地文件 + ossutil access-point --method list oss://bucket local_xml_file + + 7) 删除bucket的access point名字为ap-name配置 + ossutil access-point --method delete oss://bucket ap-name + + 8) 设置bucket的access point名字为ap-name的policy规则 + ossutil access-point --method put --item policy oss://bucket ap-name local_json_file + + 9) 查询bucket的access point名字为ap-name的policy规则,结果输出到标准输出 + ossutil access-point --method get --item policy oss://bucket ap-name + + 10) 查询bucket的access point名字为ap-name的policy规则,结果输出到本地文件 + ossutil access-point --method get --item policy oss://bucket ap-name local_json_file + + 11) 删除bucket的access point名字为ap-name的policy规则 + ossutil access-point --method delete --item policy oss://bucket ap-name +`, +} + +var specEnglishBucketAccessPoint = SpecText{ + synopsisText: "Set, get, list, delete bucket access point configuration", + paramText: "bucket_url|ap-alias local_xml_file [options]", + + syntaxText: ` + ossutil access-point --method put oss://bucket local_xml_file [local_xml_result] [options] + ossutil access-point --method get oss://bucket ap-name [local_xml_file] [options] + ossutil access-point --method list oss://bucket [local_xml_file] [options] + ossutil access-point --method delete oss://bucket ap-name [options] + ossutil access-point --method put --item policy oss://bucket local_json_file [options] + ossutil access-point --method put --item policy oss://ap-alias local_json_file [options] + ossutil access-point --method get --item policy oss://bucket ap-name [local_json_file] [options] + ossutil access-point --method get --item policy oss://ap-alias ap-name [local_json_file] [options] + ossutil access-point --method delete --item policy oss://bucket ap-name [options] + ossutil access-point --method delete --item policy oss://ap-alias ap-name [options] +`, + + detailHelpText: ` + access-point command can set, get, list, delete the access point configuration of the oss bucket by + set method option value to put, get, list, delete, + +Usage: + 1) ossutil access-point --method put oss://bucket local_xml_file [local_xml_result] [options] + The command sets the access point configuration of bucket from local file local_xml_file + If you input parameter local_xml_result,the configuration will be output to local_xml_result + If you don't input parameter local_xml_result,the configuration will be output to stdout + the local_xml_file is xml format, The following is an example: + + + + ap-01 + vpc + + vpc-t4nlw426y44rd3iq4**** + + + + or + + + + ap-01 + internet + + + 2) ossutil access-point --method get oss://bucket ap-name [local_xml_file] [options] + The command gets the access point name of bucket as ap-name configuration + If you input parameter local_xml_file,the configuration will be output to local_xml_file + If you don't input parameter local_xml_file,the configuration will be output to stdout + + 3) ossutil access-point --method list oss://bucket [local_xml_file] [options] + The command lists the access point of bucket configuration + If you input parameter local_xml_file,the configuration will be output to local_xml_file + If you don't input parameter local_xml_file,the configuration will be output to stdout + + 4) ossutil access-point --method delete oss://bucket ap-name [options] + The command delete the access point name of bucket as ap-name configuration + + 5) ossutil access-point --method put --item policy oss://bucket ap-name local_json_file [options] + The command sets the policy for access point name of bucket as ap-name from local file local_json_file + the local_json_file is json format,for example + + { + "Version": "1", + "Statement": [{ + "Effect": "Deny", + "Action": [ + "oss:PutObject", + "oss:GetObject" + ], + "Principal": [ + "123456" + ], + "Resource": [ + "acs:oss:oss-cn-hangzhou:123456:accesspoint/ap-name", + "acs:oss:oss-cn-hangzhou:123456:accesspoint/ap-name/object/*" + ] + }] + } + + 6) ossutil access-point --method get --item policy oss://bucket ap-name [local_json_file] [options] + The command gets the policy for access point name of bucket as ap-name from local file local_json_file + If you input parameter local_json_file,the configuration will be output to local_json_file + If you don't input parameter local_json_file,the configuration will be output to stdout + + 7) ossutil access-point --method get --item policy oss://bucket ap-name [options] + The command deletes the policy for access point name of bucket as ap-name +`, + + sampleText: ` + 1) put bucket access point to stdout + ossutil access-point --method put oss://bucket local_xml_file + + 2) put bucket access point to local file + ossutil access-point --method put oss://bucket local_xml_file local_xml_result + + 3) get the access point name of bucket as ap-name configuration to stdout + ossutil access-point --method get oss://bucket ap-name + + 4) get the access point name of bucket as ap-name configuration to local file + ossutil access-point --method get oss://bucket ap-name local_xml_file + + 5) list bucket access point configuration to stdout + ossutil access-point --method list oss://bucket + + 6) list bucket access point configuration to local file + ossutil access-point --method list oss://bucket local_xml_file + + 7) delete the access point name of bucket as ap-name configuration + ossutil access-point --method delete oss://bucket ap-name + + 8) put the policy for access point name of bucket as ap-name + ossutil access-point --method put --item policy oss://bucket ap-name local_json_file + + 9) get the policy for access point name of bucket as ap-name to stdout + ossutil access-point --method get --item policy oss://bucket ap-name + + 10) get the policy for access point name of bucket as ap-name to local file + ossutil access-point --method get --item policy oss://bucket ap-name local_json_file + + 11) delete the policy for access point name of bucket as ap-name + ossutil access-point --method delete --item policy oss://bucket ap-name +`, +} + +type bucketAccessPointOptionType struct { + bucketName string +} + +type BucketAccessPointCommand struct { + command Command + blOption bucketAccessPointOptionType +} + +var bucketAccessPointCommand = BucketAccessPointCommand{ + command: Command{ + name: "access-point", + nameAlias: []string{"access-point"}, + minArgc: 1, + maxArgc: 3, + specChinese: specChineseBucketAccessPoint, + specEnglish: specEnglishBucketAccessPoint, + group: GroupTypeNormalCommand, + validOptionNames: []string{ + OptionConfigFile, + OptionEndpoint, + OptionAccessKeyID, + OptionAccessKeySecret, + OptionSTSToken, + OptionProxyHost, + OptionProxyUser, + OptionProxyPwd, + OptionLogLevel, + OptionMethod, + OptionPassword, + OptionMode, + OptionECSRoleName, + OptionTokenTimeout, + OptionRamRoleArn, + OptionRoleSessionName, + OptionReadTimeout, + OptionConnectTimeout, + OptionSTSRegion, + OptionSkipVerifyCert, + OptionUserAgent, + OptionSignVersion, + OptionRegion, + OptionCloudBoxID, + OptionItem, + }, + }, +} + +// function for FormatHelper interface +func (bapc *BucketAccessPointCommand) formatHelpForWhole() string { + return bapc.command.formatHelpForWhole() +} + +func (bapc *BucketAccessPointCommand) formatIndependHelp() string { + return bapc.command.formatIndependHelp() +} + +// Init simulate inheritance, and polymorphism +func (bapc *BucketAccessPointCommand) Init(args []string, options OptionMapType) error { + return bapc.command.Init(args, options, bapc) +} + +// RunCommand simulate inheritance, and polymorphism +func (bapc *BucketAccessPointCommand) RunCommand() error { + strMethod, _ := GetString(OptionMethod, bapc.command.options) + if strMethod == "" { + return fmt.Errorf("--method value is empty") + } + + strMethod = strings.ToLower(strMethod) + if strMethod != "put" && strMethod != "get" && strMethod != "list" && strMethod != "delete" { + return fmt.Errorf("--method value is not in the optional value:put|get|list|delete") + } + + strItem, _ := GetString(OptionItem, bapc.command.options) + + strItem = strings.ToLower(strItem) + if strItem != "" && strItem != "policy" { + return fmt.Errorf("--item value is not in the optional value:policy") + } + + srcBucketUrL, err := GetCloudUrl(bapc.command.args[0], "") + if err != nil { + return err + } + + bapc.blOption.bucketName = srcBucketUrL.bucket + + if strItem == "policy" { + switch strMethod { + case "put": + err = bapc.PutAccessPointPolicy() + case "get": + err = bapc.GetAccessPointPolicy() + case "delete": + err = bapc.DeleteAccessPointPolicy() + } + } else { + switch strMethod { + case "put": + err = bapc.PutBucketAccessPoint() + case "get": + err = bapc.GetBucketAccessPoint() + case "list": + err = bapc.ListBucketAccessPoint() + case "delete": + err = bapc.DeleteBucketAccessPoint() + } + } + + return err +} + +func (bapc *BucketAccessPointCommand) PutBucketAccessPoint() error { + if len(bapc.command.args) < 2 { + return fmt.Errorf("put bucket access point need at least 2 parameters,the local xml file is empty") + } + + xmlFile := bapc.command.args[1] + fileInfo, err := os.Stat(xmlFile) + if err != nil { + return err + } + + if fileInfo.IsDir() { + return fmt.Errorf("%s is dir,not the expected file", xmlFile) + } + + if fileInfo.Size() == 0 { + return fmt.Errorf("%s is empty file", xmlFile) + } + + // parsing the xml file + file, err := os.Open(xmlFile) + if err != nil { + return err + } + defer file.Close() + xmlBody, err := ioutil.ReadAll(file) + if err != nil { + return err + } + + client, err := bapc.command.ossClient(bapc.blOption.bucketName) + if err != nil { + return err + } + + output, err := client.CreateBucketAccessPointXml(bapc.blOption.bucketName, string(xmlBody)) + if err != nil { + return err + } + + var outFile *os.File + if len(bapc.command.args) >= 3 { + fileName := bapc.command.args[2] + _, err = os.Stat(fileName) + if err == nil { + bConitnue := bapc.confirm(fileName) + if !bConitnue { + return nil + } + } + + outFile, err = os.OpenFile(fileName, os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0660) + if err != nil { + return err + } + defer outFile.Close() + } else { + outFile = os.Stdout + } + + outFile.Write([]byte(output)) + + fmt.Printf("\n\n") + return nil +} + +func (bapc *BucketAccessPointCommand) confirm(str string) bool { + var val string + fmt.Printf(getClearStr(fmt.Sprintf("bucket access point: overwrite \"%s\"(y or N)? ", str))) + if _, err := fmt.Scanln(&val); err != nil || (strings.ToLower(val) != "yes" && strings.ToLower(val) != "y") { + return false + } + return true +} + +func (bapc *BucketAccessPointCommand) GetBucketAccessPoint() error { + if len(bapc.command.args) < 2 { + return fmt.Errorf("get bucket access point need at least 2 parameters,the parameter ap name is empty") + } + client, err := bapc.command.ossClient(bapc.blOption.bucketName) + if err != nil { + return err + } + apName := bapc.command.args[1] + output, err := client.GetBucketAccessPointXml(bapc.blOption.bucketName, apName) + if err != nil { + return err + } + + var outFile *os.File + if len(bapc.command.args) >= 3 { + fileName := bapc.command.args[2] + _, err = os.Stat(fileName) + if err == nil { + bConitnue := bapc.confirm(fileName) + if !bConitnue { + return nil + } + } + + outFile, err = os.OpenFile(fileName, os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0660) + if err != nil { + return err + } + defer outFile.Close() + } else { + outFile = os.Stdout + } + + outFile.Write([]byte(output)) + + fmt.Printf("\n\n") + + return nil +} + +func (bapc *BucketAccessPointCommand) ListBucketAccessPoint() error { + client, err := bapc.command.ossClient(bapc.blOption.bucketName) + if err != nil { + return err + } + + output, err := client.ListBucketAccessPointXml(bapc.blOption.bucketName) + if err != nil { + return err + } + + var outFile *os.File + if len(bapc.command.args) >= 2 { + fileName := bapc.command.args[1] + _, err = os.Stat(fileName) + if err == nil { + bConitnue := bapc.confirm(fileName) + if !bConitnue { + return nil + } + } + + outFile, err = os.OpenFile(fileName, os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0660) + if err != nil { + return err + } + defer outFile.Close() + } else { + outFile = os.Stdout + } + + outFile.Write([]byte(output)) + + fmt.Printf("\n\n") + + return nil +} + +func (bapc *BucketAccessPointCommand) DeleteBucketAccessPoint() error { + if len(bapc.command.args) < 2 { + return fmt.Errorf("delete bucket access point need at least 2 parameters,the parameter ap name is empty") + } + client, err := bapc.command.ossClient(bapc.blOption.bucketName) + if err != nil { + return err + } + apName := bapc.command.args[1] + return client.DeleteBucketAccessPoint(bapc.blOption.bucketName, apName) +} + +func (bapc *BucketAccessPointCommand) PutAccessPointPolicy() error { + if len(bapc.command.args) < 3 { + return fmt.Errorf("put access point policy need at least 3 parameters,the local xml file is empty") + } + xmlFile := bapc.command.args[2] + fileInfo, err := os.Stat(xmlFile) + if err != nil { + return err + } + if fileInfo.IsDir() { + return fmt.Errorf("%s is dir,not the expected file", xmlFile) + } + if fileInfo.Size() == 0 { + return fmt.Errorf("%s is empty file", xmlFile) + } + + // parsing the xml file + file, err := os.Open(xmlFile) + if err != nil { + return err + } + defer file.Close() + xmlBody, err := ioutil.ReadAll(file) + if err != nil { + return err + } + + client, err := bapc.command.ossClient(bapc.blOption.bucketName) + if err != nil { + return err + } + + apName := bapc.command.args[1] + + err = client.PutAccessPointPolicy(bapc.blOption.bucketName, apName, string(xmlBody)) + if err != nil { + return err + } + return nil +} + +func (bapc *BucketAccessPointCommand) GetAccessPointPolicy() error { + if len(bapc.command.args) < 2 { + return fmt.Errorf("get bucket access point policy need at least 2 parameters,the parameter ap name is empty") + } + client, err := bapc.command.ossClient(bapc.blOption.bucketName) + if err != nil { + return err + } + apName := bapc.command.args[1] + output, err := client.GetAccessPointPolicy(bapc.blOption.bucketName, apName) + if err != nil { + return err + } + + var outFile *os.File + if len(bapc.command.args) >= 3 { + fileName := bapc.command.args[2] + _, err = os.Stat(fileName) + if err == nil { + bConitnue := bapc.confirm(fileName) + if !bConitnue { + return nil + } + } + + outFile, err = os.OpenFile(fileName, os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0660) + if err != nil { + return err + } + defer outFile.Close() + } else { + outFile = os.Stdout + } + + var prettyJson bytes.Buffer + if err = json.Indent(&prettyJson, []byte(output), "", " "); err != nil { + return err + } + outFile.Write([]byte(prettyJson.String())) + fmt.Printf("\n\n") + return nil +} + +func (bapc *BucketAccessPointCommand) DeleteAccessPointPolicy() error { + if len(bapc.command.args) < 2 { + return fmt.Errorf("delete bucket access point policy need at least 2 parameters,the parameter ap name is empty") + } + client, err := bapc.command.ossClient(bapc.blOption.bucketName) + if err != nil { + return err + } + apName := bapc.command.args[1] + return client.DeleteAccessPointPolicy(bapc.blOption.bucketName, apName) +} diff --git a/lib/bucket_access_point_test.go b/lib/bucket_access_point_test.go new file mode 100644 index 00000000..68499b5b --- /dev/null +++ b/lib/bucket_access_point_test.go @@ -0,0 +1,901 @@ +package lib + +import ( + "encoding/xml" + "github.com/aliyun/aliyun-oss-go-sdk/oss" + . "gopkg.in/check.v1" + "os" + "strings" + "time" +) + +func (s *OssutilCommandSuite) TestAccessPointHelpInfo(c *C) { + // mkdir command test + options := OptionMapType{} + + mkArgs := []string{"access-point"} + _, err := cm.RunCommand("help", mkArgs, options) + c.Assert(err, IsNil) + + mkArgs = []string{} + _, err = cm.RunCommand("help", mkArgs, options) + c.Assert(err, IsNil) +} + +func (s *OssutilCommandSuite) TestPutBucketAccessPointError(c *C) { + bucketName := bucketNamePrefix + randLowStr(12) + s.putBucket(bucketName, c) + + accessFileName := "access-point" + randLowStr(12) + // access point command test + strMethod := "" + options := OptionMapType{ + "endpoint": &endpoint, + "accessKeyID": &accessKeyID, + "accessKeySecret": &accessKeySecret, + "method": &strMethod, + } + + // method is empty + accessArgs := []string{CloudURLToString(bucketName, ""), accessFileName} + _, err := cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + c.Assert(err.Error(), Equals, "--method value is empty") + + //method is error + strMethod = "puttt" + options[OptionMethod] = &strMethod + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + + // cloud url is error + strMethod = "put" + options[OptionMethod] = &strMethod + accessArgs = []string{"http://mybucket", accessFileName} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + + // local file is empty + accessArgs = []string{CloudURLToString(bucketName, ""), accessFileName} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + testLogger.Println("1" + err.Error()) + + //local file is not exist + os.Remove(accessFileName) + accessArgs = []string{CloudURLToString(bucketName, ""), accessFileName} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + testLogger.Println("2" + err.Error()) + + // local file is dir + err = os.MkdirAll(accessFileName, 0755) + c.Assert(err, IsNil) + accessArgs = []string{CloudURLToString(bucketName, ""), accessFileName} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + os.Remove(accessFileName) + + //local file is empty + s.createFile(accessFileName, "", c) + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + os.Remove(accessFileName) + + //local file is not xml file + s.createFile(accessFileName, "aaa", c) + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + os.Remove(accessFileName) + + // StorageURLFromString error + accessArgs = []string{"oss:///1.jpg"} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + + // bucket name is error + accessArgs = []string{"oss:///"} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + + //missing parameter + accessArgs = []string{CloudURLToString(bucketName, "")} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + testLogger.Println("2" + err.Error()) + + // bucket name not exist + accessArgs = []string{CloudURLToString("my-bucket", ""), accessFileName} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + + os.Remove(accessFileName) + s.removeBucket(bucketName, true, c) +} + +func (s *OssutilCommandSuite) TestGetBucketAccessPointError(c *C) { + bucketName := bucketNamePrefix + randLowStr(12) + s.putBucket(bucketName, c) + + apName := "access-point" + randLowStr(12) + + // access point command test + strMethod := "" + options := OptionMapType{ + "endpoint": &endpoint, + "accessKeyID": &accessKeyID, + "accessKeySecret": &accessKeySecret, + "method": &strMethod, + } + + // method is empty + accessArgs := []string{CloudURLToString(bucketName, ""), apName} + _, err := cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + + //method is error + strMethod = "gett" + options[OptionMethod] = &strMethod + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + + // cloud url is error + strMethod = "get" + options[OptionMethod] = &strMethod + accessArgs = []string{"http://mybucket", apName} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + + // apName not exist + accessArgs = []string{CloudURLToString(bucketName, ""), apName} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + + // StorageURLFromString error + accessArgs = []string{"oss:///1.jpg"} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + + // bucket name is error + accessArgs = []string{"oss:///"} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + + //missing parameter + accessArgs = []string{CloudURLToString(bucketName, "")} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + + // bucket name not exist + accessArgs = []string{CloudURLToString("my-bucket", ""), apName} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + + s.removeBucket(bucketName, true, c) +} + +func (s *OssutilCommandSuite) TestListBucketAccessPointError(c *C) { + accessFileName := "access-point-" + randLowStr(12) + // access point command test + strMethod := "" + options := OptionMapType{ + "endpoint": &endpoint, + "accessKeyID": &accessKeyID, + "accessKeySecret": &accessKeySecret, + "method": &strMethod, + } + + // method is empty + accessArgs := []string{CloudURLToString(bucketNameExist, ""), accessFileName} + _, err := cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + + //method is error + strMethod = "listss" + options[OptionMethod] = &strMethod + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + + // cloud url is error + strMethod = "list" + options[OptionMethod] = &strMethod + accessArgs = []string{"http://mybucket", accessFileName} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + + // StorageURLFromString error + accessArgs = []string{"oss:///1.jpg"} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + testLogger.Println(err.Error()) + + // bucket name is error + accessArgs = []string{"oss:///"} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + testLogger.Println(err.Error()) + + // bucket name not exist + accessArgs = []string{CloudURLToString("my-bucket", "")} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + testLogger.Println(err.Error()) + + os.Remove(accessFileName) +} + +func (s *OssutilCommandSuite) TestDeleteBucketAccessPointError(c *C) { + bucketName := bucketNamePrefix + randLowStr(12) + s.putBucket(bucketName, c) + + apName := "access-point" + randLowStr(12) + + // access point command test + strMethod := "" + options := OptionMapType{ + "endpoint": &endpoint, + "accessKeyID": &accessKeyID, + "accessKeySecret": &accessKeySecret, + "method": &strMethod, + } + + // method is empty + accessArgs := []string{CloudURLToString(bucketName, ""), apName} + _, err := cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + + //method is error + strMethod = "deleteteddd" + options[OptionMethod] = &strMethod + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + + // cloud url is error + strMethod = "delete" + options[OptionMethod] = &strMethod + accessArgs = []string{"http://mybucket", apName} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + testLogger.Println(err.Error()) + + // apName not exist + accessArgs = []string{CloudURLToString(bucketName, ""), apName} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + testLogger.Println(err.Error()) + + // StorageURLFromString error + accessArgs = []string{"oss:///1.jpg"} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + testLogger.Println(err.Error()) + + // bucket name is error + accessArgs = []string{"oss:///"} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + testLogger.Println(err.Error()) + + //missing ap name + accessArgs = []string{CloudURLToString(bucketName, "")} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + testLogger.Println(err.Error()) + + // bucket name not exist + accessArgs = []string{CloudURLToString("my-bucket", ""), apName} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + testLogger.Println(err.Error()) + + s.removeBucket(bucketName, true, c) +} + +func (s *OssutilCommandSuite) TestAccessPointPolicyError(c *C) { + bucketName := bucketNamePrefix + randLowStr(12) + s.putBucket(bucketName, c) + + if accountID == "" { + c.ExpectFailure("account ID is empty!") + } + apName := "access-point-" + randLowStr(8) + tmp := strings.SplitN(endpoint, ".", 3) + region := tmp[0] + policy := `{ + "Version":"1", + "Statement":[ + { + "Action":[ + "oss:PutObject", + "oss:GetObject" + ], + "Effect":"Deny", + "Principal":["1234567890"], + "Resource":[ + "acs:oss:` + region + `:` + accountID + `:accesspoint/` + apName + `", + "acs:oss:` + region + `:` + accountID + `:accesspoint/` + apName + `/object/*" + ] + } + ] + }` + accessFileName := "ap-policy-" + randLowStr(8) + s.createFile(accessFileName, policy, c) + + // access point policy command test + strMethod := "put" + strItem := "policy" + get := "get" + del := "delete" + options := OptionMapType{ + "endpoint": &endpoint, + "accessKeyID": &accessKeyID, + "accessKeySecret": &accessKeySecret, + "method": &strMethod, + "item": &strItem, + } + + // missing ap name + accessArgs := []string{CloudURLToString(bucketName, "")} + _, err := cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + testLogger.Println(err.Error()) + c.Assert(strings.Contains(err.Error(), "put access point policy need at least 3 parameters"), Equals, true) + + // missing json file + accessArgs = []string{CloudURLToString(bucketName, ""), apName} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + c.Assert(strings.Contains(err.Error(), "put access point policy need at least 3 parameters"), Equals, true) + + // apName not exist + accessArgs = []string{CloudURLToString(bucketName, ""), apName, accessFileName} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + testLogger.Println(err.Error()) + + // StorageURLFromString error + accessArgs = []string{"oss:///1.jpg", apName, accessFileName} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + testLogger.Println(err.Error()) + + // bucket name is error + accessArgs = []string{"oss:///", apName, accessFileName} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + testLogger.Println(err.Error()) + + // bucket name not exist + accessArgs = []string{CloudURLToString("my-bucket", ""), apName, accessFileName} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + testLogger.Println(err.Error()) + + errItem := "policysss" + options[OptionItem] = &errItem + accessArgs = []string{CloudURLToString(bucketName, ""), apName, accessFileName} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + c.Assert(strings.Contains(err.Error(), "--item value is not in the optional value:policy"), Equals, true) + + accessResult := "get-policy-" + randLowStr(8) + options[OptionMethod] = &get + accessArgs = []string{CloudURLToString(bucketName, "")} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + c.Assert(strings.Contains(err.Error(), "--item value is not in the optional value:policy"), Equals, true) + + options[OptionItem] = &strItem + accessArgs = []string{"oss:///1.jpg", apName, accessResult} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + testLogger.Println(err.Error()) + + accessArgs = []string{"oss:///", apName, accessResult} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + testLogger.Println(err.Error()) + + accessArgs = []string{CloudURLToString("my-bucket", ""), apName, accessResult} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + testLogger.Println(err.Error()) + + options[OptionItem] = &errItem + accessArgs = []string{CloudURLToString(bucketName, ""), apName, accessResult} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + testLogger.Println(err.Error()) + c.Assert(strings.Contains(err.Error(), "--item value is not in the optional value:policy"), Equals, true) + + options[OptionMethod] = &del + accessArgs = []string{CloudURLToString(bucketName, "")} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + c.Assert(strings.Contains(err.Error(), "--item value is not in the optional value:policy"), Equals, true) + + options[OptionItem] = &strItem + accessArgs = []string{"oss:///1.jpg", apName} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + testLogger.Println(err.Error()) + + accessArgs = []string{"oss:///", apName} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + testLogger.Println(err.Error()) + + accessArgs = []string{CloudURLToString("my-bucket", ""), apName} + _, err = cm.RunCommand("access-point", accessArgs, options) + c.Assert(err, NotNil) + testLogger.Println(err.Error()) + + os.Remove(accessFileName) + s.removeBucket(bucketName, true, c) +} + +func (s *OssutilCommandSuite) TestBucketAccessPoint(c *C) { + if accountID == "" { + c.ExpectFailure("account ID is empty!") + } + apName := "ap1-" + randLowStr(8) + accessXml := ` + + ` + apName + ` + internet +` + + accessFileName := "ap-config-" + randLowStr(8) + s.createFile(accessFileName, accessXml, c) + + bucketName := bucketNamePrefix + randLowStr(12) + s.putBucket(bucketName, c) + + // access point command test + str := "" + strMethod := "put" + options := OptionMapType{ + "endpoint": &endpoint, + "accessKeyID": &accessKeyID, + "accessKeySecret": &accessKeySecret, + "method": &strMethod, + } + accessResult := "ap-result-" + randLowStr(8) + command := "access-point" + accessArgs := []string{CloudURLToString(bucketName, ""), accessFileName, accessResult} + _, err := cm.RunCommand(command, accessArgs, options) + c.Assert(err, IsNil) + + _, err = os.Stat(accessResult) + c.Assert(err, IsNil) + accessBody := s.readFile(accessResult, c) + + var putOut oss.CreateBucketAccessPointResult + err = xml.Unmarshal([]byte(accessBody), &putOut) + c.Assert(err, IsNil) + + os.Remove(accessFileName) + os.Remove(accessResult) + + time.Sleep(3 * time.Second) + + apName1 := "ap2-" + randLowStr(8) + accessXml = ` + + ` + apName1 + ` + vpc + + vpc-1234567890 + +` + + s.createFile(accessFileName, accessXml, c) + + accessArgs = []string{CloudURLToString(bucketName, ""), accessFileName} + _, err = cm.RunCommand(command, accessArgs, options) + c.Assert(err, IsNil) + os.Remove(accessFileName) + + strMethod = "get" + options[OptionMethod] = &strMethod + accessGetResult := "ap-get-" + randLowStr(8) + accessArgs = []string{CloudURLToString(bucketName, ""), apName, accessGetResult} + _, err = cm.RunCommand(command, accessArgs, options) + c.Assert(err, IsNil) + + // check access point DownName + _, err = os.Stat(accessGetResult) + c.Assert(err, IsNil) + + accessBody = s.readFile(accessGetResult, c) + + var out oss.GetBucketAccessPointResult + err = xml.Unmarshal([]byte(accessBody), &out) + c.Assert(err, IsNil) + c.Assert(out.AccessPointName, Equals, apName) + accessPointArn := out.AccessPointArn + aliasName := out.Alias + os.Remove(accessFileName) + os.Remove(accessGetResult) + time.Sleep(3 * time.Second) + + accessListResult := "ap-list-" + randLowStr(8) + strMethod = "list" + options[OptionMethod] = &strMethod + accessArgs = []string{CloudURLToString(bucketName, ""), accessListResult} + _, err = cm.RunCommand(command, accessArgs, options) + c.Assert(err, IsNil) + time.Sleep(3 * time.Second) + _, err = os.Stat(accessListResult) + c.Assert(err, IsNil) + accessBody = s.readFile(accessListResult, c) + var list oss.ListBucketAccessPointsResult + err = xml.Unmarshal([]byte(accessBody), &list) + c.Assert(err, IsNil) + c.Assert(len(list.AccessPoints), Equals, 2) + + c.Assert(list.AccessPoints[1].AccessPointName, Equals, apName1) + c.Assert(list.AccessPoints[1].Bucket, Equals, bucketName) + c.Assert(list.AccessPoints[1].Alias != "", Equals, true) + c.Assert(list.AccessPoints[1].NetworkOrigin, Equals, "vpc") + c.Assert(list.AccessPoints[1].Status != "", Equals, true) + os.Remove(accessListResult) + + policy := `{ + "Version":"1", + "Statement":[ + { + "Action":[ + "oss:*" + ], + "Effect": "Allow", + "Principal":["` + accountID + `"], + "Resource":[ + "` + accessPointArn + `", + "` + accessPointArn + `/object/*" + ] + } + ] + }` + accessJsonName := "ap-policy-" + randLowStr(6) + s.createFile(accessJsonName, policy, c) + strMethod = "put" + strItem := "policy" + options[OptionMethod] = &strMethod + options[OptionItem] = &strItem + accessArgs = []string{CloudURLToString(bucketName, ""), apName, accessJsonName} + _, err = cm.RunCommand(command, accessArgs, options) + c.Assert(err, IsNil) + os.Remove(accessJsonName) + time.Sleep(3 * time.Second) + + strMethod = "get" + options[OptionMethod] = &strMethod + accessArgs = []string{CloudURLToString(bucketName, ""), apName} + _, err = cm.RunCommand(command, accessArgs, options) + c.Assert(err, IsNil) + time.Sleep(3 * time.Second) + + accessArgs = []string{CloudURLToString(bucketName, ""), apName, accessJsonName} + _, err = cm.RunCommand(command, accessArgs, options) + c.Assert(err, IsNil) + time.Sleep(3 * time.Second) + + _, err = os.Stat(accessJsonName) + c.Assert(err, IsNil) + accessBody = s.readFile(accessJsonName, c) + //c.Assert(accessBody,Equals,policy) + os.Remove(accessJsonName) + + policy1 := `{ + "Version":"1", + "Statement":[ + { + "Action":[ + "oss:*" + ], + "Effect": "Allow", + "Principal":["` + accountID + `"], + "Resource":[ + "` + accessPointArn + `", + "` + accessPointArn + `/object/*" + ] + }, + { + "Action":[ + "oss:PutObject", + "oss:GetObject" + ], + "Effect":"Deny", + "Principal":["123456"], + "Resource":[ + "` + accessPointArn + `", + "` + accessPointArn + `/object/*" + ] + } + ] + }` + for { + strMethod = "get" + options[OptionMethod] = &strMethod + options[OptionItem] = &str + accessArgs = []string{CloudURLToString(bucketName, ""), apName, accessGetResult} + _, err = cm.RunCommand(command, accessArgs, options) + c.Assert(err, IsNil) + _, err = os.Stat(accessGetResult) + c.Assert(err, IsNil) + accessBody = s.readFile(accessGetResult, c) + var out oss.GetBucketAccessPointResult + err = xml.Unmarshal([]byte(accessBody), &out) + c.Assert(err, IsNil) + os.Remove(accessGetResult) + if out.Status == "enable" { + break + } + time.Sleep(3 * time.Second) + } + s.createFile(accessJsonName, policy1, c) + strMethod = "put" + options[OptionItem] = &strItem + options[OptionMethod] = &strMethod + accessArgs = []string{CloudURLToString(aliasName, ""), apName, accessJsonName} + _, err = cm.RunCommand(command, accessArgs, options) + c.Assert(err, IsNil) + + strMethod = "get" + options[OptionMethod] = &strMethod + accessArgs = []string{CloudURLToString(aliasName, ""), apName} + _, err = cm.RunCommand(command, accessArgs, options) + c.Assert(err, IsNil) + + downJsonName := "ap-down-" + randLowStr(5) + strMethod = "get" + options[OptionMethod] = &strMethod + accessArgs = []string{CloudURLToString(aliasName, ""), apName, downJsonName} + _, err = cm.RunCommand(command, accessArgs, options) + c.Assert(err, IsNil) + os.Remove(downJsonName) + + strMethod = "delete" + options[OptionMethod] = &strMethod + accessArgs = []string{CloudURLToString(aliasName, ""), apName} + _, err = cm.RunCommand(command, accessArgs, options) + c.Assert(err, IsNil) + + strMethod = "put" + options[OptionMethod] = &strMethod + accessArgs = []string{CloudURLToString(bucketName, ""), apName, accessJsonName} + _, err = cm.RunCommand(command, accessArgs, options) + c.Assert(err, IsNil) + os.Remove(accessJsonName) + + strMethod = "delete" + options[OptionMethod] = &strMethod + accessArgs = []string{CloudURLToString(bucketName, ""), apName} + _, err = cm.RunCommand(command, accessArgs, options) + c.Assert(err, IsNil) + + for { + strMethod = "list" + options[OptionMethod] = &strMethod + options[OptionItem] = &str + accessArgs = []string{CloudURLToString(bucketName, ""), accessListResult} + _, err = cm.RunCommand(command, accessArgs, options) + c.Assert(err, IsNil) + accessBody = s.readFile(accessListResult, c) + var list2 oss.ListBucketAccessPointsResult + err = xml.Unmarshal([]byte(accessBody), &list2) + c.Assert(err, IsNil) + os.Remove(accessListResult) + if len(list2.AccessPoints) > 0 { + for _, point := range list2.AccessPoints { + if point.Status == "enable" { + strMethod = "delete" + options[OptionMethod] = &strMethod + accessArgs = []string{CloudURLToString(bucketName, ""), point.AccessPointName} + _, err = cm.RunCommand(command, accessArgs, options) + c.Assert(err, IsNil) + } + } + } else { + break + } + time.Sleep(60 * time.Second) + } + s.removeBucket(bucketName, true, c) +} + +func (s *OssutilCommandSuite) TestBucketAccessPointOtherError(c *C) { + if accountID == "" { + c.ExpectFailure("account ID is empty!") + } + apName := "ap1-" + randLowStr(8) + accessXml := ` + + ` + apName + ` + internet +` + + accessFileName := "ap-config-" + randLowStr(8) + s.createFile(accessFileName, accessXml, c) + + bucketName := bucketNamePrefix + randLowStr(12) + s.putBucket(bucketName, c) + + // access point command test + str := "" + strMethod := "put" + options := OptionMapType{ + "endpoint": &endpoint, + "accessKeyID": &accessKeyID, + "accessKeySecret": &accessKeySecret, + "method": &strMethod, + } + accessResult := "ap-result-" + randLowStr(8) + command := "access-point" + accessArgs := []string{CloudURLToString(bucketName, ""), accessFileName, accessResult} + _, err := cm.RunCommand(command, accessArgs, options) + c.Assert(err, IsNil) + + _, err = os.Stat(accessResult) + c.Assert(err, IsNil) + accessBody := s.readFile(accessResult, c) + + var putOut oss.CreateBucketAccessPointResult + err = xml.Unmarshal([]byte(accessBody), &putOut) + c.Assert(err, IsNil) + os.Remove(accessFileName) + os.Remove(accessResult) + + time.Sleep(3 * time.Second) + + strMethod = "get" + options[OptionMethod] = &strMethod + accessGetResult := "ap-get-" + randLowStr(8) + accessArgs = []string{CloudURLToString(bucketName, ""), apName, accessGetResult} + _, err = cm.RunCommand(command, accessArgs, options) + c.Assert(err, IsNil) + accessBody = s.readFile(accessGetResult, c) + var out oss.GetBucketAccessPointResult + err = xml.Unmarshal([]byte(accessBody), &out) + c.Assert(err, IsNil) + c.Assert(out.AccessPointName, Equals, apName) + accessPointArn := out.AccessPointArn + os.Remove(accessGetResult) + time.Sleep(3 * time.Second) + + strMethod = "get" + options[OptionMethod] = &strMethod + accessArgs = []string{CloudURLToString(bucketName, ""), "not-exist-ap", accessGetResult} + _, err = cm.RunCommand(command, accessArgs, options) + c.Assert(err, NotNil) + time.Sleep(3 * time.Second) + + policy := `{ + "Version":"1", + "Statement":[ + { + "Action":[ + "oss:*" + ], + "Effect": "Allow", + "Principal":["` + accountID + `"], + "Resource":[ + "` + accessPointArn + `", + "` + accessPointArn + `/object/*" + ] + } + ] + }` + accessJsonName := "ap-policy-" + randLowStr(6) + s.createFile(accessJsonName, policy, c) + strMethod = "put" + strItem := "policy" + options[OptionMethod] = &strMethod + options[OptionItem] = &strItem + accessArgs = []string{CloudURLToString(bucketName, ""), apName, accessJsonName} + _, err = cm.RunCommand(command, accessArgs, options) + c.Assert(err, IsNil) + os.Remove(accessJsonName) + time.Sleep(3 * time.Second) + + s.createFile(accessJsonName, "error-policy", c) + accessArgs = []string{CloudURLToString(bucketName, ""), apName, accessJsonName} + _, err = cm.RunCommand(command, accessArgs, options) + c.Assert(err, NotNil) + os.Remove(accessJsonName) + time.Sleep(3 * time.Second) + + strMethod = "get" + options[OptionMethod] = &strMethod + accessArgs = []string{CloudURLToString(bucketName, ""), apName} + _, err = cm.RunCommand(command, accessArgs, options) + c.Assert(err, IsNil) + time.Sleep(3 * time.Second) + + strMethod = "get" + options[OptionMethod] = &strMethod + accessArgs = []string{CloudURLToString(bucketName, ""), "not-exist-ap-name"} + _, err = cm.RunCommand(command, accessArgs, options) + c.Assert(err, NotNil) + time.Sleep(3 * time.Second) + + accessArgs = []string{CloudURLToString(bucketName, ""), apName, accessJsonName} + _, err = cm.RunCommand(command, accessArgs, options) + c.Assert(err, IsNil) + time.Sleep(3 * time.Second) + + _, err = os.Stat(accessJsonName) + c.Assert(err, IsNil) + accessBody = s.readFile(accessJsonName, c) + os.Remove(accessJsonName) + + for { + strMethod = "get" + options[OptionMethod] = &strMethod + options[OptionItem] = &str + accessArgs = []string{CloudURLToString(bucketName, ""), apName, accessGetResult} + _, err = cm.RunCommand(command, accessArgs, options) + c.Assert(err, IsNil) + _, err = os.Stat(accessGetResult) + c.Assert(err, IsNil) + accessBody = s.readFile(accessGetResult, c) + var out oss.GetBucketAccessPointResult + err = xml.Unmarshal([]byte(accessBody), &out) + c.Assert(err, IsNil) + os.Remove(accessGetResult) + if out.Status == "enable" { + break + } + time.Sleep(3 * time.Second) + } + + strMethod = "get" + options[OptionMethod] = &strMethod + accessArgs = []string{CloudURLToString("error-alias", ""), apName} + _, err = cm.RunCommand(command, accessArgs, options) + c.Assert(err, NotNil) + + downJsonName := "ap-down-" + randLowStr(5) + strMethod = "get" + options[OptionMethod] = &strMethod + accessArgs = []string{CloudURLToString("error-alias", ""), apName, downJsonName} + _, err = cm.RunCommand(command, accessArgs, options) + c.Assert(err, NotNil) + + strMethod = "delete" + options[OptionMethod] = &strMethod + accessArgs = []string{CloudURLToString("error-alias", ""), apName} + _, err = cm.RunCommand(command, accessArgs, options) + c.Assert(err, NotNil) + + accessListResult := "ap-list-" + randLowStr(8) + for { + strMethod = "list" + options[OptionMethod] = &strMethod + options[OptionItem] = &str + accessArgs = []string{CloudURLToString(bucketName, ""), accessListResult} + _, err = cm.RunCommand(command, accessArgs, options) + c.Assert(err, IsNil) + accessBody = s.readFile(accessListResult, c) + var list2 oss.ListBucketAccessPointsResult + err = xml.Unmarshal([]byte(accessBody), &list2) + c.Assert(err, IsNil) + os.Remove(accessListResult) + if len(list2.AccessPoints) > 0 { + for _, point := range list2.AccessPoints { + if point.Status == "enable" { + strMethod = "delete" + options[OptionMethod] = &strMethod + accessArgs = []string{CloudURLToString(bucketName, ""), point.AccessPointName} + _, err = cm.RunCommand(command, accessArgs, options) + c.Assert(err, IsNil) + } + } + } else { + break + } + time.Sleep(60 * time.Second) + } + s.removeBucket(bucketName, true, c) +} diff --git a/lib/command.go b/lib/command.go index cdbe7704..50251903 100644 --- a/lib/command.go +++ b/lib/command.go @@ -890,5 +890,6 @@ func GetAllCommands() []interface{} { &lcbCommand, &bucketAccessMonitorCommand, &bucketResourceGroupCommand, + &bucketAccessPointCommand, } }