github.com/sacloud/libsacloud/v2@v2.32.3/helper/service/database/apply_request.go (about) 1 // Copyright 2016-2022 The Libsacloud 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 database 16 17 import ( 18 "github.com/sacloud/libsacloud/v2/pkg/mapconv" 19 20 "github.com/sacloud/libsacloud/v2/helper/validate" 21 "github.com/sacloud/libsacloud/v2/sacloud" 22 "github.com/sacloud/libsacloud/v2/sacloud/types" 23 ) 24 25 type ApplyRequest struct { 26 Zone string `request:"-" validate:"required"` 27 28 ID types.ID `request:"-"` 29 Name string `validate:"required"` 30 Description string `validate:"min=0,max=512"` 31 Tags types.Tags 32 IconID types.ID 33 PlanID types.ID `validate:"required"` 34 SwitchID types.ID `validate:"required"` 35 IPAddresses []string `validate:"required,min=1,max=2,dive,ipv4"` 36 NetworkMaskLen int `validate:"required,min=1,max=32"` 37 DefaultRoute string `validate:"omitempty,ipv4"` 38 Port int `validate:"omitempty,min=1,max=65535"` 39 SourceNetwork []string `validate:"dive,cidrv4"` 40 DatabaseType string `validate:"required,oneof=mariadb postgres"` 41 Username string `validate:"required"` 42 Password string `validate:"required"` 43 EnableReplication bool 44 ReplicaUserPassword string `validate:"required_with=EnableReplication"` 45 EnableWebUI bool 46 EnableBackup bool 47 BackupWeekdays []types.EBackupSpanWeekday `validate:"required_with=EnableBackup,max=7"` 48 BackupStartTimeHour int `validate:"omitempty,min=0,max=23"` 49 BackupStartTimeMinute int `validate:"omitempty,oneof=0 15 30 45"` 50 Parameters map[string]interface{} 51 52 NoWait bool 53 } 54 55 func (req *ApplyRequest) Validate() error { 56 return validate.Struct(req) 57 } 58 59 func (req *ApplyRequest) Builder(caller sacloud.APICaller) (*Builder, error) { 60 builder := &Builder{Caller: caller} 61 if err := mapconv.ConvertTo(req, builder); err != nil { 62 return nil, err 63 } 64 return builder, nil 65 }