github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/vpn/v5/connections/results.go (about)

     1  package connections
     2  
     3  import "github.com/chnsz/golangsdk/pagination"
     4  
     5  type Connections struct {
     6  	ID                  string       `json:"id"`
     7  	Name                string       `json:"name"`
     8  	Status              string       `json:"status"`
     9  	VgwId               string       `json:"vgw_id"`
    10  	VgwIp               string       `json:"vgw_ip"`
    11  	Style               string       `json:"style"`
    12  	CgwId               string       `json:"cgw_id"`
    13  	PeerSubnets         []string     `json:"peer_subnets"`
    14  	TunnelLocalAddress  string       `json:"tunnel_local_address"`
    15  	TunnelPeerAddress   string       `json:"tunnel_peer_address"`
    16  	EnableNqa           bool         `json:"enable_nqa"`
    17  	PolicyRules         []PolicyRule `json:"policy_rules"`
    18  	Ikepolicy           IkePolicy    `json:"ikepolicy"`
    19  	Ipsecpolicy         IpsecPolicy  `json:"ipsecpolicy"`
    20  	CreatedAt           string       `json:"created_at"`
    21  	UpdatedAt           string       `json:"updated_at"`
    22  	EnterpriseProjectID string       `json:"enterprise_project_id"`
    23  	ConnectionMonitorID string       `json:"connection_monitor_id"`
    24  	HaRole              string       `json:"ha_role"`
    25  }
    26  
    27  type listResp struct {
    28  	Connections []Connections `json:"vpn_connections"`
    29  	RequestId   string        `json:"request_id"`
    30  	PageInfo    pageInfo      `json:"page_info"`
    31  	TotalCount  int64         `json:"total_count"`
    32  }
    33  
    34  type PolicyRule struct {
    35  	RuleIndex   int      `json:"rule_index"`
    36  	Source      string   `json:"source"`
    37  	Destination []string `json:"destination"`
    38  }
    39  
    40  type IkePolicy struct {
    41  	IkeVersion              string `json:"ike_version"`
    42  	Phase1NegotiationMode   string `json:"phase1_negotiation_mode"`
    43  	AuthenticationAlgorithm string `json:"authentication_algorithm"`
    44  	EncryptionAlgorithm     string `json:"encryption_algorithm"`
    45  	DhGroup                 string `json:"dh_group"`
    46  	AuthenticationMethod    string `json:"authentication_method"`
    47  	LifetimeSeconds         int    `json:"lifetime_seconds"`
    48  	LocalIdType             string `json:"local_id_type"`
    49  	LocalId                 string `json:"local_id"`
    50  	PeerIdType              string `json:"peer_id_type"`
    51  	PeerId                  string `json:"peer_id"`
    52  	Dpd                     Dpd    `json:"dpd"`
    53  }
    54  
    55  type Dpd struct {
    56  	Timeout  int    `json:"timeout"`
    57  	Interval int    `json:"interval"`
    58  	Msg      string `json:"msg"`
    59  }
    60  
    61  type IpsecPolicy struct {
    62  	AuthenticationAlgorithm string `json:"authentication_algorithm"`
    63  	EncryptionAlgorithm     string `json:"encryption_algorithm"`
    64  	Pfs                     string `json:"pfs"`
    65  	TransformProtocol       string `json:"transform_protocol"`
    66  	LifetimeSeconds         int64  `json:"lifetime_seconds"`
    67  	EncapsulationMode       string `json:"encapsulation_mode"`
    68  }
    69  
    70  type pageInfo struct {
    71  	NextMarker   string `json:"next_marker"`
    72  	CurrentCount int    `json:"current_count"`
    73  }
    74  
    75  type ConnectionsPage struct {
    76  	pagination.MarkerPageBase
    77  }
    78  
    79  // IsEmpty returns true if a ListResult is empty.
    80  func (r ConnectionsPage) IsEmpty() (bool, error) {
    81  	resp, err := extractConnections(r)
    82  	return len(resp) == 0, err
    83  }
    84  
    85  // LastMarker returns the last marker index in a ListResult.
    86  func (r ConnectionsPage) LastMarker() (string, error) {
    87  	resp, err := extractPageInfo(r)
    88  	if err != nil {
    89  		return "", err
    90  	}
    91  	return resp.NextMarker, nil
    92  }
    93  
    94  // extractConnections is a method which to extract the response to a VpnConnection list.
    95  func extractConnections(r pagination.Page) ([]Connections, error) {
    96  	var s listResp
    97  	err := r.(ConnectionsPage).Result.ExtractInto(&s)
    98  	return s.Connections, err
    99  }
   100  
   101  // extractPageInfo is a method which to extract the response of the page information.
   102  func extractPageInfo(r pagination.Page) (*pageInfo, error) {
   103  	var s listResp
   104  	err := r.(ConnectionsPage).Result.ExtractInto(&s)
   105  	return &s.PageInfo, err
   106  }