github.com/sacloud/iaas-api-go@v1.12.0/naked/vpc_router.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 naked
    16  
    17  import (
    18  	"encoding/json"
    19  	"time"
    20  
    21  	"github.com/sacloud/iaas-api-go/types"
    22  )
    23  
    24  // VPCRouter VPCルータ
    25  type VPCRouter struct {
    26  	ID           types.ID            `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    27  	Class        string              `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    28  	Name         string              `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    29  	Description  string              `yaml:"description"`
    30  	Plan         *AppliancePlan      `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    31  	Settings     *VPCRouterSettings  `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    32  	SettingsHash string              `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    33  	Remark       *ApplianceRemark    `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    34  	Availability types.EAvailability `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    35  	Instance     *Instance           `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    36  	ServiceClass string              `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    37  	CreatedAt    *time.Time          `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    38  	Icon         *Icon               `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    39  	Switch       *Switch             `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    40  	Interfaces   Interfaces          `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    41  	Tags         types.Tags          `yaml:"tags"`
    42  }
    43  
    44  // VPCRouterSettingsUpdate VPCルータ
    45  type VPCRouterSettingsUpdate struct {
    46  	Settings     *VPCRouterSettings `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    47  	SettingsHash string             `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    48  }
    49  
    50  // VPCRouterSettings VPCルータ 設定
    51  type VPCRouterSettings struct {
    52  	Router *VPCRouterSetting `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    53  }
    54  
    55  // VPCRouterSetting VPCルータ 設定
    56  type VPCRouterSetting struct {
    57  	InternetConnection   *VPCRouterInternetConnection   `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    58  	Interfaces           VPCRouterInterfaces            `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    59  	VRID                 int                            `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    60  	StaticNAT            *VPCRouterStaticNAT            `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    61  	PortForwarding       *VPCRouterPortForwarding       `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    62  	Firewall             *VPCRouterFirewall             `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    63  	DHCPServer           *VPCRouterDHCPServer           `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    64  	DHCPStaticMapping    *VPCRouterDHCPStaticMappings   `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    65  	DNSForwarding        *VPCRouterDNSForwarding        `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    66  	PPTPServer           *VPCRouterPPTPServer           `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    67  	L2TPIPsecServer      *VPCRouterL2TPIPsecServer      `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    68  	WireGuard            *VPCRouterWireGuard            `json:"WireGuardServer,omitempty" yaml:",omitempty" structs:",omitempty"`
    69  	RemoteAccessUsers    *VPCRouterRemoteAccessUsers    `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    70  	SiteToSiteIPsecVPN   *VPCRouterSiteToSiteIPsecVPN   `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    71  	StaticRoutes         *VPCRouterStaticRoutes         `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    72  	SyslogHost           string                         `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    73  	ScheduledMaintenance *VPCRouterScheduledMaintenance `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    74  }
    75  
    76  // VPCRouterInternetConnection インターフェース
    77  type VPCRouterInternetConnection struct {
    78  	Enabled types.StringFlag `yaml:"enabled"`
    79  }
    80  
    81  // VPCRouterInterface インターフェース
    82  type VPCRouterInterface struct {
    83  	IPAddress        []string `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    84  	VirtualIPAddress string   `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    85  	IPAliases        []string `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    86  	NetworkMaskLen   int      `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
    87  	// Index 仮想フィールド、VPCルータなどでInterfaces(実体は[]*Interface)を扱う場合にUnmarshalJSONの中で設定される
    88  	//
    89  	// Findした際のAPIからの応答にも同名のフィールドが含まれるが無関係。
    90  	Index int `json:"-"`
    91  }
    92  
    93  // VPCRouterInterfaces Interface配列
    94  //
    95  // 配列中にnullが返ってくる(VPCルータなど)への対応のためのtype
    96  type VPCRouterInterfaces []*VPCRouterInterface
    97  
    98  // UnmarshalJSON 配列中にnullが返ってくる(VPCルータなど)への対応
    99  func (i *VPCRouterInterfaces) UnmarshalJSON(b []byte) error {
   100  	type alias VPCRouterInterfaces
   101  	var a alias
   102  	if err := json.Unmarshal(b, &a); err != nil {
   103  		return err
   104  	}
   105  
   106  	var dest []*VPCRouterInterface
   107  	for i, v := range a {
   108  		if v != nil {
   109  			if v.Index == 0 {
   110  				v.Index = i
   111  			}
   112  			dest = append(dest, v)
   113  		}
   114  	}
   115  
   116  	*i = VPCRouterInterfaces(dest)
   117  	return nil
   118  }
   119  
   120  // MarshalJSON 配列中にnullが入る場合(VPCルータなど)への対応
   121  func (i *VPCRouterInterfaces) MarshalJSON() ([]byte, error) {
   122  	max := 0
   123  	for _, iface := range *i {
   124  		if max < iface.Index {
   125  			max = iface.Index
   126  		}
   127  	}
   128  
   129  	var dest = make([]*VPCRouterInterface, max+1)
   130  	for _, iface := range *i {
   131  		dest[iface.Index] = iface
   132  	}
   133  
   134  	return json.Marshal(dest)
   135  }
   136  
   137  // MarshalJSON JSON
   138  func (i *VPCRouterInterface) MarshalJSON() ([]byte, error) {
   139  	type alias struct {
   140  		IPAddress        []string `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   141  		VirtualIPAddress string   `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   142  		IPAliases        []string `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   143  		NetworkMaskLen   int      `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   144  	}
   145  
   146  	tmp := alias{
   147  		IPAddress:        i.IPAddress,
   148  		VirtualIPAddress: i.VirtualIPAddress,
   149  		IPAliases:        i.IPAliases,
   150  		NetworkMaskLen:   i.NetworkMaskLen,
   151  	}
   152  	return json.Marshal(tmp)
   153  }
   154  
   155  // VPCRouterStaticNAT スタティックNAT
   156  type VPCRouterStaticNAT struct {
   157  	Config  []*VPCRouterStaticNATConfig `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   158  	Enabled types.StringFlag            `yaml:"enabled"`
   159  }
   160  
   161  // MarshalJSON Configが一つ以上ある場合にEnabledをtrueに設定する
   162  func (f *VPCRouterStaticNAT) MarshalJSON() ([]byte, error) {
   163  	if f == nil || f.Config == nil {
   164  		return nil, nil
   165  	}
   166  	if len(f.Config) > 0 {
   167  		f.Enabled = types.StringTrue
   168  	}
   169  	type alias VPCRouterStaticNAT
   170  	a := alias(*f)
   171  	return json.Marshal(&a)
   172  }
   173  
   174  // VPCRouterStaticNATConfig スタティックNAT
   175  type VPCRouterStaticNATConfig struct {
   176  	GlobalAddress  string `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   177  	PrivateAddress string `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   178  	Description    string `yaml:"description"`
   179  }
   180  
   181  // VPCRouterPortForwarding ポートフォワーディング設定
   182  type VPCRouterPortForwarding struct {
   183  	Config  []*VPCRouterPortForwardingConfig `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   184  	Enabled types.StringFlag                 `yaml:"enabled"`
   185  }
   186  
   187  // MarshalJSON Configが一つ以上ある場合にEnabledをtrueに設定する
   188  func (f *VPCRouterPortForwarding) MarshalJSON() ([]byte, error) {
   189  	if f == nil || f.Config == nil {
   190  		return nil, nil
   191  	}
   192  	if len(f.Config) > 0 {
   193  		f.Enabled = types.StringTrue
   194  	}
   195  	type alias VPCRouterPortForwarding
   196  	a := alias(*f)
   197  	return json.Marshal(&a)
   198  }
   199  
   200  // VPCRouterPortForwardingConfig ポートフォワーディング設定
   201  type VPCRouterPortForwardingConfig struct {
   202  	Protocol       types.EVPCRouterPortForwardingProtocol `json:",omitempty"` // プロトコル(tcp/udp)
   203  	GlobalPort     types.StringNumber                     `json:",omitempty"` // グローバル側ポート
   204  	PrivateAddress string                                 `json:",omitempty"` // プライベートIPアドレス
   205  	PrivatePort    types.StringNumber                     `json:",omitempty"` // プライベート側ポート
   206  	Description    string                                 `json:",omitempty"` // 説明
   207  }
   208  
   209  // VPCRouterFirewall ファイアウォール
   210  type VPCRouterFirewall struct {
   211  	Config  VPCRouterFirewallConfigs `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   212  	Enabled types.StringFlag         `yaml:"enabled"`
   213  }
   214  
   215  // MarshalJSON 常にEnabledをtrueに設定する
   216  func (f *VPCRouterFirewall) MarshalJSON() ([]byte, error) {
   217  	if f == nil {
   218  		return nil, nil
   219  	}
   220  	f.Enabled = types.StringTrue
   221  	type alias VPCRouterFirewall
   222  	a := alias(*f)
   223  	return json.Marshal(&a)
   224  }
   225  
   226  // VPCRouterFirewallConfigs VPCルータのファイアウォール設定
   227  //
   228  // 配列のインデックスで対象インターフェースを表す
   229  type VPCRouterFirewallConfigs [8]*VPCRouterFirewallConfig
   230  
   231  // UnmarshalJSON 配列中にnullが返ってくる(VPCルータなど)への対応
   232  func (i *VPCRouterFirewallConfigs) UnmarshalJSON(b []byte) error {
   233  	type alias VPCRouterFirewallConfigs
   234  	var a alias
   235  	if err := json.Unmarshal(b, &a); err != nil {
   236  		return err
   237  	}
   238  
   239  	var dest [8]*VPCRouterFirewallConfig
   240  	for i, v := range a {
   241  		if v != nil {
   242  			if v.Index == 0 {
   243  				v.Index = i
   244  			}
   245  			dest[v.Index] = v
   246  		}
   247  	}
   248  
   249  	*i = VPCRouterFirewallConfigs(dest)
   250  	return nil
   251  }
   252  
   253  // MarshalJSON 配列中にnullが入る場合(VPCルータなど)への対応
   254  func (i *VPCRouterFirewallConfigs) MarshalJSON() ([]byte, error) {
   255  	var dest [8]*VPCRouterFirewallConfig
   256  	for _, iface := range *i {
   257  		if iface != nil {
   258  			if iface.Receive == nil {
   259  				iface.Receive = make([]*VPCRouterFirewallRule, 0)
   260  			}
   261  			if iface.Send == nil {
   262  				iface.Send = make([]*VPCRouterFirewallRule, 0)
   263  			}
   264  			dest[iface.Index] = iface
   265  		}
   266  	}
   267  
   268  	for i, v := range dest {
   269  		if v == nil {
   270  			dest[i] = &VPCRouterFirewallConfig{
   271  				Receive: make([]*VPCRouterFirewallRule, 0),
   272  				Send:    make([]*VPCRouterFirewallRule, 0),
   273  				Index:   i,
   274  			}
   275  		}
   276  	}
   277  
   278  	return json.Marshal(dest)
   279  }
   280  
   281  // VPCRouterFirewallConfig ファイアウォール
   282  type VPCRouterFirewallConfig struct {
   283  	Receive []*VPCRouterFirewallRule `yaml:"receive"`
   284  	Send    []*VPCRouterFirewallRule `yaml:"send"`
   285  
   286  	// Index 仮想フィールド UnmarshalJSONの中で設定される
   287  	Index int `json:"-"`
   288  }
   289  
   290  // VPCRouterFirewallRule ファイアウォール ルール
   291  type VPCRouterFirewallRule struct {
   292  	Protocol           types.Protocol           `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   293  	SourceNetwork      types.VPCFirewallNetwork `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   294  	SourcePort         types.VPCFirewallPort    `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   295  	DestinationNetwork types.VPCFirewallNetwork `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   296  	DestinationPort    types.VPCFirewallPort    `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   297  	Action             types.Action             `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   298  	Logging            types.StringFlag         `yaml:"enabled"`
   299  	Description        string                   `yaml:"description"`
   300  }
   301  
   302  // VPCRouterDHCPServer DHCPサーバ
   303  type VPCRouterDHCPServer struct {
   304  	Config  []*VPCRouterDHCPServerConfig `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   305  	Enabled types.StringFlag             `yaml:"enabled"`
   306  }
   307  
   308  // MarshalJSON Configが一つ以上ある場合にEnabledをtrueに設定する
   309  func (f *VPCRouterDHCPServer) MarshalJSON() ([]byte, error) {
   310  	if f == nil {
   311  		return nil, nil
   312  	}
   313  	if len(f.Config) > 0 {
   314  		f.Enabled = types.StringTrue
   315  	}
   316  	type alias VPCRouterDHCPServer
   317  	a := alias(*f)
   318  	return json.Marshal(&a)
   319  }
   320  
   321  // VPCRouterDHCPServerConfig DHCPサーバ
   322  type VPCRouterDHCPServerConfig struct {
   323  	Interface  string   `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   324  	RangeStop  string   `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   325  	RangeStart string   `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   326  	DNSServers []string `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   327  }
   328  
   329  // VPCRouterDHCPStaticMappings DHCPスタティックマッピング
   330  type VPCRouterDHCPStaticMappings struct {
   331  	Config  []*VPCRouterDHCPStaticMappingConfig `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   332  	Enabled types.StringFlag                    `yaml:"enabled"`
   333  }
   334  
   335  // MarshalJSON Configが一つ以上ある場合にEnabledをtrueに設定する
   336  func (f *VPCRouterDHCPStaticMappings) MarshalJSON() ([]byte, error) {
   337  	if f == nil {
   338  		return nil, nil
   339  	}
   340  	if len(f.Config) > 0 {
   341  		f.Enabled = types.StringTrue
   342  	}
   343  	type alias VPCRouterDHCPStaticMappings
   344  	a := alias(*f)
   345  	return json.Marshal(&a)
   346  }
   347  
   348  // VPCRouterDHCPStaticMappingConfig DHCPスタティックマッピング
   349  type VPCRouterDHCPStaticMappingConfig struct {
   350  	MACAddress string `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   351  	IPAddress  string `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   352  }
   353  
   354  // VPCRouterDNSForwarding DNSフォワーディング
   355  type VPCRouterDNSForwarding struct {
   356  	Interface  string `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   357  	DNSServers []string
   358  	Enabled    types.StringFlag `yaml:"enabled"`
   359  }
   360  
   361  // MarshalJSON Configが一つ以上ある場合にEnabledをtrueに設定する
   362  func (f *VPCRouterDNSForwarding) MarshalJSON() ([]byte, error) {
   363  	if f == nil {
   364  		return nil, nil
   365  	}
   366  	if f.Interface != "" || len(f.DNSServers) > 0 {
   367  		f.Enabled = types.StringTrue
   368  	}
   369  	type alias VPCRouterDNSForwarding
   370  	a := alias(*f)
   371  	return json.Marshal(&a)
   372  }
   373  
   374  // VPCRouterPPTPServer PPTP
   375  type VPCRouterPPTPServer struct {
   376  	Config  *VPCRouterPPTPServerConfig `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   377  	Enabled types.StringFlag           `yaml:"enabled"`
   378  }
   379  
   380  // VPCRouterPPTPServerConfig PPTP
   381  type VPCRouterPPTPServerConfig struct {
   382  	RangeStart string `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   383  	RangeStop  string `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   384  }
   385  
   386  // VPCRouterL2TPIPsecServer L2TP
   387  type VPCRouterL2TPIPsecServer struct {
   388  	Config  *VPCRouterL2TPIPsecServerConfig `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   389  	Enabled types.StringFlag                `yaml:"enabled"`
   390  }
   391  
   392  // VPCRouterL2TPIPsecServerConfig L2TP
   393  type VPCRouterL2TPIPsecServerConfig struct {
   394  	RangeStart      string `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   395  	RangeStop       string `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   396  	PreSharedSecret string `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   397  }
   398  
   399  // VPCRouterWireGuard WireGuardサーバ
   400  type VPCRouterWireGuard struct {
   401  	Config  *VPCRouterWireGuardConfig `yaml:"config"`
   402  	Enabled types.StringFlag          `yaml:"enabled"`
   403  }
   404  
   405  // MarshalJSON Configが一つ以上ある場合にEnabledをtrueに設定する
   406  func (f *VPCRouterWireGuard) MarshalJSON() ([]byte, error) {
   407  	if f == nil {
   408  		return nil, nil
   409  	}
   410  	if f.Config == nil {
   411  		f.Config = &VPCRouterWireGuardConfig{}
   412  	}
   413  	if f.Config.IPAddress != "" {
   414  		f.Enabled = types.StringTrue
   415  	}
   416  	type alias VPCRouterWireGuard
   417  	a := alias(*f)
   418  	return json.Marshal(&a)
   419  }
   420  
   421  // VPCRouterWireGuardConfig WireGuardサーバコンフィグ
   422  type VPCRouterWireGuardConfig struct {
   423  	IPAddress string                    `yaml:"ip_address"` // xxx.xxx.xxx.xxx/nn
   424  	Peers     []*VPCRouterWireGuardPeer `yaml:"peers"`
   425  }
   426  
   427  // MarshalJSON Peersがnullを許容しないため代わりに[]を設定する
   428  func (f *VPCRouterWireGuardConfig) MarshalJSON() ([]byte, error) {
   429  	if f == nil {
   430  		return nil, nil
   431  	}
   432  	if f.Peers == nil {
   433  		f.Peers = []*VPCRouterWireGuardPeer{}
   434  	}
   435  	type alias VPCRouterWireGuardConfig
   436  	a := alias(*f)
   437  	return json.Marshal(&a)
   438  }
   439  
   440  // VPCRouterWireGuardPeer ピアの設定
   441  type VPCRouterWireGuardPeer struct {
   442  	Name      string `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   443  	IPAddress string `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   444  	PublicKey string `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   445  }
   446  
   447  // VPCRouterRemoteAccessUserConfig リモートアクセスユーザー
   448  type VPCRouterRemoteAccessUserConfig struct {
   449  	UserName string `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   450  	Password string `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   451  }
   452  
   453  // VPCRouterRemoteAccessUsers リモートアクセスユーザー
   454  type VPCRouterRemoteAccessUsers struct {
   455  	Config  []*VPCRouterRemoteAccessUserConfig `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   456  	Enabled types.StringFlag                   `yaml:"enabled"`
   457  }
   458  
   459  // MarshalJSON Configが一つ以上ある場合にEnabledをtrueに設定する
   460  func (f *VPCRouterRemoteAccessUsers) MarshalJSON() ([]byte, error) {
   461  	if f == nil {
   462  		return nil, nil
   463  	}
   464  	if len(f.Config) > 0 {
   465  		f.Enabled = types.StringTrue
   466  	}
   467  	type alias VPCRouterRemoteAccessUsers
   468  	a := alias(*f)
   469  	return json.Marshal(&a)
   470  }
   471  
   472  // VPCRouterSiteToSiteIPsecVPN サイト間VPN
   473  type VPCRouterSiteToSiteIPsecVPN struct {
   474  	Config         []*VPCRouterSiteToSiteIPsecVPNConfig `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   475  	IKE            *VPCRouterSiteToSiteIPsecVPNIKE      `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   476  	ESP            *VPCRouterSiteToSiteIPsecVPNESP      `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   477  	EncryptionAlgo string                               `json:",omitempty" yaml:",omitempty" structs:",omitempty"` // aes128 or aes256
   478  	HashAlgo       string                               `json:",omitempty" yaml:",omitempty" structs:",omitempty"` // sha1 or sha256
   479  	DHGroup        string                               `json:",omitempty" yaml:",omitempty" structs:",omitempty"` // modp1024 or modp2048 or modp3072 or modp4096
   480  	Enabled        types.StringFlag                     `yaml:"enabled"`
   481  }
   482  
   483  // MarshalJSON Configが一つ以上ある場合にEnabledをtrueに設定する
   484  func (f *VPCRouterSiteToSiteIPsecVPN) MarshalJSON() ([]byte, error) {
   485  	if f == nil {
   486  		return nil, nil
   487  	}
   488  	if len(f.Config) > 0 {
   489  		f.Enabled = types.StringTrue
   490  	}
   491  	type alias VPCRouterSiteToSiteIPsecVPN
   492  	a := alias(*f)
   493  	return json.Marshal(&a)
   494  }
   495  
   496  // VPCRouterSiteToSiteIPsecVPNConfig サイト間VPN
   497  type VPCRouterSiteToSiteIPsecVPNConfig struct {
   498  	Peer            string   `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   499  	PreSharedSecret string   `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   500  	RemoteID        string   `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   501  	Routes          []string `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   502  	LocalPrefix     []string `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   503  }
   504  
   505  // VPCRouterSiteToSiteIPsecVPNIKE サイト間VPNのIKE設定値
   506  type VPCRouterSiteToSiteIPsecVPNIKE struct {
   507  	Lifetime int // ISAKMP SAの寿命
   508  	DPD      VPCRouterSiteToSiteIPsecVPNIKEDPD
   509  }
   510  
   511  // VPCRouterSiteToSiteIPsecVPNIKEDPD サイト間VPNのIKE設定値 - DPD
   512  type VPCRouterSiteToSiteIPsecVPNIKEDPD struct {
   513  	Interval int // IKEキープアライブ(DPD) インターバル
   514  	Timeout  int // IKEキープアライブ(DPD) タイムアウト
   515  }
   516  
   517  // VPCRouterSiteToSiteIPsecVPNESP サイト間VPNのESP設定値
   518  type VPCRouterSiteToSiteIPsecVPNESP struct {
   519  	Lifetime int // IPsec SAの寿命
   520  }
   521  
   522  // VPCRouterStaticRoutes スタティックルート
   523  type VPCRouterStaticRoutes struct {
   524  	Config  []*VPCRouterStaticRouteConfig `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   525  	Enabled types.StringFlag              `yaml:"enabled"`
   526  }
   527  
   528  // MarshalJSON Configが一つ以上ある場合にEnabledをtrueに設定する
   529  func (f *VPCRouterStaticRoutes) MarshalJSON() ([]byte, error) {
   530  	if f == nil {
   531  		return nil, nil
   532  	}
   533  	if len(f.Config) > 0 {
   534  		f.Enabled = types.StringTrue
   535  	}
   536  	type alias VPCRouterStaticRoutes
   537  	a := alias(*f)
   538  	return json.Marshal(&a)
   539  }
   540  
   541  // VPCRouterStaticRouteConfig スタティックルート
   542  type VPCRouterStaticRouteConfig struct {
   543  	Prefix  string `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   544  	NextHop string `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   545  }
   546  
   547  // VPCRouterScheduledMaintenance
   548  type VPCRouterScheduledMaintenance struct {
   549  	DayOfWeek int // 0が日曜日
   550  	Hour      int // 0-23時
   551  }
   552  
   553  // VPCRouterStatus ステータス
   554  type VPCRouterStatus struct {
   555  	FirewallReceiveLogs    []string             `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   556  	FirewallSendLogs       []string             `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   557  	VPNLogs                []string             `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   558  	SessionCount           int                  `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   559  	PercentageOfMemoryFree []types.StringNumber `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   560  	DHCPServerLeases       []struct {
   561  		IPAddress  string
   562  		MACAddress string
   563  	} `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   564  	L2TPIPsecServerSessions []struct {
   565  		User      string
   566  		IPAddress string
   567  		TimeSec   int
   568  	} `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   569  	PPTPServerSessions []struct {
   570  		User      string
   571  		IPAddress string
   572  		TimeSec   int
   573  	} `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   574  	WireGuard *struct {
   575  		PublicKey string `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   576  	} `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   577  	SiteToSiteIPsecVPNPeers []struct {
   578  		Status string
   579  		Peer   string
   580  	} `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   581  	SessionAnalysis *struct {
   582  		SourceAndDestination []*VPCRouterStatisticsValue `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   583  		DestinationAddress   []*VPCRouterStatisticsValue `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   584  		DestinationPort      []*VPCRouterStatisticsValue `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   585  		SourceAddress        []*VPCRouterStatisticsValue `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   586  	} `json:",omitempty" yaml:",omitempty" structs:",omitempty"`
   587  }
   588  
   589  type VPCRouterLog struct {
   590  	Log string
   591  }
   592  
   593  type VPCRouterPingResult struct {
   594  	Result []string
   595  }
   596  
   597  // VPCRouterStatisticsValue VPCルータのセッション統計情報
   598  type VPCRouterStatisticsValue struct {
   599  	Name  string `json:"name,omitempty" yaml:"name,omitempty" structs:",omitempty"`
   600  	Count int    `json:"count,omitempty" yaml:"count,omitempty" structs:",omitempty"`
   601  }