github.com/cloudfoundry-community/cloudfoundry-cli@v6.44.1-0.20240130060226-cda5ed8e89a5+incompatible/resources/domain_resource.go (about)

     1  package resources
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/types"
     5  	"code.cloudfoundry.org/jsonry"
     6  )
     7  
     8  type Domain struct {
     9  	GUID             string         `json:"guid,omitempty"`
    10  	Name             string         `json:"name"`
    11  	Internal         types.NullBool `json:"internal,omitempty"`
    12  	OrganizationGUID string         `jsonry:"relationships.organization.data.guid,omitempty"`
    13  	RouterGroup      string         `jsonry:"router_group.guid,omitempty"`
    14  	Protocols        []string       `jsonry:"supported_protocols,omitempty"`
    15  
    16  	// Metadata is used for custom tagging of API resources
    17  	Metadata *Metadata `json:"metadata,omitempty"`
    18  }
    19  
    20  func (d Domain) MarshalJSON() ([]byte, error) {
    21  	type domainWithBoolPointer struct {
    22  		GUID             string   `jsonry:"guid,omitempty"`
    23  		Name             string   `jsonry:"name"`
    24  		Internal         *bool    `jsonry:"internal,omitempty"`
    25  		OrganizationGUID string   `jsonry:"relationships.organization.data.guid,omitempty"`
    26  		RouterGroup      string   `jsonry:"router_group.guid,omitempty"`
    27  		Protocols        []string `jsonry:"supported_protocols,omitempty"`
    28  	}
    29  
    30  	clone := domainWithBoolPointer{
    31  		GUID:             d.GUID,
    32  		Name:             d.Name,
    33  		OrganizationGUID: d.OrganizationGUID,
    34  		RouterGroup:      d.RouterGroup,
    35  		Protocols:        d.Protocols,
    36  	}
    37  
    38  	if d.Internal.IsSet {
    39  		clone.Internal = &d.Internal.Value
    40  	}
    41  	return jsonry.Marshal(clone)
    42  }
    43  
    44  func (d *Domain) UnmarshalJSON(data []byte) error {
    45  	type alias Domain
    46  	var defaultUnmarshalledDomain alias
    47  	err := jsonry.Unmarshal(data, &defaultUnmarshalledDomain)
    48  	if err != nil {
    49  		return err
    50  	}
    51  
    52  	*d = Domain(defaultUnmarshalledDomain)
    53  
    54  	return nil
    55  }
    56  
    57  func (d Domain) Shared() bool {
    58  	return d.OrganizationGUID == ""
    59  }
    60  
    61  func (d *Domain) IsTCP() bool {
    62  	for _, p := range d.Protocols {
    63  		if p == "tcp" {
    64  			return true
    65  		}
    66  	}
    67  
    68  	return false
    69  }