From 61f9d3a9fea80086a72c527adc9caa02a7cb6786 Mon Sep 17 00:00:00 2001 From: "mingsheng.su" Date: Sat, 12 Oct 2019 16:46:21 +0800 Subject: [PATCH] add ucloud import --- .../ucloud/{uhost => common}/access_config.go | 24 +- .../{uhost => common}/access_config_test.go | 2 +- builder/ucloud/{uhost => common}/artifact.go | 6 +- .../ucloud/{uhost => common}/artifact_test.go | 14 +- builder/ucloud/{uhost => common}/client.go | 62 +-- builder/ucloud/common/consts.go | 25 ++ builder/ucloud/{uhost => common}/errors.go | 14 +- .../ucloud/{uhost => common}/image_config.go | 2 +- .../{uhost => common}/image_config_test.go | 2 +- .../ucloud/{uhost => common}/run_config.go | 6 +- .../{uhost => common}/run_config_test.go | 2 +- builder/ucloud/common/type_converter.go | 31 ++ builder/ucloud/{uhost => common}/types.go | 50 +-- .../ucloud/{uhost => common}/types_test.go | 20 +- builder/ucloud/{uhost => common}/utils.go | 12 +- builder/ucloud/uhost/builder.go | 15 +- builder/ucloud/uhost/builder_acc_test.go | 23 +- builder/ucloud/uhost/builder_test.go | 3 +- builder/ucloud/uhost/consts.go | 24 -- .../ucloud/uhost/step_check_source_image.go | 13 +- .../uhost/step_config_security_group.go | 19 +- builder/ucloud/uhost/step_config_subnet.go | 11 +- builder/ucloud/uhost/step_config_vpc.go | 11 +- builder/ucloud/uhost/step_copy_image.go | 31 +- builder/ucloud/uhost/step_create_image.go | 25 +- builder/ucloud/uhost/step_create_instance.go | 78 ++-- builder/ucloud/uhost/step_pre_validate.go | 9 +- builder/ucloud/uhost/step_stop_instance.go | 23 +- command/plugin.go | 2 + examples/ucloud/basic.json | 53 +-- examples/ucloud/local/http/centos-6.8/ks.cfg | 42 ++ examples/ucloud/local/local.json | 61 +++ examples/ucloud/local/test.json | 62 +++ go.mod | 5 +- go.sum | 65 +-- .../ucloud-import/post-processor.go | 349 ++++++++++++++++ .../ucloud-sdk-go/private/utils/accessor.go | 5 +- .../ucloud-sdk-go/services/uaccount/client.go | 5 +- .../ucloud-sdk-go/services/ufile/client.go | 21 + .../services/ufile/create_bucket.go | 63 +++ .../services/ufile/create_ufile_token.go | 69 ++++ .../services/ufile/delete_bucket.go | 60 +++ .../services/ufile/delete_ufile_token.go | 54 +++ .../services/ufile/describe_bucket.go | 64 +++ .../services/ufile/describe_ufile_token.go | 66 +++ .../ucloud-sdk-go/services/ufile/doc.go | 13 + .../services/ufile/types_ufile_bucket_set.go | 45 +++ .../services/ufile/types_ufile_domain_set.go | 24 ++ .../services/ufile/types_ufile_token_set.go | 45 +++ .../services/ufile/update_bucket.go | 62 +++ .../services/ufile/update_ufile_token.go | 69 ++++ .../ucloud-sdk-go/services/uhost/client.go | 5 +- .../services/uhost/create_isolation_group.go | 59 +++ .../services/uhost/create_uhost_instance.go | 9 + .../services/uhost/delete_isolation_group.go | 56 +++ .../uhost/describe_isolation_group.go | 62 +++ .../services/uhost/leave_isolation_group.go | 62 +++ .../services/uhost/types_isolation_group.go | 22 + .../services/uhost/types_spread_info.go | 16 + .../ucloud-sdk-go/services/unet/client.go | 5 +- .../services/unet/describe_vip.go | 30 +- ...pdetail_set.go => types_vip_detail_set.go} | 30 +- .../services/unet/update_vip_attribute.go | 63 +++ .../services/vpc/add_white_list_resource.go | 57 +++ .../ucloud-sdk-go/services/vpc/client.go | 7 +- .../services/vpc/create_natgw.go | 78 ++++ .../services/vpc/create_natgw_policy.go | 75 ++++ .../services/vpc/delete_natgw.go | 57 +++ .../services/vpc/delete_natgw_policy.go | 57 +++ .../vpc/delete_white_list_resource.go | 57 +++ .../services/vpc/describe_natgw.go | 66 +++ .../services/vpc/describe_natgw_policy.go | 66 +++ .../vpc/describe_white_list_resource.go | 60 +++ .../services/vpc/enable_white_list.go | 57 +++ .../vpc/get_available_resource_for_policy.go | 63 +++ .../get_available_resource_for_white_list.go | 60 +++ .../services/vpc/list_subnet_for_natgw.go | 57 +++ .../services/vpc/set_gw_default_export.go | 60 +++ ...ribe_white_list_resource_object_ip_info.go | 39 ++ ..._available_resource_for_policy_data_set.go | 21 + ...ilable_resource_for_white_list_data_set.go | 39 ++ .../vpc/types_nat_gateway_data_set.go | 45 +++ .../services/vpc/types_nat_gateway_ip_set.go | 27 ++ .../vpc/types_nat_gateway_subnet_set.go | 21 + .../services/vpc/types_nat_gw_ip_res_info.go | 18 + .../vpc/types_nat_gw_whitelist_data_set.go | 21 + .../vpc/types_natgw_policy_data_set.go | 39 ++ .../vpc/types_natgw_subnet_data_set.go | 27 ++ .../services/vpc/update_natgw_policy.go | 75 ++++ .../services/vpc/update_natgw_subnet.go | 57 +++ .../ucloud-sdk-go/ucloud/auth/credential.go | 61 +-- .../ucloud/ucloud-sdk-go/ucloud/client.go | 22 + .../ucloud/ucloud-sdk-go/ucloud/config.go | 6 + .../ucloud-sdk-go/ucloud/request/common.go | 1 - .../ucloud-sdk-go/ucloud/request/encoder.go | 6 + .../ucloud-sdk-go/ucloud/request/schema.go | 70 ++++ .../ucloud-sdk-go/ucloud/response/common.go | 15 + .../ucloud/ucloud-sdk-go/ucloud/schema.go | 83 +--- .../ucloud-sdk-go/ucloud/version/version.go | 2 +- .../ufilesdk-dev/ufile-gosdk/.gitignore | 4 + .../ufilesdk-dev/ufile-gosdk/README.md | 71 ++++ .../ufilesdk-dev/ufile-gosdk/auth.go | 116 ++++++ .../ufilesdk-dev/ufile-gosdk/bucket.go | 183 +++++++++ .../ufilesdk-dev/ufile-gosdk/file.go | 380 ++++++++++++++++++ .../ufile-gosdk/file_mutipart_upload.go | 291 ++++++++++++++ .../file_mutipart_upload_with_policy.go | 166 ++++++++ .../github.com/ufilesdk-dev/ufile-gosdk/io.go | 104 +++++ .../ufilesdk-dev/ufile-gosdk/request.go | 181 +++++++++ .../ufilesdk-dev/ufile-gosdk/utils.go | 183 +++++++++ vendor/modules.txt | 7 +- .../source/docs/builders/ucloud-uhost.html.md | 4 +- 111 files changed, 5089 insertions(+), 453 deletions(-) rename builder/ucloud/{uhost => common}/access_config.go (88%) rename builder/ucloud/{uhost => common}/access_config_test.go (97%) rename builder/ucloud/{uhost => common}/artifact.go (96%) rename builder/ucloud/{uhost => common}/artifact_test.go (85%) rename builder/ucloud/{uhost => common}/client.go (57%) create mode 100644 builder/ucloud/common/consts.go rename builder/ucloud/{uhost => common}/errors.go (73%) rename builder/ucloud/{uhost => common}/image_config.go (99%) rename builder/ucloud/{uhost => common}/image_config_test.go (98%) rename builder/ucloud/{uhost => common}/run_config.go (96%) rename builder/ucloud/{uhost => common}/run_config_test.go (98%) create mode 100644 builder/ucloud/common/type_converter.go rename builder/ucloud/{uhost => common}/types.go (81%) rename builder/ucloud/{uhost => common}/types_test.go (69%) rename builder/ucloud/{uhost => common}/utils.go (82%) delete mode 100644 builder/ucloud/uhost/consts.go create mode 100644 examples/ucloud/local/http/centos-6.8/ks.cfg create mode 100644 examples/ucloud/local/local.json create mode 100644 examples/ucloud/local/test.json create mode 100644 post-processor/ucloud-import/post-processor.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/client.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/create_bucket.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/create_ufile_token.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/delete_bucket.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/delete_ufile_token.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/describe_bucket.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/describe_ufile_token.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/doc.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/types_ufile_bucket_set.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/types_ufile_domain_set.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/types_ufile_token_set.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/update_bucket.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/update_ufile_token.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/create_isolation_group.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/delete_isolation_group.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/describe_isolation_group.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/leave_isolation_group.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/types_isolation_group.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/types_spread_info.go rename vendor/github.com/ucloud/ucloud-sdk-go/services/unet/{types_vipdetail_set.go => types_vip_detail_set.go} (65%) create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/unet/update_vip_attribute.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/add_white_list_resource.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/create_natgw.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/create_natgw_policy.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/delete_natgw.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/delete_natgw_policy.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/delete_white_list_resource.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/describe_natgw.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/describe_natgw_policy.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/describe_white_list_resource.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/enable_white_list.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/get_available_resource_for_policy.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/get_available_resource_for_white_list.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/list_subnet_for_natgw.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/set_gw_default_export.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_describe_white_list_resource_object_ip_info.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_get_available_resource_for_policy_data_set.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_get_available_resource_for_white_list_data_set.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_nat_gateway_data_set.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_nat_gateway_ip_set.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_nat_gateway_subnet_set.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_nat_gw_ip_res_info.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_nat_gw_whitelist_data_set.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_natgw_policy_data_set.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_natgw_subnet_data_set.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/update_natgw_policy.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/update_natgw_subnet.go create mode 100644 vendor/github.com/ucloud/ucloud-sdk-go/ucloud/request/schema.go create mode 100644 vendor/github.com/ufilesdk-dev/ufile-gosdk/.gitignore create mode 100644 vendor/github.com/ufilesdk-dev/ufile-gosdk/README.md create mode 100644 vendor/github.com/ufilesdk-dev/ufile-gosdk/auth.go create mode 100644 vendor/github.com/ufilesdk-dev/ufile-gosdk/bucket.go create mode 100644 vendor/github.com/ufilesdk-dev/ufile-gosdk/file.go create mode 100644 vendor/github.com/ufilesdk-dev/ufile-gosdk/file_mutipart_upload.go create mode 100644 vendor/github.com/ufilesdk-dev/ufile-gosdk/file_mutipart_upload_with_policy.go create mode 100644 vendor/github.com/ufilesdk-dev/ufile-gosdk/io.go create mode 100644 vendor/github.com/ufilesdk-dev/ufile-gosdk/request.go create mode 100644 vendor/github.com/ufilesdk-dev/ufile-gosdk/utils.go diff --git a/builder/ucloud/uhost/access_config.go b/builder/ucloud/common/access_config.go similarity index 88% rename from builder/ucloud/uhost/access_config.go rename to builder/ucloud/common/access_config.go index 389d74578..9cfdaf695 100644 --- a/builder/ucloud/uhost/access_config.go +++ b/builder/ucloud/common/access_config.go @@ -1,4 +1,4 @@ -package uhost +package common import ( "fmt" @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/packer/template/interpolate" "github.com/hashicorp/packer/version" "github.com/ucloud/ucloud-sdk-go/services/uaccount" + "github.com/ucloud/ucloud-sdk-go/services/ufile" "github.com/ucloud/ucloud-sdk-go/services/uhost" "github.com/ucloud/ucloud-sdk-go/services/unet" "github.com/ucloud/ucloud-sdk-go/services/vpc" @@ -42,10 +43,11 @@ func (c *AccessConfig) Client() (*UCloudClient, error) { cred.PrivateKey = c.PrivateKey c.client = &UCloudClient{} - c.client.uhostconn = uhost.NewClient(&cfg, &cred) - c.client.unetconn = unet.NewClient(&cfg, &cred) - c.client.vpcconn = vpc.NewClient(&cfg, &cred) - c.client.uaccountconn = uaccount.NewClient(&cfg, &cred) + c.client.UHostConn = uhost.NewClient(&cfg, &cred) + c.client.UNetConn = unet.NewClient(&cfg, &cred) + c.client.VPCConn = vpc.NewClient(&cfg, &cred) + c.client.UAccountConn = uaccount.NewClient(&cfg, &cred) + c.client.UFileConn = ufile.NewClient(&cfg, &cred) return c.client, nil } @@ -137,7 +139,7 @@ func (c *AccessConfig) ValidateZone(region, zone string) error { func (c *AccessConfig) getSupportedProjectIds() ([]string, error) { client, err := c.Client() - conn := client.uaccountconn + conn := client.UAccountConn if err != nil { return nil, err } @@ -150,7 +152,7 @@ func (c *AccessConfig) getSupportedProjectIds() ([]string, error) { validProjectIds := make([]string, len(resp.ProjectSet)) for _, val := range resp.ProjectSet { - if !isStringIn(val.ProjectId, validProjectIds) { + if !IsStringIn(val.ProjectId, validProjectIds) { validProjectIds = append(validProjectIds, val.ProjectId) } } @@ -160,7 +162,7 @@ func (c *AccessConfig) getSupportedProjectIds() ([]string, error) { func (c *AccessConfig) getSupportedRegions() ([]string, error) { client, err := c.Client() - conn := client.uaccountconn + conn := client.UAccountConn if err != nil { return nil, err } @@ -173,7 +175,7 @@ func (c *AccessConfig) getSupportedRegions() ([]string, error) { validRegions := make([]string, len(resp.Regions)) for _, val := range resp.Regions { - if !isStringIn(val.Region, validRegions) { + if !IsStringIn(val.Region, validRegions) { validRegions = append(validRegions, val.Region) } } @@ -183,7 +185,7 @@ func (c *AccessConfig) getSupportedRegions() ([]string, error) { func (c *AccessConfig) getSupportedZones(region string) ([]string, error) { client, err := c.Client() - conn := client.uaccountconn + conn := client.UAccountConn if err != nil { return nil, err } @@ -196,7 +198,7 @@ func (c *AccessConfig) getSupportedZones(region string) ([]string, error) { validZones := make([]string, len(resp.Regions)) for _, val := range resp.Regions { - if val.Region == region && !isStringIn(val.Zone, validZones) { + if val.Region == region && !IsStringIn(val.Zone, validZones) { validZones = append(validZones, val.Zone) } diff --git a/builder/ucloud/uhost/access_config_test.go b/builder/ucloud/common/access_config_test.go similarity index 97% rename from builder/ucloud/uhost/access_config_test.go rename to builder/ucloud/common/access_config_test.go index 3c949bb8b..179776e43 100644 --- a/builder/ucloud/uhost/access_config_test.go +++ b/builder/ucloud/common/access_config_test.go @@ -1,4 +1,4 @@ -package uhost +package common import ( "os" diff --git a/builder/ucloud/uhost/artifact.go b/builder/ucloud/common/artifact.go similarity index 96% rename from builder/ucloud/uhost/artifact.go rename to builder/ucloud/common/artifact.go index fc8a43ff6..961bd9399 100644 --- a/builder/ucloud/uhost/artifact.go +++ b/builder/ucloud/common/artifact.go @@ -1,4 +1,4 @@ -package uhost +package common import ( "fmt" @@ -10,7 +10,7 @@ import ( ) type Artifact struct { - UCloudImages *imageInfoSet + UCloudImages *ImageInfoSet BuilderIdValue string @@ -56,7 +56,7 @@ func (a *Artifact) State(name string) interface{} { } func (a *Artifact) Destroy() error { - conn := a.Client.uhostconn + conn := a.Client.UHostConn errors := make([]error, 0) for _, v := range a.UCloudImages.GetAll() { diff --git a/builder/ucloud/uhost/artifact_test.go b/builder/ucloud/common/artifact_test.go similarity index 85% rename from builder/ucloud/uhost/artifact_test.go rename to builder/ucloud/common/artifact_test.go index ec4278565..d3f0f12d7 100644 --- a/builder/ucloud/uhost/artifact_test.go +++ b/builder/ucloud/common/artifact_test.go @@ -1,4 +1,4 @@ -package uhost +package common import ( "github.com/hashicorp/packer/packer" @@ -13,14 +13,14 @@ func TestArtifact_Impl(t *testing.T) { func TestArtifactId(t *testing.T) { expected := `project1:region1:foo,project2:region2:bar` - images := newImageInfoSet(nil) - images.Set(imageInfo{ + images := NewImageInfoSet(nil) + images.Set(ImageInfo{ Region: "region1", ProjectId: "project1", ImageId: "foo", }) - images.Set(imageInfo{ + images.Set(ImageInfo{ Region: "region2", ProjectId: "project2", ImageId: "bar", @@ -37,14 +37,14 @@ func TestArtifactId(t *testing.T) { } func TestArtifactState_atlasMetadata(t *testing.T) { - images := newImageInfoSet(nil) - images.Set(imageInfo{ + images := NewImageInfoSet(nil) + images.Set(ImageInfo{ Region: "region1", ProjectId: "project1", ImageId: "foo", }) - images.Set(imageInfo{ + images.Set(ImageInfo{ Region: "region2", ProjectId: "project2", ImageId: "bar", diff --git a/builder/ucloud/uhost/client.go b/builder/ucloud/common/client.go similarity index 57% rename from builder/ucloud/uhost/client.go rename to builder/ucloud/common/client.go index 120f2d33c..0e1cf0434 100644 --- a/builder/ucloud/uhost/client.go +++ b/builder/ucloud/common/client.go @@ -1,7 +1,8 @@ -package uhost +package common import ( "github.com/ucloud/ucloud-sdk-go/services/uaccount" + "github.com/ucloud/ucloud-sdk-go/services/ufile" "github.com/ucloud/ucloud-sdk-go/services/uhost" "github.com/ucloud/ucloud-sdk-go/services/unet" "github.com/ucloud/ucloud-sdk-go/services/vpc" @@ -10,17 +11,18 @@ import ( ) type UCloudClient struct { - uhostconn *uhost.UHostClient - unetconn *unet.UNetClient - vpcconn *vpc.VPCClient - uaccountconn *uaccount.UAccountClient + UHostConn *uhost.UHostClient + UNetConn *unet.UNetClient + VPCConn *vpc.VPCClient + UAccountConn *uaccount.UAccountClient + UFileConn *ufile.UFileClient } -func (c *UCloudClient) describeFirewallById(sgId string) (*unet.FirewallDataSet, error) { +func (c *UCloudClient) DescribeFirewallById(sgId string) (*unet.FirewallDataSet, error) { if sgId == "" { - return nil, newNotFoundError("security group", sgId) + return nil, NewNotFoundError("security group", sgId) } - conn := c.unetconn + conn := c.UNetConn req := conn.NewDescribeFirewallRequest() req.FWId = ucloud.String(sgId) @@ -29,23 +31,23 @@ func (c *UCloudClient) describeFirewallById(sgId string) (*unet.FirewallDataSet, if err != nil { if uErr, ok := err.(uerr.Error); ok && uErr.Code() == 54002 { - return nil, newNotFoundError("security group", sgId) + return nil, NewNotFoundError("security group", sgId) } return nil, err } if len(resp.DataSet) < 1 { - return nil, newNotFoundError("security group", sgId) + return nil, NewNotFoundError("security group", sgId) } return &resp.DataSet[0], nil } -func (c *UCloudClient) describeSubnetById(subnetId string) (*vpc.VPCSubnetInfoSet, error) { +func (c *UCloudClient) DescribeSubnetById(subnetId string) (*vpc.VPCSubnetInfoSet, error) { if subnetId == "" { - return nil, newNotFoundError("Subnet", subnetId) + return nil, NewNotFoundError("Subnet", subnetId) } - conn := c.vpcconn + conn := c.VPCConn req := conn.NewDescribeSubnetRequest() req.SubnetIds = []string{subnetId} @@ -56,17 +58,17 @@ func (c *UCloudClient) describeSubnetById(subnetId string) (*vpc.VPCSubnetInfoSe } if resp == nil || len(resp.DataSet) < 1 { - return nil, newNotFoundError("Subnet", subnetId) + return nil, NewNotFoundError("Subnet", subnetId) } return &resp.DataSet[0], nil } -func (c *UCloudClient) describeVPCById(vpcId string) (*vpc.VPCInfo, error) { +func (c *UCloudClient) DescribeVPCById(vpcId string) (*vpc.VPCInfo, error) { if vpcId == "" { - return nil, newNotFoundError("VPC", vpcId) + return nil, NewNotFoundError("VPC", vpcId) } - conn := c.vpcconn + conn := c.VPCConn req := conn.NewDescribeVPCRequest() req.VPCIds = []string{vpcId} @@ -77,7 +79,7 @@ func (c *UCloudClient) describeVPCById(vpcId string) (*vpc.VPCInfo, error) { } if resp == nil || len(resp.DataSet) < 1 { - return nil, newNotFoundError("VPC", vpcId) + return nil, NewNotFoundError("VPC", vpcId) } return &resp.DataSet[0], nil @@ -85,31 +87,31 @@ func (c *UCloudClient) describeVPCById(vpcId string) (*vpc.VPCInfo, error) { func (c *UCloudClient) DescribeImageById(imageId string) (*uhost.UHostImageSet, error) { if imageId == "" { - return nil, newNotFoundError("image", imageId) + return nil, NewNotFoundError("image", imageId) } - req := c.uhostconn.NewDescribeImageRequest() + req := c.UHostConn.NewDescribeImageRequest() req.ImageId = ucloud.String(imageId) - resp, err := c.uhostconn.DescribeImage(req) + resp, err := c.UHostConn.DescribeImage(req) if err != nil { return nil, err } if len(resp.ImageSet) < 1 { - return nil, newNotFoundError("image", imageId) + return nil, NewNotFoundError("image", imageId) } return &resp.ImageSet[0], nil } -func (c *UCloudClient) describeUHostById(uhostId string) (*uhost.UHostInstanceSet, error) { +func (c *UCloudClient) DescribeUHostById(uhostId string) (*uhost.UHostInstanceSet, error) { if uhostId == "" { - return nil, newNotFoundError("instance", uhostId) + return nil, NewNotFoundError("instance", uhostId) } - req := c.uhostconn.NewDescribeUHostInstanceRequest() + req := c.UHostConn.NewDescribeUHostInstanceRequest() req.UHostIds = []string{uhostId} - resp, err := c.uhostconn.DescribeUHostInstance(req) + resp, err := c.UHostConn.DescribeUHostInstance(req) if err != nil { return nil, err } @@ -120,19 +122,19 @@ func (c *UCloudClient) describeUHostById(uhostId string) (*uhost.UHostInstanceSe return &resp.UHostSet[0], nil } -func (c *UCloudClient) describeImageByInfo(projectId, regionId, imageId string) (*uhost.UHostImageSet, error) { - req := c.uhostconn.NewDescribeImageRequest() +func (c *UCloudClient) DescribeImageByInfo(projectId, regionId, imageId string) (*uhost.UHostImageSet, error) { + req := c.UHostConn.NewDescribeImageRequest() req.ProjectId = ucloud.String(projectId) req.ImageId = ucloud.String(imageId) req.Region = ucloud.String(regionId) - resp, err := c.uhostconn.DescribeImage(req) + resp, err := c.UHostConn.DescribeImage(req) if err != nil { return nil, err } if len(resp.ImageSet) < 1 { - return nil, newNotFoundError("image", imageId) + return nil, NewNotFoundError("image", imageId) } return &resp.ImageSet[0], nil diff --git a/builder/ucloud/common/consts.go b/builder/ucloud/common/consts.go new file mode 100644 index 000000000..06d8becda --- /dev/null +++ b/builder/ucloud/common/consts.go @@ -0,0 +1,25 @@ +package common + +const ( + // DefaultPasswordStr, DefaultPasswordNum and DefaultPasswordSpe are used to general default value of root password of UHost instance + DefaultPasswordNum = "012346789" + DefaultPasswordStr = "abcdefghijklmnopqrstuvwxyz" + DefaultPasswordSpe = "-_" +) + +const ( + OsTypeWindows = "Windows" + SecurityGroupNonWeb = "recommend non web" + InstanceStateRunning = "Running" + InstanceStateStopped = "Stopped" + BootDiskStateNormal = "Normal" + ImageStateAvailable = "Available" + ImageStateUnavailable = "Unavailable" + IpTypePrivate = "Private" +) + +var BootDiskTypeMap = NewStringConverter(map[string]string{ + "cloud_ssd": "CLOUD_SSD", + "local_normal": "LOCAL_NORMAL", + "local_ssd": "LOCAL_SSD", +}) diff --git a/builder/ucloud/uhost/errors.go b/builder/ucloud/common/errors.go similarity index 73% rename from builder/ucloud/uhost/errors.go rename to builder/ucloud/common/errors.go index 2f5d85192..0ed7efcf6 100644 --- a/builder/ucloud/uhost/errors.go +++ b/builder/ucloud/common/errors.go @@ -1,4 +1,4 @@ -package uhost +package common import ( "fmt" @@ -28,33 +28,33 @@ func (e *NotCompleteError) Error() string { return e.message } -func newNotFoundError(product, id string) error { +func NewNotFoundError(product, id string) error { return &NotFoundError{fmt.Sprintf("the %s %s is not found", product, id)} } -func newExpectedStateError(product, id string) error { +func NewExpectedStateError(product, id string) error { return &ExpectedStateError{fmt.Sprintf("the %s %s not be expected state", product, id)} } -func newNotCompleteError(product string) error { +func NewNotCompleteError(product string) error { return &NotCompleteError{fmt.Sprintf("%s is not completed", product)} } -func isNotFoundError(err error) bool { +func IsNotFoundError(err error) bool { if _, ok := err.(*NotFoundError); ok { return true } return false } -func isExpectedStateError(err error) bool { +func IsExpectedStateError(err error) bool { if _, ok := err.(*ExpectedStateError); ok { return true } return false } -func isNotCompleteError(err error) bool { +func IsNotCompleteError(err error) bool { if _, ok := err.(*NotCompleteError); ok { return true } diff --git a/builder/ucloud/uhost/image_config.go b/builder/ucloud/common/image_config.go similarity index 99% rename from builder/ucloud/uhost/image_config.go rename to builder/ucloud/common/image_config.go index 7a9ada8ce..79f105917 100644 --- a/builder/ucloud/uhost/image_config.go +++ b/builder/ucloud/common/image_config.go @@ -1,6 +1,6 @@ //go:generate mapstructure-to-hcl2 -type ImageDestination -package uhost +package common import ( "fmt" diff --git a/builder/ucloud/uhost/image_config_test.go b/builder/ucloud/common/image_config_test.go similarity index 98% rename from builder/ucloud/uhost/image_config_test.go rename to builder/ucloud/common/image_config_test.go index 9388bb80d..4fcf9cccb 100644 --- a/builder/ucloud/uhost/image_config_test.go +++ b/builder/ucloud/common/image_config_test.go @@ -1,4 +1,4 @@ -package uhost +package common import ( "testing" diff --git a/builder/ucloud/uhost/run_config.go b/builder/ucloud/common/run_config.go similarity index 96% rename from builder/ucloud/uhost/run_config.go rename to builder/ucloud/common/run_config.go index 6464e2ea8..89959147b 100644 --- a/builder/ucloud/uhost/run_config.go +++ b/builder/ucloud/common/run_config.go @@ -1,4 +1,4 @@ -package uhost +package common import ( "fmt" @@ -39,7 +39,7 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error { if c.InstanceType == "" { errs = append(errs, fmt.Errorf("%q must be set", "instance_type")) - } else if _, err := parseInstanceType(c.InstanceType); err != nil { + } else if _, err := ParseInstanceType(c.InstanceType); err != nil { errs = append(errs, err) } @@ -49,7 +49,7 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error { if c.BootDiskType == "" { c.BootDiskType = "cloud_ssd" - } else if err := checkStringIn(c.BootDiskType, + } else if err := CheckStringIn(c.BootDiskType, []string{"local_normal", "local_ssd", "cloud_ssd"}); err != nil { errs = append(errs, err) } diff --git a/builder/ucloud/uhost/run_config_test.go b/builder/ucloud/common/run_config_test.go similarity index 98% rename from builder/ucloud/uhost/run_config_test.go rename to builder/ucloud/common/run_config_test.go index ff156905d..4aaebef14 100644 --- a/builder/ucloud/uhost/run_config_test.go +++ b/builder/ucloud/common/run_config_test.go @@ -1,4 +1,4 @@ -package uhost +package common import ( "testing" diff --git a/builder/ucloud/common/type_converter.go b/builder/ucloud/common/type_converter.go new file mode 100644 index 000000000..2a84940e9 --- /dev/null +++ b/builder/ucloud/common/type_converter.go @@ -0,0 +1,31 @@ +package common + +type stringConverter struct { + c map[string]string + r map[string]string +} + +func NewStringConverter(input map[string]string) stringConverter { + reversed := make(map[string]string) + for k, v := range input { + reversed[v] = k + } + return stringConverter{ + c: input, + r: reversed, + } +} + +func (c stringConverter) Convert(src string) string { + if dst, ok := c.c[src]; ok { + return dst + } + return src +} + +func (c stringConverter) UnConvert(dst string) string { + if src, ok := c.r[dst]; ok { + return src + } + return dst +} diff --git a/builder/ucloud/uhost/types.go b/builder/ucloud/common/types.go similarity index 81% rename from builder/ucloud/uhost/types.go rename to builder/ucloud/common/types.go index 9695450fb..14e883620 100644 --- a/builder/ucloud/uhost/types.go +++ b/builder/ucloud/common/types.go @@ -1,4 +1,4 @@ -package uhost +package common import ( "fmt" @@ -7,14 +7,14 @@ import ( "sync" ) -type instanceType struct { +type InstanceType struct { CPU int Memory int HostType string HostScaleType string } -func parseInstanceType(s string) (*instanceType, error) { +func ParseInstanceType(s string) (*InstanceType, error) { split := strings.Split(s, "-") if len(split) < 3 { return nil, fmt.Errorf("instance type is invalid, got %q", s) @@ -26,7 +26,7 @@ func parseInstanceType(s string) (*instanceType, error) { return parseInstanceTypeByNormal(split...) } -func (i *instanceType) String() string { +func (i *InstanceType) String() string { if i.Iscustomized() { return fmt.Sprintf("%s-%s-%v-%v", i.HostType, i.HostScaleType, i.CPU, i.Memory) } else { @@ -34,7 +34,7 @@ func (i *instanceType) String() string { } } -func (i *instanceType) Iscustomized() bool { +func (i *InstanceType) Iscustomized() bool { return i.HostScaleType == "customized" } @@ -47,13 +47,13 @@ var instanceTypeScaleMap = map[string]int{ var availableHostTypes = []string{"n"} -func parseInstanceTypeByCustomize(splited ...string) (*instanceType, error) { +func parseInstanceTypeByCustomize(splited ...string) (*InstanceType, error) { if len(splited) != 4 { return nil, fmt.Errorf("instance type is invalid, expected like n-customize-1-2") } hostType := splited[0] - err := checkStringIn(hostType, availableHostTypes) + err := CheckStringIn(hostType, availableHostTypes) if err != nil { return nil, err } @@ -95,7 +95,7 @@ func parseInstanceTypeByCustomize(splited ...string) (*instanceType, error) { return nil, fmt.Errorf("expected the number of memory must be divisible by 2 without a remainder (except single memory), got %d", memory) } - t := &instanceType{} + t := &InstanceType{} t.HostType = hostType t.HostScaleType = hostScaleType t.CPU = cpu @@ -105,13 +105,13 @@ func parseInstanceTypeByCustomize(splited ...string) (*instanceType, error) { var availableOutstandingCpu = []int{4, 8, 16, 32, 64} -func parseInstanceTypeByNormal(split ...string) (*instanceType, error) { +func parseInstanceTypeByNormal(split ...string) (*InstanceType, error) { if len(split) != 3 { return nil, fmt.Errorf("instance type is invalid, expected like n-standard-1") } hostType := split[0] - err := checkStringIn(hostType, []string{"n", "o"}) + err := CheckStringIn(hostType, []string{"n", "o"}) if err != nil { return nil, err } @@ -131,7 +131,7 @@ func parseInstanceTypeByNormal(split ...string) (*instanceType, error) { } if hostType == "o" { - if err := checkIntIn(cpu, availableOutstandingCpu); err != nil { + if err := CheckIntIn(cpu, availableOutstandingCpu); err != nil { return nil, fmt.Errorf("expected cpu of outstanding instancetype %q", err) } @@ -150,7 +150,7 @@ func parseInstanceTypeByNormal(split ...string) (*instanceType, error) { memory := cpu * scale - t := &instanceType{} + t := &InstanceType{} t.HostType = hostType t.HostScaleType = hostScaleType t.CPU = cpu @@ -159,46 +159,46 @@ func parseInstanceTypeByNormal(split ...string) (*instanceType, error) { } } -type imageInfo struct { +type ImageInfo struct { ImageId string ProjectId string Region string } -func (i *imageInfo) Id() string { +func (i *ImageInfo) Id() string { return fmt.Sprintf("%s:%s", i.ProjectId, i.Region) } -type imageInfoSet struct { - m map[string]imageInfo +type ImageInfoSet struct { + m map[string]ImageInfo once sync.Once } -func newImageInfoSet(vL []imageInfo) *imageInfoSet { - s := imageInfoSet{} +func NewImageInfoSet(vL []ImageInfo) *ImageInfoSet { + s := ImageInfoSet{} for _, v := range vL { s.Set(v) } return &s } -func (i *imageInfoSet) init() { - i.m = make(map[string]imageInfo) +func (i *ImageInfoSet) init() { + i.m = make(map[string]ImageInfo) } -func (i *imageInfoSet) Set(img imageInfo) { +func (i *ImageInfoSet) Set(img ImageInfo) { i.once.Do(i.init) i.m[img.Id()] = img } -func (i *imageInfoSet) Remove(id string) { +func (i *ImageInfoSet) Remove(id string) { i.once.Do(i.init) delete(i.m, id) } -func (i *imageInfoSet) Get(projectId, region string) *imageInfo { +func (i *ImageInfoSet) Get(projectId, region string) *ImageInfo { k := fmt.Sprintf("%s:%s", projectId, region) if v, ok := i.m[k]; ok { return &v @@ -206,8 +206,8 @@ func (i *imageInfoSet) Get(projectId, region string) *imageInfo { return nil } -func (i *imageInfoSet) GetAll() []imageInfo { - var vL []imageInfo +func (i *ImageInfoSet) GetAll() []ImageInfo { + var vL []ImageInfo for _, img := range i.m { vL = append(vL, img) } diff --git a/builder/ucloud/uhost/types_test.go b/builder/ucloud/common/types_test.go similarity index 69% rename from builder/ucloud/uhost/types_test.go rename to builder/ucloud/common/types_test.go index 1509855ca..2766149eb 100644 --- a/builder/ucloud/uhost/types_test.go +++ b/builder/ucloud/common/types_test.go @@ -1,4 +1,4 @@ -package uhost +package common import ( "testing" @@ -12,14 +12,14 @@ func Test_parseInstanceType(t *testing.T) { tests := []struct { name string args args - want *instanceType + want *InstanceType wantErr bool }{ - {"ok_highcpu", args{"n-highcpu-1"}, &instanceType{1, 1024, "n", "highcpu"}, false}, - {"ok_basic", args{"n-basic-1"}, &instanceType{1, 2048, "n", "basic"}, false}, - {"ok_standard", args{"n-standard-1"}, &instanceType{1, 4096, "n", "standard"}, false}, - {"ok_highmem", args{"n-highmem-1"}, &instanceType{1, 8192, "n", "highmem"}, false}, - {"ok_customized", args{"n-customized-1-12"}, &instanceType{1, 12288, "n", "customized"}, false}, + {"ok_highcpu", args{"n-highcpu-1"}, &InstanceType{1, 1024, "n", "highcpu"}, false}, + {"ok_basic", args{"n-basic-1"}, &InstanceType{1, 2048, "n", "basic"}, false}, + {"ok_standard", args{"n-standard-1"}, &InstanceType{1, 4096, "n", "standard"}, false}, + {"ok_highmem", args{"n-highmem-1"}, &InstanceType{1, 8192, "n", "highmem"}, false}, + {"ok_customized", args{"n-customized-1-12"}, &InstanceType{1, 12288, "n", "customized"}, false}, {"err_customized", args{"n-customized-1-5"}, nil, true}, {"err_type", args{"nx-highcpu-1"}, nil, true}, @@ -33,9 +33,9 @@ func Test_parseInstanceType(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := parseInstanceType(tt.args.s) + got, err := ParseInstanceType(tt.args.s) if (err != nil) != tt.wantErr { - t.Errorf("parseInstanceType() arg %s got %#v error = %v, wantErr %v", tt.args.s, got, err, tt.wantErr) + t.Errorf("ParseInstanceType() arg %s got %#v error = %v, wantErr %v", tt.args.s, got, err, tt.wantErr) return } @@ -47,7 +47,7 @@ func Test_parseInstanceType(t *testing.T) { !(tt.want.Memory == got.Memory) || !(tt.want.HostType == got.HostType) || !(tt.want.HostScaleType == got.HostScaleType) { - t.Errorf("parseInstanceType() = %v, want %v", got, tt.want) + t.Errorf("ParseInstanceType() = %v, want %v", got, tt.want) } }) } diff --git a/builder/ucloud/uhost/utils.go b/builder/ucloud/common/utils.go similarity index 82% rename from builder/ucloud/uhost/utils.go rename to builder/ucloud/common/utils.go index b05216bc3..1f58444d5 100644 --- a/builder/ucloud/uhost/utils.go +++ b/builder/ucloud/common/utils.go @@ -1,4 +1,4 @@ -package uhost +package common import ( "fmt" @@ -8,7 +8,7 @@ import ( "strings" ) -func checkStringIn(val string, available []string) error { +func CheckStringIn(val string, available []string) error { for _, choice := range available { if val == choice { return nil @@ -18,7 +18,7 @@ func checkStringIn(val string, available []string) error { return fmt.Errorf("should be one of %q, got %q", strings.Join(available, ","), val) } -func checkIntIn(val int, available []int) error { +func CheckIntIn(val int, available []int) error { for _, choice := range available { if val == choice { return nil @@ -28,7 +28,7 @@ func checkIntIn(val int, available []int) error { return fmt.Errorf("should be one of %v, got %d", available, val) } -func isStringIn(val string, available []string) bool { +func IsStringIn(val string, available []string) bool { for _, choice := range available { if val == choice { return true @@ -46,7 +46,7 @@ func SSHHost(usePrivateIp bool) func(multistep.StateBag) (string, error) { var privateIp, publicIp string for _, v := range instance.IPSet { - if v.Type == ipTypePrivate { + if v.Type == IpTypePrivate { privateIp = v.IP } else { publicIp = v.IP @@ -61,7 +61,7 @@ func SSHHost(usePrivateIp bool) func(multistep.StateBag) (string, error) { } } -func halt(state multistep.StateBag, err error, prefix string) multistep.StepAction { +func Halt(state multistep.StateBag, err error, prefix string) multistep.StepAction { ui := state.Get("ui").(packer.Ui) if prefix != "" { diff --git a/builder/ucloud/uhost/builder.go b/builder/ucloud/uhost/builder.go index 1c606494f..64a80500e 100644 --- a/builder/ucloud/uhost/builder.go +++ b/builder/ucloud/uhost/builder.go @@ -7,6 +7,7 @@ package uhost import ( "context" + ucloudcommon "github.com/hashicorp/packer/builder/ucloud/common" "github.com/hashicorp/packer/common" "github.com/hashicorp/packer/helper/communicator" "github.com/hashicorp/packer/helper/config" @@ -19,10 +20,10 @@ import ( const BuilderId = "ucloud.uhost" type Config struct { - common.PackerConfig `mapstructure:",squash"` - AccessConfig `mapstructure:",squash"` - ImageConfig `mapstructure:",squash"` - RunConfig `mapstructure:",squash"` + common.PackerConfig `mapstructure:",squash"` + ucloudcommon.AccessConfig `mapstructure:",squash"` + ucloudcommon.ImageConfig `mapstructure:",squash"` + ucloudcommon.RunConfig `mapstructure:",squash"` ctx interpolate.Context } @@ -111,7 +112,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack }, &communicator.StepConnect{ Config: &b.config.RunConfig.Comm, - Host: SSHHost( + Host: ucloudcommon.SSHHost( b.config.UseSSHPrivateIp), SSHConfig: b.config.RunConfig.Comm.SSHConfigFunc(), }, @@ -140,8 +141,8 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack } // Build the artifact and return it - artifact := &Artifact{ - UCloudImages: state.Get("ucloud_images").(*imageInfoSet), + artifact := &ucloudcommon.Artifact{ + UCloudImages: state.Get("ucloud_images").(*ucloudcommon.ImageInfoSet), BuilderIdValue: BuilderId, Client: client, } diff --git a/builder/ucloud/uhost/builder_acc_test.go b/builder/ucloud/uhost/builder_acc_test.go index e7f4ad3ce..f4a9f04dc 100644 --- a/builder/ucloud/uhost/builder_acc_test.go +++ b/builder/ucloud/uhost/builder_acc_test.go @@ -2,6 +2,7 @@ package uhost import ( "fmt" + ucloudcommon "github.com/hashicorp/packer/builder/ucloud/common" "github.com/hashicorp/packer/packer" "github.com/stretchr/testify/assert" "os" @@ -20,7 +21,7 @@ func TestBuilderAcc_validateRegion(t *testing.T) { testAccPreCheck(t) - access := &AccessConfig{Region: "cn-bj2"} + access := &ucloudcommon.AccessConfig{Region: "cn-bj2"} err := access.Config() if err != nil { t.Fatalf("Error on initing UCloud AccessConfig, %s", err) @@ -94,8 +95,8 @@ func TestBuilderAcc_regionCopy(t *testing.T) { Template: testBuilderAccRegionCopy(projectId), Check: checkRegionCopy( projectId, - []ImageDestination{ - {projectId, "cn-sh2", "packer-test-regionCopy-sh", "test"}, + []ucloudcommon.ImageDestination{ + {ProjectId: projectId, Region: "cn-sh2", Name: "packer-test-regionCopy-sh", Description: "test"}, }), }) } @@ -121,21 +122,21 @@ func testBuilderAccRegionCopy(projectId string) string { }`, projectId) } -func checkRegionCopy(projectId string, imageDst []ImageDestination) builderT.TestCheckFunc { +func checkRegionCopy(projectId string, imageDst []ucloudcommon.ImageDestination) builderT.TestCheckFunc { return func(artifacts []packer.Artifact) error { if len(artifacts) > 1 { return fmt.Errorf("more than 1 artifact") } artifactSet := artifacts[0] - artifact, ok := artifactSet.(*Artifact) + artifact, ok := artifactSet.(*ucloudcommon.Artifact) if !ok { return fmt.Errorf("unknown artifact: %#v", artifactSet) } - destSet := newImageInfoSet(nil) + destSet := ucloudcommon.NewImageInfoSet(nil) for _, dest := range imageDst { - destSet.Set(imageInfo{ + destSet.Set(ucloudcommon.ImageInfo{ Region: dest.Region, ProjectId: dest.ProjectId, }) @@ -163,9 +164,9 @@ func checkRegionCopy(projectId string, imageDst []ImageDestination) builderT.Tes if r.ProjectId == projectId && r.Region == "cn-bj2" { continue } - imageSet, err := client.describeImageByInfo(r.ProjectId, r.Region, r.ImageId) + imageSet, err := client.DescribeImageByInfo(r.ProjectId, r.Region, r.ImageId) if err != nil { - if isNotFoundError(err) { + if ucloudcommon.IsNotFoundError(err) { return fmt.Errorf("image %s in artifacts can not be found", r.ImageId) } return err @@ -205,8 +206,8 @@ func TestUCloudClientBaseUrlConfigurable(t *testing.T) { assert.Equal(t, url, client.vpcconn.Client.GetConfig().BaseUrl, "vpc conn's base url not configurable") } -func testUCloudClient() (*UCloudClient, error) { - access := &AccessConfig{Region: "cn-bj2"} +func testUCloudClient() (*ucloudcommon.UCloudClient, error) { + access := &ucloudcommon.AccessConfig{Region: "cn-bj2"} err := access.Config() if err != nil { return nil, err diff --git a/builder/ucloud/uhost/builder_test.go b/builder/ucloud/uhost/builder_test.go index 250444fb5..dca944bc5 100644 --- a/builder/ucloud/uhost/builder_test.go +++ b/builder/ucloud/uhost/builder_test.go @@ -1,6 +1,7 @@ package uhost import ( + ucloudcommon "github.com/hashicorp/packer/builder/ucloud/common" "github.com/hashicorp/packer/packer" "reflect" "testing" @@ -120,7 +121,7 @@ func TestBuilderPrepare_ImageDestinations(t *testing.T) { t.Fatalf("should not have error: %s", err) } - if !reflect.DeepEqual(b.config.ImageDestinations, []ImageDestination{ + if !reflect.DeepEqual(b.config.ImageDestinations, []ucloudcommon.ImageDestination{ { ProjectId: "project1", Region: "region1", diff --git a/builder/ucloud/uhost/consts.go b/builder/ucloud/uhost/consts.go deleted file mode 100644 index a275c4230..000000000 --- a/builder/ucloud/uhost/consts.go +++ /dev/null @@ -1,24 +0,0 @@ -package uhost - -const ( - // defaultPasswordStr, defaultPasswordNum and defaultPasswordSpe are used to general default value of root password of UHost instance - defaultPasswordNum = "012346789" - defaultPasswordStr = "abcdefghijklmnopqrstuvwxyz" - defaultPasswordSpe = "-_" -) - -const ( - osTypeWindows = "Windows" - securityGroupNonWeb = "recommend non web" - instanceStateRunning = "Running" - instanceStateStopped = "Stopped" - bootDiskStateNormal = "Normal" - imageStateAvailable = "Available" - ipTypePrivate = "Private" -) - -var bootDiskTypeMap = map[string]string{ - "cloud_ssd": "CLOUD_SSD", - "local_normal": "LOCAL_NORMAL", - "local_ssd": "LOCAL_SSD", -} diff --git a/builder/ucloud/uhost/step_check_source_image.go b/builder/ucloud/uhost/step_check_source_image.go index b8a570610..fd77d7eee 100644 --- a/builder/ucloud/uhost/step_check_source_image.go +++ b/builder/ucloud/uhost/step_check_source_image.go @@ -3,6 +3,7 @@ package uhost import ( "context" "fmt" + ucloudcommon "github.com/hashicorp/packer/builder/ucloud/common" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" ) @@ -13,20 +14,20 @@ type stepCheckSourceImageId struct { func (s *stepCheckSourceImageId) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { ui := state.Get("ui").(packer.Ui) - client := state.Get("client").(*UCloudClient) + client := state.Get("client").(*ucloudcommon.UCloudClient) ui.Say("Querying source image id...") imageSet, err := client.DescribeImageById(s.SourceUHostImageId) if err != nil { - if isNotFoundError(err) { - return halt(state, err, "") + if ucloudcommon.IsNotFoundError(err) { + return ucloudcommon.Halt(state, err, "") } - return halt(state, err, fmt.Sprintf("Error on querying specified source_image_id %q", s.SourceUHostImageId)) + return ucloudcommon.Halt(state, err, fmt.Sprintf("Error on querying specified source_image_id %q", s.SourceUHostImageId)) } - if imageSet.OsType == osTypeWindows { - return halt(state, err, "The ucloud-uhost builder does not support Windows images yet") + if imageSet.OsType == ucloudcommon.OsTypeWindows { + return ucloudcommon.Halt(state, err, "The ucloud-uhost builder does not support Windows images yet") } state.Put("source_image", imageSet) diff --git a/builder/ucloud/uhost/step_config_security_group.go b/builder/ucloud/uhost/step_config_security_group.go index eee0d0977..66c4cd27c 100644 --- a/builder/ucloud/uhost/step_config_security_group.go +++ b/builder/ucloud/uhost/step_config_security_group.go @@ -3,6 +3,7 @@ package uhost import ( "context" "fmt" + ucloudcommon "github.com/hashicorp/packer/builder/ucloud/common" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" "github.com/ucloud/ucloud-sdk-go/ucloud" @@ -13,19 +14,19 @@ type stepConfigSecurityGroup struct { } func (s *stepConfigSecurityGroup) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { - client := state.Get("client").(*UCloudClient) - conn := client.unetconn + client := state.Get("client").(*ucloudcommon.UCloudClient) + conn := client.UNetConn ui := state.Get("ui").(packer.Ui) if len(s.SecurityGroupId) != 0 { ui.Say(fmt.Sprintf("Trying to use specified security group %q...", s.SecurityGroupId)) - securityGroupSet, err := client.describeFirewallById(s.SecurityGroupId) + securityGroupSet, err := client.DescribeFirewallById(s.SecurityGroupId) if err != nil { - if isNotFoundError(err) { + if ucloudcommon.IsNotFoundError(err) { err = fmt.Errorf("the specified security group %q does not exist", s.SecurityGroupId) - return halt(state, err, "") + return ucloudcommon.Halt(state, err, "") } - return halt(state, err, fmt.Sprintf("Error on querying specified security group %q", s.SecurityGroupId)) + return ucloudcommon.Halt(state, err, fmt.Sprintf("Error on querying specified security group %q", s.SecurityGroupId)) } state.Put("security_group_id", securityGroupSet.FWId) @@ -44,7 +45,7 @@ func (s *stepConfigSecurityGroup) Run(ctx context.Context, state multistep.State resp, err := conn.DescribeFirewall(req) if err != nil { - return halt(state, err, "Error on querying default security group") + return ucloudcommon.Halt(state, err, "Error on querying default security group") } if resp == nil || len(resp.DataSet) < 1 { @@ -52,7 +53,7 @@ func (s *stepConfigSecurityGroup) Run(ctx context.Context, state multistep.State } for _, item := range resp.DataSet { - if item.Type == securityGroupNonWeb { + if item.Type == ucloudcommon.SecurityGroupNonWeb { securityGroupId = item.FWId break } @@ -66,7 +67,7 @@ func (s *stepConfigSecurityGroup) Run(ctx context.Context, state multistep.State } if securityGroupId == "" { - return halt(state, fmt.Errorf("the default security group does not exist"), "") + return ucloudcommon.Halt(state, fmt.Errorf("the default security group does not exist"), "") } state.Put("security_group_id", securityGroupId) diff --git a/builder/ucloud/uhost/step_config_subnet.go b/builder/ucloud/uhost/step_config_subnet.go index 44e22c6db..b6bb4bd53 100644 --- a/builder/ucloud/uhost/step_config_subnet.go +++ b/builder/ucloud/uhost/step_config_subnet.go @@ -3,6 +3,7 @@ package uhost import ( "context" "fmt" + ucloudcommon "github.com/hashicorp/packer/builder/ucloud/common" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" ) @@ -12,18 +13,18 @@ type stepConfigSubnet struct { } func (s *stepConfigSubnet) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { - client := state.Get("client").(*UCloudClient) + client := state.Get("client").(*ucloudcommon.UCloudClient) ui := state.Get("ui").(packer.Ui) if len(s.SubnetId) != 0 { ui.Say(fmt.Sprintf("Trying to use specified subnet %q...", s.SubnetId)) - subnetSet, err := client.describeSubnetById(s.SubnetId) + subnetSet, err := client.DescribeSubnetById(s.SubnetId) if err != nil { - if isNotFoundError(err) { + if ucloudcommon.IsNotFoundError(err) { err = fmt.Errorf("the specified subnet %q does not exist", s.SubnetId) - return halt(state, err, "") + return ucloudcommon.Halt(state, err, "") } - return halt(state, err, fmt.Sprintf("Error on querying specified subnet %q", s.SubnetId)) + return ucloudcommon.Halt(state, err, fmt.Sprintf("Error on querying specified subnet %q", s.SubnetId)) } state.Put("subnet_id", subnetSet.SubnetId) diff --git a/builder/ucloud/uhost/step_config_vpc.go b/builder/ucloud/uhost/step_config_vpc.go index 3378071f4..e8e2bcec4 100644 --- a/builder/ucloud/uhost/step_config_vpc.go +++ b/builder/ucloud/uhost/step_config_vpc.go @@ -3,6 +3,7 @@ package uhost import ( "context" "fmt" + ucloudcommon "github.com/hashicorp/packer/builder/ucloud/common" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" @@ -13,19 +14,19 @@ type stepConfigVPC struct { } func (s *stepConfigVPC) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { - client := state.Get("client").(*UCloudClient) + client := state.Get("client").(*ucloudcommon.UCloudClient) ui := state.Get("ui").(packer.Ui) if len(s.VPCId) != 0 { ui.Say(fmt.Sprintf("Trying to use specified vpc %q...", s.VPCId)) - vpcSet, err := client.describeVPCById(s.VPCId) + vpcSet, err := client.DescribeVPCById(s.VPCId) if err != nil { - if isNotFoundError(err) { + if ucloudcommon.IsNotFoundError(err) { err = fmt.Errorf("the specified vpc %q does not exist", s.VPCId) - return halt(state, err, "") + return ucloudcommon.Halt(state, err, "") } - return halt(state, err, fmt.Sprintf("Error on querying specified vpc %q", s.VPCId)) + return ucloudcommon.Halt(state, err, fmt.Sprintf("Error on querying specified vpc %q", s.VPCId)) } state.Put("vpc_id", vpcSet.VPCId) diff --git a/builder/ucloud/uhost/step_copy_image.go b/builder/ucloud/uhost/step_copy_image.go index dab78bbd7..a24c520f5 100644 --- a/builder/ucloud/uhost/step_copy_image.go +++ b/builder/ucloud/uhost/step_copy_image.go @@ -3,6 +3,7 @@ package uhost import ( "context" "fmt" + ucloudcommon "github.com/hashicorp/packer/builder/ucloud/common" "github.com/hashicorp/packer/common/retry" "strings" "time" @@ -13,7 +14,7 @@ import ( ) type stepCopyUCloudImage struct { - ImageDestinations []ImageDestination + ImageDestinations []ucloudcommon.ImageDestination RegionId string ProjectId string } @@ -23,13 +24,13 @@ func (s *stepCopyUCloudImage) Run(ctx context.Context, state multistep.StateBag) return multistep.ActionContinue } - client := state.Get("client").(*UCloudClient) - conn := client.uhostconn + client := state.Get("client").(*ucloudcommon.UCloudClient) + conn := client.UHostConn ui := state.Get("ui").(packer.Ui) srcImageId := state.Get("image_id").(string) - artifactImages := state.Get("ucloud_images").(*imageInfoSet) - expectedImages := newImageInfoSet(nil) + artifactImages := state.Get("ucloud_images").(*ucloudcommon.ImageInfoSet) + expectedImages := ucloudcommon.NewImageInfoSet(nil) ui.Say(fmt.Sprintf("Copying images from %q...", srcImageId)) for _, v := range s.ImageDestinations { if v.ProjectId == s.ProjectId && v.Region == s.RegionId { @@ -45,10 +46,10 @@ func (s *stepCopyUCloudImage) Run(ctx context.Context, state multistep.StateBag) resp, err := conn.CopyCustomImage(req) if err != nil { - return halt(state, err, fmt.Sprintf("Error on copying image %q to %s:%s", srcImageId, v.ProjectId, v.Region)) + return ucloudcommon.Halt(state, err, fmt.Sprintf("Error on copying image %q to %s:%s", srcImageId, v.ProjectId, v.Region)) } - image := imageInfo{ + image := ucloudcommon.ImageInfo{ Region: v.Region, ProjectId: v.ProjectId, ImageId: resp.TargetImageId, @@ -63,23 +64,23 @@ func (s *stepCopyUCloudImage) Run(ctx context.Context, state multistep.StateBag) err := retry.Config{ Tries: 200, - ShouldRetry: func(err error) bool { return isNotCompleteError(err) }, + ShouldRetry: func(err error) bool { return ucloudcommon.IsNotCompleteError(err) }, RetryDelay: (&retry.Backoff{InitialBackoff: 2 * time.Second, MaxBackoff: 12 * time.Second, Multiplier: 2}).Linear, }.Run(ctx, func(ctx context.Context) error { for _, v := range expectedImages.GetAll() { - imageSet, err := client.describeImageByInfo(v.ProjectId, v.Region, v.ImageId) + imageSet, err := client.DescribeImageByInfo(v.ProjectId, v.Region, v.ImageId) if err != nil { return fmt.Errorf("reading %s:%s:%s failed, %s", v.ProjectId, v.Region, v.ImageId, err) } - if imageSet.State == imageStateAvailable { + if imageSet.State == ucloudcommon.ImageStateAvailable { expectedImages.Remove(v.Id()) continue } } if len(expectedImages.GetAll()) != 0 { - return newNotCompleteError("copying image") + return ucloudcommon.NewNotCompleteError("copying image") } return nil @@ -91,7 +92,7 @@ func (s *stepCopyUCloudImage) Run(ctx context.Context, state multistep.StateBag) s = append(s, fmt.Sprintf("%s:%s:%s", v.ProjectId, v.Region, v.ImageId)) } - return halt(state, err, fmt.Sprintf("Error on waiting for copying images %q to become available", strings.Join(s, ","))) + return ucloudcommon.Halt(state, err, fmt.Sprintf("Error on waiting for copying images %q to become available", strings.Join(s, ","))) } ui.Message(fmt.Sprintf("Copying image complete")) @@ -107,7 +108,7 @@ func (s *stepCopyUCloudImage) Cleanup(state multistep.StateBag) { } srcImageId := state.Get("image_id").(string) - ucloudImages := state.Get("ucloud_images").(*imageInfoSet) + ucloudImages := state.Get("ucloud_images").(*ucloudcommon.ImageInfoSet) imageInfos := ucloudImages.GetAll() if len(imageInfos) == 0 { return @@ -116,8 +117,8 @@ func (s *stepCopyUCloudImage) Cleanup(state multistep.StateBag) { } ui := state.Get("ui").(packer.Ui) - client := state.Get("client").(*UCloudClient) - conn := client.uhostconn + client := state.Get("client").(*ucloudcommon.UCloudClient) + conn := client.UHostConn ui.Say(fmt.Sprintf("Deleting copied image because of cancellation or error...")) for _, v := range imageInfos { diff --git a/builder/ucloud/uhost/step_create_image.go b/builder/ucloud/uhost/step_create_image.go index 6389b4b22..80d13c978 100644 --- a/builder/ucloud/uhost/step_create_image.go +++ b/builder/ucloud/uhost/step_create_image.go @@ -3,6 +3,7 @@ package uhost import ( "context" "fmt" + ucloudcommon "github.com/hashicorp/packer/builder/ucloud/common" "github.com/hashicorp/packer/common/retry" "time" @@ -17,8 +18,8 @@ type stepCreateImage struct { } func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { - client := state.Get("client").(*UCloudClient) - conn := client.uhostconn + client := state.Get("client").(*ucloudcommon.UCloudClient) + conn := client.UHostConn instance := state.Get("instance").(*uhost.UHostInstanceSet) ui := state.Get("ui").(packer.Ui) config := state.Get("config").(*Config) @@ -32,14 +33,14 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul resp, err := conn.CreateCustomImage(req) if err != nil { - return halt(state, err, "Error on creating image") + return ucloudcommon.Halt(state, err, "Error on creating image") } ui.Message(fmt.Sprintf("Waiting for the created image %q to become available...", resp.ImageId)) err = retry.Config{ Tries: 200, ShouldRetry: func(err error) bool { - return isExpectedStateError(err) + return ucloudcommon.IsExpectedStateError(err) }, RetryDelay: (&retry.Backoff{InitialBackoff: 2 * time.Second, MaxBackoff: 12 * time.Second, Multiplier: 2}).Linear, }.Run(ctx, func(ctx context.Context) error { @@ -47,26 +48,26 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul if err != nil { return err } - if inst == nil || inst.State != imageStateAvailable { - return newExpectedStateError("image", resp.ImageId) + if inst == nil || inst.State != ucloudcommon.ImageStateAvailable { + return ucloudcommon.NewExpectedStateError("image", resp.ImageId) } return nil }) if err != nil { - return halt(state, err, fmt.Sprintf("Error on waiting for image %q to become available", resp.ImageId)) + return ucloudcommon.Halt(state, err, fmt.Sprintf("Error on waiting for image %q to become available", resp.ImageId)) } imageSet, err := client.DescribeImageById(resp.ImageId) if err != nil { - return halt(state, err, fmt.Sprintf("Error on reading image when creating %q", resp.ImageId)) + return ucloudcommon.Halt(state, err, fmt.Sprintf("Error on reading image when creating %q", resp.ImageId)) } s.image = imageSet state.Put("image_id", imageSet.ImageId) - images := []imageInfo{ + images := []ucloudcommon.ImageInfo{ { ImageId: imageSet.ImageId, ProjectId: config.ProjectId, @@ -74,7 +75,7 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul }, } - state.Put("ucloud_images", newImageInfoSet(images)) + state.Put("ucloud_images", ucloudcommon.NewImageInfoSet(images)) ui.Message(fmt.Sprintf("Creating image %q complete", imageSet.ImageId)) return multistep.ActionContinue } @@ -89,8 +90,8 @@ func (s *stepCreateImage) Cleanup(state multistep.StateBag) { return } - client := state.Get("client").(*UCloudClient) - conn := client.uhostconn + client := state.Get("client").(*ucloudcommon.UCloudClient) + conn := client.UHostConn ui := state.Get("ui").(packer.Ui) ui.Say("Deleting image because of cancellation or error...") diff --git a/builder/ucloud/uhost/step_create_instance.go b/builder/ucloud/uhost/step_create_instance.go index f5554ee70..331a6931e 100644 --- a/builder/ucloud/uhost/step_create_instance.go +++ b/builder/ucloud/uhost/step_create_instance.go @@ -3,6 +3,7 @@ package uhost import ( "context" "fmt" + ucloudcommon "github.com/hashicorp/packer/builder/ucloud/common" "github.com/hashicorp/packer/common/retry" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" @@ -26,25 +27,25 @@ type stepCreateInstance struct { } func (s *stepCreateInstance) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { - client := state.Get("client").(*UCloudClient) - conn := client.uhostconn + client := state.Get("client").(*ucloudcommon.UCloudClient) + conn := client.UHostConn ui := state.Get("ui").(packer.Ui) ui.Say("Creating Instance...") resp, err := conn.CreateUHostInstance(s.buildCreateInstanceRequest(state)) if err != nil { - return halt(state, err, "Error on creating instance") + return ucloudcommon.Halt(state, err, "Error on creating instance") } instanceId := resp.UHostIds[0] err = retry.Config{ Tries: 20, ShouldRetry: func(err error) bool { - return isExpectedStateError(err) + return ucloudcommon.IsExpectedStateError(err) }, RetryDelay: (&retry.Backoff{InitialBackoff: 2 * time.Second, MaxBackoff: 6 * time.Second, Multiplier: 2}).Linear, }.Run(ctx, func(ctx context.Context) error { - inst, err := client.describeUHostById(instanceId) + inst, err := client.DescribeUHostById(instanceId) if err != nil { return err } @@ -57,27 +58,27 @@ func (s *stepCreateInstance) Run(ctx context.Context, state multistep.StateBag) return fmt.Errorf("install failed") } - if inst == nil || inst.State != instanceStateRunning { - return newExpectedStateError("instance", instanceId) + if inst == nil || inst.State != ucloudcommon.InstanceStateRunning { + return ucloudcommon.NewExpectedStateError("instance", instanceId) } return nil }) if err != nil { - return halt(state, err, fmt.Sprintf("Error on waiting for instance %q to become available", instanceId)) + return ucloudcommon.Halt(state, err, fmt.Sprintf("Error on waiting for instance %q to become available", instanceId)) } ui.Message(fmt.Sprintf("Creating instance %q complete", instanceId)) - instance, err := client.describeUHostById(instanceId) + instance, err := client.DescribeUHostById(instanceId) if err != nil { - return halt(state, err, fmt.Sprintf("Error on reading instance when creating %q", instanceId)) + return ucloudcommon.Halt(state, err, fmt.Sprintf("Error on reading instance when creating %q", instanceId)) } s.instanceId = instanceId state.Put("instance", instance) - if instance.BootDiskState != bootDiskStateNormal { + if instance.BootDiskState != ucloudcommon.BootDiskStateNormal { ui.Say("Waiting for boot disk of instance initialized") if s.BootDiskType == "local_normal" || s.BootDiskType == "local_ssd" { ui.Message(fmt.Sprintf("Warning: It takes around 10 mins for boot disk initialization when `boot_disk_type` is %q", s.BootDiskType)) @@ -86,23 +87,23 @@ func (s *stepCreateInstance) Run(ctx context.Context, state multistep.StateBag) err = retry.Config{ Tries: 200, ShouldRetry: func(err error) bool { - return isExpectedStateError(err) + return ucloudcommon.IsExpectedStateError(err) }, RetryDelay: (&retry.Backoff{InitialBackoff: 2 * time.Second, MaxBackoff: 12 * time.Second, Multiplier: 2}).Linear, }.Run(ctx, func(ctx context.Context) error { - inst, err := client.describeUHostById(instanceId) + inst, err := client.DescribeUHostById(instanceId) if err != nil { return err } - if inst.BootDiskState != bootDiskStateNormal { - return newExpectedStateError("boot_disk of instance", instanceId) + if inst.BootDiskState != ucloudcommon.BootDiskStateNormal { + return ucloudcommon.NewExpectedStateError("boot_disk of instance", instanceId) } return nil }) if err != nil { - return halt(state, err, fmt.Sprintf("Error on waiting for boot disk of instance %q initialized", instanceId)) + return ucloudcommon.Halt(state, err, fmt.Sprintf("Error on waiting for boot disk of instance %q initialized", instanceId)) } ui.Message(fmt.Sprintf("Waiting for boot disk of instance %q initialized complete", instanceId)) @@ -127,12 +128,12 @@ func (s *stepCreateInstance) Cleanup(state multistep.StateBag) { ui.Say("Deleting instance...") } - client := state.Get("client").(*UCloudClient) - conn := client.uhostconn + client := state.Get("client").(*ucloudcommon.UCloudClient) + conn := client.UHostConn - instance, err := client.describeUHostById(s.instanceId) + instance, err := client.DescribeUHostById(s.instanceId) if err != nil { - if isNotFoundError(err) { + if ucloudcommon.IsNotFoundError(err) { return } ui.Error(fmt.Sprintf("Error on reading instance when deleting %q, %s", @@ -140,7 +141,7 @@ func (s *stepCreateInstance) Cleanup(state multistep.StateBag) { return } - if instance.State != instanceStateStopped { + if instance.State != ucloudcommon.InstanceStateStopped { stopReq := conn.NewStopUHostInstanceRequest() stopReq.UHostId = ucloud.String(s.instanceId) if _, err = conn.StopUHostInstance(stopReq); err != nil { @@ -152,17 +153,17 @@ func (s *stepCreateInstance) Cleanup(state multistep.StateBag) { err = retry.Config{ Tries: 30, ShouldRetry: func(err error) bool { - return isExpectedStateError(err) + return ucloudcommon.IsExpectedStateError(err) }, RetryDelay: (&retry.Backoff{InitialBackoff: 2 * time.Second, MaxBackoff: 6 * time.Second, Multiplier: 2}).Linear, }.Run(ctx, func(ctx context.Context) error { - instance, err := client.describeUHostById(s.instanceId) + instance, err := client.DescribeUHostById(s.instanceId) if err != nil { return err } - if instance.State != instanceStateStopped { - return newExpectedStateError("instance", s.instanceId) + if instance.State != ucloudcommon.InstanceStateStopped { + return ucloudcommon.NewExpectedStateError("instance", s.instanceId) } return nil @@ -188,10 +189,10 @@ func (s *stepCreateInstance) Cleanup(state multistep.StateBag) { err = retry.Config{ Tries: 30, - ShouldRetry: func(err error) bool { return !isNotFoundError(err) }, + ShouldRetry: func(err error) bool { return !ucloudcommon.IsNotFoundError(err) }, RetryDelay: (&retry.Backoff{InitialBackoff: 2 * time.Second, MaxBackoff: 6 * time.Second, Multiplier: 2}).Linear, }.Run(ctx, func(ctx context.Context) error { - _, err := client.describeUHostById(s.instanceId) + _, err := client.DescribeUHostById(s.instanceId) return err }) @@ -205,8 +206,8 @@ func (s *stepCreateInstance) Cleanup(state multistep.StateBag) { } func (s *stepCreateInstance) buildCreateInstanceRequest(state multistep.StateBag) *uhost.CreateUHostInstanceRequest { - client := state.Get("client").(*UCloudClient) - conn := client.uhostconn + client := state.Get("client").(*ucloudcommon.UCloudClient) + conn := client.UHostConn srcImage := state.Get("source_image").(*uhost.UHostImageSet) config := state.Get("config").(*Config) connectConfig := &config.RunConfig.Comm @@ -218,16 +219,16 @@ func (s *stepCreateInstance) buildCreateInstanceRequest(state multistep.StateBag if password == "" { password = fmt.Sprintf("%s%s%s", - s.randStringFromCharSet(5, defaultPasswordStr), - s.randStringFromCharSet(1, defaultPasswordSpe), - s.randStringFromCharSet(5, defaultPasswordNum)) + s.randStringFromCharSet(5, ucloudcommon.DefaultPasswordStr), + s.randStringFromCharSet(1, ucloudcommon.DefaultPasswordSpe), + s.randStringFromCharSet(5, ucloudcommon.DefaultPasswordNum)) if srcImage.OsType == "Linux" { connectConfig.SSHPassword = password } } req := conn.NewCreateUHostInstanceRequest() - t, _ := parseInstanceType(s.InstanceType) + t, _ := ucloudcommon.ParseInstanceType(s.InstanceType) req.CPU = ucloud.Int(t.CPU) req.Memory = ucloud.Int(t.Memory) @@ -238,6 +239,13 @@ func (s *stepCreateInstance) buildCreateInstanceRequest(state multistep.StateBag req.ChargeType = ucloud.String("Dynamic") req.Password = ucloud.String(password) + req.MachineType = ucloud.String("N") + req.MinimalCpuPlatform = ucloud.String("Intel/Auto") + if t.HostType == "o" { + req.MachineType = ucloud.String("O") + req.MinimalCpuPlatform = ucloud.String("Intel/Cascadelake") + } + if v, ok := state.GetOk("security_group_id"); ok { req.SecurityGroupId = ucloud.String(v.(string)) } @@ -253,14 +261,14 @@ func (s *stepCreateInstance) buildCreateInstanceRequest(state multistep.StateBag bootDisk := uhost.UHostDisk{} bootDisk.IsBoot = ucloud.String("true") bootDisk.Size = ucloud.Int(srcImage.ImageSize) - bootDisk.Type = ucloud.String(bootDiskTypeMap[s.BootDiskType]) + bootDisk.Type = ucloud.String(ucloudcommon.BootDiskTypeMap.Convert(s.BootDiskType)) req.Disks = append(req.Disks, bootDisk) if !s.UsePrivateIp { operatorName := ucloud.String("International") if strings.HasPrefix(s.Region, "cn-") { - operatorName = ucloud.String("Bgp") + operatorName = ucloud.String("BGP") } networkInterface := uhost.CreateUHostInstanceParamNetworkInterface{ EIP: &uhost.CreateUHostInstanceParamNetworkInterfaceEIP{ diff --git a/builder/ucloud/uhost/step_pre_validate.go b/builder/ucloud/uhost/step_pre_validate.go index 5c578d08a..843616c10 100644 --- a/builder/ucloud/uhost/step_pre_validate.go +++ b/builder/ucloud/uhost/step_pre_validate.go @@ -2,6 +2,7 @@ package uhost import ( "context" + ucloudcommon "github.com/hashicorp/packer/builder/ucloud/common" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" ) @@ -10,20 +11,20 @@ type stepPreValidate struct { ProjectId string Region string Zone string - ImageDestinations []ImageDestination + ImageDestinations []ucloudcommon.ImageDestination } func (s *stepPreValidate) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { if err := s.validateProjectIds(state); err != nil { - return halt(state, err, "") + return ucloudcommon.Halt(state, err, "") } if err := s.validateRegions(state); err != nil { - return halt(state, err, "") + return ucloudcommon.Halt(state, err, "") } if err := s.validateZones(state); err != nil { - return halt(state, err, "") + return ucloudcommon.Halt(state, err, "") } return multistep.ActionContinue diff --git a/builder/ucloud/uhost/step_stop_instance.go b/builder/ucloud/uhost/step_stop_instance.go index 548a8d20f..463428d1a 100644 --- a/builder/ucloud/uhost/step_stop_instance.go +++ b/builder/ucloud/uhost/step_stop_instance.go @@ -3,6 +3,7 @@ package uhost import ( "context" "fmt" + ucloudcommon "github.com/hashicorp/packer/builder/ucloud/common" "github.com/hashicorp/packer/common/retry" "time" @@ -16,17 +17,17 @@ type stepStopInstance struct { } func (s *stepStopInstance) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { - client := state.Get("client").(*UCloudClient) - conn := client.uhostconn + client := state.Get("client").(*ucloudcommon.UCloudClient) + conn := client.UHostConn instance := state.Get("instance").(*uhost.UHostInstanceSet) ui := state.Get("ui").(packer.Ui) - instance, err := client.describeUHostById(instance.UHostId) + instance, err := client.DescribeUHostById(instance.UHostId) if err != nil { - return halt(state, err, fmt.Sprintf("Error on reading instance when stopping %q", instance.UHostId)) + return ucloudcommon.Halt(state, err, fmt.Sprintf("Error on reading instance when stopping %q", instance.UHostId)) } - if instance.State != instanceStateStopped { + if instance.State != ucloudcommon.InstanceStateStopped { stopReq := conn.NewStopUHostInstanceRequest() stopReq.UHostId = ucloud.String(instance.UHostId) ui.Say(fmt.Sprintf("Stopping instance %q", instance.UHostId)) @@ -44,30 +45,30 @@ func (s *stepStopInstance) Run(ctx context.Context, state multistep.StateBag) mu }) if err != nil { - return halt(state, err, fmt.Sprintf("Error on stopping instance %q", instance.UHostId)) + return ucloudcommon.Halt(state, err, fmt.Sprintf("Error on stopping instance %q", instance.UHostId)) } err = retry.Config{ Tries: 20, ShouldRetry: func(err error) bool { - return isExpectedStateError(err) + return ucloudcommon.IsExpectedStateError(err) }, RetryDelay: (&retry.Backoff{InitialBackoff: 2 * time.Second, MaxBackoff: 6 * time.Second, Multiplier: 2}).Linear, }.Run(ctx, func(ctx context.Context) error { - instance, err := client.describeUHostById(instance.UHostId) + instance, err := client.DescribeUHostById(instance.UHostId) if err != nil { return err } - if instance.State != instanceStateStopped { - return newExpectedStateError("instance", instance.UHostId) + if instance.State != ucloudcommon.InstanceStateStopped { + return ucloudcommon.NewExpectedStateError("instance", instance.UHostId) } return nil }) if err != nil { - return halt(state, err, fmt.Sprintf("Error on waiting for stopping instance when stopping %q", instance.UHostId)) + return ucloudcommon.Halt(state, err, fmt.Sprintf("Error on waiting for stopping instance when stopping %q", instance.UHostId)) } ui.Message(fmt.Sprintf("Stopping instance %q complete", instance.UHostId)) diff --git a/command/plugin.go b/command/plugin.go index 277685a9b..7b24d76f1 100644 --- a/command/plugin.go +++ b/command/plugin.go @@ -75,6 +75,7 @@ import ( googlecomputeimportpostprocessor "github.com/hashicorp/packer/post-processor/googlecompute-import" manifestpostprocessor "github.com/hashicorp/packer/post-processor/manifest" shelllocalpostprocessor "github.com/hashicorp/packer/post-processor/shell-local" + ucloudimportpostprocessor "github.com/hashicorp/packer/post-processor/ucloud-import" vagrantpostprocessor "github.com/hashicorp/packer/post-processor/vagrant" vagrantcloudpostprocessor "github.com/hashicorp/packer/post-processor/vagrant-cloud" vspherepostprocessor "github.com/hashicorp/packer/post-processor/vsphere" @@ -174,6 +175,7 @@ var Provisioners = map[string]packer.Provisioner{ var PostProcessors = map[string]packer.PostProcessor{ "alicloud-import": new(alicloudimportpostprocessor.PostProcessor), + "ucloud-import": new(ucloudimportpostprocessor.PostProcessor), "amazon-import": new(amazonimportpostprocessor.PostProcessor), "artifice": new(artificepostprocessor.PostProcessor), "checksum": new(checksumpostprocessor.PostProcessor), diff --git a/examples/ucloud/basic.json b/examples/ucloud/basic.json index df1dc32af..e0ef9161b 100644 --- a/examples/ucloud/basic.json +++ b/examples/ucloud/basic.json @@ -4,30 +4,35 @@ "ucloud_private_key": "{{env `UCLOUD_PRIVATE_KEY`}}", "ucloud_project_id": "{{env `UCLOUD_PROJECT_ID`}}" }, - - "builders": [{ - "type": "ucloud-uhost", - "public_key": "{{user `ucloud_public_key`}}", - "private_key": "{{user `ucloud_private_key`}}", - "project_id": "{{user `ucloud_project_id`}}", - "region": "cn-bj2", - "availability_zone": "cn-bj2-02", - "instance_type": "n-basic-2", - "source_image_id": "uimage-f1chxn", - "ssh_username":"root", - "image_name": "packer-test-basic-bj", - "image_copy_to_mappings": [{ + "builders": [ + { + "type": "ucloud-uhost", + "public_key": "{{user `ucloud_public_key`}}", + "private_key": "{{user `ucloud_private_key`}}", "project_id": "{{user `ucloud_project_id`}}", - "region": "cn-sh2", - "description": "test", - "name": "packer-test-basic-sh" - }] - }], - "provisioners": [{ - "type": "shell", - "inline": [ - "yum install -y nginx" - ] - }] + "region": "cn-bj2", + "availability_zone": "cn-bj2-02", + "instance_type": "n-basic-2", + "source_image_id": "uimage-f1chxn", + "ssh_username": "root", + "image_name": "packer-test-basic-bj", + "image_copy_to_mappings": [ + { + "project_id": "{{user `ucloud_project_id`}}", + "region": "cn-sh2", + "description": "test", + "name": "packer-test-basic-sh" + } + ] + } + ], + "provisioners": [ + { + "type": "shell", + "inline": [ + "yum install -y nginx" + ] + } + ] } diff --git a/examples/ucloud/local/http/centos-6.8/ks.cfg b/examples/ucloud/local/http/centos-6.8/ks.cfg new file mode 100644 index 000000000..44f8403fb --- /dev/null +++ b/examples/ucloud/local/http/centos-6.8/ks.cfg @@ -0,0 +1,42 @@ +install +cdrom +lang en_US.UTF-8 +keyboard us +network --bootproto=dhcp +rootpw vagrant +firewall --disabled +selinux --permissive +timezone UTC +unsupported_hardware +bootloader --location=mbr +text +skipx +zerombr +clearpart --all +autopart +auth --enableshadow --passalgo=sha512 +firstboot --disabled +reboot +user --name=vagrant --password=vagrant + +%packages --nobase --ignoremissing +# vagrant needs this to copy initial files via scp +openssh-clients +sudo +kernel-headers +kernel-devel +gcc +make +perl +wget +nfs-utils +-fprintd-pam +-intltool +%end + +%post +# Force to set SELinux to a permissive mode +sed -i -e 's/\(^SELINUX=\).*$/\1permissive/' /etc/selinux/config +# sudo +echo "%vagrant ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/vagrant +%end \ No newline at end of file diff --git a/examples/ucloud/local/local.json b/examples/ucloud/local/local.json new file mode 100644 index 000000000..77fee9390 --- /dev/null +++ b/examples/ucloud/local/local.json @@ -0,0 +1,61 @@ +{"variables": { + "build_timestamp": "{{isotime \"20060102150405\"}}", + "cpus": "1", + "disk_size": "4096", + "git_revision": "__unknown_git_revision__", + "headless": "", + "http_proxy": "{{env `http_proxy`}}", + "https_proxy": "{{env `https_proxy`}}", + "iso_checksum": "7002b56184180591a8fa08c2fe0c7338", + "iso_checksum_type": "md5", + "iso_name": "CentOS-7-x86_64-Minimal-1908.iso", + "ks_path": "centos-6.8/ks.cfg", + "memory": "512", + "metadata": "floppy/dummy_metadata.json", + "mirror": "https://mirrors.sjtug.sjtu.edu.cn/centos", + "mirror_directory": "7.7.1908/isos/x86_64", + "no_proxy": "{{env `no_proxy`}}", + "template": "centos-7.7-x86_64", + "version": "2.1.TIMESTAMP" +}, + "builders":[ + { + "type": "qemu", + "boot_command": [ + " text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/{{user `ks_path`}}" + ], + "boot_wait": "10s", + "disk_size": "{{user `disk_size`}}", + "headless": "{{ user `headless` }}", + "http_directory": "http", + "iso_checksum": "{{user `iso_checksum`}}", + "iso_checksum_type": "{{user `iso_checksum_type`}}", + "iso_url": "{{user `mirror`}}/{{user `mirror_directory`}}/{{user `iso_name`}}", + "output_directory": "packer-{{user `template`}}-qemu", + "shutdown_command": "echo 'vagrant'|sudo -S /sbin/halt -h -p", + "ssh_password": "vagrant", + "ssh_port": 22, + "ssh_username": "root", + "ssh_timeout": "10000s", + "vm_name": "{{ user `template` }}.raw", + "net_device": "virtio-net", + "disk_interface": "virtio", + "format": "raw", + "use_default_display": "false", + "qemuargs": [ + ["-display", "cocoa"] + ] + } + ], + "post-processors":[ + { + "type":"ucloud-import", + "ufile_bucket_name": "packer", + "image_name": "packer_import", + "image_os_type": "CentOS", + "image_os_name": "CentOS 6.8 64位", + "format": "raw", + "region":"cn-bj2" + } + ] +} \ No newline at end of file diff --git a/examples/ucloud/local/test.json b/examples/ucloud/local/test.json new file mode 100644 index 000000000..de5684d37 --- /dev/null +++ b/examples/ucloud/local/test.json @@ -0,0 +1,62 @@ +{"variables": { + "build_timestamp": "{{isotime \"20060102150405\"}}", + "cpus": "1", + "disk_size": "4096", + "git_revision": "__unknown_git_revision__", + "headless": "", + "http_proxy": "{{env `http_proxy`}}", + "https_proxy": "{{env `https_proxy`}}", + "iso_checksum": "7002b56184180591a8fa08c2fe0c7338", + "iso_checksum_type": "md5", + "iso_name": "CentOS-7-x86_64-Minimal-1908.iso", + "ks_path": "centos-6.8/ks.cfg", + "memory": "512", + "metadata": "floppy/dummy_metadata.json", + "mirror": "http://mirrors.aliyun.com/centos", + "mirror_directory": "7/isos/x86_64", + "no_proxy": "{{env `no_proxy`}}", + "template": "centos-7-x86_64", + "version": "2.1.TIMESTAMP" +}, + "builders":[ + { + "type": "qemu", + "boot_command": [ + " text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/{{user `ks_path`}}" + ], + "boot_wait": "10s", + "disk_size": "{{user `disk_size`}}", + "headless": "{{ user `headless` }}", + "http_directory": "http", + "iso_checksum": "{{user `iso_checksum`}}", + "iso_checksum_type": "{{user `iso_checksum_type`}}", + "iso_url": "{{user `mirror`}}/{{user `mirror_directory`}}/{{user `iso_name`}}", + "output_directory": "packer-{{user `template`}}-qemu", + "shutdown_command": "echo 'vagrant'|sudo -S /sbin/halt -h -p", + "ssh_password": "vagrant", + "ssh_port": 22, + "ssh_username": "root", + "ssh_timeout": "10000s", + "vm_name": "{{ user `template` }}.raw", + "net_device": "virtio-net", + "disk_interface": "virtio", + "format": "raw", + "use_default_display": "false", + "qemuargs": [ + ["-display", "cocoa"] + ] + } + ], + "post-processors":[ + { + "type":"ucloud-import", + "ufile_bucket_name": "packer", + "image_name": "packer_import", + "image_os_type": "CentOS", + "image_os_name": "CentOS 7.0 64位", + "format": "raw", + "region":"cn-bj2", + "project_id": "org-xp2ucn" + } + ] +} \ No newline at end of file diff --git a/go.mod b/go.mod index a3aec0f38..f456a1dec 100644 --- a/go.mod +++ b/go.mod @@ -133,8 +133,9 @@ require ( github.com/stretchr/testify v1.4.0 github.com/temoto/robotstxt v1.1.1 // indirect github.com/tencentcloud/tencentcloud-sdk-go v3.0.94+incompatible - github.com/ucloud/ucloud-sdk-go v0.8.7 - github.com/ugorji/go v0.0.0-20151218193438-646ae4a518c1 + github.com/ucloud/ucloud-sdk-go v0.11.1 + github.com/ufilesdk-dev/ufile-gosdk v0.0.0-20190730023212-866b183392c4 + github.com/ugorji/go v0.0.0-20180813092308-00b869d2f4a5 github.com/ulikunitz/xz v0.5.5 github.com/vmware/govmomi v0.0.0-20170707011325-c2105a174311 github.com/xanzy/go-cloudstack v0.0.0-20190526095453-42f262b63ed0 diff --git a/go.sum b/go.sum index 009210c9a..69049b574 100644 --- a/go.sum +++ b/go.sum @@ -33,7 +33,6 @@ github.com/Telmate/proxmox-api-go v0.0.0-20191015171801-b0c2796b9fcf h1:rVT2xsBm github.com/Telmate/proxmox-api-go v0.0.0-20191015171801-b0c2796b9fcf/go.mod h1:OGWyIMJ87/k/GCz8CGiWB2HOXsOVDM6Lpe/nFPkC4IQ= github.com/abdullin/seq v0.0.0-20160510034733-d5467c17e7af h1:DBNMBMuMiWYu0b+8KMJuWmfCkcxl09JwdlqwDZZ6U14= github.com/abdullin/seq v0.0.0-20160510034733-d5467c17e7af/go.mod h1:5Jv4cbFiHJMsVxt52+i0Ha45fjshj6wxYr1r19tB9bw= -github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8= github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= github.com/aliyun/alibaba-cloud-sdk-go v0.0.0-20190418113227-25233c783f4e h1:/8wOj52pewmIX/8d5eVO3t7Rr3astkBI/ruyg4WNqRo= github.com/aliyun/alibaba-cloud-sdk-go v0.0.0-20190418113227-25233c783f4e/go.mod h1:T9M45xf79ahXVelWoOBmH0y4aC1t5kXO5BxwyakgIGA= @@ -134,8 +133,6 @@ github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJA github.com/gocolly/colly v1.2.0 h1:qRz9YAn8FIH0qzgNUw+HT9UN7wm1oF9OBAilwEWpyrI= github.com/gocolly/colly v1.2.0/go.mod h1:Hof5T3ZswNVsOHYmba1u03W65HDWgpV5HifSuueE0EA= github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE= -github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE= -github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3 h1:zN2lZNZRflqFyxVaTIU61KNKQ9C0055u9CAfpmqUvo4= @@ -146,19 +143,15 @@ github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfb github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c h1:964Od4U6p2jUkFxvCydnIczKteheJEzHRToSGK3Bnlw= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= @@ -199,7 +192,6 @@ github.com/hashicorp/go-getter v1.3.1-0.20190906090232-a0f878cb75da h1:HAasZmyRr github.com/hashicorp/go-getter v1.3.1-0.20190906090232-a0f878cb75da/go.mod h1:7qxyCd8rBfcShwsvxgIguu4KbS3l8bUCwg2Umn7RjeY= github.com/hashicorp/go-immutable-radix v1.0.0 h1:AKDB1HM5PWEA7i4nhcpwOrO2byshxBjXVn/J/3+z5/0= github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= -github.com/hashicorp/go-msgpack v0.5.3 h1:zKjpN5BK/P5lMYrLmBHdBULWbJ0XpYR+7NGzqkZzoD4= github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= @@ -217,12 +209,10 @@ github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdv github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1BE= github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/hashicorp/go-version v1.1.0 h1:bPIoEKD27tNdebFGGxxYwcL4nepeY4j1QP23PFRGzg0= github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go-version v1.2.0 h1:3vNe/fWF5CBgRIguda1meWhsZHy3m8gCJ5wx+dIzX/E= github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= -github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCOH9wdo= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= @@ -260,7 +250,6 @@ github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCV github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jtolds/gls v4.2.1+incompatible h1:fSuqC+Gmlu6l/ZYAoZzx2pyucC8Xza35fpRVWLVmUEE= github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= -github.com/kardianos/osext v0.0.0-20170510131534-ae77be60afb1 h1:PJPDf8OUfOK1bb/NeTKd4f1QXZItOX389VN3B6qC8ro= github.com/kardianos/osext v0.0.0-20170510131534-ae77be60afb1/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8= github.com/kennygrant/sanitize v1.2.4 h1:gN25/otpP5vAsO2djbMhF/LQX6R7+O1TB4yv8NzpJ3o= github.com/kennygrant/sanitize v1.2.4/go.mod h1:LGsjYYtgxbetdg5owWB2mpgUL6e2nfw2eObZ0u0qvak= @@ -283,7 +272,6 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 h1:MtvEpTB6LX3vkb4ax0b5D2DHbNAUsen0Gx5wZoq3lV4= github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= github.com/linode/linodego v0.7.1 h1:4WZmMpSA2NRwlPZcc0+4Gyn7rr99Evk9bnr0B3gXRKE= github.com/linode/linodego v0.7.1/go.mod h1:ga11n3ivecUrPCHN0rANxKmfWBJVkOXfLMZinAbj2sY= @@ -291,12 +279,10 @@ github.com/masterzen/azure-sdk-for-go v0.0.0-20161014135628-ee4f0065d00c h1:FMUO github.com/masterzen/azure-sdk-for-go v0.0.0-20161014135628-ee4f0065d00c/go.mod h1:mf8fjOu33zCqxUjuiU3I8S1lJMyEAlH+0F2+M5xl3hE= github.com/masterzen/simplexml v0.0.0-20190410153822-31eea3082786 h1:2ZKn+w/BJeL43sCxI2jhPLRv73oVVOjEKZjKkflyqxg= github.com/masterzen/simplexml v0.0.0-20190410153822-31eea3082786/go.mod h1:kCEbxUJlNDEBNbdQMkPSp6yaKcRXVI6f4ddk8Riv4bc= -github.com/masterzen/winrm v0.0.0-20180224160350-7e40f93ae939 h1:cRFHA33ER97Xy5jmjS519OXCS/yE3AT3zdbQAg0Z53g= -github.com/masterzen/winrm v0.0.0-20180224160350-7e40f93ae939/go.mod h1:CfZSN7zwz5gJiFhZJz49Uzk7mEBHIceWmbFmYx7Hf7E= +github.com/masterzen/winrm v0.0.0-20190223112901-5e5c9a7fe54b h1:/1RFh2SLCJ+tEnT73+Fh5R2AO89sQqs8ba7o+hx1G0Y= +github.com/masterzen/winrm v0.0.0-20190223112901-5e5c9a7fe54b/go.mod h1:wr1VqkwW0AB5JS0QLy5GpVMS9E3VtRoSYXUYyVk46KY= github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4= -github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= @@ -309,13 +295,11 @@ github.com/mitchellh/cli v1.0.0 h1:iGBIsUe3+HZ/AD/Vd7DErOt5sU9fa8Uj7A2s1aggv1Y= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/go-fs v0.0.0-20180402234041-7b48fa161ea7 h1:PXPMDtfqV+rZJshQHOiwUFqlqErXaAcuWy+/ZmyRfNc= github.com/mitchellh/go-fs v0.0.0-20180402234041-7b48fa161ea7/go.mod h1:g7SZj7ABpStq3tM4zqHiVEG5un/DZ1+qJJKO7qx1EvU= -github.com/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnGC8aR0= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-testing-interface v1.0.0 h1:fzU/JVNcaqHQEcVFAKeR41fkiLdIPrefOvVG1VZ96U0= github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= github.com/mitchellh/go-vnc v0.0.0-20150629162542-723ed9867aed h1:FI2NIv6fpef6BQl2u3IZX/Cj20tfypRF4yd+uaHOMtI= github.com/mitchellh/go-vnc v0.0.0-20150629162542-723ed9867aed/go.mod h1:3rdaFaCv4AyBgu5ALFM0+tSuHrBh6v692nyQe3ikrq0= -github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM= github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= github.com/mitchellh/iochan v1.0.0 h1:C+X3KsSTLFVBr/tK1eYN/vs4rJcvsiLU338UhYPJWeY= @@ -359,7 +343,6 @@ github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c h1:Lgl0gzECD8GnQ5 github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pierrec/lz4 v2.0.5+incompatible h1:2xWsjqPFWcplujydGg4WmhC/6fZqK42wMM8aXeqhl0I= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= -github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -367,7 +350,6 @@ github.com/pkg/sftp v0.0.0-20160118190721-e84cc8c755ca h1:k8gsErq3rkcbAyCnpOycQs github.com/pkg/sftp v0.0.0-20160118190721-e84cc8c755ca/go.mod h1:NxmoDg/QLVWluQDUYG7XBZTLUpKeFa8e3aMf1BfjyHk= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/posener/complete v1.1.1 h1:ccV59UEOTzVDnDUEFdT95ZzHVZ+5+158q8+SJb2QV5w= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/profitbricks/profitbricks-sdk-go v4.0.2+incompatible h1:ZoVHH6voxW9Onzo6z2yLtocVoN6mBocyDoqoyAMHokE= github.com/profitbricks/profitbricks-sdk-go v4.0.2+incompatible/go.mod h1:T3/WrziK7fYH3C8ilAFAHe99R452/IzIG3YYkqaOFeQ= @@ -390,7 +372,6 @@ github.com/shirou/gopsutil v2.18.12+incompatible h1:1eaJvGomDnH74/5cF4CTmTbLHAri github.com/shirou/gopsutil v2.18.12+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 h1:udFKJ0aHUL60LboW/A+DfgoHVedieIzIXE8uylPue0U= github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc= -github.com/sirupsen/logrus v1.3.0 h1:hI/7Q+DtNZ2kINb6qt/lS+IyXnHQe9e90POfeewL/ME= github.com/sirupsen/logrus v1.3.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= @@ -402,9 +383,7 @@ github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnIn github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= @@ -412,10 +391,19 @@ github.com/temoto/robotstxt v1.1.1 h1:Gh8RCs8ouX3hRSxxK7B1mO5RFByQ4CmJZDwgom++Ja github.com/temoto/robotstxt v1.1.1/go.mod h1:+1AmkuG3IYkh1kv0d2qEB9Le88ehNO0zwOr3ujewlOo= github.com/tencentcloud/tencentcloud-sdk-go v3.0.94+incompatible h1:G8i7dPMK1RCpbQz+VpfFp679vmVna38NI8tz5xsybXI= github.com/tencentcloud/tencentcloud-sdk-go v3.0.94+incompatible/go.mod h1:0PfYow01SHPMhKY31xa+EFz2RStxIqj6JFAJS+IkCi4= +<<<<<<< HEAD github.com/ucloud/ucloud-sdk-go v0.8.7 h1:BmXOb5RivI0Uu4oZRpjI6SQ9/y7n/H9wxTGR1txIE8o= github.com/ucloud/ucloud-sdk-go v0.8.7/go.mod h1:lM6fpI8y6iwACtlbHUav823/uKPdXsNBlnBpRF2fj3c= github.com/ugorji/go v0.0.0-20151218193438-646ae4a518c1 h1:U6ufy3mLDgg9RYupntOvAF7xCmNNquyKaYaaVHo1Nnk= github.com/ugorji/go v0.0.0-20151218193438-646ae4a518c1/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ= +======= +github.com/ucloud/ucloud-sdk-go v0.11.1 h1:rnyoqM3oJ1c3vX0IqDF4JPgVBYgPGiAxrQ6mv2woNDg= +github.com/ucloud/ucloud-sdk-go v0.11.1/go.mod h1:lM6fpI8y6iwACtlbHUav823/uKPdXsNBlnBpRF2fj3c= +github.com/ufilesdk-dev/ufile-gosdk v0.0.0-20190730023212-866b183392c4 h1:KYfTP8NJHDb1ETR4KC3cnCKgXzugY/1UhO4EecPTuIQ= +github.com/ufilesdk-dev/ufile-gosdk v0.0.0-20190730023212-866b183392c4/go.mod h1:R5FMQxkQ+QK/9Vz+jfnJP4rZIktYrRcWmuAnbOSkROI= +github.com/ugorji/go v0.0.0-20180813092308-00b869d2f4a5 h1:cMjKdf4PxEBN9K5HaD9UMW8gkTbM0kMzkTa9SJe0WNQ= +github.com/ugorji/go v0.0.0-20180813092308-00b869d2f4a5/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ= +>>>>>>> add ucloud import github.com/ulikunitz/xz v0.5.5 h1:pFrO0lVpTBXLpYw+pnLj6TbvHuyjXMfjGeCwSqCVwok= github.com/ulikunitz/xz v0.5.5/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= @@ -429,7 +417,6 @@ github.com/yandex-cloud/go-sdk v0.0.0-20190916101744-c781afa45829 h1:2FGwbx03GpP github.com/yandex-cloud/go-sdk v0.0.0-20190916101744-c781afa45829/go.mod h1:Eml0jFLU4VVHgIN8zPHMuNwZXVzUMILyO6lQZSfz854= github.com/zclconf/go-cty v1.1.0 h1:uJwc9HiBOCpoKIObTQaLR+tsEXx1HBHnOsOOpcdhZgw= github.com/zclconf/go-cty v1.1.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s= -go.opencensus.io v0.21.0 h1:mU6zScU4U1YAFPHEHYk+3JC4SY7JxgkqS10ZOSyksNg= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0 h1:C9hSCOW830chIVkdja34wa6Ky+IzWllkUinR+BtRZd4= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= @@ -437,13 +424,15 @@ go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3 h1:KYQXGkl6vs02hK7pK4eIbw0NpNPedieTSTEiJ//bwGs= golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +<<<<<<< HEAD golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= +======= +golang.org/x/crypto v0.0.0-20190222235706-ffb98f73852f/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +>>>>>>> add ucloud import golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5 h1:58fnuSXlxZmFdJyvtTFVmVhcMLU6v5fEb/ok4wyqtNU= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -461,13 +450,10 @@ golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181201002055-351d144fa1fc h1:a3CU5tJYVj92DY2LaA1kUkrsqD5/3mLDhx2NcNqyW+0= golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190213061140-3a22650c66bd h1:HuTn7WObtcDo9uEEU7rEqL0jYthdXAmZ6PP+meazmaU= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -476,28 +462,22 @@ golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421 h1:Wo7BWFiOk0QRFMLYMqJGFMd9CgUAcGx7V+qEg/h5IBI= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 h1:bjcUS9ztw9kFmmIxJInhon/0Is3p+EHBKNgquIzo1OI= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5 h1:x6r4Jo0KNzOOzYd8lbcRsqjuqEASK6ob3auvWYM4/8U= golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190209173611-3b5209105503/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -506,15 +486,17 @@ golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0 h1:HyfiK1WMnHj5FXFXatD+Qs1A/xC2Run6RzeW1SyHxpc= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +<<<<<<< HEAD golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +======= +golang.org/x/sys v0.0.0-20190804053845-51ab0e2deafa h1:KIDDMLT1O0Nr7TSxp8xM5tJcdn8tgyAONntO829og1M= +golang.org/x/sys v0.0.0-20190804053845-51ab0e2deafa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +>>>>>>> add ucloud import golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2 h1:z99zHgr7hKfrUcX/KsoJk5FJfjTceCKIp96+biqP4To= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/time v0.0.0-20181108054448-85acf8d2951c h1:fqgJT0MGcGpPgpWU7VRdRjuArfcOvC4AoJmILihzhDg= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZenJ2O330aBsf7JfSUXmQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -524,27 +506,23 @@ golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190312170243-e65039ee4138 h1:H3uGjxCR/6Ds0Mjgyp7LMK81+LvmbvWWEnJhzk1Pi9E= golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0 h1:Dh6fw+p6FyRl5x/FvNswO1ji0lIGzm3KP8Y9VkS9PTE= golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -google.golang.org/api v0.4.0 h1:KKgc1aqhV8wDPbDzlDtpvyjZFY3vjz85FP7p4wcQUyI= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= google.golang.org/api v0.9.0 h1:jbyannxz0XFD3zdjgrSUsaJbgpH4eTrkdhRChkHPfO8= google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.6.1 h1:QzqyMA1tlu6CgqCDUtU9V+ZKhLFT2dkJuANu5QaxI3I= google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19 h1:Lj2SnHtxkRGJDqnGaSjo+CCdIieEnwVazbOXILwQemk= google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= @@ -553,11 +531,9 @@ google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98 google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.20.1 h1:Hz2g2wirWK7H0qIIhGIqRGTuMwTE8HEKFnDZZ7lm9NU= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1 h1:j6XxA85m/6txkUCHvzlV5f+HBNl/1r5cZ2A/3IEFOO8= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -576,7 +552,6 @@ gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= -gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/post-processor/ucloud-import/post-processor.go b/post-processor/ucloud-import/post-processor.go new file mode 100644 index 000000000..20a0160ca --- /dev/null +++ b/post-processor/ucloud-import/post-processor.go @@ -0,0 +1,349 @@ +package ucloudimport + +import ( + "context" + "fmt" + ucloudcommon "github.com/hashicorp/packer/builder/ucloud/common" + "github.com/hashicorp/packer/common" + "github.com/hashicorp/packer/common/retry" + "github.com/hashicorp/packer/helper/config" + "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/template/interpolate" + "github.com/ucloud/ucloud-sdk-go/services/ufile" + "github.com/ucloud/ucloud-sdk-go/services/uhost" + "github.com/ucloud/ucloud-sdk-go/ucloud" + ufsdk "github.com/ufilesdk-dev/ufile-gosdk" + "log" + "strings" + "time" +) + +const ( + BuilderId = "packer.post-processor.ucloud-import" + RAWFileFormat = "raw" + VHDFileFormat = "vhd" + VMDKFileFormat = "vmdk" + QCOW2FileFormat = "qcow2" +) + +var regionForFileMap = ucloudcommon.NewStringConverter(map[string]string{ + "cn-bj2": "cn-bj", + "cn-bj1": "cn-bj", +}) + +var imageFormatMap = ucloudcommon.NewStringConverter(map[string]string{ + "raw": "RAW", + "vhd": "VHD", + "vmdk": "VMDK", +}) + +// Configuration of this post processor +type Config struct { + common.PackerConfig `mapstructure:",squash"` + ucloudcommon.AccessConfig `mapstructure:",squash"` + + // Variables specific to this post processor + UFileBucket string `mapstructure:"ufile_bucket_name"` + UFileKey string `mapstructure:"ufile_key_name"` + SkipClean bool `mapstructure:"skip_clean"` + ImageName string `mapstructure:"image_name"` + ImageDescription string `mapstructure:"image_description"` + OSType string `mapstructure:"image_os_type"` + OSName string `mapstructure:"image_os_name"` + Format string `mapstructure:"format"` + + ctx interpolate.Context +} + +type PostProcessor struct { + config Config +} + +// Entry point for configuration parsing when we've defined +func (p *PostProcessor) Configure(raws ...interface{}) error { + err := config.Decode(&p.config, &config.DecodeOpts{ + Interpolate: true, + InterpolateContext: &p.config.ctx, + InterpolateFilter: &interpolate.RenderFilter{ + Exclude: []string{ + "ufile_key_name", + }, + }, + }, raws...) + if err != nil { + return err + } + + // Set defaults + if p.config.UFileKey == "" { + //fmt.Sprintf("packer_%s", uuid.TimeOrderedUUID()[:8]) + p.config.UFileKey = "packer-import-{{timestamp}}." + p.config.Format + } + + errs := new(packer.MultiError) + + // Check and render ufile_key_name + if err = interpolate.Validate(p.config.UFileKey, &p.config.ctx); err != nil { + errs = packer.MultiErrorAppend( + errs, fmt.Errorf("Error parsing ufile_key_name template: %s", err)) + } + + // Check we have ucloud access variables defined somewhere + errs = packer.MultiErrorAppend(errs, p.config.AccessConfig.Prepare(&p.config.ctx)...) + + // define all our required parameters + templates := map[string]*string{ + "ufile_bucket_name": &p.config.UFileBucket, + "image_name": &p.config.ImageName, + "image_os_type": &p.config.OSName, + "image_os_name": &p.config.OSType, + } + // Check out required params are defined + for key, ptr := range templates { + if *ptr == "" { + errs = packer.MultiErrorAppend( + errs, fmt.Errorf("%s must be set", key)) + } + } + + switch p.config.Format { + case VHDFileFormat, RAWFileFormat, VMDKFileFormat, QCOW2FileFormat: + default: + errs = packer.MultiErrorAppend( + errs, fmt.Errorf("invalid format '%s'. Only 'raw', 'vhd', 'vmdk', or 'qcow2' are allowed", p.config.Format)) + } + + // Anything which flagged return back up the stack + if len(errs.Errors) > 0 { + return errs + } + + packer.LogSecretFilter.Set(p.config.PublicKey, p.config.PrivateKey) + log.Println(p.config) + return nil +} + +func (p *PostProcessor) PostProcess(ctx context.Context, ui packer.Ui, artifact packer.Artifact) (packer.Artifact, bool, bool, error) { + var err error + + client, err := p.config.Client() + if err != nil { + return nil, false, false, err + } + uhostconn := client.UHostConn + ufileconn := client.UFileConn + + // Render this key since we didn't in the configure phase + p.config.UFileKey, err = interpolate.Render(p.config.UFileKey, &p.config.ctx) + if err != nil { + return nil, false, false, fmt.Errorf("Error rendering ufile_key_name template: %s", err) + } + + log.Printf("Rendered ufile_key_name as %s", p.config.UFileKey) + + log.Println("Looking for image in artifact") + // Locate the files output from the builder + var source string + for _, path := range artifact.Files() { + if strings.HasSuffix(path, "."+p.config.Format) { + source = path + break + } + } + + // Hope we found something useful + if source == "" { + return nil, false, false, fmt.Errorf("No %s image file found in artifact from builder", p.config.Format) + } + + region := regionForFileMap.Convert(p.config.Region) + projectId := p.config.ProjectId + keyName := p.config.UFileKey + bucketName := p.config.UFileBucket + + config := &ufsdk.Config{ + PublicKey: p.config.PublicKey, + PrivateKey: p.config.PrivateKey, + BucketName: bucketName, + FileHost: fmt.Sprintf(region + ".ufileos.com"), + BucketHost: "api.ucloud.cn", + } + if err != nil { + return nil, false, false, fmt.Errorf("Load config error %s", err) + } + + if err := queryOrCreateBucket(ufileconn, config, region, projectId); err != nil { + return nil, false, false, fmt.Errorf("Query or create bucket error %s", err) + } + + bucketUrl := fmt.Sprintf("http://" + bucketName + "." + region + ".ufileos.com") + ui.Say(fmt.Sprintf("Waiting for uploading file %s to %s/%s...", source, bucketUrl, p.config.UFileKey)) + + privateUrl, err := uploadFile(config, keyName, source, projectId) + if err != nil { + return nil, false, false, fmt.Errorf("Upload file error %s", err) + } + + ui.Say(fmt.Sprintf("Image file %s has been uploaded to UFile %s", source, privateUrl)) + + importImageRequest := p.buildImportImageRequest(uhostconn, privateUrl) + importImageResponse, err := uhostconn.ImportCustomImage(importImageRequest) + if err != nil { + return nil, false, false, fmt.Errorf("Failed to import from %s/%s: %s", bucketUrl, p.config.UFileKey, err) + } + + imageId := importImageResponse.ImageId + + ui.Say(fmt.Sprintf("Waiting for importing %s/%s to ucloud...", bucketUrl, p.config.UFileKey)) + + err = retry.Config{ + Tries: 30, + ShouldRetry: func(err error) bool { + return ucloudcommon.IsExpectedStateError(err) + }, + RetryDelay: (&retry.Backoff{InitialBackoff: 2 * time.Second, MaxBackoff: 6 * time.Second, Multiplier: 2}).Linear, + }.Run(ctx, func(ctx context.Context) error { + image, err := client.DescribeImageById(imageId) + if err != nil { + return err + } + + if image.State == ucloudcommon.ImageStateUnavailable { + return fmt.Errorf("Unavailable importing image %s", imageId) + } + + if image.State != ucloudcommon.ImageStateAvailable { + return ucloudcommon.NewExpectedStateError("image", imageId) + } + + return nil + }) + + if err != nil { + return nil, false, false, fmt.Errorf("Error on waiting for importing image %q, %s", + imageId, err.Error()) + } + + // Add the reported UCloud image ID to the artifact list + ui.Say(fmt.Sprintf("Importing created ucloud image ID %s in region %s Finished.", imageId, p.config.Region)) + images := []ucloudcommon.ImageInfo{ + { + ImageId: imageId, + ProjectId: p.config.ProjectId, + Region: p.config.Region, + }, + } + + artifact = &ucloudcommon.Artifact{ + UCloudImages: ucloudcommon.NewImageInfoSet(images), + BuilderIdValue: BuilderId, + Client: client, + } + + if !p.config.SkipClean { + ui.Message(fmt.Sprintf("Deleting import source %s/%s/%s", bucketUrl, p.config.UFileBucket, p.config.UFileKey)) + if err = deleteFile(config, p.config.UFileKey); err != nil { + return nil, false, false, fmt.Errorf("Failed to delete %s/%s/%s: %s", bucketUrl, p.config.UFileBucket, p.config.UFileKey, err) + } + } + + return artifact, false, false, nil +} + +func (p *PostProcessor) buildImportImageRequest(conn *uhost.UHostClient, privateUrl string) *uhost.ImportCustomImageRequest { + req := conn.NewImportCustomImageRequest() + req.ImageName = ucloud.String(p.config.ImageName) + req.ImageDescription = ucloud.String(p.config.ImageDescription) + req.UFileUrl = ucloud.String(privateUrl) + req.OsType = ucloud.String(p.config.OSType) + req.OsName = ucloud.String(p.config.OSName) + req.Format = ucloud.String(imageFormatMap.Convert(p.config.Format)) + req.Auth = ucloud.Bool(true) + return req +} + +func queryOrCreateBucket(conn *ufile.UFileClient, config *ufsdk.Config, region, projectId string) error { + var limit = 100 + var offset int + var bucketList []ufile.UFileBucketSet + for { + req := conn.NewDescribeBucketRequest() + req.Limit = ucloud.Int(limit) + req.Offset = ucloud.Int(offset) + resp, err := conn.DescribeBucket(req) + if err != nil { + return fmt.Errorf("error on reading bucket list, %s", err) + } + + if resp == nil || len(resp.DataSet) < 1 { + break + } + + bucketList = append(bucketList, resp.DataSet...) + + if len(resp.DataSet) < limit { + break + } + + offset = offset + limit + } + + var bucketNames []string + for _, v := range bucketList { + bucketNames = append(bucketNames, v.BucketName) + } + + if !ucloudcommon.IsStringIn(config.BucketName, bucketNames) { + req := conn.NewCreateBucketRequest() + req.BucketName = ucloud.String(config.BucketName) + req.Type = ucloud.String("private") + + _, err := conn.CreateBucket(req) + if err != nil { + return fmt.Errorf("error on creating bucket %s, %s", config.BucketName, err) + } + } + + return nil +} + +func uploadFile(config *ufsdk.Config, keyName, filePath, projectId string) (string, error) { + reqFile, err := ufsdk.NewFileRequest(config, nil) + if err != nil { + return "", fmt.Errorf("NewFileErr:%s", err) + } + + err = reqFile.AsyncMPut(filePath, keyName, "") + if err != nil { + return "", fmt.Errorf("AsyncMPutErr:%s, Response:%s", err, reqFile.DumpResponse(true)) + } + + reqBucket, err := ufsdk.NewBucketRequest(config, nil) + if err != nil { + return "", err + } + + bucketList, err := reqBucket.DescribeBucket(config.BucketName, 0, 1, projectId) + if err != nil { + return "", nil + } + + if bucketList.DataSet[0].Type == "private" { + return reqFile.GetPrivateURL(keyName, 24*60*60), nil + } + + return reqBucket.GetPublicURL(keyName), nil +} + +func deleteFile(config *ufsdk.Config, keyName string) error { + req, err := ufsdk.NewFileRequest(config, nil) + if err != nil { + return fmt.Errorf("error on new deleting file, %s", err) + } + req.DeleteFile(keyName) + if err != nil { + return fmt.Errorf("error on deleting file, %s", err) + } + + return nil +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/private/utils/accessor.go b/vendor/github.com/ucloud/ucloud-sdk-go/private/utils/accessor.go index efe834c6b..5dc2ac8e2 100644 --- a/vendor/github.com/ucloud/ucloud-sdk-go/private/utils/accessor.go +++ b/vendor/github.com/ucloud/ucloud-sdk-go/private/utils/accessor.go @@ -57,7 +57,10 @@ func ValueAtPath(v interface{}, path string) (interface{}, error) { } if rv.Kind() == reflect.Struct { - itemV := rv.FieldByName(components[0]) + itemV := rv.FieldByNameFunc(func(s string) bool { + return strings.ToLower(s) == strings.ToLower(components[0]) + }) + if !itemV.IsValid() { return nil, errors.Errorf("path %s is invalid for struct", path) } diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/uaccount/client.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/uaccount/client.go index 26c8f390c..2dd7e401b 100644 --- a/vendor/github.com/ucloud/ucloud-sdk-go/services/uaccount/client.go +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/uaccount/client.go @@ -1,3 +1,5 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + package uaccount import ( @@ -12,7 +14,8 @@ type UAccountClient struct { // NewClient will return a instance of UAccountClient func NewClient(config *ucloud.Config, credential *auth.Credential) *UAccountClient { - client := ucloud.NewClient(config, credential) + meta := ucloud.ClientMeta{Product: "UAccount"} + client := ucloud.NewClientWithMeta(config, credential, meta) return &UAccountClient{ client, } diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/client.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/client.go new file mode 100644 index 000000000..479a8df2f --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/client.go @@ -0,0 +1,21 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package ufile + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud" + "github.com/ucloud/ucloud-sdk-go/ucloud/auth" +) + +// UFileClient is the client of UFile +type UFileClient struct { + *ucloud.Client +} + +// NewClient will return a instance of UFileClient +func NewClient(config *ucloud.Config, credential *auth.Credential) *UFileClient { + client := ucloud.NewClient(config, credential) + return &UFileClient{ + client, + } +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/create_bucket.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/create_bucket.go new file mode 100644 index 000000000..081ac606d --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/create_bucket.go @@ -0,0 +1,63 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package ufile + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +// CreateBucketRequest is request schema for CreateBucket action +type CreateBucketRequest struct { + request.CommonBase + + // [公共参数] 项目ID。不填写为默认项目,子帐号必须填写。 请参考[GetProjectList接口](../summary/get_project_list.html) + // ProjectId *string `required:"false"` + + // [公共参数] 地域。 参见 [地域和可用区列表](../summary/regionlist.html) + // Region *string `required:"true"` + + // 待创建Bucket的名称,具有全局唯一性 + BucketName *string `required:"true"` + + // Bucket访问类型,public或private; 默认为private + Type *string `required:"false"` +} + +// CreateBucketResponse is response schema for CreateBucket action +type CreateBucketResponse struct { + response.CommonBase + + // 已创建Bucket的ID + BucketId string + + // 已创建Bucket的名称 + BucketName string +} + +// NewCreateBucketRequest will create request of CreateBucket action. +func (c *UFileClient) NewCreateBucketRequest() *CreateBucketRequest { + req := &CreateBucketRequest{} + + // setup request with client config + c.Client.SetupRequest(req) + + // setup retryable with default retry policy (retry for non-create action and common error) + req.SetRetryable(false) + return req +} + +// CreateBucket - 创建Bucket +func (c *UFileClient) CreateBucket(req *CreateBucketRequest) (*CreateBucketResponse, error) { + var err error + var res CreateBucketResponse + + reqCopier := *req + + err = c.Client.InvokeAction("CreateBucket", &reqCopier, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/create_ufile_token.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/create_ufile_token.go new file mode 100644 index 000000000..47887bf79 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/create_ufile_token.go @@ -0,0 +1,69 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package ufile + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +// CreateUFileTokenRequest is request schema for CreateUFileToken action +type CreateUFileTokenRequest struct { + request.CommonBase + + // [公共参数] 项目ID。不填写为默认项目,子帐号必须填写。 请参考[GetProjectList接口](../summary/get_project_list.html) + // ProjectId *string `required:"true"` + + // [公共参数] 地域。 参见 [地域和可用区列表](../summary/regionlist.html) + // Region *string `required:"false"` + + // 令牌允许操作的bucket,默认*表示全部 + AllowedBuckets []string `required:"false"` + + // 令牌允许执行的操作,[ TOKEN_ALLOW_NONE , TOKEN_ALLOW_READ , TOKEN_ALLOW_WRITE , TOKEN_ALLOW_DELETE , TOKEN_ALLOW_LIST, TOKEN_ALLOW_IOP , TOKEN_ALLOW_DP ]。默认TOKEN_ALLOW_NONE + AllowedOps []string `required:"false"` + + // 令牌允许操作的key前缀,默认*表示全部 + AllowedPrefixes []string `required:"false"` + + // 令牌的超时时间点(时间戳),默认一天;注意:过期时间不能超过 4102416000 + ExpireTime *int `required:"false"` + + // 令牌名称 + TokenName *string `required:"true"` +} + +// CreateUFileTokenResponse is response schema for CreateUFileToken action +type CreateUFileTokenResponse struct { + response.CommonBase + + // 创建令牌的token_id + TokenId string +} + +// NewCreateUFileTokenRequest will create request of CreateUFileToken action. +func (c *UFileClient) NewCreateUFileTokenRequest() *CreateUFileTokenRequest { + req := &CreateUFileTokenRequest{} + + // setup request with client config + c.Client.SetupRequest(req) + + // setup retryable with default retry policy (retry for non-create action and common error) + req.SetRetryable(false) + return req +} + +// CreateUFileToken - 创建ufile令牌 +func (c *UFileClient) CreateUFileToken(req *CreateUFileTokenRequest) (*CreateUFileTokenResponse, error) { + var err error + var res CreateUFileTokenResponse + + reqCopier := *req + + err = c.Client.InvokeAction("CreateUFileToken", &reqCopier, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/delete_bucket.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/delete_bucket.go new file mode 100644 index 000000000..8d62e1fd3 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/delete_bucket.go @@ -0,0 +1,60 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package ufile + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud" + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +// DeleteBucketRequest is request schema for DeleteBucket action +type DeleteBucketRequest struct { + request.CommonBase + + // [公共参数] 项目ID。不填写为默认项目,子帐号必须填写。 请参考[GetProjectList接口](../summary/get_project_list.html) + // ProjectId *string `required:"false"` + + // 待删除Bucket的名称 + BucketName *string `required:"true"` +} + +// DeleteBucketResponse is response schema for DeleteBucket action +type DeleteBucketResponse struct { + response.CommonBase + + // Bucket的ID + BucketId string + + // Bucket的名称 + BucketName string +} + +// NewDeleteBucketRequest will create request of DeleteBucket action. +func (c *UFileClient) NewDeleteBucketRequest() *DeleteBucketRequest { + req := &DeleteBucketRequest{} + + // setup request with client config + c.Client.SetupRequest(req) + + // setup retryable with default retry policy (retry for non-create action and common error) + req.SetRetryable(true) + return req +} + +// DeleteBucket - 删除Bucket +func (c *UFileClient) DeleteBucket(req *DeleteBucketRequest) (*DeleteBucketResponse, error) { + var err error + var res DeleteBucketResponse + + reqCopier := *req + // In order to ignore the parameters about Region + reqCopier.Region = ucloud.String("") + + err = c.Client.InvokeAction("DeleteBucket", &reqCopier, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/delete_ufile_token.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/delete_ufile_token.go new file mode 100644 index 000000000..c8a460089 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/delete_ufile_token.go @@ -0,0 +1,54 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package ufile + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +// DeleteUFileTokenRequest is request schema for DeleteUFileToken action +type DeleteUFileTokenRequest struct { + request.CommonBase + + // [公共参数] 项目ID。不填写为默认项目,子帐号必须填写。 请参考[GetProjectList接口](../summary/get_project_list.html) + // ProjectId *string `required:"true"` + + // [公共参数] 地域。 参见 [地域和可用区列表](../summary/regionlist.html) + // Region *string `required:"true"` + + // 令牌ID + TokenId *string `required:"true"` +} + +// DeleteUFileTokenResponse is response schema for DeleteUFileToken action +type DeleteUFileTokenResponse struct { + response.CommonBase +} + +// NewDeleteUFileTokenRequest will create request of DeleteUFileToken action. +func (c *UFileClient) NewDeleteUFileTokenRequest() *DeleteUFileTokenRequest { + req := &DeleteUFileTokenRequest{} + + // setup request with client config + c.Client.SetupRequest(req) + + // setup retryable with default retry policy (retry for non-create action and common error) + req.SetRetryable(true) + return req +} + +// DeleteUFileToken - 删除令牌 +func (c *UFileClient) DeleteUFileToken(req *DeleteUFileTokenRequest) (*DeleteUFileTokenResponse, error) { + var err error + var res DeleteUFileTokenResponse + + reqCopier := *req + + err = c.Client.InvokeAction("DeleteUFileToken", &reqCopier, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/describe_bucket.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/describe_bucket.go new file mode 100644 index 000000000..6cc873192 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/describe_bucket.go @@ -0,0 +1,64 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package ufile + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud" + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +// DescribeBucketRequest is request schema for DescribeBucket action +type DescribeBucketRequest struct { + request.CommonBase + + // [公共参数] 项目ID。不填写为默认项目,子帐号必须填写。 请参考[GetProjectList接口](../summary/get_project_list.html) + // ProjectId *string `required:"false"` + + // 待获取Bucket的名称,若不提供,则获取所有Bucket + BucketName *string `required:"false"` + + // 获取所有Bucket列表的限制数目,默认为20 + Limit *int `required:"false"` + + // 获取所有Bucket列表的偏移数目,默认为0 + Offset *int `required:"false"` +} + +// DescribeBucketResponse is response schema for DescribeBucket action +type DescribeBucketResponse struct { + response.CommonBase + + // Bucket的描述信息 参数见 UFileBucketSet + DataSet []UFileBucketSet +} + +// NewDescribeBucketRequest will create request of DescribeBucket action. +func (c *UFileClient) NewDescribeBucketRequest() *DescribeBucketRequest { + req := &DescribeBucketRequest{} + + // setup request with client config + c.Client.SetupRequest(req) + + // setup retryable with default retry policy (retry for non-create action and common error) + req.SetRetryable(true) + return req +} + +// DescribeBucket - 获取Bucket的描述信息 +func (c *UFileClient) DescribeBucket(req *DescribeBucketRequest) (*DescribeBucketResponse, error) { + var err error + var res DescribeBucketResponse + + reqCopier := *req + + // In order to ignore the parameters about Region + reqCopier.Region = ucloud.String("") + + err = c.Client.InvokeAction("DescribeBucket", &reqCopier, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/describe_ufile_token.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/describe_ufile_token.go new file mode 100644 index 000000000..c935f4309 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/describe_ufile_token.go @@ -0,0 +1,66 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package ufile + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +// DescribeUFileTokenRequest is request schema for DescribeUFileToken action +type DescribeUFileTokenRequest struct { + request.CommonBase + + // [公共参数] 项目ID。不填写为默认项目,子帐号必须填写。 请参考[GetProjectList接口](../summary/get_project_list.html) + // ProjectId *string `required:"true"` + + // [公共参数] 地域。 参见 [地域和可用区列表](../summary/regionlist.html) + // Region *string `required:"false"` + + // 0表示显示部分token信息;不传递和其他情况表示显示全部token信息 + Display *int `required:"false"` + + // 令牌ID,只返回指定ID信息,否则拉取所有令牌 + TokenId *string `required:"false"` +} + +// DescribeUFileTokenResponse is response schema for DescribeUFileToken action +type DescribeUFileTokenResponse struct { + response.CommonBase + + // 操作名称 + Action string + + // 令牌描述信息 + DataSet []UFileTokenSet + + // 返回码 + RetCode int +} + +// NewDescribeUFileTokenRequest will create request of DescribeUFileToken action. +func (c *UFileClient) NewDescribeUFileTokenRequest() *DescribeUFileTokenRequest { + req := &DescribeUFileTokenRequest{} + + // setup request with client config + c.Client.SetupRequest(req) + + // setup retryable with default retry policy (retry for non-create action and common error) + req.SetRetryable(true) + return req +} + +// DescribeUFileToken - 获取令牌信息 +func (c *UFileClient) DescribeUFileToken(req *DescribeUFileTokenRequest) (*DescribeUFileTokenResponse, error) { + var err error + var res DescribeUFileTokenResponse + + reqCopier := *req + + err = c.Client.InvokeAction("DescribeUFileToken", &reqCopier, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/doc.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/doc.go new file mode 100644 index 000000000..1be7726ee --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/doc.go @@ -0,0 +1,13 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +/* +Package ufile include resources of ucloud ufile product + +See also + + - API: https://docs.ucloud.cn/api/ufile-api/index + - Product: https://www.ucloud.cn/site/product/ufile.html + +for detail. +*/ +package ufile diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/types_ufile_bucket_set.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/types_ufile_bucket_set.go new file mode 100644 index 000000000..5747ae002 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/types_ufile_bucket_set.go @@ -0,0 +1,45 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package ufile + +/* +UFileBucketSet - DescribeBucket + +this model is auto created by ucloud code generater for open api, +you can also see https://docs.ucloud.cn/api for detail. +*/ +type UFileBucketSet struct { + + // Bucket所属业务, general或vod或udb general: 普通业务; vod: 视频云业务; udb: 云数据库业务 + Biz string + + // Bucket的ID + BucketId string + + // Bucket名称 + BucketName string + + // 与Bucket关联的CND加速域名的ID列表 + CdnDomainId []string + + // Bucket的创建时间 + CreateTime int + + // Bucket的域名集合 参数见 UFileDomainSet + Domain UFileDomainSet + + // 是否存在自定义域名。0不存在,1存在,2错误 + HasUserDomain int + + // Bucket的修改时间 + ModifyTime int + + // Bucket所属地域 + Region string + + // 所属业务组 + Tag string + + // Bucket访问类型 + Type string +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/types_ufile_domain_set.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/types_ufile_domain_set.go new file mode 100644 index 000000000..6960186d0 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/types_ufile_domain_set.go @@ -0,0 +1,24 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package ufile + +/* +UFileDomainSet - DescribeBucket + +this model is auto created by ucloud code generater for open api, +you can also see https://docs.ucloud.cn/api for detail. +*/ +type UFileDomainSet struct { + + // UCDN加速域名 + Cdn []string + + // 用户自定义CDN加速域名 + CustomCdn []string + + // 用户自定义源站域名 + CustomSrc []string + + // 源站域名 + Src []string +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/types_ufile_token_set.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/types_ufile_token_set.go new file mode 100644 index 000000000..596773ffe --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/types_ufile_token_set.go @@ -0,0 +1,45 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package ufile + +/* +UFileTokenSet - ufile令牌集合 + +this model is auto created by ucloud code generater for open api, +you can also see https://docs.ucloud.cn/api for detail. +*/ +type UFileTokenSet struct { + + // 令牌允许操作的bucket + AllowedBuckets []string + + // 令牌允许执行的操作,[ TOKEN_ALLOW_NONE , TOKEN_ALLOW_READ , TOKEN_ALLOW_WRITE , TOKEN_ALLOW_DELETE , TOKEN_ALLOW_LIST, TOKEN_ALLOW_IOP , TOKEN_ALLOW_DP ] + AllowedOps []string + + // 令牌允许操作的key前缀 + AllowedPrefixes []string + + // 创建时间 + CreateTime int + + // 令牌的超时时间点 + ExpireTime int + + // 修改时间 + ModifyTime int + + // 令牌私钥 + PrivateKey string + + // 令牌公钥 + PublicKey string + + // 所属地区 + Region string + + // 令牌ID + TokenId string + + // 令牌名称 + TokenName string +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/update_bucket.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/update_bucket.go new file mode 100644 index 000000000..ff5c79885 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/update_bucket.go @@ -0,0 +1,62 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package ufile + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud" + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +// UpdateBucketRequest is request schema for UpdateBucket action +type UpdateBucketRequest struct { + request.CommonBase + + // [公共参数] 项目ID。不填写为默认项目,子帐号必须填写。 请参考[GetProjectList接口](../summary/get_project_list.html) + // ProjectId *string `required:"true"` + + // 待修改Bucket的名称 + BucketName *string `required:"true"` + + // Bucket访问类型;public或private + Type *string `required:"true"` +} + +// UpdateBucketResponse is response schema for UpdateBucket action +type UpdateBucketResponse struct { + response.CommonBase + + // Bucket的ID + BucketId string + + // Bucket的名称 + BucketName string +} + +// NewUpdateBucketRequest will create request of UpdateBucket action. +func (c *UFileClient) NewUpdateBucketRequest() *UpdateBucketRequest { + req := &UpdateBucketRequest{} + + // setup request with client config + c.Client.SetupRequest(req) + + // setup retryable with default retry policy (retry for non-create action and common error) + req.SetRetryable(true) + return req +} + +// UpdateBucket - 更改Bucket的属性 +func (c *UFileClient) UpdateBucket(req *UpdateBucketRequest) (*UpdateBucketResponse, error) { + var err error + var res UpdateBucketResponse + + reqCopier := *req + reqCopier.Region = ucloud.String("") + + err = c.Client.InvokeAction("UpdateBucket", &reqCopier, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/update_ufile_token.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/update_ufile_token.go new file mode 100644 index 000000000..e801cb873 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/ufile/update_ufile_token.go @@ -0,0 +1,69 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package ufile + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +// UpdateUFileTokenRequest is request schema for UpdateUFileToken action +type UpdateUFileTokenRequest struct { + request.CommonBase + + // [公共参数] 项目ID。不填写为默认项目,子帐号必须填写。 请参考[GetProjectList接口](../summary/get_project_list.html) + // ProjectId *string `required:"true"` + + // [公共参数] 地域。 参见 [地域和可用区列表](../summary/regionlist.html) + // Region *string `required:"false"` + + // 令牌允许操作的bucket + AllowedBuckets []string `required:"false"` + + // 令牌允许执行的操作,[ TOKEN_ALLOW_NONE , TOKEN_ALLOW_READ , TOKEN_ALLOW_WRITE , TOKEN_ALLOW_DELETE , TOKEN_ALLOW_LIST, TOKEN_ALLOW_IOP , TOKEN_ALLOW_DP ] + AllowedOps []string `required:"false"` + + // 令牌允许操作的key前缀 + AllowedPrefixes []string `required:"false"` + + // 令牌的超时时间点(时间戳);注意:过期时间不能超过 4102416000 + ExpireTime *int `required:"false"` + + // 令牌ID + TokenId *string `required:"true"` + + // 令牌名称 + TokenName *string `required:"false"` +} + +// UpdateUFileTokenResponse is response schema for UpdateUFileToken action +type UpdateUFileTokenResponse struct { + response.CommonBase +} + +// NewUpdateUFileTokenRequest will create request of UpdateUFileToken action. +func (c *UFileClient) NewUpdateUFileTokenRequest() *UpdateUFileTokenRequest { + req := &UpdateUFileTokenRequest{} + + // setup request with client config + c.Client.SetupRequest(req) + + // setup retryable with default retry policy (retry for non-create action and common error) + req.SetRetryable(true) + return req +} + +// UpdateUFileToken - 更新令牌的操作权限,可操作key的前缀,可操作bucket和令牌超时时间点 +func (c *UFileClient) UpdateUFileToken(req *UpdateUFileTokenRequest) (*UpdateUFileTokenResponse, error) { + var err error + var res UpdateUFileTokenResponse + + reqCopier := *req + + err = c.Client.InvokeAction("UpdateUFileToken", &reqCopier, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/client.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/client.go index 85b57089a..bf38bf07b 100644 --- a/vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/client.go +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/client.go @@ -1,3 +1,5 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + package uhost import ( @@ -12,7 +14,8 @@ type UHostClient struct { // NewClient will return a instance of UHostClient func NewClient(config *ucloud.Config, credential *auth.Credential) *UHostClient { - client := ucloud.NewClient(config, credential) + meta := ucloud.ClientMeta{Product: "UHost"} + client := ucloud.NewClientWithMeta(config, credential, meta) return &UHostClient{ client, } diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/create_isolation_group.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/create_isolation_group.go new file mode 100644 index 000000000..1c64bf7b2 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/create_isolation_group.go @@ -0,0 +1,59 @@ +//Code is generated by ucloud code generator, don't modify it by hand, it will cause undefined behaviors. +//go:generate ucloud-gen-go-api UHost CreateIsolationGroup + +package uhost + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +// CreateIsolationGroupRequest is request schema for CreateIsolationGroup action +type CreateIsolationGroupRequest struct { + request.CommonBase + + // [公共参数] 地域。 参见 [地域和可用区列表](../summary/regionlist.html) + // Region *string `required:"true"` + + // [公共参数] 项目id + // ProjectId *string `required:"false"` + + // 硬件隔离组名称。请遵照[[api:uhost-api:specification|字段规范]]设定隔离组名称。 + GroupName *string `required:"true"` + + // 备注。请遵照[[api:uhost-api:specification|字段规范]]设定隔离组备注。 + Remark *string `required:"false"` +} + +// CreateIsolationGroupResponse is response schema for CreateIsolationGroup action +type CreateIsolationGroupResponse struct { + response.CommonBase + + // 硬件隔离组id + GroupId string +} + +// NewCreateIsolationGroupRequest will create request of CreateIsolationGroup action. +func (c *UHostClient) NewCreateIsolationGroupRequest() *CreateIsolationGroupRequest { + req := &CreateIsolationGroupRequest{} + + // setup request with client config + c.Client.SetupRequest(req) + + // setup retryable with default retry policy (retry for non-create action and common error) + req.SetRetryable(false) + return req +} + +// CreateIsolationGroup - 创建硬件隔离组,组内机器严格隔离在不同宿主机上。 +func (c *UHostClient) CreateIsolationGroup(req *CreateIsolationGroupRequest) (*CreateIsolationGroupResponse, error) { + var err error + var res CreateIsolationGroupResponse + + err = c.Client.InvokeAction("CreateIsolationGroup", req, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/create_uhost_instance.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/create_uhost_instance.go index 805211729..0a87ab99e 100644 --- a/vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/create_uhost_instance.go +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/create_uhost_instance.go @@ -90,6 +90,9 @@ type CreateUHostInstanceRequest struct { // 防火墙Id,默认:Web推荐防火墙。如何查询SecurityGroupId请参见 [DescribeSecurityGroup](../unet-api/describe_security_group.html) SecurityGroupId *string `required:"false"` + // 硬件隔离组id。可通过DescribeIsolationGroup获取。 + IsolationGroup *string `required:"false"` + // 【暂不支持】cloudinit方式下,用户初始化脚本 UserDataScript *string `required:"false"` @@ -111,6 +114,12 @@ type CreateUHostInstanceRequest struct { // 最低cpu平台,枚举值["Intel/Auto", "Intel/LvyBridge", "Intel/Haswell", "Intel/Broadwell", "Intel/Skylake", "Intel/Cascadelake"(只有O型云主机可选)] MinimalCpuPlatform *string `required:"false"` + // 【批量创建主机时必填】最大创建主机数量,取值范围是[1,100]; + MaxCount *int `required:"false"` + + // GPU类型,枚举值["K80", "P40", "V100"],MachineType为G时必填 + GpuType *string `required:"false"` + // NetworkInterface NetworkInterface []CreateUHostInstanceParamNetworkInterface } diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/delete_isolation_group.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/delete_isolation_group.go new file mode 100644 index 000000000..64f7510ce --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/delete_isolation_group.go @@ -0,0 +1,56 @@ +//Code is generated by ucloud code generator, don't modify it by hand, it will cause undefined behaviors. +//go:generate ucloud-gen-go-api UHost DeleteIsolationGroup + +package uhost + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +// DeleteIsolationGroupRequest is request schema for DeleteIsolationGroup action +type DeleteIsolationGroupRequest struct { + request.CommonBase + + // [公共参数] 地域。 参见 [地域和可用区列表](../summary/regionlist.html) + // Region *string `required:"true"` + + // [公共参数] 项目id + // ProjectId *string `required:"false"` + + // 硬件隔离组id + GroupId *string `required:"true"` +} + +// DeleteIsolationGroupResponse is response schema for DeleteIsolationGroup action +type DeleteIsolationGroupResponse struct { + response.CommonBase + + // 硬件隔离组id + GroupId string +} + +// NewDeleteIsolationGroupRequest will create request of DeleteIsolationGroup action. +func (c *UHostClient) NewDeleteIsolationGroupRequest() *DeleteIsolationGroupRequest { + req := &DeleteIsolationGroupRequest{} + + // setup request with client config + c.Client.SetupRequest(req) + + // setup retryable with default retry policy (retry for non-create action and common error) + req.SetRetryable(true) + return req +} + +// DeleteIsolationGroup - 删除硬件隔离组。 +func (c *UHostClient) DeleteIsolationGroup(req *DeleteIsolationGroupRequest) (*DeleteIsolationGroupResponse, error) { + var err error + var res DeleteIsolationGroupResponse + + err = c.Client.InvokeAction("DeleteIsolationGroup", req, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/describe_isolation_group.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/describe_isolation_group.go new file mode 100644 index 000000000..7be4f9043 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/describe_isolation_group.go @@ -0,0 +1,62 @@ +//Code is generated by ucloud code generator, don't modify it by hand, it will cause undefined behaviors. +//go:generate ucloud-gen-go-api UHost DescribeIsolationGroup + +package uhost + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +// DescribeIsolationGroupRequest is request schema for DescribeIsolationGroup action +type DescribeIsolationGroupRequest struct { + request.CommonBase + + // [公共参数] 地域。 参见 [地域和可用区列表](../summary/regionlist.html) + // Region *string `required:"true"` + + // [公共参数] 项目id + // ProjectId *string `required:"false"` + + // 待查的硬件隔离组id + GroupId *string `required:"false"` + + // 列表起始位置偏移量,默认为0 + Offset *int `required:"false"` + + // 返回数据长度,默认为20,最大100 + Limit *int `required:"false"` +} + +// DescribeIsolationGroupResponse is response schema for DescribeIsolationGroup action +type DescribeIsolationGroupResponse struct { + response.CommonBase + + // 硬件隔离组集合。参见数据结构IsolationGroup。 + IsolationGroupSet []IsolationGroup +} + +// NewDescribeIsolationGroupRequest will create request of DescribeIsolationGroup action. +func (c *UHostClient) NewDescribeIsolationGroupRequest() *DescribeIsolationGroupRequest { + req := &DescribeIsolationGroupRequest{} + + // setup request with client config + c.Client.SetupRequest(req) + + // setup retryable with default retry policy (retry for non-create action and common error) + req.SetRetryable(true) + return req +} + +// DescribeIsolationGroup - 查询硬件隔离组列表。 +func (c *UHostClient) DescribeIsolationGroup(req *DescribeIsolationGroupRequest) (*DescribeIsolationGroupResponse, error) { + var err error + var res DescribeIsolationGroupResponse + + err = c.Client.InvokeAction("DescribeIsolationGroup", req, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/leave_isolation_group.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/leave_isolation_group.go new file mode 100644 index 000000000..4b0b683c7 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/leave_isolation_group.go @@ -0,0 +1,62 @@ +//Code is generated by ucloud code generator, don't modify it by hand, it will cause undefined behaviors. +//go:generate ucloud-gen-go-api UHost LeaveIsolationGroup + +package uhost + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +// LeaveIsolationGroupRequest is request schema for LeaveIsolationGroup action +type LeaveIsolationGroupRequest struct { + request.CommonBase + + // [公共参数] 地域。 参见 [地域和可用区列表](../summary/regionlist.html) + // Region *string `required:"true"` + + // [公共参数] 可用区信息 + // Zone *string `required:"false"` + + // [公共参数] 项目id + // ProjectId *string `required:"false"` + + // 硬件隔离组id + GroupId *string `required:"true"` + + // 主机id + UHostId *string `required:"true"` +} + +// LeaveIsolationGroupResponse is response schema for LeaveIsolationGroup action +type LeaveIsolationGroupResponse struct { + response.CommonBase + + // 主机id + UHostId string +} + +// NewLeaveIsolationGroupRequest will create request of LeaveIsolationGroup action. +func (c *UHostClient) NewLeaveIsolationGroupRequest() *LeaveIsolationGroupRequest { + req := &LeaveIsolationGroupRequest{} + + // setup request with client config + c.Client.SetupRequest(req) + + // setup retryable with default retry policy (retry for non-create action and common error) + req.SetRetryable(true) + return req +} + +// LeaveIsolationGroup - 移除硬件隔离组中的主机 +func (c *UHostClient) LeaveIsolationGroup(req *LeaveIsolationGroupRequest) (*LeaveIsolationGroupResponse, error) { + var err error + var res LeaveIsolationGroupResponse + + err = c.Client.InvokeAction("LeaveIsolationGroup", req, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/types_isolation_group.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/types_isolation_group.go new file mode 100644 index 000000000..a82ea65f3 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/types_isolation_group.go @@ -0,0 +1,22 @@ +package uhost + +/* +IsolationGroup - 硬件隔离组信息 + +this model is auto created by ucloud code generater for open api, +you can also see https://docs.ucloud.cn for detail. +*/ +type IsolationGroup struct { + + // 硬件隔离组名称 + GroupName string + + // 硬件隔离组id + GroupId string + + // 每个可用区中的机器数量。参见数据结构SpreadInfo。 + SpreadInfoSet []SpreadInfo + + // 备注 + Remark string +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/types_spread_info.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/types_spread_info.go new file mode 100644 index 000000000..b8d2ef8c3 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/uhost/types_spread_info.go @@ -0,0 +1,16 @@ +package uhost + +/* +SpreadInfo - 每个可用区中硬件隔离组信息 + +this model is auto created by ucloud code generater for open api, +you can also see https://docs.ucloud.cn for detail. +*/ +type SpreadInfo struct { + + // 可用区信息 + Zone string + + // 可用区中硬件隔离组中云主机的数量,不超过7。 + UHostCount int +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/unet/client.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/unet/client.go index 745ad23ee..e714444f2 100644 --- a/vendor/github.com/ucloud/ucloud-sdk-go/services/unet/client.go +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/unet/client.go @@ -1,3 +1,5 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + package unet import ( @@ -12,7 +14,8 @@ type UNetClient struct { // NewClient will return a instance of UNetClient func NewClient(config *ucloud.Config, credential *auth.Credential) *UNetClient { - client := ucloud.NewClient(config, credential) + meta := ucloud.ClientMeta{Product: "UNet"} + client := ucloud.NewClientWithMeta(config, credential, meta) return &UNetClient{ client, } diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/unet/describe_vip.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/unet/describe_vip.go index fd8c972f0..df70ab839 100644 --- a/vendor/github.com/ucloud/ucloud-sdk-go/services/unet/describe_vip.go +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/unet/describe_vip.go @@ -1,5 +1,4 @@ -//Code is generated by ucloud code generator, don't modify it by hand, it will cause undefined behaviors. -//go:generate ucloud-gen-go-api UNet DescribeVIP +// Code is generated by ucloud-model, DO NOT EDIT IT. package unet @@ -12,17 +11,17 @@ import ( type DescribeVIPRequest struct { request.CommonBase + // [公共参数] 项目ID。不填写为默认项目,子帐号必须填写。 请参考[GetProjectList接口](../summary/get_project_list.html) + // ProjectId *string `required:"true"` + // [公共参数] 地域。 参见 [地域和可用区列表](../summary/regionlist.html) // Region *string `required:"true"` // [公共参数] 可用区。参见 [可用区列表](../summary/regionlist.html) // Zone *string `required:"false"` - // [公共参数] 项目ID。不填写为默认项目,子帐号必须填写。 请参考[GetProjectList接口](../summary/get_project_list.html) - // ProjectId *string `required:"false"` - - // vpc的id,指定SubnetId时必填 - VPCId *string `required:"false"` + // 业务组 + BusinessId *string `required:"false"` // 子网id,不指定则获取VPCId下的所有vip SubnetId *string `required:"false"` @@ -30,22 +29,25 @@ type DescribeVIPRequest struct { // 业务组名称, 默认为 Default Tag *string `required:"false"` - // 业务组 - BusinessId *string `required:"false"` + // VIP ID + VIPId *string `required:"false"` + + // vpc的id,指定SubnetId时必填 + VPCId *string `required:"false"` } // DescribeVIPResponse is response schema for DescribeVIP action type DescribeVIPResponse struct { response.CommonBase - // 内网VIP详情,请见VIPDetailSet - VIPSet []VIPDetailSet - // 内网VIP地址列表 DataSet []string // vip数量 TotalCount int + + // 内网VIP详情,请见VIPDetailSet + VIPSet []VIPDetailSet } // NewDescribeVIPRequest will create request of DescribeVIP action. @@ -65,7 +67,9 @@ func (c *UNetClient) DescribeVIP(req *DescribeVIPRequest) (*DescribeVIPResponse, var err error var res DescribeVIPResponse - err = c.Client.InvokeAction("DescribeVIP", req, &res) + reqCopier := *req + + err = c.Client.InvokeAction("DescribeVIP", &reqCopier, &res) if err != nil { return &res, err } diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/unet/types_vipdetail_set.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/unet/types_vip_detail_set.go similarity index 65% rename from vendor/github.com/ucloud/ucloud-sdk-go/services/unet/types_vipdetail_set.go rename to vendor/github.com/ucloud/ucloud-sdk-go/services/unet/types_vip_detail_set.go index 44bcbf41a..918daa3eb 100644 --- a/vendor/github.com/ucloud/ucloud-sdk-go/services/unet/types_vipdetail_set.go +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/unet/types_vip_detail_set.go @@ -1,34 +1,42 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + package unet /* VIPDetailSet - VIPDetailSet this model is auto created by ucloud code generater for open api, -you can also see https://docs.ucloud.cn for detail. +you can also see https://docs.ucloud.cn/api for detail. */ type VIPDetailSet struct { - // 地域 - Zone string - - // 虚拟ip id - VIPId string - // 创建时间 CreateTime int + // VIP名称 + Name string + // 真实主机ip RealIp string - // 虚拟ip - VIP string + // VIP备注 + Remark string // 子网id SubnetId string + // VIP所属业务组 + Tag string + + // 虚拟ip + VIP string + + // 虚拟ip id + VIPId string + // VPC id VPCId string - // Virtual IP 名称 - Name string + // 地域 + Zone string } diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/unet/update_vip_attribute.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/unet/update_vip_attribute.go new file mode 100644 index 000000000..cc36dee25 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/unet/update_vip_attribute.go @@ -0,0 +1,63 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package unet + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +// UpdateVIPAttributeRequest is request schema for UpdateVIPAttribute action +type UpdateVIPAttributeRequest struct { + request.CommonBase + + // [公共参数] 项目ID。不填写为默认项目,子帐号必须填写。 请参考[GetProjectList接口](../summary/get_project_list.html) + // ProjectId *string `required:"true"` + + // [公共参数] 地域。 参见 [地域和可用区列表](../summary/regionlist.html) + // Region *string `required:"true"` + + // 内网VIP的名称 + Name *string `required:"false"` + + // 内网VIP的备注 + Remark *string `required:"false"` + + // 内网VIP所属的业务组 + Tag *string `required:"false"` + + // 内网VIP的资源Id + VIPId *string `required:"true"` +} + +// UpdateVIPAttributeResponse is response schema for UpdateVIPAttribute action +type UpdateVIPAttributeResponse struct { + response.CommonBase +} + +// NewUpdateVIPAttributeRequest will create request of UpdateVIPAttribute action. +func (c *UNetClient) NewUpdateVIPAttributeRequest() *UpdateVIPAttributeRequest { + req := &UpdateVIPAttributeRequest{} + + // setup request with client config + c.Client.SetupRequest(req) + + // setup retryable with default retry policy (retry for non-create action and common error) + req.SetRetryable(true) + return req +} + +// UpdateVIPAttribute - 更新VIP信息 +func (c *UNetClient) UpdateVIPAttribute(req *UpdateVIPAttributeRequest) (*UpdateVIPAttributeResponse, error) { + var err error + var res UpdateVIPAttributeResponse + + reqCopier := *req + + err = c.Client.InvokeAction("UpdateVIPAttribute", &reqCopier, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/add_white_list_resource.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/add_white_list_resource.go new file mode 100644 index 000000000..32d54ae04 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/add_white_list_resource.go @@ -0,0 +1,57 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package vpc + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +// AddWhiteListResourceRequest is request schema for AddWhiteListResource action +type AddWhiteListResourceRequest struct { + request.CommonBase + + // [公共参数] 项目Id。不填写为默认项目,子帐号必须填写。 请参考[GetProjectList接口](../summary/get_project_list.html) + // ProjectId *string `required:"false"` + + // [公共参数] 地域。 参见 [地域和可用区列表](../summary/regionlist.html) + // Region *string `required:"true"` + + // NAT网关Id + NATGWId *string `required:"true"` + + // 可添加白名单的资源Id + ResourceIds []string `required:"true"` +} + +// AddWhiteListResourceResponse is response schema for AddWhiteListResource action +type AddWhiteListResourceResponse struct { + response.CommonBase +} + +// NewAddWhiteListResourceRequest will create request of AddWhiteListResource action. +func (c *VPCClient) NewAddWhiteListResourceRequest() *AddWhiteListResourceRequest { + req := &AddWhiteListResourceRequest{} + + // setup request with client config + c.Client.SetupRequest(req) + + // setup retryable with default retry policy (retry for non-create action and common error) + req.SetRetryable(false) + return req +} + +// AddWhiteListResource - 添加NAT网关白名单 +func (c *VPCClient) AddWhiteListResource(req *AddWhiteListResourceRequest) (*AddWhiteListResourceResponse, error) { + var err error + var res AddWhiteListResourceResponse + + reqCopier := *req + + err = c.Client.InvokeAction("AddWhiteListResource", &reqCopier, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/client.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/client.go index fe52e6c3d..1298deba4 100644 --- a/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/client.go +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/client.go @@ -1,3 +1,5 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + package vpc import ( @@ -5,14 +7,15 @@ import ( "github.com/ucloud/ucloud-sdk-go/ucloud/auth" ) -// VPCClient is the client of VPC2.0 +// VPCClient is the client of VPC type VPCClient struct { *ucloud.Client } // NewClient will return a instance of VPCClient func NewClient(config *ucloud.Config, credential *auth.Credential) *VPCClient { - client := ucloud.NewClient(config, credential) + meta := ucloud.ClientMeta{Product: "VPC2.0"} + client := ucloud.NewClientWithMeta(config, credential, meta) return &VPCClient{ client, } diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/create_natgw.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/create_natgw.go new file mode 100644 index 000000000..f62f28b9f --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/create_natgw.go @@ -0,0 +1,78 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package vpc + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +// CreateNATGWRequest is request schema for CreateNATGW action +type CreateNATGWRequest struct { + request.CommonBase + + // [公共参数] 项目Id。不填写为默认项目,子帐号必须填写。 请参考[GetProjectList接口](../summary/get_project_list.html) + // ProjectId *string `required:"false"` + + // [公共参数] 地域。 参见 [地域和可用区列表](../summary/regionlist.html) + // Region *string `required:"true"` + + // NAT网关绑定的EIPId + EIPIds []string `required:"true"` + + // NAT网关绑定的防火墙Id + FirewallId *string `required:"true"` + + // 白名单开关标记。0表示关闭,1表示开启。默认为0 + IfOpen *int `required:"false"` + + // NAT网关名称 + NATGWName *string `required:"true"` + + // 备注。默认为空 + Remark *string `required:"false"` + + // NAT网关绑定的子网Id + SubnetworkIds []string `required:"true"` + + // 业务组。默认为空 + Tag *string `required:"false"` + + // NAT网关所属的VPC Id。默认为Default VPC Id + VPCId *string `required:"false"` +} + +// CreateNATGWResponse is response schema for CreateNATGW action +type CreateNATGWResponse struct { + response.CommonBase + + // 申请到的NATGateWay Id + NATGWId string +} + +// NewCreateNATGWRequest will create request of CreateNATGW action. +func (c *VPCClient) NewCreateNATGWRequest() *CreateNATGWRequest { + req := &CreateNATGWRequest{} + + // setup request with client config + c.Client.SetupRequest(req) + + // setup retryable with default retry policy (retry for non-create action and common error) + req.SetRetryable(false) + return req +} + +// CreateNATGW - 创建NAT网关 +func (c *VPCClient) CreateNATGW(req *CreateNATGWRequest) (*CreateNATGWResponse, error) { + var err error + var res CreateNATGWResponse + + reqCopier := *req + + err = c.Client.InvokeAction("CreateNATGW", &reqCopier, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/create_natgw_policy.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/create_natgw_policy.go new file mode 100644 index 000000000..008e01b50 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/create_natgw_policy.go @@ -0,0 +1,75 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package vpc + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +// CreateNATGWPolicyRequest is request schema for CreateNATGWPolicy action +type CreateNATGWPolicyRequest struct { + request.CommonBase + + // [公共参数] 项目Id。不填写为默认项目,子帐号必须填写。 请参考[GetProjectList接口](../summary/get_project_list.html) + // ProjectId *string `required:"false"` + + // [公共参数] 地域。 参见 [地域和可用区列表](../summary/regionlist.html) + // Region *string `required:"true"` + + // 目标IP。填写对应的目标IP地址 + DstIP *string `required:"true"` + + // 目标端口。可填写固定端口,也可填写端口范围。支持的端口范围为1-65535 + DstPort *string `required:"true"` + + // NAT网关Id + NATGWId *string `required:"true"` + + // 转发策略名称。默认为空 + PolicyName *string `required:"false"` + + // 协议类型。枚举值为:TCP、UDP + Protocol *string `required:"true"` + + // 源IP。填写对应的EIP Id + SrcEIPId *string `required:"true"` + + // 源端口。可填写固定端口,也可填写端口范围。支持的端口范围为1-65535 + SrcPort *string `required:"true"` +} + +// CreateNATGWPolicyResponse is response schema for CreateNATGWPolicy action +type CreateNATGWPolicyResponse struct { + response.CommonBase + + // 创建时分配的策略Id + PolicyId string +} + +// NewCreateNATGWPolicyRequest will create request of CreateNATGWPolicy action. +func (c *VPCClient) NewCreateNATGWPolicyRequest() *CreateNATGWPolicyRequest { + req := &CreateNATGWPolicyRequest{} + + // setup request with client config + c.Client.SetupRequest(req) + + // setup retryable with default retry policy (retry for non-create action and common error) + req.SetRetryable(false) + return req +} + +// CreateNATGWPolicy - 添加NAT网关端口转发规则 +func (c *VPCClient) CreateNATGWPolicy(req *CreateNATGWPolicyRequest) (*CreateNATGWPolicyResponse, error) { + var err error + var res CreateNATGWPolicyResponse + + reqCopier := *req + + err = c.Client.InvokeAction("CreateNATGWPolicy", &reqCopier, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/delete_natgw.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/delete_natgw.go new file mode 100644 index 000000000..258ad84b6 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/delete_natgw.go @@ -0,0 +1,57 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package vpc + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +// DeleteNATGWRequest is request schema for DeleteNATGW action +type DeleteNATGWRequest struct { + request.CommonBase + + // [公共参数] 项目Id。不填写为默认项目,子帐号必须填写。 请参考[GetProjectList接口](../summary/get_project_list.html) + // ProjectId *string `required:"false"` + + // [公共参数] 地域。 参见 [地域和可用区列表](../summary/regionlist.html) + // Region *string `required:"true"` + + // NAT网关Id + NATGWId *string `required:"true"` + + // 是否释放绑定的EIP。true:解绑并释放;false:只解绑不释放。默认为false + ReleaseEip *bool `required:"false"` +} + +// DeleteNATGWResponse is response schema for DeleteNATGW action +type DeleteNATGWResponse struct { + response.CommonBase +} + +// NewDeleteNATGWRequest will create request of DeleteNATGW action. +func (c *VPCClient) NewDeleteNATGWRequest() *DeleteNATGWRequest { + req := &DeleteNATGWRequest{} + + // setup request with client config + c.Client.SetupRequest(req) + + // setup retryable with default retry policy (retry for non-create action and common error) + req.SetRetryable(true) + return req +} + +// DeleteNATGW - 删除NAT网关 +func (c *VPCClient) DeleteNATGW(req *DeleteNATGWRequest) (*DeleteNATGWResponse, error) { + var err error + var res DeleteNATGWResponse + + reqCopier := *req + + err = c.Client.InvokeAction("DeleteNATGW", &reqCopier, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/delete_natgw_policy.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/delete_natgw_policy.go new file mode 100644 index 000000000..3779d9d09 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/delete_natgw_policy.go @@ -0,0 +1,57 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package vpc + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +// DeleteNATGWPolicyRequest is request schema for DeleteNATGWPolicy action +type DeleteNATGWPolicyRequest struct { + request.CommonBase + + // [公共参数] 项目Id。不填写为默认项目,子帐号必须填写。 请参考[GetProjectList接口](../summary/get_project_list.html) + // ProjectId *string `required:"false"` + + // [公共参数] 地域。 参见 [地域和可用区列表](../summary/regionlist.html) + // Region *string `required:"true"` + + // NAT网关Id + NATGWId *string `required:"true"` + + // 端口转发规则Id + PolicyId *string `required:"true"` +} + +// DeleteNATGWPolicyResponse is response schema for DeleteNATGWPolicy action +type DeleteNATGWPolicyResponse struct { + response.CommonBase +} + +// NewDeleteNATGWPolicyRequest will create request of DeleteNATGWPolicy action. +func (c *VPCClient) NewDeleteNATGWPolicyRequest() *DeleteNATGWPolicyRequest { + req := &DeleteNATGWPolicyRequest{} + + // setup request with client config + c.Client.SetupRequest(req) + + // setup retryable with default retry policy (retry for non-create action and common error) + req.SetRetryable(true) + return req +} + +// DeleteNATGWPolicy - 删除NAT网关端口转发规则 +func (c *VPCClient) DeleteNATGWPolicy(req *DeleteNATGWPolicyRequest) (*DeleteNATGWPolicyResponse, error) { + var err error + var res DeleteNATGWPolicyResponse + + reqCopier := *req + + err = c.Client.InvokeAction("DeleteNATGWPolicy", &reqCopier, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/delete_white_list_resource.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/delete_white_list_resource.go new file mode 100644 index 000000000..dd7f08d22 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/delete_white_list_resource.go @@ -0,0 +1,57 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package vpc + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +// DeleteWhiteListResourceRequest is request schema for DeleteWhiteListResource action +type DeleteWhiteListResourceRequest struct { + request.CommonBase + + // [公共参数] 项目Id。不填写为默认项目,子帐号必须填写。 请参考[GetProjectList接口](../summary/get_project_list.html) + // ProjectId *string `required:"false"` + + // [公共参数] 地域。 参见 [地域和可用区列表](../summary/regionlist.html) + // Region *string `required:"true"` + + // NAT网关Id + NATGWId *string `required:"true"` + + // 删除白名单的资源Id + ResourceIds []string `required:"true"` +} + +// DeleteWhiteListResourceResponse is response schema for DeleteWhiteListResource action +type DeleteWhiteListResourceResponse struct { + response.CommonBase +} + +// NewDeleteWhiteListResourceRequest will create request of DeleteWhiteListResource action. +func (c *VPCClient) NewDeleteWhiteListResourceRequest() *DeleteWhiteListResourceRequest { + req := &DeleteWhiteListResourceRequest{} + + // setup request with client config + c.Client.SetupRequest(req) + + // setup retryable with default retry policy (retry for non-create action and common error) + req.SetRetryable(true) + return req +} + +// DeleteWhiteListResource - 删除NAT网关白名单列表 +func (c *VPCClient) DeleteWhiteListResource(req *DeleteWhiteListResourceRequest) (*DeleteWhiteListResourceResponse, error) { + var err error + var res DeleteWhiteListResourceResponse + + reqCopier := *req + + err = c.Client.InvokeAction("DeleteWhiteListResource", &reqCopier, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/describe_natgw.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/describe_natgw.go new file mode 100644 index 000000000..40d303174 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/describe_natgw.go @@ -0,0 +1,66 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package vpc + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +// DescribeNATGWRequest is request schema for DescribeNATGW action +type DescribeNATGWRequest struct { + request.CommonBase + + // [公共参数] 项目Id。不填写为默认项目,子帐号必须填写。 请参考[GetProjectList接口](../summary/get_project_list.html) + // ProjectId *string `required:"false"` + + // [公共参数] 地域。 参见 [地域和可用区列表](../summary/regionlist.html) + // Region *string `required:"true"` + + // 数据分页值。默认为20 + Limit *int `required:"false"` + + // NAT网关Id。默认为该项目下所有NAT网关 + NATGWIds []string `required:"false"` + + // 数据偏移量。默认为0 + Offset *int `required:"false"` +} + +// DescribeNATGWResponse is response schema for DescribeNATGW action +type DescribeNATGWResponse struct { + response.CommonBase + + // 查到的NATGW信息列表 + DataSet []NatGatewayDataSet + + // 满足条件的实例的总数 + TotalCount int +} + +// NewDescribeNATGWRequest will create request of DescribeNATGW action. +func (c *VPCClient) NewDescribeNATGWRequest() *DescribeNATGWRequest { + req := &DescribeNATGWRequest{} + + // setup request with client config + c.Client.SetupRequest(req) + + // setup retryable with default retry policy (retry for non-create action and common error) + req.SetRetryable(true) + return req +} + +// DescribeNATGW - 获取NAT网关信息 +func (c *VPCClient) DescribeNATGW(req *DescribeNATGWRequest) (*DescribeNATGWResponse, error) { + var err error + var res DescribeNATGWResponse + + reqCopier := *req + + err = c.Client.InvokeAction("DescribeNATGW", &reqCopier, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/describe_natgw_policy.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/describe_natgw_policy.go new file mode 100644 index 000000000..cd0b2b421 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/describe_natgw_policy.go @@ -0,0 +1,66 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package vpc + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +// DescribeNATGWPolicyRequest is request schema for DescribeNATGWPolicy action +type DescribeNATGWPolicyRequest struct { + request.CommonBase + + // [公共参数] 项目Id。不填写为默认项目,子帐号必须填写。 请参考[GetProjectList接口](../summary/get_project_list.html) + // ProjectId *string `required:"false"` + + // [公共参数] 地域。 参见 [地域和可用区列表](../summary/regionlist.html) + // Region *string `required:"true"` + + // 返回数据长度,默认为10000 + Limit *int `required:"false"` + + // NAT网关Id + NATGWId *string `required:"true"` + + // 列表起始位置偏移量,默认为0 + Offset *int `required:"false"` +} + +// DescribeNATGWPolicyResponse is response schema for DescribeNATGWPolicy action +type DescribeNATGWPolicyResponse struct { + response.CommonBase + + // 查到的NATGW 转发策略的详细信息 + DataSet []NATGWPolicyDataSet + + // 满足条件的转发策略总数 + TotalCount int +} + +// NewDescribeNATGWPolicyRequest will create request of DescribeNATGWPolicy action. +func (c *VPCClient) NewDescribeNATGWPolicyRequest() *DescribeNATGWPolicyRequest { + req := &DescribeNATGWPolicyRequest{} + + // setup request with client config + c.Client.SetupRequest(req) + + // setup retryable with default retry policy (retry for non-create action and common error) + req.SetRetryable(true) + return req +} + +// DescribeNATGWPolicy - 展示NAT网关端口转发规则 +func (c *VPCClient) DescribeNATGWPolicy(req *DescribeNATGWPolicyRequest) (*DescribeNATGWPolicyResponse, error) { + var err error + var res DescribeNATGWPolicyResponse + + reqCopier := *req + + err = c.Client.InvokeAction("DescribeNATGWPolicy", &reqCopier, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/describe_white_list_resource.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/describe_white_list_resource.go new file mode 100644 index 000000000..8d64a3eba --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/describe_white_list_resource.go @@ -0,0 +1,60 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package vpc + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +// DescribeWhiteListResourceRequest is request schema for DescribeWhiteListResource action +type DescribeWhiteListResourceRequest struct { + request.CommonBase + + // [公共参数] 项目id + // ProjectId *string `required:"true"` + + // [公共参数] 地域。 参见 [地域和可用区列表](../summary/regionlist.html) + // Region *string `required:"true"` + + // NAT网关的Id + NATGWIds []string `required:"true"` +} + +// DescribeWhiteListResourceResponse is response schema for DescribeWhiteListResource action +type DescribeWhiteListResourceResponse struct { + response.CommonBase + + // 白名单资源的详细信息,详见DescribeResourceWhiteListDataSet + DataSet []NatGWWhitelistDataSet + + // 上述DataSet总数量 + TotalCount int +} + +// NewDescribeWhiteListResourceRequest will create request of DescribeWhiteListResource action. +func (c *VPCClient) NewDescribeWhiteListResourceRequest() *DescribeWhiteListResourceRequest { + req := &DescribeWhiteListResourceRequest{} + + // setup request with client config + c.Client.SetupRequest(req) + + // setup retryable with default retry policy (retry for non-create action and common error) + req.SetRetryable(true) + return req +} + +// DescribeWhiteListResource - 展示NAT网关白名单资源列表 +func (c *VPCClient) DescribeWhiteListResource(req *DescribeWhiteListResourceRequest) (*DescribeWhiteListResourceResponse, error) { + var err error + var res DescribeWhiteListResourceResponse + + reqCopier := *req + + err = c.Client.InvokeAction("DescribeWhiteListResource", &reqCopier, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/enable_white_list.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/enable_white_list.go new file mode 100644 index 000000000..90f1fd499 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/enable_white_list.go @@ -0,0 +1,57 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package vpc + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +// EnableWhiteListRequest is request schema for EnableWhiteList action +type EnableWhiteListRequest struct { + request.CommonBase + + // [公共参数] 项目Id。不填写为默认项目,子帐号必须填写。 请参考[GetProjectList接口](../summary/get_project_list.html) + // ProjectId *string `required:"false"` + + // [公共参数] 地域。 参见 [地域和可用区列表](../summary/regionlist.html) + // Region *string `required:"true"` + + // 白名单开关标记。0:关闭;1:开启。默认为0 + IfOpen *int `required:"true"` + + // NAT网关Id + NATGWId *string `required:"true"` +} + +// EnableWhiteListResponse is response schema for EnableWhiteList action +type EnableWhiteListResponse struct { + response.CommonBase +} + +// NewEnableWhiteListRequest will create request of EnableWhiteList action. +func (c *VPCClient) NewEnableWhiteListRequest() *EnableWhiteListRequest { + req := &EnableWhiteListRequest{} + + // setup request with client config + c.Client.SetupRequest(req) + + // setup retryable with default retry policy (retry for non-create action and common error) + req.SetRetryable(true) + return req +} + +// EnableWhiteList - 修改NAT网关白名单开关 +func (c *VPCClient) EnableWhiteList(req *EnableWhiteListRequest) (*EnableWhiteListResponse, error) { + var err error + var res EnableWhiteListResponse + + reqCopier := *req + + err = c.Client.InvokeAction("EnableWhiteList", &reqCopier, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/get_available_resource_for_policy.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/get_available_resource_for_policy.go new file mode 100644 index 000000000..c3a8dd235 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/get_available_resource_for_policy.go @@ -0,0 +1,63 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package vpc + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +// GetAvailableResourceForPolicyRequest is request schema for GetAvailableResourceForPolicy action +type GetAvailableResourceForPolicyRequest struct { + request.CommonBase + + // [公共参数] 项目Id。不填写为默认项目,子帐号必须填写。 请参考[GetProjectList接口](../summary/get_project_list.html) + // ProjectId *string `required:"false"` + + // [公共参数] 地域。 参见 [地域和可用区列表](../summary/regionlist.html) + // Region *string `required:"true"` + + // 返回数据长度,默认为10000 + Limit *int `required:"false"` + + // NAT网关Id + NATGWId *string `required:"true"` + + // 列表起始位置偏移量,默认为0 + Offset *int `required:"false"` +} + +// GetAvailableResourceForPolicyResponse is response schema for GetAvailableResourceForPolicy action +type GetAvailableResourceForPolicyResponse struct { + response.CommonBase + + // 支持资源类型的信息 + DataSet []GetAvailableResourceForPolicyDataSet +} + +// NewGetAvailableResourceForPolicyRequest will create request of GetAvailableResourceForPolicy action. +func (c *VPCClient) NewGetAvailableResourceForPolicyRequest() *GetAvailableResourceForPolicyRequest { + req := &GetAvailableResourceForPolicyRequest{} + + // setup request with client config + c.Client.SetupRequest(req) + + // setup retryable with default retry policy (retry for non-create action and common error) + req.SetRetryable(true) + return req +} + +// GetAvailableResourceForPolicy - 获取NAT网关可配置端口转发规则的资源信息 +func (c *VPCClient) GetAvailableResourceForPolicy(req *GetAvailableResourceForPolicyRequest) (*GetAvailableResourceForPolicyResponse, error) { + var err error + var res GetAvailableResourceForPolicyResponse + + reqCopier := *req + + err = c.Client.InvokeAction("GetAvailableResourceForPolicy", &reqCopier, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/get_available_resource_for_white_list.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/get_available_resource_for_white_list.go new file mode 100644 index 000000000..ea29920cb --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/get_available_resource_for_white_list.go @@ -0,0 +1,60 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package vpc + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +// GetAvailableResourceForWhiteListRequest is request schema for GetAvailableResourceForWhiteList action +type GetAvailableResourceForWhiteListRequest struct { + request.CommonBase + + // [公共参数] 项目Id。不填写为默认项目,子帐号必须填写。 请参考[GetProjectList接口](../summary/get_project_list.html) + // ProjectId *string `required:"false"` + + // [公共参数] 地域。 参见 [地域和可用区列表](../summary/regionlist.html) + // Region *string `required:"true"` + + // NAT网关Id + NATGWId *string `required:"true"` +} + +// GetAvailableResourceForWhiteListResponse is response schema for GetAvailableResourceForWhiteList action +type GetAvailableResourceForWhiteListResponse struct { + response.CommonBase + + // 返回白名单列表的详细信息 + DataSet []GetAvailableResourceForWhiteListDataSet + + // 白名单资源列表的总的个数 + TotalCount int +} + +// NewGetAvailableResourceForWhiteListRequest will create request of GetAvailableResourceForWhiteList action. +func (c *VPCClient) NewGetAvailableResourceForWhiteListRequest() *GetAvailableResourceForWhiteListRequest { + req := &GetAvailableResourceForWhiteListRequest{} + + // setup request with client config + c.Client.SetupRequest(req) + + // setup retryable with default retry policy (retry for non-create action and common error) + req.SetRetryable(true) + return req +} + +// GetAvailableResourceForWhiteList - 获取NAT网关可添加白名单的资源 +func (c *VPCClient) GetAvailableResourceForWhiteList(req *GetAvailableResourceForWhiteListRequest) (*GetAvailableResourceForWhiteListResponse, error) { + var err error + var res GetAvailableResourceForWhiteListResponse + + reqCopier := *req + + err = c.Client.InvokeAction("GetAvailableResourceForWhiteList", &reqCopier, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/list_subnet_for_natgw.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/list_subnet_for_natgw.go new file mode 100644 index 000000000..f38c6ac75 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/list_subnet_for_natgw.go @@ -0,0 +1,57 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package vpc + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +// ListSubnetForNATGWRequest is request schema for ListSubnetForNATGW action +type ListSubnetForNATGWRequest struct { + request.CommonBase + + // [公共参数] 项目Id。不填写为默认项目,子帐号必须填写。 请参考[GetProjectList接口](../summary/get_project_list.html) + // ProjectId *string `required:"false"` + + // [公共参数] 地域。 参见 [地域和可用区列表](../summary/regionlist.html) + // Region *string `required:"true"` + + // NAT网关所属VPC Id。默认值为Default VPC Id + VPCId *string `required:"false"` +} + +// ListSubnetForNATGWResponse is response schema for ListSubnetForNATGW action +type ListSubnetForNATGWResponse struct { + response.CommonBase + + // 具体参数请见NatgwSubnetDataSet + DataSet []NatgwSubnetDataSet +} + +// NewListSubnetForNATGWRequest will create request of ListSubnetForNATGW action. +func (c *VPCClient) NewListSubnetForNATGWRequest() *ListSubnetForNATGWRequest { + req := &ListSubnetForNATGWRequest{} + + // setup request with client config + c.Client.SetupRequest(req) + + // setup retryable with default retry policy (retry for non-create action and common error) + req.SetRetryable(true) + return req +} + +// ListSubnetForNATGW - 展示NAT网关可绑定的子网列表 +func (c *VPCClient) ListSubnetForNATGW(req *ListSubnetForNATGWRequest) (*ListSubnetForNATGWResponse, error) { + var err error + var res ListSubnetForNATGWResponse + + reqCopier := *req + + err = c.Client.InvokeAction("ListSubnetForNATGW", &reqCopier, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/set_gw_default_export.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/set_gw_default_export.go new file mode 100644 index 000000000..e0713d4d3 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/set_gw_default_export.go @@ -0,0 +1,60 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package vpc + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +// SetGwDefaultExportRequest is request schema for SetGwDefaultExport action +type SetGwDefaultExportRequest struct { + request.CommonBase + + // [公共参数] 项目Id。不填写为默认项目,子帐号必须填写。 请参考[GetProjectList接口](../summary/get_project_list.html) + // ProjectId *string `required:"false"` + + // [公共参数] 地域。 参见 [地域和可用区列表](../summary/regionlist.html) + // Region *string `required:"true"` + + // NAT网关绑定的EIP Id。ExportIp和ExportEipId必填一个 + ExportEipId *string `required:"false"` + + // NAT网关绑定的EIP。ExportIp和ExportEipId必填一个 + ExportIp *string `required:"false"` + + // NAT网关Id + NATGWId *string `required:"true"` +} + +// SetGwDefaultExportResponse is response schema for SetGwDefaultExport action +type SetGwDefaultExportResponse struct { + response.CommonBase +} + +// NewSetGwDefaultExportRequest will create request of SetGwDefaultExport action. +func (c *VPCClient) NewSetGwDefaultExportRequest() *SetGwDefaultExportRequest { + req := &SetGwDefaultExportRequest{} + + // setup request with client config + c.Client.SetupRequest(req) + + // setup retryable with default retry policy (retry for non-create action and common error) + req.SetRetryable(true) + return req +} + +// SetGwDefaultExport - 设置NAT网关的默认出口 +func (c *VPCClient) SetGwDefaultExport(req *SetGwDefaultExportRequest) (*SetGwDefaultExportResponse, error) { + var err error + var res SetGwDefaultExportResponse + + reqCopier := *req + + err = c.Client.InvokeAction("SetGwDefaultExport", &reqCopier, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_describe_white_list_resource_object_ip_info.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_describe_white_list_resource_object_ip_info.go new file mode 100644 index 000000000..2798b852d --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_describe_white_list_resource_object_ip_info.go @@ -0,0 +1,39 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package vpc + +/* +DescribeWhiteListResourceObjectIPInfo - DescribeWhiteListResource + +this model is auto created by ucloud code generater for open api, +you can also see https://docs.ucloud.cn/api for detail. +*/ +type DescribeWhiteListResourceObjectIPInfo struct { + + // natgw字符串 + GwType string + + // 白名单资源的内网IP + PrivateIP string + + // 白名单资源Id信息 + ResourceId string + + // 白名单资源名称 + ResourceName string + + // 白名单资源类型 + ResourceType string + + // 资源绑定的虚拟网卡的实例ID + SubResourceId string + + // 资源绑定的虚拟网卡的实例名称 + SubResourceName string + + // 资源绑定的虚拟网卡的类型 + SubResourceType string + + // 白名单资源所属VPCId + VPCId string +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_get_available_resource_for_policy_data_set.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_get_available_resource_for_policy_data_set.go new file mode 100644 index 000000000..295e4ab4f --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_get_available_resource_for_policy_data_set.go @@ -0,0 +1,21 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package vpc + +/* +GetAvailableResourceForPolicyDataSet - GetAvailableResourceForPolicy + +this model is auto created by ucloud code generater for open api, +you can also see https://docs.ucloud.cn/api for detail. +*/ +type GetAvailableResourceForPolicyDataSet struct { + + // 资源对应的内网Ip + PrivateIP string + + // 资源的Id + ResourceId string + + // 资源类型。"uhost":云主机; "upm",物理云主机; "hadoophost":hadoop节点; "fortresshost":堡垒机: "udockhost",容器 + ResourceType string +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_get_available_resource_for_white_list_data_set.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_get_available_resource_for_white_list_data_set.go new file mode 100644 index 000000000..7b1af27bc --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_get_available_resource_for_white_list_data_set.go @@ -0,0 +1,39 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package vpc + +/* +GetAvailableResourceForWhiteListDataSet - GetAvailableResourceForWhiteList + +this model is auto created by ucloud code generater for open api, +you can also see https://docs.ucloud.cn/api for detail. +*/ +type GetAvailableResourceForWhiteListDataSet struct { + + // 资源的内网Ip + PrivateIP string + + // 资源类型Id + ResourceId string + + // 资源名称 + ResourceName string + + // 资源类型。"uhost":云主机; "upm",物理云主机; "hadoophost":hadoop节点; "fortresshost":堡垒机: "udockhost",容器 + ResourceType string + + // 资源绑定的虚拟网卡的实例ID + SubResouceId string + + // 资源绑定的虚拟网卡的实例类型 + SubResouceType string + + // 资源绑定的虚拟网卡的实例名称 + SubResourceName string + + // 资源所属子网Id + SubnetworkId string + + // 资源所属VPCId + VPCId string +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_nat_gateway_data_set.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_nat_gateway_data_set.go new file mode 100644 index 000000000..022792727 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_nat_gateway_data_set.go @@ -0,0 +1,45 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package vpc + +/* +NatGatewayDataSet - natgw的信息 + +this model is auto created by ucloud code generater for open api, +you can also see https://docs.ucloud.cn/api for detail. +*/ +type NatGatewayDataSet struct { + + // natgw创建时间 + CreateTime int + + // 绑定的防火墙Id + FirewallId string + + // 绑定的EIP 信息 + IPSet []NatGatewayIPSet + + // natgw id + NATGWId string + + // natgw名称 + NATGWName string + + // 转发策略Id + PolicyId []string + + // 备注 + Remark string + + // 子网 Id + SubnetSet []NatGatewaySubnetSet + + // 业务组 + Tag string + + // 所属VPC Id + VPCId string + + // 所属VPC 信息 + VPCInfo string +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_nat_gateway_ip_set.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_nat_gateway_ip_set.go new file mode 100644 index 000000000..85cfac2f5 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_nat_gateway_ip_set.go @@ -0,0 +1,27 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package vpc + +/* +NatGatewayIPSet - IPSet信息 + +this model is auto created by ucloud code generater for open api, +you can also see https://docs.ucloud.cn/api for detail. +*/ +type NatGatewayIPSet struct { + + // 带宽 + Bandwidth int + + // EIP带宽类型 + BandwidthType string + + // 外网IP的 EIPId + EIPId string + + // 外网IP信息 + IPResInfo []NatGWIPResInfo + + // 权重为100的为出口 + Weight int +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_nat_gateway_subnet_set.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_nat_gateway_subnet_set.go new file mode 100644 index 000000000..d8b919543 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_nat_gateway_subnet_set.go @@ -0,0 +1,21 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package vpc + +/* +NatGatewaySubnetSet - natgw里面的子网信息 + +this model is auto created by ucloud code generater for open api, +you can also see https://docs.ucloud.cn/api for detail. +*/ +type NatGatewaySubnetSet struct { + + // 子网网段 + Subnet string + + // 子网名字 + SubnetName string + + // 子网id + SubnetworkId string +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_nat_gw_ip_res_info.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_nat_gw_ip_res_info.go new file mode 100644 index 000000000..dd2694fe6 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_nat_gw_ip_res_info.go @@ -0,0 +1,18 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package vpc + +/* +NatGWIPResInfo - IP信息 + +this model is auto created by ucloud code generater for open api, +you can also see https://docs.ucloud.cn/api for detail. +*/ +type NatGWIPResInfo struct { + + // 外网IP + EIP string + + // IP的运营商信息 + OperatorName string +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_nat_gw_whitelist_data_set.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_nat_gw_whitelist_data_set.go new file mode 100644 index 000000000..b4ec7a39a --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_nat_gw_whitelist_data_set.go @@ -0,0 +1,21 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package vpc + +/* +NatGWWhitelistDataSet - nat网关白名单数据 + +this model is auto created by ucloud code generater for open api, +you can also see https://docs.ucloud.cn/api for detail. +*/ +type NatGWWhitelistDataSet struct { + + // 白名单开关标记 + IfOpen int + + // NATGateWay Id + NATGWId string + + // 白名单详情 + ObjectIPInfo []DescribeWhiteListResourceObjectIPInfo +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_natgw_policy_data_set.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_natgw_policy_data_set.go new file mode 100644 index 000000000..4b476cb2b --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_natgw_policy_data_set.go @@ -0,0 +1,39 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package vpc + +/* +NATGWPolicyDataSet - DescribeNATGWPolicy + +this model is auto created by ucloud code generater for open api, +you can also see https://docs.ucloud.cn/api for detail. +*/ +type NATGWPolicyDataSet struct { + + // 目的地址 + DstIP string + + // 目的端口 + DstPort string + + // NAT网关Id + NATGWId string + + // 转发策略Id + PolicyId string + + // 转发策略名称 + PolicyName string + + // 协议类型 + Protocol string + + // 端口转发前端EIP + SrcEIP string + + // 端口转发前端EIP Id + SrcEIPId string + + // 源端口 + SrcPort string +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_natgw_subnet_data_set.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_natgw_subnet_data_set.go new file mode 100644 index 000000000..5700c1f4f --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/types_natgw_subnet_data_set.go @@ -0,0 +1,27 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package vpc + +/* +NatgwSubnetDataSet - natgw可以绑定的子网 + +this model is auto created by ucloud code generater for open api, +you can also see https://docs.ucloud.cn/api for detail. +*/ +type NatgwSubnetDataSet struct { + + // 是否绑定NATGW + HasNATGW bool + + // 掩码 + Netmask string + + // 子网网段 + Subnet string + + // 子网id + SubnetId string + + // 子网名字 + SubnetName string +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/update_natgw_policy.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/update_natgw_policy.go new file mode 100644 index 000000000..8dee917c0 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/update_natgw_policy.go @@ -0,0 +1,75 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package vpc + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +// UpdateNATGWPolicyRequest is request schema for UpdateNATGWPolicy action +type UpdateNATGWPolicyRequest struct { + request.CommonBase + + // [公共参数] 项目Id。不填写为默认项目,子帐号必须填写。 请参考[GetProjectList接口](../summary/get_project_list.html) + // ProjectId *string `required:"false"` + + // [公共参数] 地域。 参见 [地域和可用区列表](../summary/regionlist.html) + // Region *string `required:"true"` + + // 目标IP。填写对饮的目标IP地址 + DstIP *string `required:"true"` + + // 目标端口。可填写固定端口,也可填写端口范围。支持的端口范围为1-65535 + DstPort *string `required:"true"` + + // NAT网关Id + NATGWId *string `required:"true"` + + // 转发策略Id + PolicyId *string `required:"true"` + + // 转发策略名称。默认为空 + PolicyName *string `required:"false"` + + // 协议类型。枚举值为:TCP 、 UDP + Protocol *string `required:"true"` + + // 源IP。填写对应的EIP Id + SrcEIPId *string `required:"true"` + + // 源端口。可填写固定端口,也可填写端口范围。支持的端口范围为1-6553 + SrcPort *string `required:"true"` +} + +// UpdateNATGWPolicyResponse is response schema for UpdateNATGWPolicy action +type UpdateNATGWPolicyResponse struct { + response.CommonBase +} + +// NewUpdateNATGWPolicyRequest will create request of UpdateNATGWPolicy action. +func (c *VPCClient) NewUpdateNATGWPolicyRequest() *UpdateNATGWPolicyRequest { + req := &UpdateNATGWPolicyRequest{} + + // setup request with client config + c.Client.SetupRequest(req) + + // setup retryable with default retry policy (retry for non-create action and common error) + req.SetRetryable(true) + return req +} + +// UpdateNATGWPolicy - 更新NAT网关端口转发规则 +func (c *VPCClient) UpdateNATGWPolicy(req *UpdateNATGWPolicyRequest) (*UpdateNATGWPolicyResponse, error) { + var err error + var res UpdateNATGWPolicyResponse + + reqCopier := *req + + err = c.Client.InvokeAction("UpdateNATGWPolicy", &reqCopier, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/update_natgw_subnet.go b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/update_natgw_subnet.go new file mode 100644 index 000000000..31178e5a2 --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/services/vpc/update_natgw_subnet.go @@ -0,0 +1,57 @@ +// Code is generated by ucloud-model, DO NOT EDIT IT. + +package vpc + +import ( + "github.com/ucloud/ucloud-sdk-go/ucloud/request" + "github.com/ucloud/ucloud-sdk-go/ucloud/response" +) + +// UpdateNATGWSubnetRequest is request schema for UpdateNATGWSubnet action +type UpdateNATGWSubnetRequest struct { + request.CommonBase + + // [公共参数] 项目Id。不填写为默认项目,子帐号必须填写。 请参考[GetProjectList接口](../summary/get_project_list.html) + // ProjectId *string `required:"false"` + + // [公共参数] 地域。 参见 [地域和可用区列表](../summary/regionlist.html) + // Region *string `required:"true"` + + // NAT网关Id + NATGWId *string `required:"true"` + + // NAT网关绑定的子网Id + SubnetworkIds []string `required:"true"` +} + +// UpdateNATGWSubnetResponse is response schema for UpdateNATGWSubnet action +type UpdateNATGWSubnetResponse struct { + response.CommonBase +} + +// NewUpdateNATGWSubnetRequest will create request of UpdateNATGWSubnet action. +func (c *VPCClient) NewUpdateNATGWSubnetRequest() *UpdateNATGWSubnetRequest { + req := &UpdateNATGWSubnetRequest{} + + // setup request with client config + c.Client.SetupRequest(req) + + // setup retryable with default retry policy (retry for non-create action and common error) + req.SetRetryable(true) + return req +} + +// UpdateNATGWSubnet - 更新NAT网关绑定的子网 +func (c *VPCClient) UpdateNATGWSubnet(req *UpdateNATGWSubnetRequest) (*UpdateNATGWSubnetResponse, error) { + var err error + var res UpdateNATGWSubnetResponse + + reqCopier := *req + + err = c.Client.InvokeAction("UpdateNATGWSubnet", &reqCopier, &res) + if err != nil { + return &res, err + } + + return &res, nil +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/auth/credential.go b/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/auth/credential.go index 05ff2409c..79c04c33f 100644 --- a/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/auth/credential.go +++ b/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/auth/credential.go @@ -9,7 +9,6 @@ import ( "io" "net/url" "sort" - "strings" ) // Credential is the information of credential keys @@ -25,32 +24,44 @@ func NewCredential() Credential { // CreateSign will encode query string to credential signature. func (c *Credential) CreateSign(query string) string { - // replace "=" "&" - str := strings.Replace(query, "&", "", -1) - str = strings.Replace(str, "=", "", -1) - - // crypto by SHA1 - strUnescaped, _ := url.QueryUnescape(str) - h := sha1.New() - s := strUnescaped + c.PrivateKey - io.WriteString(h, s) - bs := h.Sum(nil) - result := hex.EncodeToString(bs) - - return result + urlValues, err := url.ParseQuery(query) + if err != nil { + return "" + } + urlValues.Set("PublicKey", c.PublicKey) + return c.verifyAc(urlValues) } // BuildCredentialedQuery will build query string with signature query param. -func (c *Credential) BuildCredentialedQuery(query map[string]string) string { - var queryList []string - for k, v := range query { - queryList = append(queryList, k+"="+url.QueryEscape(v)) +func (c *Credential) BuildCredentialedQuery(params map[string]string) string { + urlValues := url.Values{} + for k, v := range params { + urlValues.Set(k, v) } - queryList = append(queryList, "PublicKey="+url.QueryEscape(c.PublicKey)) - sort.Strings(queryList) - queryString := strings.Join(queryList, "&") - - sign := c.CreateSign(queryString) - queryString = queryString + "&Signature=" + sign - return queryString + urlValues.Set("PublicKey", c.PublicKey) + urlValues.Set("Signature", c.verifyAc(urlValues)) + return urlValues.Encode() +} + +func (c *Credential) verifyAc(urlValues url.Values) string { + // sort keys + var keys []string + for k := range urlValues { + keys = append(keys, k) + } + sort.Strings(keys) + + signQuery := "" + for _, k := range keys { + signQuery += k + urlValues.Get(k) + } + signQuery += c.PrivateKey + return encodeSha1(signQuery) +} + +func encodeSha1(s string) string { + h := sha1.New() + _, _ = io.WriteString(h, s) + bs := h.Sum(nil) + return hex.EncodeToString(bs) } diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/client.go b/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/client.go index a2e2cc989..eedb56d05 100644 --- a/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/client.go +++ b/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/client.go @@ -16,6 +16,10 @@ import ( "github.com/ucloud/ucloud-sdk-go/ucloud/response" ) +type ClientMeta struct { + Product string +} + // Client 客户端 type Client struct { // configurations @@ -31,6 +35,9 @@ type Client struct { httpRequestHandlers []HttpRequestHandler responseHandlers []ResponseHandler httpResponseHandlers []HttpResponseHandler + + // client information injection + meta ClientMeta } // NewClient will create an client of ucloud sdk @@ -38,6 +45,7 @@ func NewClient(config *Config, credential *auth.Credential) *Client { client := Client{ credential: credential, config: config, + meta: ClientMeta{}, } client.requestHandlers = append(client.requestHandlers, defaultRequestHandlers...) @@ -51,6 +59,12 @@ func NewClient(config *Config, credential *auth.Credential) *Client { return &client } +func NewClientWithMeta(config *Config, credential *auth.Credential, meta ClientMeta) *Client { + client := NewClient(config, credential) + client.meta = meta + return client +} + // SetHttpClient will setup a http client func (c *Client) SetHttpClient(httpClient http.Client) error { c.httpClient = httpClient @@ -67,6 +81,11 @@ func (c *Client) GetConfig() *Config { return c.config } +// GetMeta will return the meta data of client. +func (c *Client) GetMeta() ClientMeta { + return c.meta +} + // SetLogger will set the logger of client func (c *Client) SetLogger(logger log.Logger) { c.logger = logger @@ -131,6 +150,9 @@ func (c *Client) InvokeActionWithPatcher(action string, req request.Common, resp } err = c.unmarshalHTTPResponse(body, resp) + + uuid := httpResp.GetHeaders().Get(headerKeyRequestUUID) + resp.SetRequestUUID(uuid) } // use response middle to build and convert response when response has been created. diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/config.go b/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/config.go index 2b79bc119..a8f3fc507 100644 --- a/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/config.go +++ b/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/config.go @@ -4,8 +4,14 @@ import ( "time" "github.com/ucloud/ucloud-sdk-go/ucloud/log" + "github.com/ucloud/ucloud-sdk-go/ucloud/version" ) +// Version is the version of sdk +const Version = version.Version + +const headerKeyRequestUUID = "X-UCLOUD-REQUEST-UUID" + // Config is the config of ucloud sdk, use for setting up client type Config struct { // Region is the region of backend service diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/request/common.go b/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/request/common.go index 62bddd859..eb17917f2 100644 --- a/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/request/common.go +++ b/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/request/common.go @@ -59,7 +59,6 @@ type CommonBase struct { retryCount int timeout time.Duration requestTime time.Time - requestUUID string } // SetRetryCount will set retry count of request diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/request/encoder.go b/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/request/encoder.go index f6c78f39d..c06816707 100644 --- a/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/request/encoder.go +++ b/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/request/encoder.go @@ -1,12 +1,18 @@ package request import ( + "encoding/base64" "errors" "fmt" "reflect" "strconv" ) +// ToBase64Query will encode a wrapped string as base64 wrapped string +func ToBase64Query(s *string) *string { + return String(base64.StdEncoding.EncodeToString([]byte(StringValue(s)))) +} + // ToQueryMap will convert a request to string map func ToQueryMap(req Common) (map[string]string, error) { v := reflect.ValueOf(req) diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/request/schema.go b/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/request/schema.go new file mode 100644 index 000000000..dfd09163f --- /dev/null +++ b/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/request/schema.go @@ -0,0 +1,70 @@ +package request + +import ( + "time" +) + +// String will return a pointer to string +func String(val string) *string { + return &val +} + +// StringValue will return a string from string pointer +func StringValue(ptr *string) string { + if ptr != nil { + return *ptr + } + return "" +} + +// Int will return a pointer to int +func Int(val int) *int { + return &val +} + +// IntValue will return a int from int pointer +func IntValue(ptr *int) int { + if ptr != nil { + return *ptr + } + return 0 +} + +// Bool will return a pointer to bool +func Bool(val bool) *bool { + return &val +} + +// BoolValue will return a bool from bool pointer +func BoolValue(ptr *bool) bool { + if ptr != nil { + return *ptr + } + return false +} + +// Float64 will return a pointer to float64 +func Float64(val float64) *float64 { + return &val +} + +// Float64Value will return a float64 from float64 pointer +func Float64Value(ptr *float64) float64 { + if ptr != nil { + return *ptr + } + return 0.0 +} + +// TimeDuration will return a pointer to time.Duration +func TimeDuration(val time.Duration) *time.Duration { + return &val +} + +// TimeDurationValue will return a time.Duration from a time.Duration pointer +func TimeDurationValue(ptr *time.Duration) time.Duration { + if ptr != nil { + return *ptr + } + return 0 +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/response/common.go b/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/response/common.go index 1677a785c..6b175df8c 100644 --- a/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/response/common.go +++ b/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/response/common.go @@ -16,6 +16,9 @@ type Common interface { GetRequest() request.Common SetRequest(request.Common) + + SetRequestUUID(string) + GetRequestUUID() string } // CommonBase has common attribute and method, @@ -25,6 +28,8 @@ type CommonBase struct { RetCode int Message string + requestUUID string + request request.Common } @@ -53,3 +58,13 @@ func (c *CommonBase) GetRequest() request.Common { func (c *CommonBase) SetRequest(req request.Common) { c.request = req } + +// SetRequestUUID will set uuid of request +func (c *CommonBase) SetRequestUUID(uuid string) { + c.requestUUID = uuid +} + +// GetRequestUUID will get uuid of request +func (c *CommonBase) GetRequestUUID() string { + return c.requestUUID +} diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/schema.go b/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/schema.go index 26ffec2de..cca0cceed 100644 --- a/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/schema.go +++ b/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/schema.go @@ -1,75 +1,18 @@ package ucloud import ( - "time" - - "github.com/ucloud/ucloud-sdk-go/ucloud/version" + "github.com/ucloud/ucloud-sdk-go/ucloud/request" ) -// Version is the version of sdk -const Version = version.Version - -// String will return a pointer to string -func String(val string) *string { - return &val -} - -// StringValue will return a string from string pointer -func StringValue(ptr *string) string { - if ptr != nil { - return *ptr - } - return "" -} - -// Int will return a pointer to int -func Int(val int) *int { - return &val -} - -// IntValue will return a int from int pointer -func IntValue(ptr *int) int { - if ptr != nil { - return *ptr - } - return 0 -} - -// Bool will return a pointer to bool -func Bool(val bool) *bool { - return &val -} - -// BoolValue will return a bool from bool pointer -func BoolValue(ptr *bool) bool { - if ptr != nil { - return *ptr - } - return false -} - -// Float64 will return a pointer to float64 -func Float64(val float64) *float64 { - return &val -} - -// Float64Value will return a float64 from float64 pointer -func Float64Value(ptr *float64) float64 { - if ptr != nil { - return *ptr - } - return 0.0 -} - -// TimeDuration will return a pointer to time.Duration -func TimeDuration(val time.Duration) *time.Duration { - return &val -} - -// TimeDurationValue will return a time.Duration from a time.Duration pointer -func TimeDurationValue(ptr *time.Duration) time.Duration { - if ptr != nil { - return *ptr - } - return 0 -} +var ( + String = request.String + StringValue = request.StringValue + Int = request.Int + IntValue = request.IntValue + Bool = request.Bool + BoolValue = request.BoolValue + Float64 = request.Float64 + Float64Value = request.Float64Value + TimeDuration = request.TimeDuration + TimeDurationValue = request.TimeDurationValue +) diff --git a/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/version/version.go b/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/version/version.go index c067977df..b81e4b8d1 100644 --- a/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/version/version.go +++ b/vendor/github.com/ucloud/ucloud-sdk-go/ucloud/version/version.go @@ -4,4 +4,4 @@ Package version is the version of sdk package version // Version see also semantic version: https://semver.org/ -const Version = "0.8.7" +const Version = "0.11.1" diff --git a/vendor/github.com/ufilesdk-dev/ufile-gosdk/.gitignore b/vendor/github.com/ufilesdk-dev/ufile-gosdk/.gitignore new file mode 100644 index 000000000..f3d3ced63 --- /dev/null +++ b/vendor/github.com/ufilesdk-dev/ufile-gosdk/.gitignore @@ -0,0 +1,4 @@ +example/config.json +example/*.txt +*.exe + diff --git a/vendor/github.com/ufilesdk-dev/ufile-gosdk/README.md b/vendor/github.com/ufilesdk-dev/ufile-gosdk/README.md new file mode 100644 index 000000000..bb331efbb --- /dev/null +++ b/vendor/github.com/ufilesdk-dev/ufile-gosdk/README.md @@ -0,0 +1,71 @@ +# UCloud 对象存储 SDK GoDoc +> Modules are interface and implementation. +> The best modules are where interface is much simpler than implementation. +> **By: John Ousterhout** + +## UFile 对象存储基本概念 +在对象存储系统中,存储空间(Bucket)是文件(File)的组织管理单位,文件(File)是存储空间的逻辑存储单元。对于每个账号,该账号里存放的每个文件都有唯一的一对存储空间(Bucket)与键(Key)作为标识。我们可以把 Bucket 理解成一类文件的集合,Key 理解成文件名。由于每个 Bucket 需要配置和权限不同,每个账户里面会有多个 Bucket。在 UFile 里面,Bucket 主要分为公有和私有两种,公有 Bucket 里面的文件可以对任何人开放,私有 Bucket 需要配置对应访问签名才能访问。 + +### 签名 +本 SDK 接口是基于 HTTP 的,为了连接的安全性,UFile 使用 HMAC SHA1 对每个连接进行签名校验。使用本 SDK 可以忽略签名相关的算法过程,只要把公私钥写入到配置文件里面(注意不要传到版本控制里面),读取并传给 UFileRequest 里面的 New 方法即可。 +签名相关的算法与详细实现请见 [Auth 模块](auth.go) + +## 安装 +`go get github.com/ufilesdk-dev/ufile-gosdk` + +### 执行测试 +`cd example; go run demo_file.go` + +## 功能列表 +### 文件操作相关功能 +[Put 上传](https://godoc.org/pkg/github.com/ufilesdk-dev/ufile-gosdk/#UFileRequest.PutFile) +[Post 上传](https://godoc.org/pkg/github.com/ufilesdk-dev/ufile-gosdk/#UFileRequest.PostFile) +分片上传 [同步分片上传](https://godoc.org/pkg/github.com/ufilesdk-dev/ufile-gosdk/#UFileRequest.MPut),[异步分片上传](https://godoc.org/pkg/github.com/ufilesdk-dev/ufile-gosdk/#UFileRequest.AsyncMPut) +手动分片上传,[步骤一](https://godoc.org/pkg/github.com/ufilesdk-dev/ufile-gosdk/#UFileRequest.InitiateMultipartUpload),[步骤二](https://godoc.org/pkg/github.com/ufilesdk-dev/ufile-gosdk/#UFileRequest.UploadPart),[步骤三](https://godoc.org/pkg/github.com/ufilesdk-dev/ufile-gosdk/#UFileRequest.FinishMultipartUpload)。[取消分片上传](https://godoc.org/pkg/github.com/ufilesdk-dev/ufile-gosdk/#UFileRequest.AbortMultipartUpload) +[文件秒传](https://godoc.org/pkg/github.com/ufilesdk-dev/ufile-gosdk/#UFileRequest.UploadHit) +[获取文件列表](https://godoc.org/pkg/github.com/ufilesdk-dev/ufile-gosdk/#UFileRequest.PrefixFileList) +[获取私有空间下载地址](https://godoc.org/pkg/github.com/ufilesdk-dev/ufile-gosdk/#UFileRequest.GetPrivateURL),[获取公有空间下载地址](https://godoc.org/pkg/github.com/ufilesdk-dev/ufile-gosdk/#UFileRequest.GetPublicURL)。 +[删除文件](https://godoc.org/pkg/github.com/ufilesdk-dev/ufile-gosdk/#UFileRequest.DeleteFile) +[查看文件信息](https://godoc.org/pkg/github.com/ufilesdk-dev/ufile-gosdk/#UFileRequest.HeadFile) +[下载文件](https://godoc.org/pkg/github.com/ufilesdk-dev/ufile-gosdk/#UFileRequest.DownloadFile) +[比对本地与远程文件的 Etag](https://godoc.org/pkg/github.com/ufilesdk-dev/ufile-gosdk/#UFileRequest.CompareFileEtag) +[Put 带回调上传](https://godoc.org/pkg/github.com/ufilesdk-dev/ufile-gosdk/#UFileRequest.PutFileWithPolicy) +[同步分片上传-带回调](https://godoc.org/pkg/github.com/ufilesdk-dev/ufile-gosdk/#UFileRequest.MPutWithPolicy), +[异步分片上传-带回调](https://godoc.org/pkg/github.com/ufilesdk-dev/ufile-gosdk/#UFileRequest.AsyncMPutWithPolicy) + +### Bucket 操作相关功能 +[创建 bucket](https://godoc.org/pkg/github.com/ufilesdk-dev/ufile-gosdk/#UFileRequest.CreateBucket) +[删除 bucket](https://godoc.org/pkg/github.com/ufilesdk-dev/ufile-gosdk/#UFileRequest.DeleteBucket) +[获取 bucket 列表](https://godoc.org/pkg/github.com/ufilesdk-dev/ufile-gosdk/#UFileRequest.DescribeBucket) +[修改 bucket](https://godoc.org/pkg/github.com/ufilesdk-dev/ufile-gosdk/#UFileRequest.UpdateBucket) + +### 签名构造 +[构造文件管理签名](https://godoc.org/pkg/github.com/ufilesdk-dev/ufile-gosdk/#Auth.Authorization) +[构造私有空间下载签名](https://godoc.org/pkg/github.com/ufilesdk-dev/ufile-gosdk/#Auth.AuthorizationPrivateURL) +[构造 bucket 管理签名](https://godoc.org/pkg/github.com/ufilesdk-dev/ufile-gosdk/#Auth.AuthorizationBucketMgr) + +## 示例代码 +SDK 主要分为两个模块,一个是 bucket 管理,一个是 file 管理。使用对象存储你需要频繁的调用 file 管理相关的接口,bucket 管理用到的地方不会太频繁。以下是用 SDK 上传一个文件的例子: +```go +import ufsdk "github.com/ufilesdk-dev/ufile-gosdk" +config, err := ufsdk.LoadConfig(configFile) +if err != nil { + panic(err.Error()) +} +req := ufsdk.NewFileRequest(config, nil) +err = req.PutFile(filePath, keyName, "") +if err != nil { + fmt.Println("文件上传失败!!,错误信息为:", err.Error()) + //把 HTTP 详细的 HTTP response dump 出来 + fmt.Printf("%s\n",req.DumpResponse(true)) +} +``` +更详细的代码请参考 [example/demo_file.go](/example/demo_file.go) 和 [example/demo_bucket.go](example/demo_bucket.go) + +## 文档说明 +本 SDK 使用 [godoc](https://blog.golang.org/godoc-documenting-go-code) 约定的方法对每个 export 出来的接口进行注释。 +你可以直接访问生成好的[在线文档](https://godoc.org/github.com/ufilesdk-dev/ufile-gosdk)。 + +## 如何排错? +使用 UFileRequest 里面的方法对返回的 error 进行检查。如果不为 nil,调用 Error() 查看错误信息。调用 DumpResponse(true) 并获取返回值查看详细的 HTTP 返回值。 + diff --git a/vendor/github.com/ufilesdk-dev/ufile-gosdk/auth.go b/vendor/github.com/ufilesdk-dev/ufile-gosdk/auth.go new file mode 100644 index 000000000..82738d855 --- /dev/null +++ b/vendor/github.com/ufilesdk-dev/ufile-gosdk/auth.go @@ -0,0 +1,116 @@ +package ufsdk + +import ( + "crypto/hmac" + "crypto/sha1" + "encoding/base64" + "fmt" + "io" + "net/http" + "net/url" + "sort" + "strings" +) + +//Auth 构造签名的工具,使用本 SDK 你不需要关心 Auth 这一整个模块,以及它暴露出来的签名算法。 +//如果你希望自己封装 API 可以使用这里面的暴露出来的接口来填充 http authorization。 +type Auth struct { + publicKey string + privateKey string +} + +//NewAuth 构造一个新的签名工具,传入你的公钥匙和私钥。 +func NewAuth(publicKey, privateKey string) Auth { + return Auth{ + publicKey: publicKey, + privateKey: privateKey, + } +} + +//Authorization 构造一个主要用于上传文件的签名,返回 HMAC-Sh1 的签名字符串,可以直接填充到 HTTP authorization header 里面。 +//key 是传到 ufile 所使用的文件名,bucekt 是文件上传后存放的 bucket。 +//method 就是你当前这个 HTTP 请求的 Method。 +//header 就是你当前这个 HTTP 的 header,我们主要拿里面的 content-type 来做签名 hash 计算。 +func (A Auth) Authorization(method, bucket, key string, header http.Header) string { + var sigData string + method = strings.ToUpper(method) + + md5 := header.Get("Content-MD5") + contentType := header.Get("Content-Type") + date := header.Get("Date") + + sigData = method + "\n" + md5 + "\n" + contentType + "\n" + date + "\n" + resource := "/" + bucket + "/" + key + sigData += resource + + signature := A.signature(sigData) + + return "UCloud " + A.publicKey + ":" + signature +} + +//AuthorizationPrivateURL 构造私有空间文件下载链接的签名,其中 expires 是当前的时间加上一个过期的时间,再转为字符串。格式是 unix time second. +//其他的参数含义和 Authoriazation 函数一样。 +//有时我们需要把签名后的 URL 直接拿来用,header 参数可以直接构造一个空的 http.Header{} 传入即可。 +func (A Auth) AuthorizationPrivateURL(method, bucket, key, expires string, header http.Header) (string, string) { + var sigData string + method = strings.ToUpper(method) + md5 := header.Get("Content-MD5") + contentType := header.Get("Content-Type") + + sigData = method + "\n" + md5 + "\n" + contentType + "\n" + expires + "\n" + resource := "/" + bucket + "/" + key + sigData += resource + + signature := A.signature(sigData) + + return signature, A.publicKey +} + +//AuthorizationPolicy 构造支持回调策略的签名,policy 是经过 base64 编码后的 json string。 +//本签名函数就是多了一个 policy 字段,其他的参数和 Authoriazation 一样。 +func (A Auth) AuthorizationPolicy(method, bucket, key, policy string, header http.Header) string { + var sigData string + method = strings.ToUpper(method) + + md5 := header.Get("Content-MD5") + contentType := header.Get("Content-Type") + date := header.Get("Date") + + sigData = method + "\n" + md5 + "\n" + contentType + "\n" + date + "\n" + resource := "/" + bucket + "/" + key + sigData += resource + sigData += policy + + signature := A.signature(sigData) + + return "UCloud " + A.publicKey + ":" + signature + ":" + policy +} + +func (A Auth) signature(data string) string { + mac := hmac.New(sha1.New, []byte(A.privateKey)) + mac.Write([]byte(data)) + + return base64.StdEncoding.EncodeToString(mac.Sum(nil)) +} + +//AuthorizationBucketMgr 生成用于管理 bucket 的签名。 +func (A Auth) AuthorizationBucketMgr(query url.Values) string { + query.Add("PublicKey", A.publicKey) + + var signstring string + var keys []string + for k := range query { + keys = append(keys, k) + } + sort.Strings(keys) + for _, k := range keys { + signstring += k + query.Get(k) //Get first value + } + signstring += A.privateKey + + h := sha1.New() + io.WriteString(h, signstring) + + query.Add("Signature", fmt.Sprintf("%x", h.Sum(nil))) + return query.Encode() +} diff --git a/vendor/github.com/ufilesdk-dev/ufile-gosdk/bucket.go b/vendor/github.com/ufilesdk-dev/ufile-gosdk/bucket.go new file mode 100644 index 000000000..14cae238a --- /dev/null +++ b/vendor/github.com/ufilesdk-dev/ufile-gosdk/bucket.go @@ -0,0 +1,183 @@ +package ufsdk + +import ( + "encoding/json" + "errors" + "net/http" + "net/url" + "strconv" +) + +type response interface { + Error() error +} + +//BucketResponse 用于 Bucket 模块返回的数据。 +type BucketResponse struct { + RetCode int `json:"RetCode,omitempty"` + Action string `json:"Action,omitempty"` + BucketName string `json:"BucketName,omitempty"` + BucketID string `json:"BucketId,omitempty"` + Message string `json:"Message,omitempty"` +} + +func (b BucketResponse) Error() error { + if b.RetCode != 0 { + return errors.New(b.Message) + } + return nil +} + +func (b BucketResponse) String() string { + return structPrettyStr(b) +} + +//DomainSet 用于 BucketDataSet 里面的 Domain 字段 +type DomainSet struct { + Src []string `json:"Src,omitempty"` + Cdn []string `json:"Cdn,omitempty"` + CustomSrc []string `json:"CustomSrc,omitempty"` + CustomCdn []string `json:"CustomCdn,omitempty"` +} + +//BucketDataSet 用于 BucketListResponse 里面的 DataSet 字段 +type BucketDataSet struct { + BucketName string `json:"BucketName,omitempty"` + BucketID string `json:"BucketId,omitempty"` + Domain DomainSet `json:"Domain,omitempty"` + Type string `json:"Type,omitempty"` + CreateTime int `json:"CreateTime,omitempty"` + ModifyTime int `json:"ModifyTime,omitempty"` + CdnDomainID []string `json:"CdnDomainId,omitempty"` + Biz string `json:"Biz,omitempty"` + Region string `json:"Region,omitempty"` + HasUserDomain int `json:"HasUserDomain,omitempty"` +} + +//BucketListResponse 用于 DescribeBucket 返回的数据。 +type BucketListResponse struct { + RetCode int `json:"RetCode,omitempty"` + Action string `json:"Action,omitempty"` + Message string `json:"Message,omitempty"` + DataSet []BucketDataSet `json:"DataSet,omitempty"` +} + +func (b BucketListResponse) Error() error { + if b.RetCode != 0 { + return errors.New(b.Message) + } + return nil +} + +//String 把 BucketListResponse 里面的字段格式化。 +func (b BucketListResponse) String() string { + return structPrettyStr(b) +} + +//CreateBucket 创建一个 bucket, bucketName 必须全部为小写字母,不能带符号和特殊字符。 +// +//region 表示 ufile 所在的可用区,目前支持北京,香港,广州,上海二,雅加达,洛杉矶。一下是可用区值的映射: +// +//北京 cn-bj +// +//广州 cn-gd +// +//可用区以控制台列出来的为准,更多可用区具体的值在 https://docs.ucloud.cn/api/summary/regionlist 查看。 +// +//bucketType 可以填 public(公有空间) 和 private(私有空间) +//projectID bucket 所在的项目 ID,可为空。 +func (u *UFileRequest) CreateBucket(bucketName, region, bucketType, projectID string) (bucket BucketResponse, err error) { + query := url.Values{} + query.Add("Action", "CreateBucket") + query.Add("BucketName", bucketName) + query.Add("Type", bucketType) + query.Add("Region", region) + + if projectID != "" { + query.Add("ProjectId", projectID) + } + + err = u.bucketRequest(query, &bucket) + return +} + +//DeleteBucket 删除一个 bucket,如果成功,status code 会返回 204 no-content +func (u *UFileRequest) DeleteBucket(bucketName, projectID string) (bucket BucketResponse, err error) { + query := url.Values{} + query.Add("Action", "DeleteBucket") + query.Add("BucketName", bucketName) + if projectID != "" { + query.Add("ProjectId", projectID) + } + + err = u.bucketRequest(query, &bucket) + return +} + +//UpdateBucket 更新一个 bucket,你可以改 bucket 的类型(私有或公有)和 项目 ID。 +//bucketType 填公有(public)或私有(private)。 +//projectID 没有可以填空("")。 +func (u *UFileRequest) UpdateBucket(bucketName, bucketType, projectID string) (bucket BucketResponse, err error) { + query := url.Values{} + query.Add("Action", "UpdateBucket") + query.Add("BucketName", bucketName) + query.Add("Type", bucketType) + if projectID != "" { + query.Add("ProjectId", projectID) + } + + err = u.bucketRequest(query, &bucket) + return +} + +//DescribeBucket 获取 bucket 的详细信息,如果 bucketName 为空,返回当前账号下所有的 bucket。 +//limit 是限制返回的 bucket 列表数量。 +//offset 是列表的偏移量,默认为 0。 +//projectID 可为空。 +func (u *UFileRequest) DescribeBucket(bucketName string, offset, limit int, projectID string) (list BucketListResponse, err error) { + query := url.Values{} + query.Add("Action", "DescribeBucket") + if bucketName != "" { + query.Add("BucketName", bucketName) + } + //offset default is 0 + query.Add("Offset", strconv.Itoa(offset)) + + if limit == 0 { + limit = 20 + } + query.Add("Limit", strconv.Itoa(limit)) + + if projectID != "" { + query.Add("ProjectId", projectID) + } + err = u.bucketRequest(query, &list) + return +} + +func (u *UFileRequest) bucketRequest(query url.Values, data response) error { + reqURL := u.genBucketURL(query) + req, err := http.NewRequest("GET", reqURL, nil) + if err != nil { + return err + } + + resp, err := u.Client.Do(req) + if err != nil { + return err + } + err = u.responseParse(resp) + if err != nil { + return err + } + err = json.Unmarshal(u.LastResponseBody, data) + if err != nil { + return err + } + return data.Error() +} + +func (u *UFileRequest) genBucketURL(query url.Values) string { + u.baseURL.RawQuery = u.Auth.AuthorizationBucketMgr(query) + return u.baseURL.String() +} diff --git a/vendor/github.com/ufilesdk-dev/ufile-gosdk/file.go b/vendor/github.com/ufilesdk-dev/ufile-gosdk/file.go new file mode 100644 index 000000000..49c1df8b6 --- /dev/null +++ b/vendor/github.com/ufilesdk-dev/ufile-gosdk/file.go @@ -0,0 +1,380 @@ +package ufsdk + +import ( + "bytes" + "encoding/base64" + "crypto/md5" + "encoding/json" + "fmt" + "io" + "io/ioutil" + "net/http" + "net/url" + "strconv" + "strings" + "time" +) + +const ( + fourMegabyte = 1 << 22 //4M +) + +//FileDataSet 用于 FileListResponse 里面的 DataSet 字段。 +type FileDataSet struct { + BucketName string `json:"BucketName,omitempty"` + FileName string `json:"FileName,omitempty"` + Hash string `json:"Hash,omitempty"` + MimeType string `json:"MimeType,omitempty"` + FirstObject string `json:"first_object,omitempty"` + Size int `json:"Size,omitempty"` + CreateTime int `json:"CreateTime,omitempty"` + ModifyTime int `json:"ModifyTime,omitempty"` + StorageClass string `json:"StorageClass,omitempty"` + RestoreStatus string `json:"RestoreStatus,omitempty"` +} + +//FileListResponse 用 PrefixFileList 接口返回的 list 数据。 +type FileListResponse struct { + BucketName string `json:"BucketName,omitempty"` + BucketID string `json:"BucketId,omitempty"` + NextMarker string `json:"NextMarker,omitempty"` + DataSet []FileDataSet `json:"DataSet,omitempty"` +} + +func (f FileListResponse) String() string { + return structPrettyStr(f) +} + +//UploadHit 文件秒传,它的原理是计算出文件的 etag 值与远端服务器进行对比,如果文件存在就快速返回。 +func (u *UFileRequest) UploadHit(filePath, keyName string) (err error) { + file, err := openFile(filePath) + if err != nil { + return err + } + defer file.Close() + fsize := getFileSize(file) + etag := calculateEtag(file) + + query := &url.Values{} + query.Add("Hash", etag) + query.Add("FileName", keyName) + query.Add("FileSize", strconv.FormatInt(fsize, 10)) + reqURL := u.genFileURL("uploadhit") + "?" + query.Encode() + req, err := http.NewRequest("POST", reqURL, nil) + if err != nil { + return err + } + authorization := u.Auth.Authorization("POST", u.BucketName, keyName, req.Header) + req.Header.Add("authorization", authorization) + + return u.request(req) +} + +//PostFile 使用 HTTP Form 的方式上传一个文件。 +//注意:使用本接口上传文件后,调用 UploadHit 接口会返回 404,因为经过 form 包装的文件,etag 值会不一样,所以会调用失败。 +//mimeType 如果为空的话,会调用 net/http 里面的 DetectContentType 进行检测。 +//keyName 表示传到 ufile 的文件名。 +//小于 100M 的文件推荐使用本接口上传。 +func (u *UFileRequest) PostFile(filePath, keyName, mimeType string) (err error) { + file, err := openFile(filePath) + if err != nil { + return err + } + defer file.Close() + + h := make(http.Header) + for k, v := range u.RequestHeader { + for i := 0; i < len(v); i++ { + h.Add(k, v[i]) + } + } + if mimeType == "" { + mimeType = getMimeType(file) + } + h.Add("Content-Type", mimeType) + + authorization := u.Auth.Authorization("POST", u.BucketName, keyName, h) + + boundry := makeBoundry() + body := makeFormBody(authorization, boundry, keyName, mimeType, u.verifyUploadMD5, file) + //lastline 一定要写,否则后端解析不到。 + lastline := fmt.Sprintf("\r\n--%s--\r\n", boundry) + body.Write([]byte(lastline)) + + reqURL := u.genFileURL("") + req, err := http.NewRequest("POST", reqURL, body) + if err != nil { + return err + } + + req.Header.Add("Content-Type", "multipart/form-data; boundary="+boundry) + contentLength := body.Len() + req.Header.Add("Content-Length", strconv.Itoa(contentLength)) + for k, v := range u.RequestHeader { + for i := 0; i < len(v); i++ { + req.Header.Add(k, v[i]) + } + } + return u.request(req) +} + +//PutFile 把文件直接放到 HTTP Body 里面上传,相对 PostFile 接口,这个要更简单,速度会更快(因为不用包装 form)。 +//mimeType 如果为空的,会调用 net/http 里面的 DetectContentType 进行检测。 +//keyName 表示传到 ufile 的文件名。 +//小于 100M 的文件推荐使用本接口上传。 +func (u *UFileRequest) PutFile(filePath, keyName, mimeType string) error { + reqURL := u.genFileURL(keyName) + file, err := openFile(filePath) + if err != nil { + return err + } + defer file.Close() + + b, err := ioutil.ReadAll(file) + if err != nil { + return err + } + + req, err := http.NewRequest("PUT", reqURL, bytes.NewBuffer(b)) + if err != nil { + return err + } + + if mimeType == "" { + mimeType = getMimeType(file) + } + req.Header.Add("Content-Type", mimeType) + for k, v := range u.RequestHeader { + for i := 0; i < len(v); i++ { + req.Header.Add(k, v[i]) + } + } + + if u.verifyUploadMD5 { + md5Str := fmt.Sprintf("%x", md5.Sum(b)) + req.Header.Add("Content-MD5", md5Str) + } + + authorization := u.Auth.Authorization("PUT", u.BucketName, keyName, req.Header) + req.Header.Add("authorization", authorization) + fileSize := getFileSize(file) + req.Header.Add("Content-Length", strconv.FormatInt(fileSize, 10)) + + return u.request(req) +} + +//PutFile 把文件直接放到 HTTP Body 里面上传,相对 PostFile 接口,这个要更简单,速度会更快(因为不用包装 form)。 +//mimeType 如果为空的,会调用 net/http 里面的 DetectContentType 进行检测。 +//keyName 表示传到 ufile 的文件名。 +//小于 100M 的文件推荐使用本接口上传。 +//支持带上传回调的参数, policy_json 为json 格式字符串 +func (u *UFileRequest) PutFileWithPolicy(filePath, keyName, mimeType string, policy_json string) error { + reqURL := u.genFileURL(keyName) + file, err := openFile(filePath) + if err != nil { + return err + } + defer file.Close() + + b, err := ioutil.ReadAll(file) + if err != nil { + return err + } + + req, err := http.NewRequest("PUT", reqURL, bytes.NewBuffer(b)) + if err != nil { + return err + } + + if mimeType == "" { + mimeType = getMimeType(file) + } + req.Header.Add("Content-Type", mimeType) + + if u.verifyUploadMD5 { + md5Str := fmt.Sprintf("%x", md5.Sum(b)) + req.Header.Add("Content-MD5", md5Str) + } + + policy := base64.URLEncoding.EncodeToString([]byte(policy_json)) + authorization := u.Auth.AuthorizationPolicy("PUT", u.BucketName, keyName, policy, req.Header) + req.Header.Add("authorization", authorization) + fileSize := getFileSize(file) + req.Header.Add("Content-Length", strconv.FormatInt(fileSize, 10)) + + return u.request(req) +} + + +//DeleteFile 删除一个文件,如果删除成功 statuscode 会返回 204,否则会返回 404 表示文件不存在。 +//keyName 表示传到 ufile 的文件名。 +func (u *UFileRequest) DeleteFile(keyName string) error { + reqURL := u.genFileURL(keyName) + req, err := http.NewRequest("DELETE", reqURL, nil) + if err != nil { + return err + } + authorization := u.Auth.Authorization("DELETE", u.BucketName, keyName, req.Header) + req.Header.Add("authorization", authorization) + return u.request(req) +} + +//HeadFile 获取一个文件的基本信息,返回的信息全在 header 里面。包含 mimeType, content-length(文件大小), etag, Last-Modified:。 +//keyName 表示传到 ufile 的文件名。 +func (u *UFileRequest) HeadFile(keyName string) error { + reqURL := u.genFileURL(keyName) + req, err := http.NewRequest("HEAD", reqURL, nil) + if err != nil { + return err + } + authorization := u.Auth.Authorization("HEAD", u.BucketName, keyName, req.Header) + req.Header.Add("authorization", authorization) + return u.request(req) +} + +//PrefixFileList 获取文件列表。 +//prefix 表示匹配文件前缀。 +//marker 标志字符串 +//limit 列表数量限制,传 0 会默认设置为 20. +func (u *UFileRequest) PrefixFileList(prefix, marker string, limit int) (list FileListResponse, err error) { + query := &url.Values{} + query.Add("prefix", prefix) + query.Add("marker", marker) + if limit == 0 { + limit = 20 + } + query.Add("limit", strconv.Itoa(limit)) + reqURL := u.genFileURL("") + "?list&" + query.Encode() + + req, err := http.NewRequest("GET", reqURL, nil) + if err != nil { + return + } + + authorization := u.Auth.Authorization("GET", u.BucketName, "", req.Header) + req.Header.Add("authorization", authorization) + + err = u.request(req) + if err != nil { + return + } + err = json.Unmarshal(u.LastResponseBody, &list) + return +} + +//GetPublicURL 获取公有空间的文件下载 URL +//keyName 表示传到 ufile 的文件名。 +func (u *UFileRequest) GetPublicURL(keyName string) string { + return u.genFileURL(keyName) +} + +//GetPrivateURL 获取私有空间的文件下载 URL。 +//keyName 表示传到 ufile 的文件名。 +//expiresDuation 表示下载链接的过期时间,从现在算起,24 * time.Hour 表示过期时间为一天。 +func (u *UFileRequest) GetPrivateURL(keyName string, expiresDuation time.Duration) string { + t := time.Now() + t = t.Add(expiresDuation) + expires := strconv.FormatInt(t.Unix(), 10) + signature, publicKey := u.Auth.AuthorizationPrivateURL("GET", u.BucketName, keyName, expires, http.Header{}) + query := url.Values{} + query.Add("UCloudPublicKey", publicKey) + query.Add("Signature", signature) + query.Add("Expires", expires) + reqURL := u.genFileURL(keyName) + return reqURL + "?" + query.Encode() +} + +//Download 把文件下载到 HTTP Body 里面,这里只能用来下载小文件,建议使用 DownloadFile 来下载大文件。 +func (u *UFileRequest) Download(reqURL string) error { + req, err := http.NewRequest("GET", reqURL, nil) + if err != nil { + return err + } + return u.request(req) +} + +//Download 文件下载接口,下载前会先获取文件大小,如果小于 4M 直接下载。大于 4M 每次会按 4M 的分片来下载。 +func (u *UFileRequest) DownloadFile(writer io.Writer, keyName string) error { + err := u.HeadFile(keyName) + if err != nil { + return err + } + size := u.LastResponseHeader.Get("Content-Length") + fileSize, err := strconv.ParseInt(size, 10, 0) + if err != nil || fileSize <= 0 { + return fmt.Errorf("Parse content-lengt returned error") + } + + reqURL := u.GetPrivateURL(keyName, 24*time.Hour) + req, err := http.NewRequest("GET", reqURL, nil) + if err != nil { + return err + } + + if fileSize < fourMegabyte { + err = u.request(req) + if err != nil { + return err + } + writer.Write(u.LastResponseBody) + } else { + var i int64 + for i = 0; i < fileSize; i += fourMegabyte { // 一次下载 4 M + start := i + end := i + fourMegabyte - 1 //数组是从 0 开始的。 &_& ..... + if end > fileSize { + end = fileSize + } + req.Header.Set("Range", fmt.Sprintf("bytes=%d-%d", start, end)) + err = u.request(req) + if err != nil { + return err + } + writer.Write(u.LastResponseBody) + } + } + return nil +} + +//CompareFileEtag 检查远程文件的 etag 和本地文件的 etag 是否一致 +func (u *UFileRequest) CompareFileEtag(remoteKeyName, localFilePath string) bool { + err := u.HeadFile(remoteKeyName) + if err != nil { + return false + } + remoteEtag := strings.Trim(u.LastResponseHeader.Get("Etag"), "\"") + localEtag := GetFileEtag(localFilePath) + return remoteEtag == localEtag +} + +func (u *UFileRequest) genFileURL(keyName string) string { + return u.baseURL.String() + keyName +} + +//Restore 用于解冻冷存类型的文件 +func (u *UFileRequest) Restore(keyName string) (err error) { + reqURL := u.genFileURL(keyName) + "?restore" + req, err := http.NewRequest("PUT", reqURL, nil) + if err != nil { + return err + } + authorization := u.Auth.Authorization("PUT", u.BucketName, keyName, req.Header) + req.Header.Add("authorization", authorization) + return u.request(req) +} + +//ClassSwitch 存储类型转换接口 +//keyName 文件名称 +//storageClass 所要转换的新文件存储类型,目前支持的类型分别是标准:"STANDARD"、低频:"IA"、冷存:"ARCHIVE" +func (u *UFileRequest) ClassSwitch(keyName string, storageClass string) (err error) { + query := &url.Values{} + query.Add("storageClass", storageClass) + reqURL := u.genFileURL(keyName) + "?" + query.Encode() + req, err := http.NewRequest("PUT", reqURL, nil) + if err != nil { + return err + } + authorization := u.Auth.Authorization("PUT", u.BucketName, keyName, req.Header) + req.Header.Add("authorization", authorization) + return u.request(req) +} diff --git a/vendor/github.com/ufilesdk-dev/ufile-gosdk/file_mutipart_upload.go b/vendor/github.com/ufilesdk-dev/ufile-gosdk/file_mutipart_upload.go new file mode 100644 index 000000000..06150970c --- /dev/null +++ b/vendor/github.com/ufilesdk-dev/ufile-gosdk/file_mutipart_upload.go @@ -0,0 +1,291 @@ +package ufsdk + +import ( + "bytes" + "crypto/md5" + "encoding/json" + "fmt" + "io" + "math" + "net/http" + "net/url" + "strconv" + "strings" + "sync" +) + +//MultipartState 用于保存分片上传的中间状态 +type MultipartState struct { + BlkSize int //服务器返回的分片大小 + uploadID string + mimeType string + keyName string + etags map[int]string + mux sync.Mutex +} + +//UnmarshalJSON custom unmarshal json +func (m *MultipartState) UnmarshalJSON(bytes []byte) error { + tmp := struct { + BlkSize int `json:"BlkSize"` + UploadID string `json:"UploadId"` + }{} + err := json.Unmarshal(bytes, &tmp) + if err != nil { + return err + } + m.BlkSize = tmp.BlkSize + m.uploadID = tmp.UploadID + return nil +} + +type uploadChan struct { + etag string + err error +} + +//MPut 分片上传一个文件,filePath 是本地文件所在的路径,内部会自动对文件进行分片上传,上传的方式是同步一片一片的上传。 +//mimeType 如果为空的话,会调用 net/http 里面的 DetectContentType 进行检测。 +//keyName 表示传到 ufile 的文件名。 +//大于 100M 的文件推荐使用本接口上传。 +func (u *UFileRequest) MPut(filePath, keyName, mimeType string) error { + file, err := openFile(filePath) + if err != nil { + return err + } + defer file.Close() + if mimeType == "" { + mimeType = getMimeType(file) + } + + state, err := u.InitiateMultipartUpload(keyName, mimeType) + if err != nil { + return err + } + + chunk := make([]byte, state.BlkSize) + var pos int + for { + bytesRead, fileErr := file.Read(chunk) + if fileErr == io.EOF || bytesRead == 0 { //后面直接读到了结尾 + break + } + buf := bytes.NewBuffer(chunk[:bytesRead]) + err := u.UploadPart(buf, state, pos) + if err != nil { + u.AbortMultipartUpload(state) + return err + } + pos++ + } + + return u.FinishMultipartUpload(state) +} + +//AsyncMPut 异步分片上传一个文件,filePath 是本地文件所在的路径,内部会自动对文件进行分片上传,上传的方式是使用异步的方式同时传多个分片的块。 +//mimeType 如果为空的话,会调用 net/http 里面的 DetectContentType 进行检测。 +//keyName 表示传到 ufile 的文件名。 +//大于 100M 的文件推荐使用本接口上传。 +//同时并发上传的分片数量为10 +func (u *UFileRequest) AsyncMPut(filePath, keyName, mimeType string) error { + return u.AsyncUpload(filePath, keyName, mimeType, 10) +} + +//AsyncUpload AsyncMPut 的升级版, jobs 表示同时并发的数量。 +func (u *UFileRequest) AsyncUpload(filePath, keyName, mimeType string, jobs int) error { + if jobs <= 0 { + jobs = 1 + } + + if jobs >= 30 { + jobs = 10 + } + + file, err := openFile(filePath) + if err != nil { + return err + } + defer file.Close() + if mimeType == "" { + mimeType = getMimeType(file) + } + + state, err := u.InitiateMultipartUpload(keyName, mimeType) + if err != nil { + return err + } + fsize := getFileSize(file) + chunkCount := divideCeil(fsize, int64(state.BlkSize)) //向上取整 + concurrentChan := make(chan error, jobs) + for i := 0; i != jobs; i++ { + concurrentChan <- nil + } + + wg := &sync.WaitGroup{} + for i := 0; i != chunkCount; i++ { + uploadErr := <-concurrentChan //最初允许启动 10 个 goroutine,超出10个后,有分片返回才会开新的goroutine. + if uploadErr != nil { + err = uploadErr + break // 中间如果出现错误立即停止继续上传 + } + wg.Add(1) + go func(pos int) { + defer wg.Done() + offset := int64(state.BlkSize * pos) + chunk := make([]byte, state.BlkSize) + bytesRead, _ := file.ReadAt(chunk, offset) + e := u.UploadPart(bytes.NewBuffer(chunk[:bytesRead]), state, pos) + concurrentChan <- e //跑完一个 goroutine 后,发信号表示可以开启新的 goroutine。 + }(i) + } + wg.Wait() //等待所有任务返回 + if err == nil { //再次检查剩余上传完的分片是否有错误 + loopCheck: + for { + select { + case e := <-concurrentChan: + err = e + if err != nil { + break loopCheck + } + default: + break loopCheck + } + } + } + close(concurrentChan) + if err != nil { + u.AbortMultipartUpload(state) + return err + } + + return u.FinishMultipartUpload(state) +} + +//AbortMultipartUpload 取消分片上传,如果掉用 UploadPart 出现错误,可以调用本函数取消分片上传。 +//state 参数是 InitiateMultipartUpload 返回的 +func (u *UFileRequest) AbortMultipartUpload(state *MultipartState) error { + query := &url.Values{} + query.Add("uploadId", state.uploadID) + reqURL := u.genFileURL(state.keyName) + "?" + query.Encode() + + req, err := http.NewRequest("DELETE", reqURL, nil) + if err != nil { + return err + } + authorization := u.Auth.Authorization("DELETE", u.BucketName, state.keyName, req.Header) + req.Header.Add("authorization", authorization) + return u.request(req) +} + +//InitiateMultipartUpload 初始化分片上传,返回一个 state 用于后续的 UploadPart, FinishMultipartUpload, AbortMultipartUpload 的接口。 +// +//keyName 表示传到 ufile 的文件名。 +// +//mimeType 表示文件的 mimeType, 传空会报错,你可以使用 GetFileMimeType 方法检测文件的 mimeType。如果您上传的不是文件,您可以使用 http.DetectContentType https://golang.org/src/net/http/sniff.go?s=646:688#L11进行检测。 +func (u *UFileRequest) InitiateMultipartUpload(keyName, mimeType string) (*MultipartState, error) { + reqURL := u.genFileURL(keyName) + "?uploads" + req, err := http.NewRequest("POST", reqURL, nil) + if err != nil { + return nil, err + } + // if mimeType == "" { + // return nil, fmt.Errorf("Mime Type 不能为空!!!") + // } + req.Header.Add("Content-Type", mimeType) + for k, v := range u.RequestHeader { + for i := 0; i < len(v); i++ { + req.Header.Add(k, v[i]) + } + } + + authorization := u.Auth.Authorization("POST", u.BucketName, keyName, req.Header) + req.Header.Add("authorization", authorization) + + err = u.request(req) + if err != nil { + return nil, err + } + response := new(MultipartState) + err = json.Unmarshal(u.LastResponseBody, response) + if err != nil { + return nil, err + } + response.keyName = keyName + response.etags = make(map[int]string) + response.mimeType = mimeType + + return response, err +} + +//UploadPart 上传一个分片,buf 就是分片数据,buf 的数据块大小必须为 state.BlkSize,否则会报错。 +//pardNumber 表示第几个分片,从 0 开始。例如一个文件按 state.BlkSize 分为 5 块,那么分片分别是 0,1,2,3,4。 +//state 参数是 InitiateMultipartUpload 返回的 +func (u *UFileRequest) UploadPart(buf *bytes.Buffer, state *MultipartState, partNumber int) error { + query := &url.Values{} + query.Add("uploadId", state.uploadID) + query.Add("partNumber", strconv.Itoa(partNumber)) + + reqURL := u.genFileURL(state.keyName) + "?" + query.Encode() + req, err := http.NewRequest("PUT", reqURL, buf) + if err != nil { + return err + } + if u.verifyUploadMD5 { + md5Str := fmt.Sprintf("%x", md5.Sum(buf.Bytes())) + req.Header.Add("Content-MD5", md5Str) + } + + req.Header.Add("Content-Type", state.mimeType) + authorization := u.Auth.Authorization("PUT", u.BucketName, state.keyName, req.Header) + req.Header.Add("Authorization", authorization) + req.Header.Add("Content-Length", strconv.Itoa(buf.Len())) + + resp, err := u.requestWithResp(req) + if err != nil { + return err + } + defer resp.Body.Close() + + etag := strings.Trim(resp.Header.Get("Etag"), "\"") //为保证线程安全,这里就不保留 lastResponse + if etag == "" { + etag = strings.Trim(resp.Header.Get("ETag"), "\"") //为保证线程安全,这里就不保留 lastResponse + } + state.mux.Lock() + state.etags[partNumber] = etag + state.mux.Unlock() + return nil +} + +//FinishMultipartUpload 完成分片上传。分片上传必须要调用的接口。 +//state 参数是 InitiateMultipartUpload 返回的 +func (u *UFileRequest) FinishMultipartUpload(state *MultipartState) error { + query := &url.Values{} + query.Add("uploadId", state.uploadID) + reqURL := u.genFileURL(state.keyName) + "?" + query.Encode() + var etagsStr string + etagLen := len(state.etags) + for i := 0; i != etagLen; i++ { + etagsStr += state.etags[i] + if i != etagLen-1 { + etagsStr += "," + } + } + + req, err := http.NewRequest("POST", reqURL, strings.NewReader(etagsStr)) + if err != nil { + return err + } + req.Header.Add("Content-Type", state.mimeType) + authorization := u.Auth.Authorization("POST", u.BucketName, state.keyName, req.Header) + req.Header.Add("Authorization", authorization) + req.Header.Add("Content-Length", strconv.Itoa(len(etagsStr))) + + return u.request(req) +} + +func divideCeil(a, b int64) int { + div := float64(a) / float64(b) + c := math.Ceil(div) + return int(c) +} diff --git a/vendor/github.com/ufilesdk-dev/ufile-gosdk/file_mutipart_upload_with_policy.go b/vendor/github.com/ufilesdk-dev/ufile-gosdk/file_mutipart_upload_with_policy.go new file mode 100644 index 000000000..51d29fa0d --- /dev/null +++ b/vendor/github.com/ufilesdk-dev/ufile-gosdk/file_mutipart_upload_with_policy.go @@ -0,0 +1,166 @@ +package ufsdk + +import ( + "bytes" + "io" + "encoding/base64" + "net/http" + "net/url" + "strconv" + "strings" + "sync" +) + +//带回调策略的mput 接口,一些基础函数依赖于 file_mput 定义的函数 + +//MPut 分片上传一个文件,filePath 是本地文件所在的路径,内部会自动对文件进行分片上传,上传的方式是同步一片一片的上传。 +//mimeType 如果为空的话,会调用 net/http 里面的 DetectContentType 进行检测。 +//keyName 表示传到 ufile 的文件名。 +//大于 100M 的文件推荐使用本接口上传。 +func (u *UFileRequest) MPutWithPolicy(filePath, keyName, mimeType string, policy_json string) error { + file, err := openFile(filePath) + if err != nil { + return err + } + defer file.Close() + if mimeType == "" { + mimeType = getMimeType(file) + } + + state, err := u.InitiateMultipartUpload(keyName, mimeType) + if err != nil { + return err + } + + chunk := make([]byte, state.BlkSize) + var pos int + for { + bytesRead, fileErr := file.Read(chunk) + if fileErr == io.EOF || bytesRead == 0 { //后面直接读到了结尾 + break + } + buf := bytes.NewBuffer(chunk[:bytesRead]) + err := u.UploadPart(buf, state, pos) + if err != nil { + u.AbortMultipartUpload(state) + return err + } + pos++ + } + + return u.FinishMultipartUploadWithPolicy(state, policy_json) +} + +//AsyncMPut 异步分片上传一个文件,filePath 是本地文件所在的路径,内部会自动对文件进行分片上传,上传的方式是使用异步的方式同时传多个分片的块。 +//mimeType 如果为空的话,会调用 net/http 里面的 DetectContentType 进行检测。 +//keyName 表示传到 ufile 的文件名。 +//大于 100M 的文件推荐使用本接口上传。 +//同时并发上传的分片数量为10 +func (u *UFileRequest) AsyncMPutWithPolicy(filePath, keyName, mimeType string, policy_json string) error { + return u.AsyncUploadWithPolicy(filePath, keyName, mimeType, 10, policy_json) +} + +//AsyncUpload AsyncMPut 的升级版, jobs 表示同时并发的数量。 +func (u *UFileRequest) AsyncUploadWithPolicy(filePath, keyName, mimeType string, jobs int, policy_json string) error { + if jobs <= 0 { + jobs = 1 + } + + if jobs >= 30 { + jobs = 10 + } + + file, err := openFile(filePath) + if err != nil { + return err + } + defer file.Close() + if mimeType == "" { + mimeType = getMimeType(file) + } + + state, err := u.InitiateMultipartUpload(keyName, mimeType) + if err != nil { + return err + } + fsize := getFileSize(file) + chunkCount := divideCeil(fsize, int64(state.BlkSize)) //向上取整 + concurrentChan := make(chan error, jobs) + for i := 0; i != jobs; i++ { + concurrentChan <- nil + } + + wg := &sync.WaitGroup{} + for i := 0; i != chunkCount; i++ { + uploadErr := <-concurrentChan //最初允许启动 10 个 goroutine,超出10个后,有分片返回才会开新的goroutine. + if uploadErr != nil { + err = uploadErr + break // 中间如果出现错误立即停止继续上传 + } + wg.Add(1) + go func(pos int) { + defer wg.Done() + offset := int64(state.BlkSize * pos) + chunk := make([]byte, state.BlkSize) + bytesRead, _ := file.ReadAt(chunk, offset) + e := u.UploadPart(bytes.NewBuffer(chunk[:bytesRead]), state, pos) + concurrentChan <- e //跑完一个 goroutine 后,发信号表示可以开启新的 goroutine。 + }(i) + } + wg.Wait() //等待所有任务返回 + if err == nil { //再次检查剩余上传完的分片是否有错误 + loopCheck: + for { + select { + case e := <-concurrentChan: + err = e + if err != nil { + break loopCheck + } + default: + break loopCheck + } + } + } + close(concurrentChan) + if err != nil { + u.AbortMultipartUpload(state) + return err + } + + return u.FinishMultipartUploadWithPolicy(state, policy_json) +} + + +//FinishMultipartUpload 完成分片上传。分片上传必须要调用的接口。 +//state 参数是 InitiateMultipartUpload 返回的 +func (u *UFileRequest) FinishMultipartUploadWithPolicy(state *MultipartState, policy_json string) error { + query := &url.Values{} + query.Add("uploadId", state.uploadID) + reqURL := u.genFileURL(state.keyName) + "?" + query.Encode() + var etagsStr string + etagLen := len(state.etags) + for i := 0; i != etagLen; i++ { + etagsStr += state.etags[i] + if i != etagLen-1 { + etagsStr += "," + } + } + + req, err := http.NewRequest("POST", reqURL, strings.NewReader(etagsStr)) + if err != nil { + return err + } + + req.Header.Add("Content-Type", state.mimeType) + + policy := base64.URLEncoding.EncodeToString([]byte(policy_json)) + authorization := u.Auth.AuthorizationPolicy("POST", u.BucketName, state.keyName, policy, req.Header) + + req.Header.Add("Authorization", authorization) + req.Header.Add("Content-Length", strconv.Itoa(len(etagsStr))) + + return u.request(req) +} + + diff --git a/vendor/github.com/ufilesdk-dev/ufile-gosdk/io.go b/vendor/github.com/ufilesdk-dev/ufile-gosdk/io.go new file mode 100644 index 000000000..097d3dc01 --- /dev/null +++ b/vendor/github.com/ufilesdk-dev/ufile-gosdk/io.go @@ -0,0 +1,104 @@ +package ufsdk + +import ( + "bytes" + "errors" + "io" + "io/ioutil" + "net/http" + "strings" + "sync" +) + +// IOPut 流式 put 上传接口,你必须确保你的 reader 接口每次调用是递进式的调用,也就是像文件那样的读取方式。 +// mimeType 在这里的检测不会很准确,你可以手动指定更精确的 mimetype。 +// 这里的 reader 接口会把数据全部读到 HTTP Body 里面,如果你接口的数据特别大,请使用 IOMutipartAsyncUpload 接口。 +func (u *UFileRequest) IOPut(reader io.Reader, keyName, mimeType string) (err error) { + if keyName == "" { + err = errors.New("keyName cannot be empty") + return + } + + switch reader.(type) { + case *bytes.Buffer, *bytes.Reader, *strings.Reader: + break + default: + b, err := ioutil.ReadAll(reader) + if err != nil { + return err + } + reader = bytes.NewReader(b) + } + + reqURL := u.genFileURL(keyName) + req, err := http.NewRequest("PUT", reqURL, reader) + if err != nil { + return err + } + + req.Header.Add("Content-Type", mimeType) + + authorization := u.Auth.Authorization("PUT", u.BucketName, keyName, req.Header) + req.Header.Add("authorization", authorization) + + return u.request(req) +} + +// +// IOMutipartAsyncUpload 流式分片上传接口,你必须确保你的 reader 接口每次调用是递进式的调用,也就是像文件那样的读取方式。 +// mimeType 在这里的检测不会很准确,你可以手动指定更精确的 mimetype。 +// 这里的会每次读取4M 的数据到 buffer 里面,适用于大量数据上传。 +func (u *UFileRequest) IOMutipartAsyncUpload(reader io.Reader, keyName, mimeType string) (err error) { + if keyName == "" { + err = errors.New("keyName cannot be empty") + return + } + state, err := u.InitiateMultipartUpload(keyName, mimeType) + if err != nil { + return + } + + maxJobRunning := 10 //最多允许 10 个线程同时跑 + concurrentChan := make(chan error, maxJobRunning) + for i := 0; i != maxJobRunning; i++ { + concurrentChan <- nil + } + wg := &sync.WaitGroup{} + for i := 0; ; i++ { + uploadErr := <-concurrentChan //最初允许启动 10 个 goroutine,超出10个后,有分片返回才会开新的goroutine. + if uploadErr != nil { + u.AbortMultipartUpload(state) + return uploadErr // 中间如果出现错误立即停止继续上传 + } + + chunk := make([]byte, state.BlkSize) + bytesRead, readErr := reader.Read(chunk) + if readErr == io.EOF || bytesRead == 0 { + break + } + if readErr != nil { + u.AbortMultipartUpload(state) + return uploadErr // 检查读文件是否出现错误。 + } + wg.Add(1) + go func(pos int, buf *bytes.Buffer) { + defer wg.Done() + e := u.UploadPart(buf, state, pos) + concurrentChan <- e //跑完一个 goroutine 后,发信号表示可以开启新的 goroutine。 + }(i, bytes.NewBuffer(chunk[:bytesRead])) + } + + go func() { + wg.Wait() + close(concurrentChan) //close channel, when all upload goroutines has finished. + }() + + for err = range concurrentChan { //waitting for all goroutine finished. It will blocked until the channel has been closed. + if err != nil { + u.AbortMultipartUpload(state) + return err + } + } + + return u.FinishMultipartUpload(state) +} diff --git a/vendor/github.com/ufilesdk-dev/ufile-gosdk/request.go b/vendor/github.com/ufilesdk-dev/ufile-gosdk/request.go new file mode 100644 index 000000000..f69c2bc52 --- /dev/null +++ b/vendor/github.com/ufilesdk-dev/ufile-gosdk/request.go @@ -0,0 +1,181 @@ +package ufsdk + +import ( + "bytes" + "context" + "errors" + "fmt" + "io/ioutil" + "net/http" + "net/url" + "strings" +) + +//UFileRequest SDK 主要的 request 模块。本 SDK 遵从以下原则: +// +//1.接口尽可能简洁,隐藏所有复杂实现。 +// +//2.本 SDK 主要的作用是封装 HTTP 请求,不做过多其他的封装(如 HTTP Body 序列化,详细的错误检查)。 +// +//3.只简单封装 HTTP 请求所需要的参数,给接口使用者提供所有原生的 HTTP response header,body,status code 返回,以便排错。 +// +//4.远端请求返回值统一返回一个 error,如果为 nil 表示无错。LastResponseStatus,LastResponseHeader,LastResponseBody 可以查看具体的 HTTP 返回信息()。如果你想少敲几行代码可以直接调用 DumpResponse(true) 查看详细返回。 +// +type UFileRequest struct { + Auth Auth + BucketName string + Host string + Client *http.Client + Context context.Context + baseURL *url.URL + RequestHeader http.Header + + LastResponseStatus int + LastResponseHeader http.Header + LastResponseBody []byte + verifyUploadMD5 bool + lastResponse *http.Response +} + +//NewFileRequest 创建一个用于管理文件的 request,管理文件的 url 与 管理 bucket 接口不一样, +//请将 bucket 和文件管理所需要的分开,NewUBucketRequest 是用来管理 bucket 的。 +//Request 创建后的 instance 不是线程安全的,如果你需要做并发的操作,请创建多个 UFileRequest。 +//config 参数里面包含了公私钥,以及其他必填的参数。详情见 config 相关文档。 +//client 这里你可以传空,会使用默认的 http.Client。如果你需要设置超时以及一些其他相关的网络配置选项请传入一个自定义的 client。 +func NewFileRequest(config *Config, client *http.Client) (*UFileRequest, error) { + config.BucketName = strings.TrimSpace(config.BucketName) + config.FileHost = strings.TrimSpace(config.FileHost) + if config.BucketName == "" || config.FileHost == "" { + return nil, errors.New("管理文件上传必须要提供 bucket 名字和所在地域的 Host 域名") + } + req := newRequest(config.PublicKey, config.PrivateKey, + config.BucketName, config.FileHost, client) + req.verifyUploadMD5 = config.VerifyUploadMD5 + if req.baseURL.Scheme == "" { //用户传了非自定义域名 + req.baseURL.Host = req.BucketName + "." + req.Host + req.baseURL.Scheme = "http" + } + return req, nil +} + +//NewFileRequestWithHeader 创建一个可携带用户自定义http请求头的 request +//Request 创建后的 instance 不是线程安全的,如果你需要做并发的操作,请创建多个 UFileRequest。 +//config 参数里面包含了公私钥,以及其他必填的参数。详情见 config 相关文档。 +//header 自定义http请求头 +//client 这里你可以传空,会使用默认的 http.Client。如果你需要设置超时以及一些其他相关的网络配置选项请传入一个自定义的 client。 +func NewFileRequestWithHeader(config *Config, header http.Header, client *http.Client) (*UFileRequest, error) { + req, err := NewFileRequest(config, client) + if err != nil{ + return nil, err + } + req.RequestHeader = header + return req, nil +} + +//NewBucketRequest 创建一个用于管理 bucket 的 request。 +//注意:不要拿它去调用文件管理的 request,我文件管理和 bucket 管理接口放到一个 request 里面的目的就是让接口更统一,代码更清晰,简洁。 +//config 参数里面包含了公私钥,以及其他必填的参数。详情见 config 相关文档。 +func NewBucketRequest(config *Config, client *http.Client) (*UFileRequest, error) { + config.BucketHost = strings.TrimSpace(config.BucketHost) + if config.BucketHost == "" { + return nil, errors.New("管理 Bucket 必须要提供对应的 API host") + } + req := newRequest(config.PublicKey, config.PrivateKey, "", config.BucketHost, client) + req.verifyUploadMD5 = config.VerifyUploadMD5 + if req.baseURL.Scheme == "" { + req.baseURL.Scheme = "http" + } + return req, nil +} + +//DumpResponse dump 当前请求的返回结果,里面有一个 print 函数,会把 body,header,status code 直接输出到 stdout。 +//如果你需要 Dump 到其他的地方,直接拿返回值即可。 +func (u *UFileRequest) DumpResponse(isDumpBody bool) []byte { + var b bytes.Buffer + if u.lastResponse == nil { + return nil + } + b.WriteString(fmt.Sprintf("%s %d\n", u.lastResponse.Proto, u.LastResponseStatus)) + for k, vs := range u.LastResponseHeader { + str := k + ": " + for i, v := range vs { + if i != 0 { + str += "; " + v + } else { + str += v + } + } + b.WriteString(str) + } + if isDumpBody { + b.Write(u.LastResponseBody) + } + return b.Bytes() +} + +func newRequest(publicKey, privateKey, bucket, host string, client *http.Client) *UFileRequest { + req := new(UFileRequest) + req.Auth = NewAuth(publicKey, privateKey) + req.BucketName = bucket + req.Host = strings.TrimSpace(host) + req.baseURL = new(url.URL) + req.baseURL.Host = req.Host + req.baseURL.Path = "/" //for default usage. + + if client == nil { + client = new(http.Client) + } + req.Client = client + req.Context = context.TODO() + return req +} + +func (u *UFileRequest) responseParse(resp *http.Response) error { + resBody, err := ioutil.ReadAll(resp.Body) + if err != nil { + return err + } + defer resp.Body.Close() + + u.LastResponseStatus = resp.StatusCode + u.LastResponseHeader = resp.Header + u.LastResponseBody = resBody + u.lastResponse = resp + return nil +} + +func (u *UFileRequest) request(req *http.Request) error { + resp, err := u.requestWithResp(req) + if err != nil { + return err + } + + err = u.responseParse(resp) + if err != nil { + return err + } + + if !VerifyHTTPCode(resp.StatusCode) { + return fmt.Errorf("Remote response code is %d - %s not 2xx call DumpResponse(true) show details", + resp.StatusCode, http.StatusText(resp.StatusCode)) + } + + return nil +} + +func (u *UFileRequest) requestWithResp(req *http.Request) (resp *http.Response, err error) { + req.Header.Set("User-Agent", "UFile-GoSDK-Client/2.0") + + resp, err = u.Client.Do(req.WithContext(u.Context)) + // If we got an error, and the context has been canceled, + // the context's error is probably more useful. + if err != nil { + select { + case <-u.Context.Done(): + err = u.Context.Err() + default: + } + return + } + return +} diff --git a/vendor/github.com/ufilesdk-dev/ufile-gosdk/utils.go b/vendor/github.com/ufilesdk-dev/ufile-gosdk/utils.go new file mode 100644 index 000000000..99c11847f --- /dev/null +++ b/vendor/github.com/ufilesdk-dev/ufile-gosdk/utils.go @@ -0,0 +1,183 @@ +package ufsdk + +import ( + "bytes" + "crypto/md5" + "crypto/sha1" + "encoding/base64" + "encoding/binary" + "encoding/json" + "fmt" + "io" + "io/ioutil" + "net/http" + "os" + "time" +) + +const ( + blkSIZE = 2 << 21 +) + +//Config 配置文件序列化所需的全部字段 +type Config struct { + PublicKey string `json:"public_key"` + PrivateKey string `json:"private_key"` + BucketName string `json:"bucket_name"` + FileHost string `json:"file_host"` + BucketHost string `json:"bucket_host"` + VerifyUploadMD5 bool `json:"verfiy_upload_md5"` +} + +//LoadConfig 从配置文件加载一个配置。 +func LoadConfig(jsonPath string) (*Config, error) { + file, err := openFile(jsonPath) + if err != nil { + return nil, err + } + defer file.Close() + configBytes, err := ioutil.ReadAll(file) + if err != nil { + return nil, err + } + c := new(Config) + err = json.Unmarshal(configBytes, c) + if err != nil { + return nil, err + } + return c, nil +} + +//VerifyHTTPCode 检查 HTTP 的返回值是否为 2XX,如果不是就返回 false。 +func VerifyHTTPCode(code int) bool { + if code < http.StatusOK || code > http.StatusIMUsed { + return false + } + return true +} + +//GetFileMimeType 获取文件的 mime type 值,接收文件路径作为参数。如果检测不到,则返回空。 +func GetFileMimeType(path string) string { + f, err := openFile(path) + if err != nil { + return "" + } + defer f.Close() + return getMimeType(f) +} + +func getMimeType(f *os.File) string { + buffer := make([]byte, 512) + + _, err := f.Read(buffer) + defer func() { f.Seek(0, 0) }() //revert file's seek + if err != nil { + return "plain/text" + } + + return http.DetectContentType(buffer) +} + +func openFile(path string) (*os.File, error) { + return os.Open(path) +} + +//getFileSize get opened file size +func getFileSize(f *os.File) int64 { + fi, err := f.Stat() + if err != nil { + panic(err.Error()) + } + return fi.Size() +} + +//GetFileEtag 获取文件的 etag 值 +func GetFileEtag(path string) string { + f, err := openFile(path) + if err != nil { + return "" + } + defer f.Close() + return calculateEtag(f) +} + +//Calculatek 计算文件的 etag 值。 +func calculateEtag(f *os.File) string { + fsize := getFileSize(f) + blkcnt := uint32(fsize / blkSIZE) + if fsize%blkSIZE != 0 { + blkcnt++ + } + + bs := make([]byte, 4) + binary.LittleEndian.PutUint32(bs, blkcnt) + + h := sha1.New() + buf := make([]byte, 0, 24) + buf = append(buf, bs...) + if fsize <= blkSIZE { + io.Copy(h, f) + } else { + var i uint32 + for i = 0; i < blkcnt; i++ { + shaBlk := sha1.New() + io.Copy(shaBlk, io.LimitReader(f, blkSIZE)) + io.Copy(h, bytes.NewReader(shaBlk.Sum(nil))) + } + } + buf = h.Sum(buf) + etag := base64.URLEncoding.EncodeToString(buf) + return etag +} + +func makeBoundry() string { + h := md5.New() + t := time.Now() + io.WriteString(h, t.String()) + return fmt.Sprintf("%x", h.Sum(nil)) +} + +func makeFormBody(authorization, boundry, keyName, mimeType string, verifyMD5 bool, file *os.File) *bytes.Buffer { + boundry = "--" + boundry + "\r\n" + boundryBytes := []byte(boundry) + body := new(bytes.Buffer) + + body.Write(boundryBytes) + body.Write(makeFormField("Authorization", authorization)) + body.Write(boundryBytes) + body.Write(makeFormField("Content-Type", mimeType)) + body.Write(boundryBytes) + body.Write(makeFormField("FileName", keyName)) + body.Write(boundryBytes) + + if verifyMD5 { + h := md5.New() + io.Copy(h, file) + md5Str := fmt.Sprintf("%x", h.Sum(nil)) + body.Write(makeFormField("Content-MD5", md5Str)) + body.Write(boundryBytes) + } + + addtionalStr := fmt.Sprintf("Content-Disposition: form-data; name=\"file\"; filename=\"%s\"\r\n", keyName) + addtionalStr += fmt.Sprintf("Content-Type: %s\r\n\r\n", mimeType) + body.Write([]byte(addtionalStr)) + body.ReadFrom(file) + body.Write([]byte("\r\n")) + body.Write(boundryBytes) + + return body +} + +func makeFormField(key, value string) []byte { + keyStr := fmt.Sprintf("Content-Disposition: form-data; name=\"%s\"\r\n\r\n", key) + valueStr := fmt.Sprintf("%s\r\n", value) + return []byte(keyStr + valueStr) +} + +func structPrettyStr(data interface{}) string { + bytes, err := json.MarshalIndent(data, "", " ") + if err == nil { + return fmt.Sprintf("%s\n", bytes) + } + return "" +} diff --git a/vendor/modules.txt b/vendor/modules.txt index fd6a5ea29..9b6c65bcc 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -508,10 +508,11 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312 -# github.com/ucloud/ucloud-sdk-go v0.8.7 +# github.com/ucloud/ucloud-sdk-go v0.11.1 github.com/ucloud/ucloud-sdk-go/private/protocol/http github.com/ucloud/ucloud-sdk-go/private/utils github.com/ucloud/ucloud-sdk-go/services/uaccount +github.com/ucloud/ucloud-sdk-go/services/ufile github.com/ucloud/ucloud-sdk-go/services/uhost github.com/ucloud/ucloud-sdk-go/services/unet github.com/ucloud/ucloud-sdk-go/services/vpc @@ -522,7 +523,9 @@ github.com/ucloud/ucloud-sdk-go/ucloud/log github.com/ucloud/ucloud-sdk-go/ucloud/request github.com/ucloud/ucloud-sdk-go/ucloud/response github.com/ucloud/ucloud-sdk-go/ucloud/version -# github.com/ugorji/go v0.0.0-20151218193438-646ae4a518c1 +# github.com/ufilesdk-dev/ufile-gosdk v0.0.0-20190730023212-866b183392c4 +github.com/ufilesdk-dev/ufile-gosdk +# github.com/ugorji/go v0.0.0-20180813092308-00b869d2f4a5 github.com/ugorji/go/codec # github.com/ulikunitz/xz v0.5.5 github.com/ulikunitz/xz diff --git a/website/source/docs/builders/ucloud-uhost.html.md b/website/source/docs/builders/ucloud-uhost.html.md index 0bdce3f72..ff165ef1e 100644 --- a/website/source/docs/builders/ucloud-uhost.html.md +++ b/website/source/docs/builders/ucloud-uhost.html.md @@ -26,7 +26,7 @@ In addition to the options listed here, a [communicator](../templates/communicator.html) can be configured for this builder. -\~> **Note:** The bulider doesn't support Windows images for now and only supports CentOS and Ubuntu images via SSH anthentication with `ssh_username` (Required) and `ssh_password` (Optional). The `ssh_username` must be `root` for CentOS images and `ubuntu` for Ubuntu images. The `ssh_password` may contain 8-30 characters, and must consist of at least 2 items out of the capital letters, lower case letters, numbers and special characters. The special characters include `()~!@#$%^&*-+=_|{}\[]:;'<>,.?/. +\~> **Note:** The builder doesn't support Windows images for now and only supports CentOS and Ubuntu images via SSH authentication with `ssh_username` (Required) and `ssh_password` (Optional). The `ssh_username` must be `root` for CentOS images and `ubuntu` for Ubuntu images. The `ssh_password` may contain 8-30 characters, and must consist of at least 2 items out of the capital letters, lower case letters, numbers and special characters. The special characters include `()~!@#$%^&*-+=_|{}\[]:;'<>,.?/. ### Required: @@ -59,7 +59,7 @@ builder. - `vpc_id` - (string) The ID of VPC linked to the UHost instance. If not defined `vpc_id`, the instance will use the default VPC in the current region. -- `subnet_id` - (string) The ID of subnet under VPC. If `vpc_id` is defined, the `subnet_id` is mandatory required. If `vpc_id` and `subnet_id` are not defined, the instance will use the default subnet in the current region. +- `subnet_id` - (string) The ID of subnet under the VPC. If `vpc_id` is defined, the `subnet_id` is mandatory required. If `vpc_id` and `subnet_id` are not defined, the instance will use the default subnet in the current region. - `security_group` - (string) The ID of the fire wall associated to UHost instance. If `security_group` is not defined, the instance will use the non-recommended web fire wall, and open port include 22, 3389 by default. It is supported by ICMP fire wall protocols.