Skip to content

Commit

Permalink
feat: full machine proxy support (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
domenicsim1 authored Oct 30, 2024
1 parent c17e4b6 commit cd43858
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions pkg/proxies/proxy_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package proxies
import (
"github.com/OctopusDeploy/go-octopusdeploy/v2/internal"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/constants"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/newclient"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/resources"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/services"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/services/api"
"github.com/dghubble/sling"
Expand All @@ -20,6 +22,7 @@ func NewProxyService(sling *sling.Sling, uriTemplate string) *ProxyService {
}
}

// Deprecated: use proxies.GetByID
func (p *ProxyService) GetById(id string) (*Proxy, error) {
if internal.IsEmpty(id) {
return nil, internal.CreateInvalidParameterError(constants.OperationGetByID, "id")
Expand All @@ -34,6 +37,7 @@ func (p *ProxyService) GetById(id string) (*Proxy, error) {
return resp.(*Proxy), nil
}

// Deprecated: use proxies.GetAll
func (p *ProxyService) GetAll() ([]*Proxy, error) {
items := []*Proxy{}
path, err := services.GetAllPath(p)
Expand All @@ -44,3 +48,36 @@ func (p *ProxyService) GetAll() ([]*Proxy, error) {
_, err = api.ApiGet(p.GetClient(), &items, path)
return items, err
}

// --- new ---
const template = "/api/{spaceId}/proxies{/id}{?skip,take,ids,partialName}"

// Get return the machine proxies that match the provided proxies query.
func Get(client newclient.Client, spaceID string, proxyQuery ProxiesQuery) (*resources.Resources[*Proxy], error) {
return newclient.GetByQuery[Proxy](client, template, spaceID, proxyQuery)
}

// Update modifies a machine proxy based on the one provided as input.
func Update(client newclient.Client, resource *Proxy) (*Proxy, error) {
return newclient.Update[Proxy](client, template, resource.SpaceID, resource.ID, resource)
}

// Add creates a new machine proxy.
func Add(client newclient.Client, proxy *Proxy) (*Proxy, error) {
return newclient.Add[Proxy](client, template, proxy.SpaceID, proxy)
}

// GetByID returns the machine proxy that matches the input ID.
func GetByID(client newclient.Client, spaceID string, ID string) (*Proxy, error) {
return newclient.GetByID[Proxy](client, template, spaceID, ID)
}

// DeleteByID deletes the machine proxy that matches the input ID.
func DeleteByID(client newclient.Client, spaceID string, ID string) error {
return newclient.DeleteByID(client, template, spaceID, ID)
}

// GetAll returns all machine proxies. If an error occurs, it returns nil.
func GetAll(client newclient.Client, spaceID string) ([]*Proxy, error) {
return newclient.GetAll[Proxy](client, template, spaceID)
}

0 comments on commit cd43858

Please sign in to comment.