github.com/sacloud/iaas-api-go@v1.12.0/naked/packet_filter.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  // PacketFilter パケットフィルタ
    25  type PacketFilter struct {
    26  	ID                  types.ID                `json:",omitempty" yaml:"id,omitempty" structs:",omitempty"`
    27  	Name                string                  `json:",omitempty" yaml:"name,omitempty" structs:",omitempty"`
    28  	Description         string                  `yaml:"description"`
    29  	RequiredHostVersion types.StringNumber      `json:",omitempty" yaml:"require_host_version,omitempty" structs:",omitempty"`
    30  	Expression          PacketFilterExpressions `yaml:"expression"`
    31  	ExpressionHash      string                  `json:",omitempty" yaml:"expression_hash,omitempty" structs:",omitempty"`
    32  	CreatedAt           time.Time               `json:",omitempty" yaml:"created_at,omitempty" structs:",omitempty"`
    33  	// Notice              interface{}               `json:"Notice"`
    34  }
    35  
    36  // PacketFilterExpressions パケットフィルターのルール
    37  type PacketFilterExpressions []*PacketFilterExpression
    38  
    39  // MarshalJSON nullの場合に空配列を出力するための実装
    40  func (p *PacketFilterExpressions) MarshalJSON() ([]byte, error) {
    41  	if *p == nil {
    42  		*p = make([]*PacketFilterExpression, 0)
    43  	}
    44  	type alias PacketFilterExpressions
    45  	tmp := alias(*p)
    46  	return json.Marshal(&tmp)
    47  }
    48  
    49  // PacketFilterExpression パケットフィルタのルール
    50  type PacketFilterExpression struct {
    51  	Protocol        types.Protocol            `yaml:"protocol"`
    52  	SourceNetwork   types.PacketFilterNetwork `yaml:"source_network"`
    53  	DestinationPort types.PacketFilterPort    `yaml:"destination_port"`
    54  	Action          types.Action              `yaml:"action"`
    55  	SourcePort      types.PacketFilterPort    `yaml:"source_port"`
    56  	Description     string                    `yaml:"description"`
    57  }
    58  
    59  // PacketFilterInfo パケットフィルタ - Interface配下などでの参照用
    60  type PacketFilterInfo struct {
    61  	ID                  types.ID           `json:",omitempty" yaml:"id,omitempty" structs:",omitempty"`
    62  	Name                string             `json:",omitempty" yaml:"name,omitempty" structs:",omitempty"`
    63  	RequiredHostVersion types.StringNumber `json:",omitempty" yaml:"require_host_version,omitempty" structs:",omitempty"`
    64  }