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

GetAll #212

Merged
merged 1 commit into from
Oct 24, 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
8 changes: 8 additions & 0 deletions pkg/accounts/account_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ func (s *AccountService) Get(accountsQuery ...AccountsQuery) (*Accounts, error)

// GetAll returns all accounts. If none are found or an error occurs, it
// returns an empty collection.
//
// Deprecated: use accounts.GetAll
func (s *AccountService) GetAll() ([]IAccount, error) {
items := []*AccountResource{}
path, err := services.GetAllPath(s)
Expand Down Expand Up @@ -194,3 +196,9 @@ func Update(client newclient.Client, account IAccount) (IAccount, error) {
func DeleteByID(client newclient.Client, spaceID string, id string) error {
return newclient.DeleteByID(client, template, spaceID, id)
}

// GetAll returns all accounts. If an error occurs, it returns nil.
func GetAll(client newclient.Client, spaceID string) ([]IAccount, error) {
items, err := newclient.GetAll[AccountResource](client, template, spaceID)
return ToAccountArray(items), err
}
3 changes: 2 additions & 1 deletion pkg/actions/community_action_template_service.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package actions

import (
"strings"

"github.com/OctopusDeploy/go-octopusdeploy/v2/internal"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/constants"
"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"
"github.com/google/go-querystring/query"
"strings"
)

// CommunityActionTemplateService handles communication with Account-related methods of the Octopus API.
Expand Down
7 changes: 7 additions & 0 deletions pkg/certificates/certificate_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ func (s *CertificateService) Get(certificatesQuery CertificatesQuery) (*resource

// GetAll returns all certificates. If none are found or an error occurs, it
// returns an empty collection.
//
// Deprecated: use certificates.GetAll
func (s *CertificateService) GetAll() ([]*CertificateResource, error) {
items := []*CertificateResource{}
path, err := services.GetAllPath(s)
Expand Down Expand Up @@ -202,3 +204,8 @@ func GetByID(client newclient.Client, spaceID string, ID string) (*CertificateRe
func Update(client newclient.Client, resource *CertificateResource) (*CertificateResource, error) {
return newclient.Update[CertificateResource](client, template, resource.SpaceID, resource.ID, resource)
}

// GetAll returns all certificates. If an error occurs, it returns nil.
func GetAll(client newclient.Client, spaceID string) ([]*CertificateResource, error) {
return newclient.GetAll[CertificateResource](client, template, spaceID)
}
7 changes: 7 additions & 0 deletions pkg/channels/channel_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ func (s *ChannelService) Get(channelsQuery Query) (*resources.Resources[*Channel

// GetAll returns all channels. If none can be found or an error occurs, it
// returns an empty collection.
//
// Depreacted: use channels.GetAll
func (s *ChannelService) GetAll() ([]*Channel, error) {
items := []*Channel{}
path, err := services.GetAllPath(s)
Expand Down Expand Up @@ -147,3 +149,8 @@ func Update(client newclient.Client, channel *Channel) (*Channel, error) {
func DeleteByID(client newclient.Client, spaceID string, ID string) error {
return newclient.DeleteByID(client, template, spaceID, ID)
}

// GetAll returns all channels. If an error occurs, it returns nil.
func GetAll(client newclient.Client, spaceID string) ([]*Channel, error) {
return newclient.GetAll[Channel](client, template, spaceID)
}
7 changes: 7 additions & 0 deletions pkg/environments/environment_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ func (s *EnvironmentService) Get(environmentsQuery EnvironmentsQuery) (*resource

// GetAll returns all environments. If none can be found or an error occurs, it
// returns an empty collection.
//
// Deprecated: use environments.GetAll
func (s *EnvironmentService) GetAll() ([]*Environment, error) {
items := []*Environment{}
path, err := services.GetAllPath(s)
Expand Down Expand Up @@ -199,3 +201,8 @@ func GetByID(client newclient.Client, spaceID string, ID string) (*Environment,
func Update(client newclient.Client, environment *Environment) (*Environment, error) {
return newclient.Update[Environment](client, template, environment.SpaceID, environment.ID, environment)
}

// GetAll returns all environments. If an error occurs, it returns nil.
func GetAll(client newclient.Client, spaceID string) ([]*Environment, error) {
return newclient.GetAll[Environment](client, template, spaceID)
}
6 changes: 6 additions & 0 deletions pkg/feeds/feed_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,9 @@ func Update(client newclient.Client, feed IFeed) (IFeed, error) {
func DeleteByID(client newclient.Client, spaceID string, id string) error {
return newclient.DeleteByID(client, template, spaceID, id)
}

// GetAll returns all feeds. If an error occurs, it returns nil.
func GetAll(client newclient.Client, spaceID string) ([]IFeed, error) {
items, err := newclient.GetAll[FeedResource](client, template, spaceID)
return ToFeedArray(items), err
}
7 changes: 7 additions & 0 deletions pkg/lifecycles/lifecycle_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ func (s *LifecycleService) Get(lifecyclesQuery Query) (*resources.Resources[*Lif

// GetAll returns all lifecycles. If none can be found or an error occurs, it
// returns an empty collection.
//
// Deprecated: use lifecycles.GetAll
func (s *LifecycleService) GetAll() ([]*Lifecycle, error) {
path, err := services.GetAllPath(s)
if err != nil {
Expand Down Expand Up @@ -222,3 +224,8 @@ func Update(client newclient.Client, lifecycle *Lifecycle) (*Lifecycle, error) {
func GetByID(client newclient.Client, spaceID string, ID string) (*Lifecycle, error) {
return newclient.GetByID[Lifecycle](client, template, spaceID, ID)
}

// GetAll returns all lifecycles. If an error occurs, it returns nil.
func GetAll(client newclient.Client, spaceID string) ([]*Lifecycle, error) {
return newclient.GetAll[Lifecycle](client, template, spaceID)
}
6 changes: 6 additions & 0 deletions pkg/machinepolicies/machine_policy_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ func Update(client newclient.Client, machinePolicy *MachinePolicy) (*MachinePoli
func DeleteByID(client newclient.Client, spaceID string, ID string) error {
return newclient.DeleteByID(client, template, spaceID, ID)
}

// GetAll returns all machine policies. If none can be found or an error
// occurs, it returns an empty collection.
func GetAll(client newclient.Client, spaceID string) ([]*MachinePolicy, error) {
return newclient.GetAll[MachinePolicy](client, template, spaceID)
}
7 changes: 7 additions & 0 deletions pkg/machines/machine_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ func (s *MachineService) GetByID(id string) (*DeploymentTarget, error) {

// GetAll returns all machines. If none can be found or an error occurs, it
// returns an empty collection.
//
// Deprecated: use machines.GetAll
func (s *MachineService) GetAll() ([]*DeploymentTarget, error) {
items := []*DeploymentTarget{}
path, err := services.GetAllPath(s)
Expand Down Expand Up @@ -215,3 +217,8 @@ func Update(client newclient.Client, deploymentTarget *DeploymentTarget) (*Deplo
func DeleteByID(client newclient.Client, spaceID string, ID string) error {
return newclient.DeleteByID(client, template, spaceID, ID)
}

// GetAll returns all machines. If an error occurs, it returns nil.
func GetAll(client newclient.Client, spaceID string) ([]*DeploymentTarget, error) {
return newclient.GetAll[DeploymentTarget](client, template, spaceID)
}
28 changes: 28 additions & 0 deletions pkg/newclient/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,31 @@ func GetByID[TResource any](client Client, template string, spaceID string, ID s

return res, nil
}

// GetAll returns all resources. If an error occurs, it returns nil.
func GetAll[TResource any](client Client, template string, spaceID string) ([]*TResource, error) {
path, err := client.URITemplateCache().Expand(template, map[string]any{
"spaceId": spaceID,
})
if err != nil {
return nil, err
}
spaces := make([]*TResource, 0)
res, err := Get[resources.Resources[*TResource]](client.HttpSession(), path)
if err != nil {
return nil, err
}
spaces = append(spaces, res.Items...)
for res.Links.PageNext != "" {
nextPagePath, err := client.URITemplateCache().Expand(res.Links.PageNext, map[string]any{})
if err != nil {
return nil, err
}
res, err = Get[resources.Resources[*TResource]](client.HttpSession(), nextPagePath)
if err != nil {
return nil, err
}
spaces = append(spaces, res.Items...)
}
return spaces, err
}
10 changes: 9 additions & 1 deletion pkg/projectgroups/project_group_service.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package projectgroups

import (
"strings"

"github.com/OctopusDeploy/go-octopusdeploy/v2/internal"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/constants"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
Expand All @@ -11,7 +13,6 @@ import (
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/services/api"
"github.com/OctopusDeploy/go-octopusdeploy/v2/uritemplates"
"github.com/dghubble/sling"
"strings"
)

// ProjectGroupService handles communication with ProjectGroup-related methods of the Octopus API.
Expand Down Expand Up @@ -74,6 +75,8 @@ func (s *ProjectGroupService) Get(projectGroupsQuery ProjectGroupsQuery) (*resou

// GetAll returns all project groups. If none can be found or an error occurs,
// it returns an empty collection.
//
// Deprecates: use projectgroups.GetAll
func (s *ProjectGroupService) GetAll() ([]*ProjectGroup, error) {
items := []*ProjectGroup{}
path, err := services.GetAllPath(s)
Expand Down Expand Up @@ -306,3 +309,8 @@ func DeleteByID(client newclient.Client, spaceID string, id string) error {

return newclient.Delete(client.HttpSession(), expandedUri)
}

// GetAll returns all project groups. If an error occurs, it returns nil.
func GetAll(client newclient.Client, spaceID string) ([]*ProjectGroup, error) {
return newclient.GetAll[ProjectGroup](client, projectGroupsTemplate, spaceID)
}
10 changes: 9 additions & 1 deletion pkg/projects/project_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package projects

import (
"fmt"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/newclient"
"net/http"
"net/url"
"strings"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/newclient"

"github.com/OctopusDeploy/go-octopusdeploy/v2/internal"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/channels"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/constants"
Expand Down Expand Up @@ -141,6 +142,8 @@ func (s *ProjectService) Get(projectsQuery ProjectsQuery) (*resources.Resources[

// GetAll returns all projects. If none can be found or an error occurs, it
// returns an empty collection.
//
// Deprecates: use projects.GetAll
func (s *ProjectService) GetAll() ([]*Project, error) {
items := []*Project{}
path, err := services.GetAllPath(s)
Expand Down Expand Up @@ -557,3 +560,8 @@ func DeleteByID(client newclient.Client, spaceID string, id string) error {

return newclient.Delete(client.HttpSession(), expandedUri)
}

// GetAll returns all projects. If an error occurs, it returns nil.
func GetAll(client newclient.Client, spaceID string) ([]*Project, error) {
return newclient.GetAll[Project](client, projectsTemplate, spaceID)
}
7 changes: 7 additions & 0 deletions pkg/tagsets/tag_set_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ func (s *TagSetService) GetByID(id string) (*TagSet, error) {

// GetAll returns all tag sets. If none can be found or an error occurs, it
// returns an empty collection.
//
// Deprecates: use tagsets.GetAll
func (s *TagSetService) GetAll() ([]*TagSet, error) {
items := []*TagSet{}
path, err := services.GetAllPath(s)
Expand Down Expand Up @@ -177,3 +179,8 @@ func Update(client newclient.Client, tagSet *TagSet) (*TagSet, error) {
func DeleteByID(client newclient.Client, spaceID string, ID string) error {
return newclient.DeleteByID(client, template, spaceID, ID)
}

// GetAll returns all tag sets. If an error occurs, it returns nil.
func GetAll(client newclient.Client, spaceID string) ([]*TagSet, error) {
return newclient.GetAll[TagSet](client, template, spaceID)
}
7 changes: 7 additions & 0 deletions pkg/tenants/tenant_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ func (s *TenantService) Get(tenantsQuery TenantsQuery) (*resources.Resources[*Te

// GetAll returns all tenants. If none can be found or an error occurs, it
// returns an empty collection.
//
// Deprecated: use tenants.GetAll
func (s *TenantService) GetAll() ([]*Tenant, error) {
items := []*Tenant{}
path, err := services.GetAllPath(s)
Expand Down Expand Up @@ -307,3 +309,8 @@ func GetByID(client newclient.Client, spaceID string, ID string) (*Tenant, error
func DeleteByID(client newclient.Client, spaceID string, ID string) error {
return newclient.DeleteByID(client, template, spaceID, ID)
}

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