github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/apigw/dedicated/v2/throttles/results.go (about)

     1  package throttles
     2  
     3  import (
     4  	"github.com/chnsz/golangsdk"
     5  	"github.com/chnsz/golangsdk/pagination"
     6  )
     7  
     8  type commonResult struct {
     9  	golangsdk.Result
    10  }
    11  
    12  // CreateResult represents a result of the Create method.
    13  type CreateResult struct {
    14  	commonResult
    15  }
    16  
    17  // UpdateResult represents a result of the Update method.
    18  type UpdateResult struct {
    19  	commonResult
    20  }
    21  
    22  // GetResult represents a result of the Get method.
    23  type GetResult struct {
    24  	commonResult
    25  }
    26  
    27  type ThrottlingPolicy struct {
    28  	// Number of APIs to which the request throttling policy has been bound.
    29  	BindNum int `json:"bind_num"`
    30  	// Indicates whether an excluded request throttling configuration has been created.
    31  	// 1: yes
    32  	// 2: no
    33  	IsIncludeSpecialThrottle int `json:"is_inclu_special_throttle"`
    34  	// Creation time.
    35  	CreateTime string `json:"create_time"`
    36  	// Description.
    37  	Description string `json:"remark"`
    38  	// Type of the request throttling policy.
    39  	// 1: exclusive, limiting the maximum number of times a single API bound to the policy can be called within
    40  	// the specified period.
    41  	// 2: shared, limiting the maximum number of times all APIs bound to the policy can be called within the
    42  	// specified period.
    43  	Type int `json:"type"`
    44  	// Period of time for limiting the number of API calls.
    45  	TimeInterval int `json:"time_interval"`
    46  	// Maximum number of times the API can be accessed by an IP address within the same period.
    47  	IpCallLimits int `json:"ip_call_limits"`
    48  	// Maximum number of times the API can be accessed by an app within the same period.
    49  	AppCallLimits int `json:"app_call_limits"`
    50  	// Request throttling policy name.
    51  	Name string `json:"name"`
    52  	// Time unit for limiting the number of API calls.
    53  	// The valid values are as following:
    54  	//     SECOND
    55  	//     MINUTE
    56  	//     HOUR
    57  	//     DAY
    58  	TimeUnit string `json:"time_unit"`
    59  	// Maximum number of times an API can be accessed within a specified period.
    60  	ApiCallLimits int `json:"api_call_limits"`
    61  	// Request throttling policy ID.
    62  	Id string `json:"id"`
    63  	// Maximum number of times the API can be accessed by a user within the same period.
    64  	UserCallLimits int `json:"user_call_limits"`
    65  }
    66  
    67  func (r commonResult) Extract() (*ThrottlingPolicy, error) {
    68  	var s ThrottlingPolicy
    69  	err := r.ExtractInto(&s)
    70  	return &s, err
    71  }
    72  
    73  // The ThorttlePage represents the result of a List operation.
    74  type ThorttlePage struct {
    75  	pagination.SinglePageBase
    76  }
    77  
    78  // ExtractPolicies its Extract method to interpret it as a throttling policy array.
    79  func ExtractPolicies(r pagination.Page) ([]ThrottlingPolicy, error) {
    80  	var s []ThrottlingPolicy
    81  	err := r.(ThorttlePage).Result.ExtractIntoSlicePtr(&s, "throttles")
    82  	return s, err
    83  }
    84  
    85  type DeleteResult struct {
    86  	golangsdk.ErrResult
    87  }
    88  
    89  // SpecThrottle is a struct that represents the result of CreateSpecThrottle, UpdateSpecThrottle and
    90  // ListSpecThrottles methods.
    91  type SpecThrottle struct {
    92  	// Maximum number of times the excluded object can access an API within the throttling period.
    93  	CallLimits int `json:"call_limits"`
    94  	// Name of the app to which the excluded request throttling configuration applies.
    95  	AppName string `json:"app_name"`
    96  	// Name of an app or a tenant to which the excluded request throttling configuration applies.
    97  	ObjectName string `json:"object_name"`
    98  	// ID of an object specified in the excluded request throttling configuration.
    99  	ObjectId string `json:"object_id"`
   100  	// Request throttling policy ID.
   101  	ThrottleId string `json:"throttle_id"`
   102  	// Time when the excluded request throttling configuration is created.
   103  	ApplyTime string `json:"apply_time"`
   104  	// Excluded request throttling configuration ID.
   105  	ID string `json:"id"`
   106  	// ID of the app to which the excluded request throttling configuration applies.
   107  	AppId string `json:"app_id"`
   108  	// Excluded object type, which can be APP or USER.
   109  	ObjectType string `json:"object_type"`
   110  }
   111  
   112  // The SpecThrottleResult represents the base result of the each special throttling polciy methods.
   113  type SpecThrottleResult struct {
   114  	commonResult
   115  }
   116  
   117  // The CreateSpecThrottleResult represents the result of the CreateSpecThrottle method.
   118  type CreateSpecThrottleResult struct {
   119  	SpecThrottleResult
   120  }
   121  
   122  // The UpdateSpecThrottleResult represents the result of the UpdateSpecThrottle method.
   123  type UpdateSpecThrottleResult struct {
   124  	SpecThrottleResult
   125  }
   126  
   127  // Extract is a method which to extract the response to a special throttling policy.
   128  func (r SpecThrottleResult) Extract() (*SpecThrottle, error) {
   129  	var s SpecThrottle
   130  	err := r.ExtractInto(&s)
   131  	return &s, err
   132  }
   133  
   134  // The SpecThrottlePage represents the result of a List operation.
   135  type SpecThrottlePage struct {
   136  	pagination.SinglePageBase
   137  }
   138  
   139  // ExtractSpecThrottles its Extract method to interpret it as a special throttling policy array.
   140  func ExtractSpecThrottles(r pagination.Page) ([]SpecThrottle, error) {
   141  	var s []SpecThrottle
   142  	err := r.(SpecThrottlePage).Result.ExtractIntoSlicePtr(&s, "throttle_specials")
   143  	return s, err
   144  }
   145  
   146  type BindResp struct {
   147  	// The ID of the binding relationship.
   148  	ID string `json:"id"`
   149  	// The publish ID.
   150  	PublishId string `json:"publish_id"`
   151  	// Policy scope, the values are as follows:
   152  	// 1: The entire API
   153  	// 2: single user
   154  	// 3: Single APP
   155  	// Currently only 1 is supported.
   156  	Scope int `json:"scope"`
   157  	// Throttling policy ID
   158  	StrategyId string `json:"strategy_id"`
   159  	// Apply time.
   160  	ApplyTime string `json:"apply_time"`
   161  }
   162  
   163  type ApiForThrottle struct {
   164  	// API authentication method.
   165  	AuthType string `json:"auth_type"`
   166  	// Group name to which the API belongs.
   167  	GroupName string `json:"group_name"`
   168  	// API publish record ID.
   169  	PublishId string `json:"publish_id"`
   170  	// The number of the binding relationship with the throttling policy.
   171  	ThrottleApplyId string `json:"throttle_apply_id"`
   172  	// Binding time of the bound throttling policy.
   173  	ApplyTime string `json:"apply_time"`
   174  	// API description.
   175  	Remark string `json:"remark"`
   176  	// The ID of the environment published by the API.
   177  	RunEnvId string `json:"run_env_id"`
   178  	// API type
   179  	Type int `json:"type"`
   180  	// Binding throttling policy name.
   181  	ThrottleName string `json:"throttle_name"`
   182  	// Request URI of the API.
   183  	ReqUri string `json:"req_uri"`
   184  	// The name of the environment published by the API.
   185  	RunEnvName string `json:"run_env_name"`
   186  	// Group ID to which the API belogns.
   187  	GroupId string `json:"group_id"`
   188  	// API Name.
   189  	Name string `json:"name"`
   190  	// API ID.
   191  	ID string `json:"id"`
   192  }
   193  
   194  type BatchResp struct {
   195  	// Number of API and throttling policy bindings that have been successfully unbound.
   196  	SuccessCount int `json:"success_count"`
   197  	// Unbinding failed API and throttling policy binding relationship and error information.
   198  	Failure []UnbindResult `json:"failure"`
   199  }
   200  
   201  type UnbindResult struct {
   202  	// API and throttling policy binding relationship ID that failed to unbind.
   203  	BindId string `json:"bind_id"`
   204  	// Unbind failed error code
   205  	ErrorCode string `json:"error_code"`
   206  	// Unbind failed error message
   207  	ErrorMsg string `json:"error_msg"`
   208  	// ID of the API that failed to unbind
   209  	ApiId string `json:"api_id"`
   210  	// The name of the API that failed to unbind
   211  	ApiName string `json:"api_name"`
   212  }