github.com/Axway/agent-sdk@v1.1.101/pkg/apic/apiserver/clients/catalog/v1/SupportContact.go (about)

     1  /*
     2   * This file is automatically generated
     3   */
     4  
     5  package catalog
     6  
     7  import (
     8  	"fmt"
     9  
    10  	v1 "github.com/Axway/agent-sdk/pkg/apic/apiserver/clients/api/v1"
    11  	apiv1 "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/api/v1"
    12  	m "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/catalog/v1"
    13  )
    14  
    15  type SupportContactMergeFunc func(*m.SupportContact, *m.SupportContact) (*m.SupportContact, error)
    16  
    17  // SupportContactMerge builds a merge option for an update operation
    18  func SupportContactMerge(f SupportContactMergeFunc) v1.UpdateOption {
    19  	return v1.Merge(func(prev, new apiv1.Interface) (apiv1.Interface, error) {
    20  		p, n := &m.SupportContact{}, &m.SupportContact{}
    21  
    22  		switch t := prev.(type) {
    23  		case *m.SupportContact:
    24  			p = t
    25  		case *apiv1.ResourceInstance:
    26  			err := p.FromInstance(t)
    27  			if err != nil {
    28  				return nil, fmt.Errorf("merge: failed to unserialise prev resource: %w", err)
    29  			}
    30  		default:
    31  			return nil, fmt.Errorf("merge: failed to unserialise prev resource, unxexpected resource type: %T", t)
    32  		}
    33  
    34  		switch t := new.(type) {
    35  		case *m.SupportContact:
    36  			n = t
    37  		case *apiv1.ResourceInstance:
    38  			err := n.FromInstance(t)
    39  			if err != nil {
    40  				return nil, fmt.Errorf("merge: failed to unserialize new resource: %w", err)
    41  			}
    42  		default:
    43  			return nil, fmt.Errorf("merge: failed to unserialise new resource, unxexpected resource type: %T", t)
    44  		}
    45  
    46  		return f(p, n)
    47  	})
    48  }
    49  
    50  // SupportContactClient - rest client for SupportContact resources that have a defined resource scope
    51  type SupportContactClient struct {
    52  	client v1.Scoped
    53  }
    54  
    55  // NewSupportContactClient - creates a client scoped to a particular resource
    56  func NewSupportContactClient(c v1.Base) (*SupportContactClient, error) {
    57  
    58  	client, err := c.ForKind(m.SupportContactGVK())
    59  	if err != nil {
    60  		return nil, err
    61  	}
    62  
    63  	return &SupportContactClient{client}, nil
    64  
    65  }
    66  
    67  // List - gets a list of resources
    68  func (c *SupportContactClient) List(options ...v1.ListOptions) ([]*m.SupportContact, error) {
    69  	riList, err := c.client.List(options...)
    70  	if err != nil {
    71  		return nil, err
    72  	}
    73  
    74  	result := make([]*m.SupportContact, len(riList))
    75  
    76  	for i := range riList {
    77  		result[i] = &m.SupportContact{}
    78  		err := result[i].FromInstance(riList[i])
    79  		if err != nil {
    80  			return nil, err
    81  		}
    82  	}
    83  
    84  	return result, nil
    85  }
    86  
    87  // Get - gets a resource by name
    88  func (c *SupportContactClient) Get(name string) (*m.SupportContact, error) {
    89  	ri, err := c.client.Get(name)
    90  	if err != nil {
    91  		return nil, err
    92  	}
    93  
    94  	service := &m.SupportContact{}
    95  	service.FromInstance(ri)
    96  
    97  	return service, nil
    98  }
    99  
   100  // Delete - deletes a resource
   101  func (c *SupportContactClient) Delete(res *m.SupportContact) error {
   102  	ri, err := res.AsInstance()
   103  
   104  	if err != nil {
   105  		return err
   106  	}
   107  
   108  	return c.client.Delete(ri)
   109  }
   110  
   111  // Create - creates a resource
   112  func (c *SupportContactClient) Create(res *m.SupportContact, opts ...v1.CreateOption) (*m.SupportContact, error) {
   113  	ri, err := res.AsInstance()
   114  
   115  	if err != nil {
   116  		return nil, err
   117  	}
   118  
   119  	cri, err := c.client.Create(ri, opts...)
   120  	if err != nil {
   121  		return nil, err
   122  	}
   123  
   124  	created := &m.SupportContact{}
   125  
   126  	err = created.FromInstance(cri)
   127  	if err != nil {
   128  		return nil, err
   129  	}
   130  
   131  	return created, err
   132  }
   133  
   134  // Update - updates a resource
   135  func (c *SupportContactClient) Update(res *m.SupportContact, opts ...v1.UpdateOption) (*m.SupportContact, error) {
   136  	ri, err := res.AsInstance()
   137  	if err != nil {
   138  		return nil, err
   139  	}
   140  	resource, err := c.client.Update(ri, opts...)
   141  	if err != nil {
   142  		return nil, err
   143  	}
   144  
   145  	updated := &m.SupportContact{}
   146  
   147  	// Updates the resource in place
   148  	err = updated.FromInstance(resource)
   149  	if err != nil {
   150  		return nil, err
   151  	}
   152  
   153  	return updated, nil
   154  }