github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/apigw/dedicated/v2/apis/requests.go (about) 1 package apis 2 3 import ( 4 "github.com/chnsz/golangsdk" 5 "github.com/chnsz/golangsdk/pagination" 6 ) 7 8 // APIOpts is a struct which will be used to create a new API or update an existing API. 9 type APIOpts struct { 10 // ID of the API group to which the API belongs. 11 GroupId string `json:"group_id" required:"true"` 12 // API name, which can contain 3 to 64 characters, starting with a letter. 13 // Only letters, digits, and underscores (_) are allowed. 14 // Chinese characters must be in UTF-8 or Unicode format. 15 Name string `json:"name" required:"true"` 16 // API type. The valid types are as following: 17 // 1: public API 18 // 2: private API 19 Type int `json:"type" required:"true"` 20 // Request protocol. The valid protocols are as following: 21 // HTTP. 22 // HTTPS (default). 23 // BOTH: The API can be accessed through both HTTP and HTTPS. 24 ReqProtocol string `json:"req_protocol" required:"true"` 25 // Request method. The valid values are GET, POST, PUT, DELETE, HEAD, PATCH, OPTIONS and ANY. 26 ReqMethod string `json:"req_method" required:"true"` 27 // Request address, which can contain a maximum of 512 characters request parameters enclosed with brackets ({}). 28 // For example, /getUserInfo/{userId}. 29 // The request address can contain special characters, such as asterisks (), percent signs (%), hyphens (-), and 30 // underscores (_) and must comply with URI specifications. 31 // The address can contain environment variables, each starting with a letter and consisting of 3 to 32 characters. 32 // Only letters, digits, hyphens (-), and underscores (_) are allowed in environment variables. 33 ReqURI string `json:"req_uri" required:"true"` 34 // Security authentication mode. The valid modes are as following: 35 // NONE 36 // APP 37 // IAM 38 // AUTHORIZER 39 AuthType string `json:"auth_type" required:"true"` 40 // Backend type. The valid types are as following: 41 // HTTP: web backend. 42 // FUNCTION: FunctionGraph backend. 43 // MOCK: Mock backend. 44 BackendType string `json:"backend_type" required:"true"` 45 // API version. The maximum length of version string is 16. 46 Version *string `json:"version,omitempty"` 47 // Security authentication parameter. 48 AuthOpt *AuthOpt `json:"auth_opt,omitempty"` 49 // Indicates whether CORS is supported. The valid values are as following: 50 // TRUE: supported. 51 // FALSE: not supported (default). 52 Cors *bool `json:"cors,omitempty"` 53 // Route matching mode. The valid modes are as following: 54 // SWA: prefix match 55 // NORMAL: exact match (default). 56 MatchMode string `json:"match_mode,omitempty"` 57 // Description of the API, which can contain a maximum of 255 characters. 58 // Chinese characters must be in UTF-8 or Unicode format. 59 Description *string `json:"remark,omitempty"` 60 // API request body, which can be an example request body, media type, or parameters. 61 // Ensure that the request body does not exceed 20,480 characters. 62 // Chinese characters must be in UTF-8 or Unicode format. 63 BodyDescription *string `json:"body_remark,omitempty"` 64 // Example response for a successful request. Ensure that the response does not exceed 20,480 characters. 65 // Chinese characters must be in UTF-8 or Unicode format. 66 ResultNormalSample *string `json:"result_normal_sample,omitempty"` 67 // Example response for a failed request. Ensure that the response does not exceed 20,480 characters. 68 // Chinese characters must be in UTF-8 or Unicode format. 69 ResultFailureSample *string `json:"result_failure_sample,omitempty"` 70 // ID of the frontend custom authorizer. 71 AuthorizerId string `json:"authorizer_id,omitempty"` 72 // List of tags. The length of the tags list is range from 1 to 128. 73 // The value can contain only letters, digits, and underscores (_), and must start with a letter. 74 Tags []string `json:"tags,omitempty"` 75 // Group response ID. 76 ResponseId string `json:"response_id,omitempty"` 77 // Request parameters. 78 ReqParams []ReqParamBase `json:"req_params,omitempty"` 79 // Backend parameters. 80 BackendParams []BackendParamBase `json:"backend_params,omitempty"` 81 // Mock backend details. 82 MockInfo *Mock `json:"mock_info,omitempty"` 83 // FunctionGraph backend details. 84 FuncInfo *FuncGraph `json:"func_info,omitempty"` 85 // Web backend details. 86 WebInfo *Web `json:"backend_api,omitempty"` 87 // Mock policy backends. 88 PolicyMocks []PolicyMock `json:"policy_mocks,omitempty"` 89 // FunctionGraph policy backends. 90 PolicyFunctions []PolicyFuncGraph `json:"policy_functions,omitempty"` 91 // Web policy backends. 92 PolicyWebs []PolicyWeb `json:"policy_https,omitempty"` 93 } 94 95 // AuthOpt is an object which will be build up an APIG application authorization. 96 type AuthOpt struct { 97 // Indicates whether AppCode authentication is enabled. The valid types are as following: 98 // DISABLE: AppCode authentication is disabled (default). 99 // HEADER: AppCode authentication is enabled and the AppCode is located in the header. 100 // This parameter is valid only if auth_type is set to App. 101 AppCodeAuthType string `json:"app_code_auth_type,omitempty"` 102 } 103 104 // Mock is an object which will be build up a mock backend. 105 type Mock struct { 106 // Description about the backend, which can contain a maximum of 255 characters. 107 // Chinese characters must be in UTF-8 or Unicode format. 108 Description *string `json:"remark,omitempty"` 109 // Response. 110 ResultContent *string `json:"result_content,omitempty"` 111 // Function version Ensure that the version does not exceed 64 characters. 112 Version string `json:"version,omitempty"` 113 // Backend custom authorizer ID. 114 AuthorizerId *string `json:"authorizer_id,omitempty"` 115 } 116 117 // FuncGraph is an object which will be build up a function graph backend. 118 type FuncGraph struct { 119 // Function URN. 120 FunctionUrn string `json:"function_urn" required:"true"` 121 // Invocation mode. The valid modes are as following: 122 // async: asynchronous 123 // sync: synchronous 124 InvocationType string `json:"invocation_type" required:"true"` 125 // Timeout, in ms, which allowed for API Gateway to request the backend service. 126 // The valid value is range from 1 to 600,000. 127 Timeout int `json:"timeout" required:"true"` 128 // Backend custom authorizer ID. 129 AuthorizerId *string `json:"authorizer_id,omitempty"` 130 // Description about the backend, which can contain a maximum of 255 characters. 131 // Chinese characters must be in UTF-8 or Unicode format. 132 Description *string `json:"remark,omitempty"` 133 // Function version. 134 // Maximum: 64 135 Version string `json:"version,omitempty"` 136 } 137 138 // Web is an object which will be build up a http backend. 139 type Web struct { 140 // Request method. The valid methods are GET, POST, PUT, DELETE, HEAD, PATCH, OPTIONS and ANY. 141 ReqMethod string `json:"req_method" required:"true"` 142 // Request protocol. The valid protocols are HTTP and HTTPS 143 ReqProtocol string `json:"req_protocol" required:"true"` 144 // Request address, which can contain a maximum of 512 characters request parameters enclosed with brackets ({}). 145 // For example, /getUserInfo/{userId}. 146 // The request address can contain special characters, such as asterisks (*), percent signs (%), hyphens (-), and 147 // underscores (_) and must comply with URI specifications. 148 // The address can contain environment variables, each starting with a letter and consisting of 3 to 32 characters. 149 // Only letters, digits, hyphens (-), and underscores (_) are allowed in environment variables. 150 ReqURI string `json:"req_uri" required:"true"` 151 // Timeout, in ms, which allowed for API Gateway to request the backend service. 152 // The valid value is range from 1 to 600,000. 153 Timeout int `json:"timeout" required:"true"` 154 // Backend custom authorizer ID. 155 AuthorizerId *string `json:"authorizer_id,omitempty"` 156 // Backend service address which consists of a domain name or IP address and a port number, with not more than 255 157 // characters. It must be in the format "Host name:Port number", for example, apig.example.com:7443. 158 // If the port number is not specified, the default HTTPS port 443 or the default HTTP port 80 is used. 159 // The backend service address can contain environment variables, each starting with a letter and consisting of 160 // 3 to 32 characters. Only letters, digits, hyphens (-), and underscores (_) are allowed. 161 DomainURL string `json:"url_domain,omitempty"` 162 // Description, which can contain a maximum of 255 characters. 163 // Chinese characters must be in UTF-8 or Unicode format. 164 Description *string `json:"remark,omitempty"` 165 // Web backend version, which can contain a maximum of 16 characters. 166 Version *string `json:"version,omitempty"` 167 // Indicates whether to enable two-way authentication. 168 ClientSslEnable *bool `json:"enable_client_ssl,omitempty"` 169 // VPC channel details. This parameter is required if vpc_channel_status is set to 1. 170 VpcChannelInfo *VpcChannel `json:"vpc_channel_info,omitempty"` 171 // Indicates whether to use a VPC channel. The valid values are as following: 172 // 1: (A VPC channel is used). 173 // 2: (No VPC channel is used). 174 VpcChannelStatus int `json:"vpc_channel_status,omitempty"` 175 // Number of retry attempts to request the backend service. 176 // The default value is –1, and the value ranges from –1 to 10. 177 // –1 indicates that idempotent APIs will retry once and non-idempotent APIs will not retry. 178 // POST and PATCH are non-idempotent. GET, HEAD, PUT, OPTIONS, and DELETE are idempotent. 179 RetryCount *string `json:"retry_count,omitempty"` 180 } 181 182 // VpcChannel is an object which will be build up a vpc channel. 183 type VpcChannel struct { 184 // VPC channel ID. 185 VpcChannelId string `json:"vpc_channel_id" required:"true"` 186 // Proxy host. 187 VpcChannelProxyHost string `json:"vpc_channel_proxy_host,omitempty"` 188 } 189 190 // ReqParamBase is an object which will be build up a front-end request parameter. 191 type ReqParamBase struct { 192 // The parameter name, which contain of 1 to 32 characters and start with a letter. 193 // Only letters, digits, hyphens (-), underscores (_), and periods (.) are allowed. 194 Name string `json:"name" required:"true"` 195 // Parameter type. The valid types are as following: 196 // STRING 197 // NUMBER 198 Type string `json:"type" required:"true"` 199 // Parameter location. The valid modes are as following: 200 // PATH 201 // QUERY 202 // HEADER 203 Location string `json:"location" required:"true"` 204 // Default value. 205 DefaultValue *string `json:"default_value,omitempty"` 206 // Example value. 207 SampleValue string `json:"sample_value,omitempty"` 208 // Indicates whether the parameter is required. The valid values are 1 (yes) and 2 (no). 209 // The value of this parameter is 1 if Location is set to PATH, and 2 if Location is set to another value. 210 Required int `json:"required,omitempty"` 211 // Indicates whether validity check is enabled. The valid modes are as following: 212 // 1: enabled. 213 // 2: disabled (default). 214 ValidEnable int `json:"valid_enable,omitempty"` 215 // Description about the backend, which can contain a maximum of 255 characters. 216 // Chinese characters must be in UTF-8 or Unicode format. 217 Description *string `json:"remark,omitempty"` 218 // Enumerated value. 219 Enumerations *string `json:"enumerations,omitempty"` 220 // Minimum value. 221 // This parameter is valid when type is set to NUMBER. 222 MinNum *int `json:"min_num,omitempty"` 223 // Maximum value. 224 // This parameter is valid when type is set to NUMBER. 225 MaxNum *int `json:"max_num,omitempty"` 226 // Minimum length. 227 // This parameter is valid when type is set to STRING. 228 MinSize *int `json:"min_size,omitempty"` 229 // Maximum length. 230 // This parameter is valid when type is set to STRING. 231 MaxSize *int `json:"max_size,omitempty"` 232 // Indicates whether to transparently transfer the parameter. The valid values are 1 (yes) and 2 (no). 233 PassThrough int `json:"pass_through,omitempty"` 234 } 235 236 // PolicyMock is an object which will be build up a backend policy of the mock. 237 type PolicyMock struct { 238 // Policy conditions. 239 Conditions []APIConditionBase `json:"conditions" required:"true"` 240 // Effective mode of the backend policy. The valid modes are as following: 241 // ALL: All conditions are met. 242 // ANY: Any condition is met. 243 EffectMode string `json:"effect_mode" required:"true"` 244 // Backend name, which consists of 3 to 64 characters and must start with a letter and can contain letters, digits, 245 // and underscores (_). 246 Name string `json:"name" required:"true"` 247 // Authorizer ID. 248 AuthorizerId *string `json:"authorizer_id,omitempty"` 249 // Backend parameters. 250 BackendParams []BackendParamBase `json:"backend_params,omitempty"` 251 // Response. 252 ResultContent string `json:"result_content,omitempty"` 253 } 254 255 // PolicyFuncGraph is an object which will be build up a backend policy of the function graph. 256 type PolicyFuncGraph struct { 257 // Policy conditions. 258 Conditions []APIConditionBase `json:"conditions" required:"true"` 259 // Effective mode of the backend policy. 260 // ALL: All conditions are met. 261 // ANY: Any condition is met. 262 EffectMode string `json:"effect_mode" required:"true"` 263 // Function URN. 264 FunctionUrn string `json:"function_urn" required:"true"` 265 // Invocation mode. The valid modes are as following: 266 // async: asynchronous 267 // sync: synchronous 268 InvocationType string `json:"invocation_type" required:"true"` 269 // The backend name consists of 3 to 64 characters, which must start with a letter and can contain letters, digits, 270 // and underscores (_). 271 Name string `json:"name" required:"true"` 272 // Authorizer ID. 273 AuthorizerId *string `json:"authorizer_id,omitempty"` 274 // Backend parameters. 275 BackendParams []BackendParamBase `json:"backend_params,omitempty"` 276 // Timeout, in ms, which allowed for API Gateway to request the backend service. 277 // The valid value is range from 1 to 600,000. 278 Timeout int `json:"timeout,omitempty"` 279 // Function version Ensure that the version does not exceed 64 characters. 280 Version string `json:"version,omitempty"` 281 } 282 283 // PolicyWeb is an object which will be build up a backend policy of the http. 284 type PolicyWeb struct { 285 // Request protocol. The value can be HTTP or HTTPS. 286 ReqProtocol string `json:"req_protocol" required:"true"` 287 // Request method. The valid methods are GET, POST, PUT, DELETE, HEAD, PATCH, OPTIONS and ANY. 288 ReqMethod string `json:"req_method" required:"true"` 289 // Request address, which can contain request parameters enclosed with brackets ({}). 290 // For example, /getUserInfo/{userId}. The request address can contain special characters, such as asterisks (), 291 // percent signs (%), hyphens (-), and underscores (_). It can contain a maximum of 512 characters and must comply 292 // with URI specifications. 293 // The request address can contain environment variables, each starting with a letter and consisting of 3 to 32 294 // characters. Only letters, digits, hyphens (-), and underscores (_) are allowed in environment variables. 295 // The request address must comply with URI specifications. 296 ReqURI string `json:"req_uri" required:"true"` 297 // Effective mode of the backend policy. The valid modes are as following: 298 // ALL: All conditions are met. 299 // ANY: Any condition is met. 300 EffectMode string `json:"effect_mode" required:"true"` 301 // Backend name, which contains of 3 to 64, must start with a letter and can contain letters, digits, and 302 // underscores (_). 303 Name string `json:"name" required:"true"` 304 // Policy conditions. 305 Conditions []APIConditionBase `json:"conditions" required:"true"` 306 // Backend parameters. 307 BackendParams []BackendParamBase `json:"backend_params,omitempty"` 308 // Authorizer ID. 309 AuthorizerId *string `json:"authorizer_id,omitempty"` 310 // VPC channel details. This parameter is required if vpc_channel_status is set to 1. 311 VpcChannelInfo *VpcChannel `json:"vpc_channel_info,omitempty"` 312 // Indicates whether to use a VPC channel. The valid value are as following: 313 // 1: A VPC channel is used. 314 // 2: No VPC channel is used. 315 VpcChannelStatus int `json:"vpc_channel_status,omitempty"` 316 // Endpoint of the policy backend. 317 // An endpoint consists of a domain name or IP address and a port number, with not more than 255 characters. 318 // It must be in the format "Domain name:Port number", for example, apig.example.com:7443. 319 // If the port number is not specified, the default HTTPS port 443 or the default HTTP port 80 is used. 320 // The endpoint can contain environment variables, each starting with letter and consisting of 3 to 32 characters. 321 // Only letters, digits, hyphens (-), and underscores (_) are allowed. 322 DomainURL string `json:"url_domain,omitempty"` 323 // Timeout, in ms, which allowed for API Gateway to request the backend service. 324 // The valid value is range from 1 to 600,000. 325 Timeout int `json:"timeout,omitempty"` 326 // Number of retry attempts to request the backend service. 327 // The default value is –1, and the value ranges from –1 to 10. 328 // –1 indicates that idempotent APIs will retry once and non-idempotent APIs will not retry. 329 // POST and PATCH are non-idempotent. GET, HEAD, PUT, OPTIONS, and DELETE are idempotent. 330 RetryCount *string `json:"retry_count,omitempty"` 331 } 332 333 // BackendParamBase is an object which will be build up a back-end parameter. 334 type BackendParamBase struct { 335 // Parameter type. The valid types are as following: 336 // REQUEST: Backend parameter. 337 // CONSTANT: Constant parameter. 338 // SYSTEM: System parameter. 339 Origin string `json:"origin" required:"true"` 340 // Parameter name, which can contains 1 to 32 characters, must start with a letter and can only contain letters, 341 // digits, hyphens (-), underscores (_) and periods (.). 342 Name string `json:"name" required:"true"` 343 // Parameter location. The valid values are PATH, QUERY and HEADER. 344 Location string `json:"location" required:"true"` 345 // Parameter value, which can contain a maximum of 255 characters. If the origin type is REQUEST, the value of this parameter is the parameter name in req_params. 346 // If the origin type is CONSTANT, the value is a constant. 347 // If the origin type is SYSTEM, the value is a system parameter name. System parameters include gateway parameters, frontend authentication parameters, and backend authentication parameters. You can set the frontend or backend authentication parameters after enabling custom frontend or backend authentication. 348 // The gateway parameters are as follows: 349 // $context.sourceIp: source IP address of the API caller. 350 // $context.stage: deployment environment in which the API is called. 351 // $context.apiId: API ID. 352 // $context.appId: ID of the app used by the API caller. 353 // $context.requestId: request ID generated when the API is called. 354 // $context.serverAddr: address of the gateway server. 355 // $context.serverName: name of the gateway server. 356 // $context.handleTime: time when the API request is processed. 357 // $context.providerAppId: ID of the app used by the API owner. This parameter is currently not supported. 358 // Frontend authentication parameter: prefixed with "$context.authorizer.frontend.". For example, to return "aaa" upon successful custom authentication, set this parameter to "$context.authorizer.frontend.aaa". 359 // Backend authentication parameter: prefixed with "$context.authorizer.backend.". For example, to return "aaa" upon successful custom authentication, set this parameter to "$context.authorizer.backend.aaa". 360 Value string `json:"value" required:"true"` 361 // Description, which can contain a maximum of 255 characters. 362 // Chinese characters must be in UTF-8 or Unicode format. 363 Description *string `json:"remark,omitempty"` 364 } 365 366 // APIConditionBase is an object which will be build up a policy condition. 367 type APIConditionBase struct { 368 // Policy type. The valid types are as following: 369 // param: input parameter 370 // source: source IP address 371 // system: gateway built-in parameter 372 // cookie: cookie parameter 373 // frontend_authorizer: frontend authentication parameter 374 ConditionOrigin string `json:"condition_origin" required:"true"` 375 // Condition value. 376 ConditionValue string `json:"condition_value" required:"true"` 377 // Input parameter name. This parameter is required if the policy type is param. 378 ReqParamName string `json:"req_param_name,omitempty"` 379 // Gateway built-in parameter name. This parameter is required if the policy type is system. 380 SysParamName string `json:"sys_param_name,omitempty"` 381 // Cookie parameter name. This parameter is required if the policy type is cookie. 382 CookieParamName string `json:"cookie_param_name,omitempty"` 383 // Frontend authentication parameter name. This parameter is required if the policy type is frontend_authorizer. 384 FrontendAuthorizerParamName string `json:"frontend_authorizer_param_name,omitempty"` 385 // Policy condition. The valid values are as following: 386 // exact: exact match 387 // enum: enumeration 388 // pattern: regular expression 389 // This parameter is required if the policy type is param, system, cookie and frontend_authorizer. 390 ConditionType string `json:"condition_type,omitempty"` 391 } 392 393 // APIOptsBuilder is an interface which to support request body build of the API creation and updation. 394 type APIOptsBuilder interface { 395 ToAPIOptsMap() (map[string]interface{}, error) 396 } 397 398 // ToAPIOptsMap is a method which to build a request body by the APIOpts. 399 func (opts APIOpts) ToAPIOptsMap() (map[string]interface{}, error) { 400 return golangsdk.BuildRequestBody(opts, "") 401 } 402 403 // Create is a method by which to create function that create a new custom API. 404 func Create(client *golangsdk.ServiceClient, instanceId string, opts APIOptsBuilder) (r CreateResult) { 405 reqBody, err := opts.ToAPIOptsMap() 406 if err != nil { 407 r.Err = err 408 return 409 } 410 _, r.Err = client.Post(rootURL(client, instanceId), reqBody, &r.Body, nil) 411 return 412 } 413 414 // Update is a method to update an existing custom API. 415 func Update(client *golangsdk.ServiceClient, instanceId, appId string, opts APIOptsBuilder) (r UpdateResult) { 416 reqBody, err := opts.ToAPIOptsMap() 417 if err != nil { 418 r.Err = err 419 return 420 } 421 _, r.Err = client.Put(resourceURL(client, instanceId, appId), reqBody, &r.Body, &golangsdk.RequestOpts{ 422 OkCodes: []int{200}, 423 }) 424 return 425 } 426 427 // Get is a method to obtain the specified API according to the instanceId and API ID. 428 func Get(client *golangsdk.ServiceClient, instanceId, apiId string) (r GetResult) { 429 _, r.Err = client.Get(resourceURL(client, instanceId, apiId), &r.Body, nil) 430 return 431 } 432 433 // ListOpts allows to filter list data using given parameters. 434 type ListOpts struct { 435 // API ID. 436 ID string `q:"id"` 437 // API name. 438 Name string `q:"name"` 439 // API group ID. 440 GroupId string `q:"group_id"` 441 // Request protocol. 442 ReqProtocol string `q:"req_protocol"` 443 // Request method. 444 ReqMethod string `q:"req_method"` 445 // Request path. 446 ReqURI string `q:"req_uri"` 447 // Security authentication mode. 448 AuthType string `q:"auth_type"` 449 // ID of the environment in which the API has been published. 450 EnvId string `q:"env_id"` 451 // API type. 452 Type int `q:"type"` 453 // Offset from which the query starts. 454 // If the offset is less than 0, the value is automatically converted to 0. Default to 0. 455 Offset int `q:"offset"` 456 // Number of items displayed on each page. The range of number is form 1 to 500, default to 20. 457 Limit int `q:"limit"` 458 // Parameter name (name or req_uri) for exact matching. 459 PreciseSearch string `q:"precise_search"` 460 } 461 462 // ListOptsBuilder is an interface which to support request query build of the API search. 463 type ListOptsBuilder interface { 464 ToListOptsQuery() (string, error) 465 } 466 467 // ToListOptsQuery is a method which to build a request query by the ListOpts. 468 func (opts ListOpts) ToListOptsQuery() (string, error) { 469 q, err := golangsdk.BuildQueryString(opts) 470 if err != nil { 471 return "", err 472 } 473 return q.String(), err 474 } 475 476 // List is a method to obtain an array of one or more APIs according to the query parameters. 477 func List(client *golangsdk.ServiceClient, instanceId string, opts ListOptsBuilder) pagination.Pager { 478 url := rootURL(client, instanceId) 479 if opts != nil { 480 query, err := opts.ToListOptsQuery() 481 if err != nil { 482 return pagination.Pager{Err: err} 483 } 484 url += query 485 } 486 487 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 488 return APIPage{pagination.SinglePageBase(r)} 489 }) 490 } 491 492 // Delete is a method to delete an existing custom API. 493 func Delete(client *golangsdk.ServiceClient, instanceId, apiId string) (r DeleteResult) { 494 _, r.Err = client.Delete(resourceURL(client, instanceId, apiId), nil) 495 return 496 } 497 498 // PublishOpts allows to publish a new version or offline an exist version for API using given parameters. 499 type PublishOpts struct { 500 // Operation to perform. 501 // online: publishing the APIs 502 // offline: taking the APIs offline 503 Action string `json:"action" required:"true"` 504 // ID of the environment in which the API will be published. 505 EnvId string `json:"env_id" required:"true"` 506 // ID of the API to be published or taken offline. 507 ApiId string `json:"api_id" required:"true"` 508 // Description about the operation, which can contain a maximum of 255 characters. 509 // Chinese characters must be in UTF-8 or Unicode format. 510 Description string `json:"remark,omitempty"` 511 } 512 513 // PublishOptsBuilder is an interface which to support request body build of the API publish method. 514 type PublishOptsBuilder interface { 515 ToPublishOptsMap() (map[string]interface{}, error) 516 } 517 518 // ToPublishOptsMap is a method which to build a request body by the ToPublishOptsMap. 519 func (opts PublishOpts) ToPublishOptsMap() (map[string]interface{}, error) { 520 return golangsdk.BuildRequestBody(opts, "") 521 } 522 523 // ToPublishOptsMap is a method which to publish a new version or offline an exist version for API. 524 func Publish(client *golangsdk.ServiceClient, instanceId string, opts PublishOptsBuilder) (r PublishResult) { 525 reqBody, err := opts.ToPublishOptsMap() 526 if err != nil { 527 r.Err = err 528 return 529 } 530 _, r.Err = client.Post(releaseURL(client, instanceId), reqBody, &r.Body, nil) 531 return 532 } 533 534 // VersionSwitchOpts allows to switch a specified version using version ID. 535 type VersionSwitchOpts struct { 536 // API version ID. 537 VersionId string `json:"version_id,omitempty"` 538 } 539 540 // VersionSwitchOptsBuilder is an interface which to support request body build of the API version switch method. 541 type VersionSwitchOptsBuilder interface { 542 ToVersionSwitchOptsMap() (map[string]interface{}, error) 543 } 544 545 // ToVersionSwitchOptsMap is a method which to build a request body by the VersionSwitchOpts. 546 func (opts VersionSwitchOpts) ToVersionSwitchOptsMap() (map[string]interface{}, error) { 547 return golangsdk.BuildRequestBody(opts, "") 548 } 549 550 // SwitchSpecVersion is a method which to switch a specified version. 551 func SwitchSpecVersion(client *golangsdk.ServiceClient, instanceId, apiId, versionId string) (r PublishResult) { 552 opts := VersionSwitchOpts{ 553 VersionId: versionId, 554 } 555 reqBody, err := opts.ToVersionSwitchOptsMap() 556 if err != nil { 557 r.Err = err 558 return 559 } 560 _, r.Err = client.Put(publishVersionURL(client, instanceId, apiId), reqBody, &r.Body, nil) 561 return 562 } 563 564 // ListPublishHistoriesOpts allows to obtains a list of publish histories using given parameters. 565 type ListPublishHistoriesOpts struct { 566 // Environment ID. 567 EnvId string `q:"env_id"` 568 // Environment name. 569 EnvName string `q:"env_name"` 570 // Offset from which the query starts. If the offset is less than 0, the value is automatically converted to 0. 571 // Default: 0 572 Offset int `q:"offset"` 573 // Number of items displayed on each page. 574 // Minimum: 1 575 // Maximum: 500 576 // Default: 20 577 Limit int `q:"limit"` 578 } 579 580 // ListPublishHistoriesBuilder is an interface which to support request query build of the publish histories search. 581 type ListPublishHistoriesBuilder interface { 582 ToListPublishHistoriesQuery() (string, error) 583 } 584 585 // ToListPublishHistoriesQuery is a method which to build a request query by the ListPublishHistoriesOpts. 586 func (opts ListPublishHistoriesOpts) ToListPublishHistoriesQuery() (string, error) { 587 q, err := golangsdk.BuildQueryString(opts) 588 return q.String(), err 589 } 590 591 // ListPublishHistories is a method to obtains a list of publish histories of the API. 592 func ListPublishHistories(client *golangsdk.ServiceClient, instanceId, apiId string, 593 opts ListPublishHistoriesBuilder) pagination.Pager { 594 url := publishVersionURL(client, instanceId, apiId) 595 if opts != nil { 596 query, err := opts.ToListPublishHistoriesQuery() 597 if err != nil { 598 return pagination.Pager{Err: err} 599 } 600 url += query 601 } 602 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 603 return PublishHistoriesPage{pagination.SinglePageBase(r)} 604 }) 605 } 606 607 // GetVersionDetail is a method to obtains a publish detail of the API for special version. 608 func GetVersionDetail(client *golangsdk.ServiceClient, instanceId, versionId string) (*APIResp, error) { 609 var r APIResp 610 _, err := client.Get(showHistoryDetailURL(client, instanceId, versionId), &r, nil) 611 return &r, err 612 }