-
Notifications
You must be signed in to change notification settings - Fork 25
/
library_variable_set_service.go
132 lines (109 loc) · 4.3 KB
/
library_variable_set_service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package variables
import (
"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"
)
type LibraryVariableSetService struct {
services.CanDeleteService
}
func NewLibraryVariableSetService(sling *sling.Sling, uriTemplate string) *LibraryVariableSetService {
return &LibraryVariableSetService{
CanDeleteService: services.CanDeleteService{
Service: services.NewService(constants.ServiceLibraryVariableSetService, sling, uriTemplate),
},
}
}
// Add creates a new library variable set.
//
// Deprecated: Use libraryvariablesets.Add
func (s *LibraryVariableSetService) Add(libraryVariableSet *LibraryVariableSet) (*LibraryVariableSet, error) {
if IsNil(libraryVariableSet) {
return nil, internal.CreateInvalidParameterError(constants.OperationAdd, constants.ParameterLibraryVariableSet)
}
path, err := services.GetAddPath(s, libraryVariableSet)
if err != nil {
return nil, err
}
resp, err := services.ApiAdd(s.GetClient(), libraryVariableSet, new(LibraryVariableSet), path)
if err != nil {
return nil, err
}
return resp.(*LibraryVariableSet), nil
}
// Get returns a collection of library variable sets 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 libraryvariablesets.Get
func (s *LibraryVariableSetService) Get(libraryVariablesQuery LibraryVariablesQuery) (*resources.Resources[*LibraryVariableSet], error) {
path, err := s.GetURITemplate().Expand(libraryVariablesQuery)
if err != nil {
return &resources.Resources[*LibraryVariableSet]{}, err
}
response, err := api.ApiGet(s.GetClient(), new(resources.Resources[*LibraryVariableSet]), path)
if err != nil {
return &resources.Resources[*LibraryVariableSet]{}, err
}
return response.(*resources.Resources[*LibraryVariableSet]), nil
}
// GetAll returns all library variable sets. If none can be found or an error
// occurs, it returns an empty collection.
func (s *LibraryVariableSetService) GetAll() ([]*LibraryVariableSet, error) {
items := []*LibraryVariableSet{}
path, err := services.GetAllPath(s)
if err != nil {
return items, err
}
_, err = api.ApiGet(s.GetClient(), &items, path)
return items, err
}
// GetByID returns the library variable set that matches the input ID. If one
// cannot be found, it returns nil and an error.
//
// Deprecated: Use libraryvariablesets.GetByID
func (s *LibraryVariableSetService) GetByID(id string) (*LibraryVariableSet, error) {
if internal.IsEmpty(id) {
return nil, internal.CreateInvalidParameterError(constants.OperationGetByID, constants.ParameterID)
}
path, err := services.GetByIDPath(s, id)
if err != nil {
return nil, err
}
resp, err := api.ApiGet(s.GetClient(), new(LibraryVariableSet), path)
if err != nil {
return nil, err
}
return resp.(*LibraryVariableSet), nil
}
// GetByPartialName performs a lookup and returns a list of library variable sets with a matching partial name.
func (s *LibraryVariableSetService) GetByPartialName(partialName string) ([]*LibraryVariableSet, error) {
if internal.IsEmpty(partialName) {
return []*LibraryVariableSet{}, internal.CreateInvalidParameterError(constants.OperationGetByPartialName, constants.ParameterPartialName)
}
path, err := services.GetByPartialNamePath(s, partialName)
if err != nil {
return []*LibraryVariableSet{}, err
}
return services.GetPagedResponse[LibraryVariableSet](s, path)
}
// Update modifies a library variable set based on the one provided as input.
//
// Deprecated: Use libraryvariablesets.Update
func (s *LibraryVariableSetService) Update(libraryVariableSet *LibraryVariableSet) (*LibraryVariableSet, error) {
if libraryVariableSet == nil {
return nil, internal.CreateInvalidParameterError(constants.OperationUpdate, constants.ParameterLibraryVariableSet)
}
path, err := services.GetUpdatePath(s, libraryVariableSet)
if err != nil {
return nil, err
}
resp, err := services.ApiUpdate(s.GetClient(), libraryVariableSet, new(LibraryVariableSet), path)
if err != nil {
return nil, err
}
return resp.(*LibraryVariableSet), nil
}