github.com/interconnectedcloud/qdr-operator@v0.0.0-20210826174505-576d2b33dac7/test/e2e/framework/qdrmanagement/entities/connection.go (about)

     1  package entities
     2  
     3  import (
     4  	"encoding/json"
     5  	"github.com/interconnectedcloud/qdr-operator/test/e2e/framework/qdrmanagement/entities/common"
     6  	"strconv"
     7  	"strings"
     8  )
     9  
    10  // Connection represents a Dispatch Router connection
    11  type Connection struct {
    12  	EntityCommon
    13  	Active          bool                   `json:"active"`
    14  	AdminStatus     AdminStatusType        `json:"adminStatus,string"`
    15  	OperStatus      ConnOperStatusType     `json:"operStatus,string"`
    16  	Container       string                 `json:"container"`
    17  	Opened          bool                   `json:"opened"`
    18  	Host            string                 `json:"host"`
    19  	Direction       common.DirectionType   `json:"dir,string"`
    20  	Role            string                 `json:"role"`
    21  	IsAuthenticated bool                   `json:"isAuthenticated"`
    22  	IsEncrypted     bool                   `json:"isEncrypted"`
    23  	Sasl            string                 `json:"sasl"`
    24  	User            string                 `json:"user"`
    25  	Ssl             bool                   `json:"ssl"`
    26  	SslProto        string                 `json:"sslProto"`
    27  	SslCipher       string                 `json:"sslCipher"`
    28  	SslSsf          int                    `json:"sslSsf"`
    29  	Tenant          string                 `json:"tenant"`
    30  	Properties      map[string]interface{} `json:"properties"`
    31  }
    32  
    33  // Implementation of Entity interface
    34  func (Connection) GetEntityId() string {
    35  	return "connection"
    36  }
    37  
    38  type AdminStatusType int
    39  
    40  const (
    41  	AdminStatusEnabled AdminStatusType = iota
    42  	AdminStatusDeleted
    43  )
    44  
    45  // UnmarshalJSON returns the appropriate AdminStatusType for parsed string
    46  func (a *AdminStatusType) UnmarshalJSON(b []byte) error {
    47  	var s string
    48  
    49  	if len(b) == 0 {
    50  		return nil
    51  	}
    52  	if b[0] != '"' {
    53  		b = []byte(strconv.Quote(string(b)))
    54  	}
    55  	if err := json.Unmarshal(b, &s); err != nil {
    56  		return err
    57  	}
    58  	switch strings.ToLower(s) {
    59  	case "enabled":
    60  		*a = AdminStatusEnabled
    61  	case "deleted":
    62  		*a = AdminStatusDeleted
    63  	}
    64  	return nil
    65  }
    66  
    67  // MarshalJSON returns the string representation of AdminStatusType
    68  func (a AdminStatusType) MarshalJSON() ([]byte, error) {
    69  	var s string
    70  	switch a {
    71  	case AdminStatusEnabled:
    72  		s = "enabled"
    73  	case AdminStatusDeleted:
    74  		s = "deleted"
    75  	}
    76  	return json.Marshal(s)
    77  }
    78  
    79  type ConnOperStatusType int
    80  
    81  const (
    82  	ConnOperStatusUp ConnOperStatusType = iota
    83  	ConnOperStatusClosing
    84  )
    85  
    86  // UnmarshalJSON returns the appropriate ConnOperStatusType for parsed string
    87  func (o *ConnOperStatusType) UnmarshalJSON(b []byte) error {
    88  	var s string
    89  
    90  	if len(b) == 0 {
    91  		return nil
    92  	}
    93  	if b[0] != '"' {
    94  		b = []byte(strconv.Quote(string(b)))
    95  	}
    96  	if err := json.Unmarshal(b, &s); err != nil {
    97  		return err
    98  	}
    99  	switch strings.ToLower(s) {
   100  	case "up":
   101  		*o = ConnOperStatusUp
   102  	case "closing":
   103  		*o = ConnOperStatusClosing
   104  	}
   105  	return nil
   106  }
   107  
   108  // MarshalJSON returns the string representation of ConnOperStatusType
   109  func (o ConnOperStatusType) MarshalJSON() ([]byte, error) {
   110  	var s string
   111  	switch o {
   112  	case ConnOperStatusUp:
   113  		s = "up"
   114  	case ConnOperStatusClosing:
   115  		s = "closing"
   116  	}
   117  	return json.Marshal(s)
   118  }