github.com/sacloud/iaas-api-go@v1.12.0/internal/define/proxylb.go (about) 1 // Copyright 2022-2023 The sacloud/iaas-api-go Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package define 16 17 import ( 18 "net/http" 19 20 "github.com/sacloud/iaas-api-go/internal/define/names" 21 "github.com/sacloud/iaas-api-go/internal/define/ops" 22 "github.com/sacloud/iaas-api-go/internal/dsl" 23 "github.com/sacloud/iaas-api-go/internal/dsl/meta" 24 "github.com/sacloud/iaas-api-go/naked" 25 ) 26 27 const ( 28 proxyLBAPIName = "ProxyLB" 29 proxyLBAPIPathName = "commonserviceitem" 30 ) 31 32 var proxyLBAPI = &dsl.Resource{ 33 Name: proxyLBAPIName, 34 PathName: proxyLBAPIPathName, 35 PathSuffix: dsl.CloudAPISuffix, 36 IsGlobal: true, 37 Operations: dsl.Operations{ 38 // find 39 ops.FindCommonServiceItem(proxyLBAPIName, proxyLBNakedType, findParameter, proxyLBView), 40 41 // create 42 ops.CreateCommonServiceItem(proxyLBAPIName, proxyLBNakedType, proxyLBCreateParam, proxyLBView), 43 44 // read 45 ops.ReadCommonServiceItem(proxyLBAPIName, proxyLBNakedType, proxyLBView), 46 47 // update 48 ops.UpdateCommonServiceItem(proxyLBAPIName, proxyLBNakedType, proxyLBUpdateParam, proxyLBView), 49 // updateSettings 50 ops.UpdateCommonServiceItemSettings(proxyLBAPIName, proxyLBUpdateSettingsNakedType, proxyLBUpdateSettingsParam, proxyLBView), 51 52 // delete 53 ops.Delete(proxyLBAPIName), 54 55 // change plan 56 { 57 ResourceName: proxyLBAPIName, 58 Name: "ChangePlan", 59 PathFormat: dsl.IDAndSuffixPathFormat("plan"), 60 Method: http.MethodPut, 61 RequestEnvelope: dsl.RequestEnvelope(&dsl.EnvelopePayloadDesc{ 62 Type: proxyLBChangePlanNakedType, 63 Name: "CommonServiceItem", 64 }), 65 Arguments: dsl.Arguments{ 66 dsl.ArgumentID, 67 dsl.MappableArgument("param", proxyLBChangePlanParam, "CommonServiceItem"), 68 }, 69 ResponseEnvelope: dsl.ResponseEnvelope(&dsl.EnvelopePayloadDesc{ 70 Type: proxyLBNakedType, 71 Name: "CommonServiceItem", 72 }), 73 Results: dsl.Results{ 74 { 75 SourceField: "CommonServiceItem", 76 DestField: proxyLBView.Name, 77 IsPlural: false, 78 Model: proxyLBView, 79 }, 80 }, 81 }, 82 83 // get certificates 84 { 85 ResourceName: proxyLBAPIName, 86 Name: "GetCertificates", 87 PathFormat: dsl.IDAndSuffixPathFormat("proxylb/sslcertificate"), 88 Method: http.MethodGet, 89 Arguments: dsl.Arguments{ 90 dsl.ArgumentID, 91 }, 92 ResponseEnvelope: dsl.ResponseEnvelope(&dsl.EnvelopePayloadDesc{ 93 Type: proxyLBCertificatesNakedType, 94 Name: proxyLBAPIName, 95 }), 96 Results: dsl.Results{ 97 { 98 SourceField: proxyLBAPIName, 99 DestField: proxyLBCertificateView.Name, 100 IsPlural: false, 101 Model: proxyLBCertificateView, 102 }, 103 }, 104 }, 105 106 // set certificates 107 { 108 ResourceName: proxyLBAPIName, 109 Name: "SetCertificates", 110 PathFormat: dsl.IDAndSuffixPathFormat("proxylb/sslcertificate"), 111 Method: http.MethodPut, 112 RequestEnvelope: dsl.RequestEnvelope(&dsl.EnvelopePayloadDesc{ 113 Type: proxyLBCertificatesNakedType, 114 Name: proxyLBAPIName, 115 }), 116 Arguments: dsl.Arguments{ 117 dsl.ArgumentID, 118 dsl.MappableArgument("param", proxyLBCertificateSetParam, proxyLBAPIName), 119 }, 120 ResponseEnvelope: dsl.ResponseEnvelope(&dsl.EnvelopePayloadDesc{ 121 Type: proxyLBCertificatesNakedType, 122 Name: proxyLBAPIName, 123 }), 124 Results: dsl.Results{ 125 { 126 SourceField: proxyLBAPIName, 127 DestField: proxyLBCertificateView.Name, 128 IsPlural: false, 129 Model: proxyLBCertificateView, 130 }, 131 }, 132 }, 133 134 // delete certificates 135 { 136 ResourceName: proxyLBAPIName, 137 Name: "DeleteCertificates", 138 PathFormat: dsl.IDAndSuffixPathFormat("proxylb/sslcertificate"), 139 Method: http.MethodDelete, 140 Arguments: dsl.Arguments{ 141 dsl.ArgumentID, 142 }, 143 }, 144 145 // renew Let's Encrypt certificates 146 ops.WithIDAction(proxyLBAPIName, "RenewLetsEncryptCert", http.MethodPut, "proxylb/letsencryptrenew"), 147 148 // Health 149 ops.HealthStatus(proxyLBAPIName, meta.Static(naked.ProxyLBHealth{}), proxyLBHealth), 150 151 // Monitor 152 ops.MonitorChild(proxyLBAPIName, "Connection", "activity/proxylb", 153 monitorParameter, monitors.connectionModel()), 154 }, 155 } 156 157 var ( 158 proxyLBNakedType = meta.Static(naked.ProxyLB{}) 159 proxyLBUpdateSettingsNakedType = meta.Static(naked.ProxyLBSettingsUpdate{}) 160 proxyLBChangePlanNakedType = meta.Static(naked.ProxyLBPlanChange{}) 161 proxyLBCertificatesNakedType = meta.Static(naked.ProxyLBCertificates{}) 162 163 proxyLBView = &dsl.Model{ 164 Name: proxyLBAPIName, 165 NakedType: proxyLBNakedType, 166 Fields: []*dsl.FieldDesc{ 167 fields.ID(), 168 fields.Name(), 169 fields.Description(), 170 fields.Tags(), 171 fields.Availability(), 172 fields.IconID(), 173 fields.CreatedAt(), 174 fields.ModifiedAt(), 175 176 fields.ProxyLBPlan(), 177 178 // settings 179 fields.ProxyLBHealthCheck(), 180 fields.ProxyLBSorryServer(), 181 fields.ProxyLBBindPorts(), 182 fields.ProxyLBServers(), 183 fields.ProxyLBRules(), 184 fields.ProxyLBLetsEncrypt(), 185 fields.ProxyLBStickySession(), 186 fields.ProxyLBGzip(), 187 fields.ProxyLBBackendHttpKeepAlive(), 188 fields.ProxyLBProxyProtocol(), 189 fields.ProxyLBSyslog(), 190 fields.ProxyLBTimeout(), 191 fields.SettingsHash(), 192 193 // status 194 fields.ProxyLBUseVIPFailover(), 195 fields.ProxyLBRegion(), 196 fields.ProxyLBProxyNetworks(), 197 fields.ProxyLBFQDN(), 198 fields.ProxyLBVIP(), 199 }, 200 } 201 202 proxyLBCreateParam = &dsl.Model{ 203 Name: names.CreateParameterName(proxyLBAPIName), 204 NakedType: proxyLBNakedType, 205 ConstFields: []*dsl.ConstFieldDesc{ 206 { 207 Name: "Class", 208 Type: meta.TypeString, 209 Tags: &dsl.FieldTags{ 210 MapConv: "Provider.Class", 211 }, 212 Value: `"proxylb"`, 213 }, 214 }, 215 Fields: []*dsl.FieldDesc{ 216 // required 217 fields.ProxyLBPlan(), 218 219 // settings 220 fields.ProxyLBHealthCheck(), 221 fields.ProxyLBSorryServer(), 222 fields.ProxyLBBindPorts(), 223 fields.ProxyLBServers(), 224 fields.ProxyLBRules(), 225 fields.ProxyLBLetsEncrypt(), 226 fields.ProxyLBStickySession(), 227 fields.ProxyLBTimeout(), 228 fields.ProxyLBGzip(), 229 fields.ProxyLBBackendHttpKeepAlive(), 230 fields.ProxyLBProxyProtocol(), 231 fields.ProxyLBSyslog(), 232 // status 233 fields.ProxyLBUseVIPFailover(), 234 fields.ProxyLBRegion(), 235 236 // common fields 237 fields.Name(), 238 fields.Description(), 239 fields.Tags(), 240 fields.IconID(), 241 }, 242 } 243 244 proxyLBUpdateParam = &dsl.Model{ 245 Name: names.UpdateParameterName(proxyLBAPIName), 246 NakedType: proxyLBNakedType, 247 Fields: []*dsl.FieldDesc{ 248 249 // settings 250 fields.ProxyLBHealthCheck(), 251 fields.ProxyLBSorryServer(), 252 fields.ProxyLBBindPorts(), 253 fields.ProxyLBServers(), 254 fields.ProxyLBRules(), 255 fields.ProxyLBLetsEncrypt(), 256 fields.ProxyLBStickySession(), 257 fields.ProxyLBTimeout(), 258 fields.ProxyLBGzip(), 259 fields.ProxyLBBackendHttpKeepAlive(), 260 fields.ProxyLBProxyProtocol(), 261 fields.ProxyLBSyslog(), 262 // settings hash 263 fields.SettingsHash(), 264 265 // common fields 266 fields.Name(), 267 fields.Description(), 268 fields.Tags(), 269 fields.IconID(), 270 }, 271 } 272 273 proxyLBUpdateSettingsParam = &dsl.Model{ 274 Name: names.UpdateSettingsParameterName(proxyLBAPIName), 275 NakedType: proxyLBNakedType, 276 Fields: []*dsl.FieldDesc{ 277 // settings 278 fields.ProxyLBHealthCheck(), 279 fields.ProxyLBSorryServer(), 280 fields.ProxyLBBindPorts(), 281 fields.ProxyLBServers(), 282 fields.ProxyLBRules(), 283 fields.ProxyLBLetsEncrypt(), 284 fields.ProxyLBStickySession(), 285 fields.ProxyLBTimeout(), 286 fields.ProxyLBGzip(), 287 fields.ProxyLBBackendHttpKeepAlive(), 288 fields.ProxyLBProxyProtocol(), 289 fields.ProxyLBSyslog(), 290 // settings hash 291 fields.SettingsHash(), 292 }, 293 } 294 295 proxyLBChangePlanParam = &dsl.Model{ 296 Name: proxyLBAPIName + "ChangePlanRequest", 297 NakedType: proxyLBNakedType, 298 Fields: []*dsl.FieldDesc{ 299 fields.Def("ServiceClass", meta.TypeString), 300 }, 301 } 302 303 proxyLBCertificateView = &dsl.Model{ 304 Name: proxyLBAPIName + "Certificates", 305 NakedType: meta.Static(naked.ProxyLBCertificates{}), 306 Fields: []*dsl.FieldDesc{ 307 { 308 Name: "PrimaryCert", 309 Type: &dsl.Model{ 310 Name: proxyLBAPIName + "PrimaryCert", 311 Fields: []*dsl.FieldDesc{ 312 fields.Def("ServerCertificate", meta.TypeString), 313 fields.Def("IntermediateCertificate", meta.TypeString), 314 fields.Def("PrivateKey", meta.TypeString), 315 fields.Def("CertificateEndDate", meta.TypeTime), 316 fields.Def("CertificateCommonName", meta.TypeString), 317 fields.Def("CertificateAltNames", meta.TypeString), 318 }, 319 }, 320 }, 321 { 322 Name: "AdditionalCerts", 323 Type: &dsl.Model{ 324 Name: proxyLBAPIName + "AdditionalCert", 325 IsArray: true, 326 Fields: []*dsl.FieldDesc{ 327 fields.Def("ServerCertificate", meta.TypeString), 328 fields.Def("IntermediateCertificate", meta.TypeString), 329 fields.Def("PrivateKey", meta.TypeString), 330 fields.Def("CertificateEndDate", meta.TypeTime), 331 fields.Def("CertificateCommonName", meta.TypeString), 332 fields.Def("CertificateAltNames", meta.TypeString), 333 }, 334 }, 335 Tags: &dsl.FieldTags{ 336 MapConv: "[]AdditionalCerts, recursive", 337 }, 338 }, 339 }, 340 } 341 342 proxyLBCertificateSetParam = &dsl.Model{ 343 Name: proxyLBAPIName + "SetCertificatesRequest", 344 NakedType: meta.Static(naked.ProxyLBCertificates{}), 345 Fields: []*dsl.FieldDesc{ 346 proxyLBPrimaryCertsField, 347 proxyLBAdditionalCerts, 348 }, 349 } 350 351 proxyLBPrimaryCertsField = &dsl.FieldDesc{ 352 Name: "PrimaryCerts", 353 Type: &dsl.Model{ 354 Name: proxyLBAPIName + "PrimaryCert", 355 Fields: []*dsl.FieldDesc{ 356 fields.Def("ServerCertificate", meta.TypeString), 357 fields.Def("IntermediateCertificate", meta.TypeString), 358 fields.Def("PrivateKey", meta.TypeString), 359 }, 360 }, 361 Tags: &dsl.FieldTags{ 362 MapConv: "PrimaryCert", 363 }, 364 } 365 366 proxyLBAdditionalCerts = &dsl.FieldDesc{ 367 Name: "AdditionalCerts", 368 Type: &dsl.Model{ 369 Name: proxyLBAPIName + "AdditionalCert", 370 IsArray: true, 371 Fields: []*dsl.FieldDesc{ 372 fields.Def("ServerCertificate", meta.TypeString), 373 fields.Def("IntermediateCertificate", meta.TypeString), 374 fields.Def("PrivateKey", meta.TypeString), 375 }, 376 }, 377 Tags: &dsl.FieldTags{ 378 MapConv: "[]AdditionalCerts, recursive", 379 }, 380 } 381 382 proxyLBHealth = &dsl.Model{ 383 Name: "ProxyLBHealth", 384 Fields: []*dsl.FieldDesc{ 385 fields.Def("ActiveConn", meta.TypeInt), 386 fields.Def("CPS", meta.TypeFloat64), 387 fields.Def("CurrentVIP", meta.TypeString), 388 { 389 Name: "Servers", 390 Type: &dsl.Model{ 391 Name: "LoadBalancerServerStatus", 392 IsArray: true, 393 Fields: []*dsl.FieldDesc{ 394 fields.Def("ActiveConn", meta.TypeInt), 395 fields.Def("Status", meta.TypeInstanceStatus), 396 fields.Def("IPAddress", meta.TypeString), 397 fields.Def("Port", meta.TypeStringNumber), 398 fields.Def("CPS", meta.TypeFloat64), 399 }, 400 }, 401 Tags: &dsl.FieldTags{ 402 MapConv: "[]Servers,recursive", 403 }, 404 }, 405 }, 406 NakedType: meta.Static(naked.ProxyLBHealth{}), 407 } 408 )