github.com/sacloud/iaas-api-go@v1.12.0/customize_envelope.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 iaas 16 17 import ( 18 "encoding/json" 19 20 "github.com/sacloud/iaas-api-go/naked" 21 "github.com/sacloud/iaas-api-go/search" 22 ) 23 24 // Note: sacloud/配下でのUnmarshalJSONの実装 25 // 26 // v2/internal/dslではAPIからの戻り値が以下のようにラップされていることを期待している 27 // { 28 // "<API名>": {}, 29 // "is_ok": true 30 // } 31 // 32 // この形式に沿っていないAPIについてはレスポンスのエンベロープ(struct xxxResponseEnvelope)でUnmarshalJSONを実装する必要がある 33 34 // UnmarshalJSON APIからの戻り値でレスポンスボディ直下にデータを持つことへの対応 35 func (a *authStatusReadResponseEnvelope) UnmarshalJSON(data []byte) error { 36 type alias authStatusReadResponseEnvelope 37 38 var tmp alias 39 if err := json.Unmarshal(data, &tmp); err != nil { 40 return err 41 } 42 43 var nakedAuthStatus naked.AuthStatus 44 if err := json.Unmarshal(data, &nakedAuthStatus); err != nil { 45 return err 46 } 47 tmp.AuthStatus = &nakedAuthStatus 48 49 *a = authStatusReadResponseEnvelope(tmp) 50 return nil 51 } 52 53 func (b *billDetailsCSVResponseEnvelope) UnmarshalJSON(data []byte) error { 54 type alias billDetailsCSVResponseEnvelope 55 56 var tmp alias 57 if err := json.Unmarshal(data, &tmp); err != nil { 58 return err 59 } 60 61 var nakedBillDetailCSV naked.BillDetailCSV 62 if err := json.Unmarshal(data, &nakedBillDetailCSV); err != nil { 63 return err 64 } 65 tmp.CSV = &nakedBillDetailCSV 66 67 *b = billDetailsCSVResponseEnvelope(tmp) 68 return nil 69 } 70 71 // UnmarshalJSON APIからの戻り値でレスポンスボディ直下にデータを持つことへの対応 72 func (a *certificateAuthorityAddClientResponseEnvelope) UnmarshalJSON(data []byte) error { 73 type alias certificateAuthorityAddClientResponseEnvelope 74 75 // is_okなどの共通的な項目 76 var tmp alias 77 if err := json.Unmarshal(data, &tmp); err != nil { 78 return err 79 } 80 81 // ラッパーが省略されている、レスポンスボディの直下にある項目 82 var result naked.CertificateAuthorityAddClientOrServerResult 83 if err := json.Unmarshal(data, &result); err != nil { 84 return err 85 } 86 tmp.CertificateAuthority = &result 87 88 *a = certificateAuthorityAddClientResponseEnvelope(tmp) 89 return nil 90 } 91 92 // UnmarshalJSON APIからの戻り値でレスポンスボディ直下にデータを持つことへの対応 93 func (a *certificateAuthorityAddServerResponseEnvelope) UnmarshalJSON(data []byte) error { 94 type alias certificateAuthorityAddServerResponseEnvelope 95 96 // is_okなどの共通的な項目 97 var tmp alias 98 if err := json.Unmarshal(data, &tmp); err != nil { 99 return err 100 } 101 102 // ラッパーが省略されている、レスポンスボディの直下にある項目 103 var result naked.CertificateAuthorityAddClientOrServerResult 104 if err := json.Unmarshal(data, &result); err != nil { 105 return err 106 } 107 tmp.CertificateAuthority = &result 108 109 *a = certificateAuthorityAddServerResponseEnvelope(tmp) 110 return nil 111 } 112 113 func (m *mobileGatewaySetSIMRoutesRequestEnvelope) MarshalJSON() ([]byte, error) { 114 type alias struct { 115 SIMRoutes []*naked.MobileGatewaySIMRoute `json:"sim_routes"` 116 } 117 tmp := &alias{ 118 SIMRoutes: m.SIMRoutes, 119 } 120 if len(tmp.SIMRoutes) == 0 { 121 tmp.SIMRoutes = make([]*naked.MobileGatewaySIMRoute, 0) 122 } 123 return json.Marshal(tmp) 124 } 125 126 // UnmarshalJSON APIからの戻り値でレスポンスボディ直下にデータを持つことへの対応 127 func (s *serverGetVNCProxyResponseEnvelope) UnmarshalJSON(data []byte) error { 128 type alias serverGetVNCProxyResponseEnvelope 129 130 var tmp alias 131 if err := json.Unmarshal(data, &tmp); err != nil { 132 return err 133 } 134 135 var nakedVNCProxy naked.VNCProxyInfo 136 if err := json.Unmarshal(data, &nakedVNCProxy); err != nil { 137 return err 138 } 139 tmp.VNCProxyInfo = &nakedVNCProxy 140 141 *s = serverGetVNCProxyResponseEnvelope(tmp) 142 return nil 143 } 144 145 /* 146 * 検索時に固定パラメータを設定するための実装 147 */ 148 149 func (s autoBackupFindRequestEnvelope) MarshalJSON() ([]byte, error) { 150 type alias autoBackupFindRequestEnvelope 151 tmp := alias(s) 152 if tmp.Filter == nil { 153 tmp.Filter = search.Filter{} 154 } 155 tmp.Filter[search.Key("Provider.Class")] = "autobackup" 156 return json.Marshal(tmp) 157 } 158 159 func (s autoScaleFindRequestEnvelope) MarshalJSON() ([]byte, error) { 160 type alias autoScaleFindRequestEnvelope 161 tmp := alias(s) 162 if tmp.Filter == nil { 163 tmp.Filter = search.Filter{} 164 } 165 tmp.Filter[search.Key("Provider.Class")] = "autoscale" 166 return json.Marshal(tmp) 167 } 168 169 func (s certificateAuthorityFindRequestEnvelope) MarshalJSON() ([]byte, error) { 170 type alias certificateAuthorityFindRequestEnvelope 171 tmp := alias(s) 172 if tmp.Filter == nil { 173 tmp.Filter = search.Filter{} 174 } 175 tmp.Filter[search.Key("Provider.Class")] = "certificateauthority" 176 return json.Marshal(tmp) 177 } 178 179 func (s containerRegistryFindRequestEnvelope) MarshalJSON() ([]byte, error) { 180 type alias containerRegistryFindRequestEnvelope 181 tmp := alias(s) 182 if tmp.Filter == nil { 183 tmp.Filter = search.Filter{} 184 } 185 tmp.Filter[search.Key("Provider.Class")] = "containerregistry" 186 return json.Marshal(tmp) 187 } 188 189 func (s eSMEFindRequestEnvelope) MarshalJSON() ([]byte, error) { 190 type alias eSMEFindRequestEnvelope 191 tmp := alias(s) 192 if tmp.Filter == nil { 193 tmp.Filter = search.Filter{} 194 } 195 tmp.Filter[search.Key("Provider.Class")] = "esme" 196 return json.Marshal(tmp) 197 } 198 199 func (s dNSFindRequestEnvelope) MarshalJSON() ([]byte, error) { 200 type alias dNSFindRequestEnvelope 201 tmp := alias(s) 202 if tmp.Filter == nil { 203 tmp.Filter = search.Filter{} 204 } 205 tmp.Filter[search.Key("Provider.Class")] = "dns" 206 return json.Marshal(tmp) 207 } 208 209 func (s simpleMonitorFindRequestEnvelope) MarshalJSON() ([]byte, error) { 210 type alias simpleMonitorFindRequestEnvelope 211 tmp := alias(s) 212 if tmp.Filter == nil { 213 tmp.Filter = search.Filter{} 214 } 215 tmp.Filter[search.Key("Provider.Class")] = "simplemon" 216 return json.Marshal(tmp) 217 } 218 219 func (s gSLBFindRequestEnvelope) MarshalJSON() ([]byte, error) { 220 type alias gSLBFindRequestEnvelope 221 tmp := alias(s) 222 if tmp.Filter == nil { 223 tmp.Filter = search.Filter{} 224 } 225 tmp.Filter[search.Key("Provider.Class")] = "gslb" 226 return json.Marshal(tmp) 227 } 228 229 func (s proxyLBFindRequestEnvelope) MarshalJSON() ([]byte, error) { 230 type alias proxyLBFindRequestEnvelope 231 tmp := alias(s) 232 if tmp.Filter == nil { 233 tmp.Filter = search.Filter{} 234 } 235 tmp.Filter[search.Key("Provider.Class")] = "proxylb" 236 return json.Marshal(tmp) 237 } 238 239 func (s sIMFindRequestEnvelope) MarshalJSON() ([]byte, error) { 240 type alias sIMFindRequestEnvelope 241 tmp := alias(s) 242 if tmp.Filter == nil { 243 tmp.Filter = search.Filter{} 244 } 245 tmp.Filter[search.Key("Provider.Class")] = "sim" 246 return json.Marshal(tmp) 247 } 248 249 func (s localRouterFindRequestEnvelope) MarshalJSON() ([]byte, error) { 250 type alias localRouterFindRequestEnvelope 251 tmp := alias(s) 252 if tmp.Filter == nil { 253 tmp.Filter = search.Filter{} 254 } 255 tmp.Filter[search.Key("Provider.Class")] = "localrouter" 256 return json.Marshal(tmp) 257 } 258 259 func (s enhancedDBFindRequestEnvelope) MarshalJSON() ([]byte, error) { 260 type alias enhancedDBFindRequestEnvelope 261 tmp := alias(s) 262 if tmp.Filter == nil { 263 tmp.Filter = search.Filter{} 264 } 265 tmp.Filter[search.Key("Provider.Class")] = "enhanceddb" 266 return json.Marshal(tmp) 267 } 268 269 func (s databaseFindRequestEnvelope) MarshalJSON() ([]byte, error) { 270 type alias databaseFindRequestEnvelope 271 tmp := alias(s) 272 if tmp.Filter == nil { 273 tmp.Filter = search.Filter{} 274 } 275 tmp.Filter[search.Key("Class")] = "database" 276 return json.Marshal(tmp) 277 } 278 279 func (s loadBalancerFindRequestEnvelope) MarshalJSON() ([]byte, error) { 280 type alias loadBalancerFindRequestEnvelope 281 tmp := alias(s) 282 if tmp.Filter == nil { 283 tmp.Filter = search.Filter{} 284 } 285 tmp.Filter[search.Key("Class")] = "loadbalancer" 286 return json.Marshal(tmp) 287 } 288 289 func (s vPCRouterFindRequestEnvelope) MarshalJSON() ([]byte, error) { 290 type alias vPCRouterFindRequestEnvelope 291 tmp := alias(s) 292 if tmp.Filter == nil { 293 tmp.Filter = search.Filter{} 294 } 295 tmp.Filter[search.Key("Class")] = "vpcrouter" 296 return json.Marshal(tmp) 297 } 298 299 func (s nFSFindRequestEnvelope) MarshalJSON() ([]byte, error) { 300 type alias nFSFindRequestEnvelope 301 tmp := alias(s) 302 if tmp.Filter == nil { 303 tmp.Filter = search.Filter{} 304 } 305 tmp.Filter[search.Key("Class")] = "nfs" 306 return json.Marshal(tmp) 307 } 308 309 func (s mobileGatewayFindRequestEnvelope) MarshalJSON() ([]byte, error) { 310 type alias mobileGatewayFindRequestEnvelope 311 tmp := alias(s) 312 if tmp.Filter == nil { 313 tmp.Filter = search.Filter{} 314 } 315 tmp.Filter[search.Key("Class")] = "mobilegateway" 316 return json.Marshal(tmp) 317 } 318 319 /* 320 * for Shared Archive 321 */ 322 323 func (s archiveShareRequestEnvelope) MarshalJSON() ([]byte, error) { 324 type alias archiveShareRequestEnvelope 325 tmp := alias(s) 326 tmp.Shared = true 327 return json.Marshal(tmp) 328 } 329 330 // UnmarshalJSON APIからの戻り値でレスポンスボディ直下にデータを持つことへの対応 331 func (s *archiveShareResponseEnvelope) UnmarshalJSON(data []byte) error { 332 type alias archiveShareResponseEnvelope 333 334 var tmp alias 335 if err := json.Unmarshal(data, &tmp); err != nil { 336 return err 337 } 338 339 var nakedData naked.ArchiveShareInfo 340 if err := json.Unmarshal(data, &nakedData); err != nil { 341 return err 342 } 343 tmp.ArchiveShareInfo = &nakedData 344 345 *s = archiveShareResponseEnvelope(tmp) 346 return nil 347 } 348 349 // UnmarshalJSON APIからの戻り値でレスポンスボディ直下にデータを持つことへの対応 350 func (a *vPCRouterLogsResponseEnvelope) UnmarshalJSON(data []byte) error { 351 type alias vPCRouterLogsResponseEnvelope 352 353 var tmp alias 354 if err := json.Unmarshal(data, &tmp); err != nil { 355 return err 356 } 357 358 var nakedLogs naked.VPCRouterLog 359 if err := json.Unmarshal(data, &nakedLogs); err != nil { 360 return err 361 } 362 tmp.VPCRouter = &nakedLogs 363 364 *a = vPCRouterLogsResponseEnvelope(tmp) 365 return nil 366 } 367 368 // UnmarshalJSON APIからの戻り値でレスポンスボディ直下にデータを持つことへの対応 369 func (a *vPCRouterPingResponseEnvelope) UnmarshalJSON(data []byte) error { 370 type alias vPCRouterPingResponseEnvelope 371 372 var tmp alias 373 if err := json.Unmarshal(data, &tmp); err != nil { 374 return err 375 } 376 377 var nakedResult naked.VPCRouterPingResult 378 if err := json.Unmarshal(data, &nakedResult); err != nil { 379 return err 380 } 381 tmp.VPCRouter = &nakedResult 382 383 *a = vPCRouterPingResponseEnvelope(tmp) 384 return nil 385 }