From d9c1f152b96ba3c672d7e328a9c799123ff88417 Mon Sep 17 00:00:00 2001 From: rogerhu Date: Tue, 4 Sep 2018 21:04:03 +0800 Subject: [PATCH 1/2] strict-http-status-validate --- request/unpacker.go | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/request/unpacker.go b/request/unpacker.go index 589ec37..5cf4a54 100644 --- a/request/unpacker.go +++ b/request/unpacker.go @@ -76,29 +76,35 @@ func (u *Unpacker) parseResponse() error { return fmt.Errorf("API Gateway output format error") } } + } else { + u.httpResponse.Body.Close() + err := fmt.Errorf("Response StatusCode: %d", u.httpResponse.StatusCode) + logger.Error(err.Error()) + return err } return nil } func (u *Unpacker) parseError() error { - + if u.output.IsNil() { + return fmt.Errorf("nil returned") + } retCodeValue := u.output.Elem().FieldByName("RetCode") messageValue := u.output.Elem().FieldByName("Message") - if !retCodeValue.Elem().IsValid() || retCodeValue.Type().String() != "*int" { - return fmt.Errorf("can not get retcode") - } - - if retCodeValue.Elem().Int() != 0 { - if !messageValue.Elem().IsValid() || messageValue.Type().String() != "*string" { - return fmt.Errorf("can not get error message") + if retCodeValue.IsValid() && retCodeValue.Type().String() == "*int" && + retCodeValue.Elem().IsValid() { + if retCodeValue.Elem().Int() == 0 { + return nil } - - return &errors.QingCloudError{ + err := &errors.QingCloudError{ RetCode: int(retCodeValue.Elem().Int()), - Message: messageValue.Elem().String(), } + if messageValue.IsValid() && messageValue.Type().String() == "*string" { + err.Message = messageValue.Elem().String() + } + return err } - return nil + return fmt.Errorf("invalid retCodeValue %v returned", retCodeValue) } From da4738e7de10cb5609aa84d6c844f6f9b4e4a83d Mon Sep 17 00:00:00 2001 From: rogerhu Date: Wed, 19 Dec 2018 20:13:52 +0800 Subject: [PATCH 2/2] support-neonsan --- request/builder.go | 2 +- service/app.go | 42 ++++++++++++++++++++++++++++++++++++++++++ service/cluster.go | 22 ++++++++++++++-------- service/types.go | 35 ++++++++++++++++++++++------------- service/volume.go | 4 ++-- 5 files changed, 81 insertions(+), 24 deletions(-) diff --git a/request/builder.go b/request/builder.go index 9c87c88..b655afc 100644 --- a/request/builder.go +++ b/request/builder.go @@ -61,7 +61,7 @@ func (b *Builder) build() (*http.Request, error) { if err != nil { return nil, err } - if b.operation.RequestMethod == "POST"{ + if b.operation.RequestMethod == "POST" { httpRequest.Header.Set("Content-Type", "application/x-www-form-urlencoded") } diff --git a/service/app.go b/service/app.go index 90b8d6a..b57646d 100644 --- a/service/app.go +++ b/service/app.go @@ -294,3 +294,45 @@ type DescribeAppsOutput struct { RetCode *int `json:"ret_code" name:"ret_code" location:"elements"` TotalCount *int `json:"total_count" name:"total_count" location:"elements"` } + +// Documentation URL: https://docs.qingcloud.com/api/bot/describe_app_version_attachments.html +func (s *AppService) GetGlobalUniqueId(i *GetGlobalUniqueIdInput) (*GetGlobalUniqueIdOutput, error) { + if i == nil { + i = &GetGlobalUniqueIdInput{} + } + o := &data.Operation{ + Config: s.Config, + Properties: s.Properties, + APIName: "GetGlobalUniqueId", + RequestMethod: "GET", + } + + x := &GetGlobalUniqueIdOutput{} + r, err := request.New(o, i, x) + if err != nil { + return nil, err + } + + err = r.Send() + if err != nil { + return nil, err + } + + return x, err +} + +type GetGlobalUniqueIdInput struct { + UserID *string `json:"user_id" name:"user_id" location:"params"` +} + +func (v *GetGlobalUniqueIdInput) Validate() error { + + return nil +} + +type GetGlobalUniqueIdOutput struct { + Message *string `json:"message" name:"message"` + Action *string `json:"action" name:"action" location:"elements"` + RetCode *int `json:"ret_code" name:"ret_code" location:"elements"` + UUID *string `json:"uuid" name:"uuid" location:"elements"` +} diff --git a/service/cluster.go b/service/cluster.go index 06f6471..071b966 100644 --- a/service/cluster.go +++ b/service/cluster.go @@ -483,8 +483,8 @@ func (s *ClusterService) DeleteClusters(i *DeleteClustersInput) (*DeleteClusters } type DeleteClustersInput struct { - Clusters []*string `json:"clusters" name:"clusters" location:"params"` // Required - DirectCease *int `json:"direct_cease" name:"direct_cease" location:"params"` + Clusters []*string `json:"clusters" name:"clusters" location:"params"` // Required + Force *int `json:"force" name:"force" location:"params"` } func (v *DeleteClustersInput) Validate() error { @@ -710,20 +710,26 @@ func (s *ClusterService) DescribeClusters(i *DescribeClustersInput) (*DescribeCl type DescribeClustersInput struct { AppVersions []*string `json:"app_versions" name:"app_versions" location:"params"` Apps []*string `json:"apps" name:"apps" location:"params"` - ClusterName *string `json:"cluster_name" name:"cluster_name" location:"params"` + CfgmgmtID *string `json:"cfgmgmt_id" name:"cfgmgmt_id" location:"params"` Clusters []*string `json:"clusters" name:"clusters" location:"params"` + Console *string `json:"console" name:"console" location:"params"` ExternalClusterID *string `json:"external_cluster_id" name:"external_cluster_id" location:"params"` Limit *int `json:"limit" name:"limit" location:"params"` Link *string `json:"link" name:"link" location:"params"` + Name *string `json:"name" name:"name" location:"params"` Offset *int `json:"offset" name:"offset" location:"params"` Owner *string `json:"owner" name:"owner" location:"params"` Reverse *int `json:"reverse" name:"reverse" location:"params"` + Role *string `json:"role" name:"role" location:"params"` // Scope's available values: all, cfgmgmt - Scope *string `json:"scope" name:"scope" location:"params"` - Status []*string `json:"status" name:"status" location:"params"` - Tags []*string `json:"tags" name:"tags" location:"params"` - Verbose *int `json:"verbose" name:"verbose" location:"params"` - VxNet *string `json:"vxnet" name:"vxnet" location:"params"` + Scope *string `json:"scope" name:"scope" location:"params"` + SearchWord *string `json:"search_word" name:"search_word" location:"params"` + SortKey *string `json:"sort_key" name:"sort_key" location:"params"` + Status *string `json:"status" name:"status" location:"params"` + TransitionStatus *string `json:"transition_status" name:"transition_status" location:"params"` + Users []*string `json:"users" name:"users" location:"params"` + Verbose *int `json:"verbose" name:"verbose" location:"params"` + VxNet *string `json:"vxnet" name:"vxnet" location:"params"` } func (v *DescribeClustersInput) Validate() error { diff --git a/service/types.go b/service/types.go index dce2dc2..67cf8af 100644 --- a/service/types.go +++ b/service/types.go @@ -465,16 +465,21 @@ func (v *CachePrivateIP) Validate() error { type Cluster struct { AdvancedActions map[string]*string `json:"advanced_actions" name:"advanced_actions"` AppID *string `json:"app_id" name:"app_id"` - AppInfo *App `json:"app_info" name:"app_info"` + AppInfo interface{} `json:"app_info" name:"app_info"` AppVersion *string `json:"app_version" name:"app_version"` - AppVersionInfo *AppVersion `json:"app_version_info" name:"app_version_info"` + AppVersionInfo interface{} `json:"app_version_info" name:"app_version_info"` AutoBackupTime *int `json:"auto_backup_time" name:"auto_backup_time"` + Backup map[string]*bool `json:"backup" name:"backup"` BackupPolicy *string `json:"backup_policy" name:"backup_policy"` + BackupService interface{} `json:"backup_service" name:"backup_service"` + CfgmgmtID *string `json:"cfgmgmt_id" name:"cfgmgmt_id"` ClusterID *string `json:"cluster_id" name:"cluster_id"` ClusterType *int `json:"cluster_type" name:"cluster_type"` ConsoleID *string `json:"console_id" name:"console_id"` + Controller *string `json:"controller" name:"controller"` CreateTime *time.Time `json:"create_time" name:"create_time" format:"ISO 8601"` CustomService interface{} `json:"custom_service" name:"custom_service"` + Debug *bool `json:"debug" name:"debug"` Description *string `json:"description" name:"description"` DisplayTabs interface{} `json:"display_tabs" name:"display_tabs"` Endpoints interface{} `json:"endpoints" name:"endpoints"` @@ -482,16 +487,24 @@ type Cluster struct { HealthCheckEnablement map[string]*bool `json:"health_check_enablement" name:"health_check_enablement"` IncrementalBackupSupported *bool `json:"incremental_backup_supported" name:"incremental_backup_supported"` LatestSnapshotTime *string `json:"latest_snapshot_time" name:"latest_snapshot_time"` + Links map[string]*string `json:"links" name:"links"` + MetadataRootAccess *int `json:"metadata_root_access" name:"metadata_root_access"` Name *string `json:"name" name:"name"` NodeCount *int `json:"node_count" name:"node_count"` + Nodes []*ClusterNode `json:"nodes" name:"nodes"` Owner *string `json:"owner" name:"owner"` + PartnerAccess *bool `json:"partner_access" name:"partner_access"` + RestoreService interface{} `json:"restore_service" name:"restore_service"` + ReuseHyper *int `json:"reuse_hyper" name:"reuse_hyper"` RoleCount map[string]*int `json:"role_count" name:"role_count"` Roles []*string `json:"roles" name:"roles"` RootUserID *string `json:"root_user_id" name:"root_user_id"` SecurityGroupID *string `json:"security_group_id" name:"security_group_id"` Status *string `json:"status" name:"status"` - Tags []*string `json:"tags" name:"tags"` + StatusTime *time.Time `json:"status_time" name:"status_time" format:"ISO 8601"` + SubCode *int `json:"sub_code" name:"sub_code"` TransitionStatus *string `json:"transition_status" name:"transition_status"` + UpgradePolicy []*string `json:"upgrade_policy" name:"upgrade_policy"` UpgradeStatus *string `json:"upgrade_status" name:"upgrade_status"` UpgradeTime *time.Time `json:"upgrade_time" name:"upgrade_time" format:"ISO 8601"` VxNet *VxNet `json:"vxnet" name:"vxnet"` @@ -499,15 +512,11 @@ type Cluster struct { func (v *Cluster) Validate() error { - if v.AppInfo != nil { - if err := v.AppInfo.Validate(); err != nil { - return err - } - } - - if v.AppVersionInfo != nil { - if err := v.AppVersionInfo.Validate(); err != nil { - return err + if len(v.Nodes) > 0 { + for _, property := range v.Nodes { + if err := property.Validate(); err != nil { + return err + } } } @@ -1216,7 +1225,7 @@ type KeyPair struct { Owner *string `json:"owner" name:"owner"` PrivKey *string `json:"priv_key" name:"priv_key"` PubKey *string `json:"pub_key" name:"pub_key"` - ResourceIDs []*string `json:"resource_ids" name:"resource_ids"` + ResourceIDs *string `json:"resource_ids" name:"resource_ids"` Tags []*Tag `json:"tags" name:"tags"` } diff --git a/service/volume.go b/service/volume.go index c3ea6a7..3c48625 100644 --- a/service/volume.go +++ b/service/volume.go @@ -262,7 +262,7 @@ type DescribeVolumesInput struct { Tags []*string `json:"tags" name:"tags" location:"params"` // Verbose's available values: 0, 1 Verbose *int `json:"verbose" name:"verbose" default:"0" location:"params"` - // VolumeType's available values: 0, 1, 2, 3 + // VolumeType's available values: 0, 1, 2, 3, 5 VolumeType *int `json:"volume_type" name:"volume_type" location:"params"` Volumes []*string `json:"volumes" name:"volumes" location:"params"` } @@ -290,7 +290,7 @@ func (v *DescribeVolumesInput) Validate() error { } if v.VolumeType != nil { - volumeTypeValidValues := []string{"0", "1", "2", "3"} + volumeTypeValidValues := []string{"0", "1", "2", "3", "5"} volumeTypeParameterValue := fmt.Sprint(*v.VolumeType) volumeTypeIsValid := false