github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/fgs/v2/versions/results.go (about) 1 package versions 2 3 import ( 4 "strconv" 5 6 "github.com/chnsz/golangsdk/pagination" 7 ) 8 9 // Version is the structure that represents the specified function version details. 10 type Version struct { 11 // Function URN. 12 FuncUrn string `json:"func_urn"` 13 // Function name. 14 FuncName string `json:"func_name"` 15 // Domain ID. 16 DomainId string `json:"domain_id"` 17 // Project ID. 18 Namespace string `json:"namespace"` 19 // Project name. 20 ProjectName string `json:"project_name"` 21 // Group package to which the function belongs. This field is defined to group functions. 22 Package string `json:"package"` 23 // Environment in which a FunctionGraph function is executed. Options: 24 // Enumeration values: 25 // + Java8 26 // + Java11 27 // + Node.js6.10 28 // + Node.js8.10 29 // + Node.js10.16 30 // + Node.js12.13 31 // + Node.js14.18 32 // + Python2.7 33 // + Python3.6 34 // + Go1.8 35 // + Go1.x 36 // + C#(.NET Core 2.0) 37 // + C#(.NET Core 2.1) 38 // + C#(.NET Core 3.1) 39 // + Custom 40 // + PHP7.3 41 // + Python3.9 42 // + http 43 Runtime string `json:"runtime"` 44 // Maximum duration the function can be executed. Value range: 3s–900s. 45 // The value can be up to 12 hours for whitelisted users. 46 // For details, contact FunctionGraph personnel. 47 Timeout int `json:"timeout"` 48 // Handler of a function in the format of "xx.xx". It must contain a period (.). 49 // For example, for Node.js function myfunction.handler, the file name is myfunction.js, 50 // and the handler function is handler. 51 Handle string `json:"handle"` 52 // Memory consumed by a function. 53 // Unit: MB. 54 // The value can be 128, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2560, 3072, 3584 or 4096. 55 // The value ranges from 128 to 4096. 56 MemorySize int `json:"memory_size"` 57 // CPU resources of a function. 58 // Unit: millicore (1 core = 1000 millicores). 59 // The value of this field is proportional to that of MemorySize. 60 // By default, 100 CPU millicores are required for 128 MB memory. 61 // The value is calculated as follows: Memory/128 x 100 + 200 (basic CPU millicores) 62 CPU int `json:"cpu"` 63 // Function code type. Options: 64 // + inline: inline code. 65 // + zip: ZIP file. 66 // + obs: function code stored in an OBS bucket. 67 // + jar: JAR file, for Java functions. 68 CodeType string `json:"code_type"` 69 // If CodeType is set to obs, enter the OBS URL of the function code package. 70 // If CodeType is not set to obs, leave this parameter blank. 71 CodeURL string `json:"code_url"` 72 // Name of a function file. This parameter is mandatory only when CodeType is set to jar or zip. 73 CodeFileName string `json:"code_filename"` 74 // Code size in bytes. 75 CodeSize int `json:"code_size"` 76 // Name/Value information defined for the function. These are parameters used in the function. 77 // For example, if a function needs to access a host, define Host={host_ip}. 78 // You can define a maximum of 20 such parameters, and their total length cannot exceed 4 KB. 79 UserData string `json:"user_data"` 80 // User-defined name/value to be encrypted. 81 EncryptedUserData string `json:"encrypted_user_data"` 82 // SHA512 hash value of function code, which is used to determine whether the function has changed. 83 Digest string `json:"digest"` 84 // Function version, which is automatically generated by the system. 85 // The version name is in the format of "vYYYYMMDD-HHMMSS" (v+year/month/day-hour/minute/second). 86 Version string `json:"version"` 87 // Internal identifier of a function version. 88 ImageName string `json:"image_name"` 89 // Agency used by the function. You need to create an agency on the IAM console. 90 // This field is mandatory when a function needs to access other services. 91 Xrole string `json:"xrole"` 92 // Agency used by the function app. You need to create an agency on the IAM console. 93 // This field is mandatory when a function needs to access other services. 94 AppXrole string `json:"app_xrole"` 95 // Time when the function was last updated. 96 LastModified string `json:"last_modified"` 97 // VPC ID. 98 FuncVpcId string `json:"func_vpc_id"` 99 // Whether the function is disabled. 100 // + 0: The function is disabled. 101 // + -1: The function is enabled. 102 Concurrency int `json:"concurrency"` 103 // Number of concurrent instances. 104 ConcurrentNum int `json:"concurrent_num"` 105 // Function policy configuration. 106 StrategyConfig StrategyConfig `json:"strategy_config"` 107 // Initializer of the function. It is in the format of "xx.xx" and must contain a period (.). 108 // For example, for Node.js function myfunction.initializer, the file name is myfunction.js, 109 // and the initialization function is initializer. 110 InitializerHandler string `json:"initializer_handler"` 111 // Maximum duration the function can be initialized. Value range: 1s–300s. 112 InitializerTimeout int `json:"initializer_timeout"` 113 // Whether long-term running is supported. 114 LongTime bool `json:"long_time"` 115 // Return struct of the asynchronous execution notification settings. 116 FunctionAsyncConfig FunctionAsyncConfig `json:"function_async_config"` 117 // Function type. 118 Type string `json:"type"` 119 // Whether to enable cloud-based debugging. 120 EnableCloudDebug string `json:"enable_cloud_debug"` 121 // Whether to enable dynamic memory allocation. 122 EnableDynamicMemory bool `json:"enable_dynamic_memory"` 123 // Enterprise project ID. This parameter is mandatory if you create a function as an enterprise user. 124 EnterpriseProjectId string `json:"enterprise_project_id"` 125 // Whether stateful functions are supported. If they are supported, set this parameter to true. 126 // This parameter is supported in FunctionGraph v2. 127 IsStatefuleFunction bool `json:"is_stateful_function"` 128 // Whether to allow authentication information in the request header. 129 EnableAuthInHeader bool `json:"enable_auth_in_header"` 130 // Container image. 131 CustomImage CustomImage `json:"custom_image"` 132 // Whether to enable idle mode for reserved instances. 133 ReservedInstanceIdleMode bool `json:"reserved_instance_idle_mode"` 134 } 135 136 // StrategyConfig is the structure that represents the function policy definition. 137 type StrategyConfig struct { 138 // Maximum number of instances for a single function. 139 // + -1: The function has unlimited instances. 140 // + 0: The function is disabled. 141 // For v1, the value can be 0 or –1; for v2, it ranges from –1 to 1000. 142 Concurrency int `json:"concurrency"` 143 // Maximum number of concurrent requests per instance. 144 // This parameter is supported only by v2. 145 // The value ranges from –1 to 1000. 146 ConcurrentNum int `json:"concurrent_num"` 147 } 148 149 // FunctionAsyncConfig is the structure that represents the asynchronous execution notification settings 150 type FunctionAsyncConfig struct { 151 // Maximum validity period of a message. Value range: 60–86,400. Unit: second. 152 MaxAsyncEventAgeInSecond int `json:"max_async_event_age_in_second"` 153 // Maximum number of retry attempts to be made if asynchronous invocation fails. 154 // Default value: 3. Value range: 0–8. 155 MaxAsyncRetryAttempts int `json:"max_async_retry_attempts"` 156 // Asynchronous invocation target. 157 DestinationConfig FuncAsyncDestinationConfig `json:"destination_config"` 158 // Time when asynchronous execution notification was configured. 159 CreatedTime string `json:"created_time"` 160 // Time when the asynchronous execution notification settings were last modified. 161 LastModifed string `json:"last_modified"` 162 } 163 164 // FuncAsyncDestinationConfig is the structure that represents the asynchronous invocation target. 165 type FuncAsyncDestinationConfig struct { 166 // Target to be invoked when a function is successfully executed. 167 OnSuccess FuncDestinationConfig `json:"on_success"` 168 // Target to be invoked when a function fails to be executed due to a system error or an internal error. 169 OnFailure FuncDestinationConfig `json:"on_failure"` 170 } 171 172 // FuncDestinationConfig is the structure that represents the destination configuration details for function. 173 type FuncDestinationConfig struct { 174 // Object type. 175 // + OBS 176 // + SMN 177 // + DIS 178 // + FunctionGraph 179 Destination string `json:"destination"` 180 // Parameters (in JSON format) corresponding to the target service. 181 // + OBS: Parameters related to the bucket name, object directory prefix, and object expiration time are included. 182 // The object expiration time ranges from 0 to 365 days. If the value is 0, the object will not expire. 183 // + SMN: The topic_urn parameter is included. 184 // + DIS: The stream_name parameter is included. 185 // + FunctionGraph: The func_urn parameter is included. 186 Param string `json:"param"` 187 } 188 189 // CustomImage is the structure that represents the container image details. 190 type CustomImage struct { 191 // Whether to enable this feature. 192 Enabled bool `json:"enabled"` 193 // Image address. 194 Image string `json:"image"` 195 // Command for starting a container image. 196 Command string `json:"command"` 197 // Command line parameter for starting a container image. 198 Args string `json:"args"` 199 // Working directory of an image container. 200 WorkingDir string `json:"working_dir"` 201 // User ID of an image container. 202 UID string `json:"uid"` 203 // User group ID of an image container. 204 GID string `json:"gid"` 205 } 206 207 type pageInfo struct { 208 // Version list. 209 Versions []Version `json:"versions"` 210 // Next record location. 211 NextMarker int `json:"next_marker"` 212 // Total number of versions. 213 Count int `json:"count"` 214 } 215 216 type VersionPage struct { 217 pagination.MarkerPageBase 218 } 219 220 // IsEmpty returns true if a list result no version. 221 func (r VersionPage) IsEmpty() (bool, error) { 222 resp, err := extractPageInfo(r) 223 return len(resp.Versions) == 0, err 224 } 225 226 // LastMarker returns the last marker index in a pageInfo. 227 func (r VersionPage) LastMarker() (string, error) { 228 resp, err := extractPageInfo(r) 229 if err != nil { 230 return "", err 231 } 232 if resp.NextMarker == resp.Count { 233 return "", nil 234 } 235 return strconv.Itoa(resp.NextMarker), nil 236 } 237 238 // extractPageInfo is a method which to extract the response of the page information. 239 func extractPageInfo(r pagination.Page) (*pageInfo, error) { 240 var s pageInfo 241 err := r.(VersionPage).Result.ExtractInto(&s) 242 return &s, err 243 }