Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APIGOV-21563 - apigee agent service #680

Merged
merged 2 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 154 additions & 0 deletions pkg/apic/apiserver/clients/catalog/v1/DocumentResource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/*
* This file is automatically generated
*/

package catalog

import (
"fmt"

v1 "github.com/Axway/agent-sdk/pkg/apic/apiserver/clients/api/v1"
apiv1 "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/api/v1"
m "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/catalog/v1"
)

type DocumentResourceMergeFunc func(*m.DocumentResource, *m.DocumentResource) (*m.DocumentResource, error)

// DocumentResourceMerge builds a merge option for an update operation
func DocumentResourceMerge(f DocumentResourceMergeFunc) v1.UpdateOption {
return v1.Merge(func(prev, new apiv1.Interface) (apiv1.Interface, error) {
p, n := &m.DocumentResource{}, &m.DocumentResource{}

switch t := prev.(type) {
case *m.DocumentResource:
p = t
case *apiv1.ResourceInstance:
err := p.FromInstance(t)
if err != nil {
return nil, fmt.Errorf("merge: failed to unserialise prev resource: %w", err)
}
default:
return nil, fmt.Errorf("merge: failed to unserialise prev resource, unxexpected resource type: %T", t)
}

switch t := new.(type) {
case *m.DocumentResource:
n = t
case *apiv1.ResourceInstance:
err := n.FromInstance(t)
if err != nil {
return nil, fmt.Errorf("merge: failed to unserialize new resource: %w", err)
}
default:
return nil, fmt.Errorf("merge: failed to unserialise new resource, unxexpected resource type: %T", t)
}

return f(p, n)
})
}

// DocumentResourceClient - rest client for DocumentResource resources that have a defined resource scope
type DocumentResourceClient struct {
client v1.Scoped
}

// NewDocumentResourceClient - creates a client scoped to a particular resource
func NewDocumentResourceClient(c v1.Base) (*DocumentResourceClient, error) {

client, err := c.ForKind(m.DocumentResourceGVK())
if err != nil {
return nil, err
}

return &DocumentResourceClient{client}, nil

}

// List - gets a list of resources
func (c *DocumentResourceClient) List(options ...v1.ListOptions) ([]*m.DocumentResource, error) {
riList, err := c.client.List(options...)
if err != nil {
return nil, err
}

result := make([]*m.DocumentResource, len(riList))

for i := range riList {
result[i] = &m.DocumentResource{}
err := result[i].FromInstance(riList[i])
if err != nil {
return nil, err
}
}

return result, nil
}

// Get - gets a resource by name
func (c *DocumentResourceClient) Get(name string) (*m.DocumentResource, error) {
ri, err := c.client.Get(name)
if err != nil {
return nil, err
}

service := &m.DocumentResource{}
service.FromInstance(ri)

return service, nil
}

// Delete - deletes a resource
func (c *DocumentResourceClient) Delete(res *m.DocumentResource) error {
ri, err := res.AsInstance()

if err != nil {
return err
}

return c.client.Delete(ri)
}

// Create - creates a resource
func (c *DocumentResourceClient) Create(res *m.DocumentResource, opts ...v1.CreateOption) (*m.DocumentResource, error) {
ri, err := res.AsInstance()

if err != nil {
return nil, err
}

cri, err := c.client.Create(ri, opts...)
if err != nil {
return nil, err
}

created := &m.DocumentResource{}

err = created.FromInstance(cri)
if err != nil {
return nil, err
}

return created, err
}

// Update - updates a resource
func (c *DocumentResourceClient) Update(res *m.DocumentResource, opts ...v1.UpdateOption) (*m.DocumentResource, error) {
ri, err := res.AsInstance()
if err != nil {
return nil, err
}
resource, err := c.client.Update(ri, opts...)
if err != nil {
return nil, err
}

updated := &m.DocumentResource{}

// Updates the resource in place
err = updated.FromInstance(resource)
if err != nil {
return nil, err
}

return updated, nil
}
201 changes: 201 additions & 0 deletions pkg/apic/apiserver/clients/catalog/v1/PublishedDocumentResource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
/*
* This file is automatically generated
*/

package catalog

import (
"fmt"

v1 "github.com/Axway/agent-sdk/pkg/apic/apiserver/clients/api/v1"
apiv1 "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/api/v1"
m "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/catalog/v1"
)

type PublishedDocumentResourceMergeFunc func(*m.PublishedDocumentResource, *m.PublishedDocumentResource) (*m.PublishedDocumentResource, error)

// PublishedDocumentResourceMerge builds a merge option for an update operation
func PublishedDocumentResourceMerge(f PublishedDocumentResourceMergeFunc) v1.UpdateOption {
return v1.Merge(func(prev, new apiv1.Interface) (apiv1.Interface, error) {
p, n := &m.PublishedDocumentResource{}, &m.PublishedDocumentResource{}

switch t := prev.(type) {
case *m.PublishedDocumentResource:
p = t
case *apiv1.ResourceInstance:
err := p.FromInstance(t)
if err != nil {
return nil, fmt.Errorf("merge: failed to unserialise prev resource: %w", err)
}
default:
return nil, fmt.Errorf("merge: failed to unserialise prev resource, unxexpected resource type: %T", t)
}

switch t := new.(type) {
case *m.PublishedDocumentResource:
n = t
case *apiv1.ResourceInstance:
err := n.FromInstance(t)
if err != nil {
return nil, fmt.Errorf("merge: failed to unserialize new resource: %w", err)
}
default:
return nil, fmt.Errorf("merge: failed to unserialise new resource, unxexpected resource type: %T", t)
}

return f(p, n)
})
}

// PublishedDocumentResourceClient - rest client for PublishedDocumentResource resources that have a defined resource scope
type PublishedDocumentResourceClient struct {
client v1.Scoped
}

// UnscopedPublishedDocumentResourceClient - rest client for PublishedDocumentResource resources that do not have a defined scope
type UnscopedPublishedDocumentResourceClient struct {
client v1.Unscoped
}

// NewPublishedDocumentResourceClient - creates a client that is not scoped to any resource
func NewPublishedDocumentResourceClient(c v1.Base) (*UnscopedPublishedDocumentResourceClient, error) {

client, err := c.ForKind(m.PublishedDocumentResourceGVK())
if err != nil {
return nil, err
}

return &UnscopedPublishedDocumentResourceClient{client}, nil

}

// WithScope - sets the resource scope for the client
func (c *UnscopedPublishedDocumentResourceClient) WithScope(scope string) *PublishedDocumentResourceClient {
return &PublishedDocumentResourceClient{
c.client.WithScope(scope),
}
}

// Get - gets a resource by name
func (c *UnscopedPublishedDocumentResourceClient) Get(name string) (*m.PublishedDocumentResource, error) {
ri, err := c.client.Get(name)
if err != nil {
return nil, err
}

service := &m.PublishedDocumentResource{}
service.FromInstance(ri)

return service, nil
}

// Update - updates a resource
func (c *UnscopedPublishedDocumentResourceClient) Update(res *m.PublishedDocumentResource, opts ...v1.UpdateOption) (*m.PublishedDocumentResource, error) {
ri, err := res.AsInstance()
if err != nil {
return nil, err
}
resource, err := c.client.Update(ri, opts...)
if err != nil {
return nil, err
}

updated := &m.PublishedDocumentResource{}

// Updates the resource in place
err = updated.FromInstance(resource)
if err != nil {
return nil, err
}

return updated, nil
}

// List - gets a list of resources
func (c *PublishedDocumentResourceClient) List(options ...v1.ListOptions) ([]*m.PublishedDocumentResource, error) {
riList, err := c.client.List(options...)
if err != nil {
return nil, err
}

result := make([]*m.PublishedDocumentResource, len(riList))

for i := range riList {
result[i] = &m.PublishedDocumentResource{}
err := result[i].FromInstance(riList[i])
if err != nil {
return nil, err
}
}

return result, nil
}

// Get - gets a resource by name
func (c *PublishedDocumentResourceClient) Get(name string) (*m.PublishedDocumentResource, error) {
ri, err := c.client.Get(name)
if err != nil {
return nil, err
}

service := &m.PublishedDocumentResource{}
service.FromInstance(ri)

return service, nil
}

// Delete - deletes a resource
func (c *PublishedDocumentResourceClient) Delete(res *m.PublishedDocumentResource) error {
ri, err := res.AsInstance()

if err != nil {
return err
}

return c.client.Delete(ri)
}

// Create - creates a resource
func (c *PublishedDocumentResourceClient) Create(res *m.PublishedDocumentResource, opts ...v1.CreateOption) (*m.PublishedDocumentResource, error) {
ri, err := res.AsInstance()

if err != nil {
return nil, err
}

cri, err := c.client.Create(ri, opts...)
if err != nil {
return nil, err
}

created := &m.PublishedDocumentResource{}

err = created.FromInstance(cri)
if err != nil {
return nil, err
}

return created, err
}

// Update - updates a resource
func (c *PublishedDocumentResourceClient) Update(res *m.PublishedDocumentResource, opts ...v1.UpdateOption) (*m.PublishedDocumentResource, error) {
ri, err := res.AsInstance()
if err != nil {
return nil, err
}
resource, err := c.client.Update(ri, opts...)
if err != nil {
return nil, err
}

updated := &m.PublishedDocumentResource{}

// Updates the resource in place
err = updated.FromInstance(resource)
if err != nil {
return nil, err
}

return updated, nil
}
Loading