Skip to content

feat: newclient support bulk update (#226) #227

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

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
13 changes: 13 additions & 0 deletions pkg/accounts/account_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ func (s *AccountService) GetByID(id string) (IAccount, error) {
}

// GetUsages lists the projects and deployments which are using an account.
//
// Deprecated: Use accounts.GetUsages
func (s *AccountService) GetUsages(account IAccount) (*AccountUsage, error) {
path := account.GetLinks()[constants.LinkUsages]
resp, err := api.ApiGet(s.GetClient(), new(AccountUsage), path)
Expand Down Expand Up @@ -197,6 +199,17 @@ func DeleteByID(client newclient.Client, spaceID string, id string) error {
return newclient.DeleteByID(client, template, spaceID, id)
}

// GetUsages lists the projects and deployments which are using an account.
func GetUsages(client newclient.Client, account IAccount) (*AccountUsage, error) {
path := account.GetLinks()[constants.LinkUsages]
res, err := newclient.Get[AccountUsage](client.HttpSession(), path)
if err != nil {
return nil, err
}

return res, nil
}

// 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)
Expand Down
94 changes: 94 additions & 0 deletions pkg/actiontemplates/action_template_service.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package actiontemplates

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

"github.com/OctopusDeploy/go-octopusdeploy/v2/internal"
Expand Down Expand Up @@ -39,6 +40,8 @@ func NewActionTemplateService(sling *sling.Sling, uriTemplate string, categories
}

// Add creates a new action template.
//
// Deprecated: Use actiontemplates.Add
func (s *ActionTemplateService) Add(actionTemplate *ActionTemplate) (*ActionTemplate, error) {
if IsNil(actionTemplate) {
return nil, internal.CreateInvalidParameterError(constants.OperationAdd, constants.ParameterActionTemplate)
Expand All @@ -64,6 +67,8 @@ func (s *ActionTemplateService) Add(actionTemplate *ActionTemplate) (*ActionTemp
// Get returns a collection of action templates based on the criteria defined
// by its input query parameter. If an error occurs, an empty collection is
// returned along with the associated error.
//
// Deprecated: Use actiontemplates.Get
func (s *ActionTemplateService) Get(actionTemplatesQuery Query) (*resources.Resources[*ActionTemplate], error) {
v, _ := query.Values(actionTemplatesQuery)
path := s.BasePath
Expand All @@ -82,6 +87,8 @@ func (s *ActionTemplateService) Get(actionTemplatesQuery Query) (*resources.Reso

// GetAll returns all action templates. If none can be found or an error
// occurs, it returns an empty collection.
//
// Deprecated: Use actiontemplates.GetAll
func (s *ActionTemplateService) GetAll() ([]*ActionTemplate, error) {
items := []*ActionTemplate{}
path, err := services.GetAllPath(s)
Expand All @@ -94,6 +101,8 @@ func (s *ActionTemplateService) GetAll() ([]*ActionTemplate, error) {
}

// GetCategories returns all action template categories.
//
// Deprecated: Use actiontemplates.GetCategories
func (s *ActionTemplateService) GetCategories() ([]ActionTemplateCategory, error) {
items := new([]ActionTemplateCategory)
if err := services.ValidateInternalState(s); err != nil {
Expand All @@ -109,6 +118,8 @@ func (s *ActionTemplateService) GetCategories() ([]ActionTemplateCategory, error

// GetByID returns the action template that matches the input ID. If one cannot
// be found, it returns nil and an error.
//
// Deprecated: Use actiontemplates.GetByID
func (s *ActionTemplateService) GetByID(id string) (*ActionTemplate, error) {
if internal.IsEmpty(id) {
return nil, internal.CreateInvalidParameterError(constants.OperationGetByID, constants.ParameterID)
Expand All @@ -129,6 +140,8 @@ func (s *ActionTemplateService) GetByID(id string) (*ActionTemplate, error) {

// Search lists all available action templates including built-in, custom, and
// community-contributed step templates.
//
// Deprecated: Use actiontemplates.Search
func (s *ActionTemplateService) Search(searchQuery string) ([]ActionTemplateSearch, error) {
searchResults := []ActionTemplateSearch{}
if err := services.ValidateInternalState(s); err != nil {
Expand All @@ -155,6 +168,8 @@ func (s *ActionTemplateService) Search(searchQuery string) ([]ActionTemplateSear
}

// Update modifies an ActionTemplate based on the one provided as input.
//
// Deprecated: Use actiontemplates.Update
func (s *ActionTemplateService) Update(actionTemplate *ActionTemplate) (*ActionTemplate, error) {
if actionTemplate == nil {
return nil, internal.CreateInvalidParameterError(constants.OperationUpdate, "actionTemplate")
Expand All @@ -172,3 +187,82 @@ func (s *ActionTemplateService) Update(actionTemplate *ActionTemplate) (*ActionT

return resp.(*ActionTemplate), nil
}

// ----- new -----
const (
template = "/api/{spaceId}/actiontemplates{/id}"
categoriesTemplate = "/api/{spaceId}/actiontemplates/categories"
searchTemplate = "/api/{spaceId}/actiontemplates/search"
)

// Add creates a new action template.
func Add(client newclient.Client, actionTemplate *ActionTemplate) (*ActionTemplate, error) {
if IsNil(actionTemplate) {
return nil, internal.CreateInvalidParameterError(constants.OperationAdd, constants.ParameterActionTemplate)
}

if err := actionTemplate.Validate(); err != nil {
return nil, internal.CreateValidationFailureError(constants.OperationAdd, err)
}

return newclient.Add[ActionTemplate](client, template, actionTemplate.SpaceID, actionTemplate)
}

// Get returns a collection of action templates based on the criteria defined
// by its input query parameter. If an error occurs, an empty collection is
// returned along with the associated error.
func Get(client newclient.Client, spaceID string, actionTemplatesQuery Query) (*resources.Resources[*ActionTemplate], error) {
return newclient.GetByQuery[ActionTemplate](client, template, spaceID, actionTemplatesQuery)
}

// GetAll returns all action templates. If none can be found or an error
// occurs, it returns an empty collection.
func GetAll(client newclient.Client, spaceID string) ([]*ActionTemplate, error) {
return newclient.GetAll[ActionTemplate](client, template, spaceID)
}

// GetCategories returns all action template categories.
func GetCategories(client newclient.Client, spaceID string) ([]*ActionTemplateCategory, error) {
return newclient.GetAll[ActionTemplateCategory](client, categoriesTemplate, spaceID)
}

// GetByID returns the action template that matches the input ID. If one cannot
// be found, it returns nil and an error.
func GetByID(client newclient.Client, spaceID string, id string) (*ActionTemplate, error) {
if internal.IsEmpty(id) {
return nil, internal.CreateInvalidParameterError(constants.OperationGetByID, constants.ParameterID)
}

return newclient.GetByID[ActionTemplate](client, template, spaceID, id)
}

// Search lists all available action templates including built-in, custom, and
// community-contributed step templates.
func Search(client newclient.Client, spaceID string, searchQuery string) (*[]ActionTemplateSearch, error) {
path, err := client.URITemplateCache().Expand(searchTemplate, map[string]any{
"spaceId": spaceID,
"type": searchQuery,
})
if err != nil {
return nil, err
}

if len(searchQuery) <= 0 {
path = strings.Split(path, "?")[0]
}

return newclient.Get[[]ActionTemplateSearch](client.HttpSession(), path)
}

// Update modifies an ActionTemplate based on the one provided as input.
func Update(client newclient.Client, actionTemplate *ActionTemplate) (*ActionTemplate, error) {
if actionTemplate == nil {
return nil, internal.CreateInvalidParameterError(constants.OperationUpdate, "actionTemplate")
}

return newclient.Update[ActionTemplate](client, template, actionTemplate.SpaceID, actionTemplate.ID, actionTemplate)
}

func DeleteByID(client newclient.Client, spaceID string, id string) error {
return newclient.DeleteByID(client, template, spaceID, id)
}
57 changes: 57 additions & 0 deletions pkg/artifacts/artifact_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package artifacts
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"
Expand All @@ -26,6 +27,8 @@ func NewArtifactService(sling *sling.Sling, uriTemplate string) *ArtifactService
}

// Add creates a new artifact.
//
// Deprecated: Use artifacts.Add
func (s *ArtifactService) Add(artifact *Artifact) (*Artifact, error) {
if IsNil(artifact) {
return nil, internal.CreateInvalidParameterError(constants.OperationAdd, constants.ParameterArtifact)
Expand All @@ -47,6 +50,8 @@ func (s *ArtifactService) Add(artifact *Artifact) (*Artifact, error) {
// Get returns a collection of artifacts based on the criteria defined by its
// input query parameter. If an error occurs, an empty collection is returned
// along with the associated error.
//
// Deprecated: Use artifacts.Get
func (s *ArtifactService) Get(artifactsQuery Query) (*resources.Resources[*Artifact], error) {
v, _ := query.Values(artifactsQuery)
path := s.BasePath
Expand All @@ -65,6 +70,8 @@ func (s *ArtifactService) Get(artifactsQuery Query) (*resources.Resources[*Artif

// GetAll returns all artifacts. If none can be found or an error occurs, it
// returns an empty collection.
//
// Deprecated: Use artifacts.GetAll
func (s *ArtifactService) GetAll() ([]*Artifact, error) {
path, err := services.GetPath(s)
if err != nil {
Expand All @@ -76,6 +83,8 @@ func (s *ArtifactService) GetAll() ([]*Artifact, error) {

// GetByID returns the artifact that matches the input ID. If one cannot be
// found, it returns nil and an error.
//
// Deprecated: Use artifacts.GetByID
func (s *ArtifactService) GetByID(id string) (*Artifact, error) {
if internal.IsEmpty(id) {
return nil, internal.CreateInvalidParameterError(constants.OperationGetByID, constants.ParameterID)
Expand All @@ -95,6 +104,8 @@ func (s *ArtifactService) GetByID(id string) (*Artifact, error) {
}

// Update modifies an Artifact based on the one provided as input.
//
// Deprecated: Use artifacts.Update
func (s *ArtifactService) Update(artifact Artifact) (*Artifact, error) {
path, err := services.GetUpdatePath(s, &artifact)
if err != nil {
Expand All @@ -108,3 +119,49 @@ func (s *ArtifactService) Update(artifact Artifact) (*Artifact, error) {

return resp.(*Artifact), nil
}

// ----- new -----

const template = "/api/{spaceId}/artifacts{/id}"

// Add creates a new artifact.
func Add(client newclient.Client, artifact *Artifact) (*Artifact, error) {
if IsNil(artifact) {
return nil, internal.CreateInvalidParameterError(constants.OperationAdd, constants.ParameterArtifact)
}

resp, err := newclient.Add[Artifact](client, template, artifact.SpaceID, artifact)
if err != nil {
return nil, err
}

return resp, nil
}

// Get returns a collection of artifacts based on the criteria defined by its
// input query parameter. If an error occurs, an empty collection is returned
// along with the associated error.
func Get(client newclient.Client, spaceID string, artifactsQuery Query) (*resources.Resources[*Artifact], error) {
return newclient.GetByQuery[Artifact](client, template, spaceID, artifactsQuery)
}

// GetAll returns all artifacts. If none can be found or an error occurs, it
// returns an empty collection.
func GetAll(client newclient.Client, spaceID string) ([]*Artifact, error) {
return newclient.GetAll[Artifact](client, template, spaceID)
}

// GetByID returns the artifact that matches the input ID. If one cannot be
// found, it returns nil and an error.
func GetByID(client newclient.Client, spaceID string, id string) (*Artifact, error) {
if internal.IsEmpty(id) {
return nil, internal.CreateInvalidParameterError(constants.OperationGetByID, constants.ParameterID)
}

return newclient.GetByID[Artifact](client, template, spaceID, id)
}

// Update modifies an Artifact based on the one provided as input.
func Update(client newclient.Client, artifact Artifact) (*Artifact, error) {
return newclient.Update[Artifact](client, template, artifact.SpaceID, artifact.ID, artifact)
}
9 changes: 9 additions & 0 deletions pkg/authentication/authentication_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package authentication

import (
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/constants"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/newclient"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/services"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/services/api"
"github.com/dghubble/sling"
Expand All @@ -22,6 +23,7 @@ func NewAuthenticationService(sling *sling.Sling, uriTemplate string, loginIniti
}
}

// Deprecated: Use authentication.Get
func (s *AuthenticationService) Get() (*Authentication, error) {
path, err := services.GetPath(s)
if err != nil {
Expand All @@ -35,3 +37,10 @@ func (s *AuthenticationService) Get() (*Authentication, error) {

return resp.(*Authentication), nil
}

// ----- new -----
const template = "/api/authentication"

func Get(client newclient.Client) (*Authentication, error) {
return newclient.Get[Authentication](client.HttpSession(), template)
}
Loading