diff --git a/go.mod b/go.mod index 6691a3093..0e35bc5e4 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,7 @@ module github.com/OctopusDeploy/terraform-provider-octopusdeploy require ( - github.com/OctopusDeploy/go-octopusdeploy v1.3.0 + github.com/OctopusDeploy/go-octopusdeploy v1.4.0 github.com/apparentlymart/go-cidr v1.0.0 // indirect github.com/armon/go-radix v1.0.0 // indirect github.com/aws/aws-sdk-go v1.15.53 // indirect diff --git a/go.sum b/go.sum index 7e678aa1f..2adb38233 100644 --- a/go.sum +++ b/go.sum @@ -10,6 +10,8 @@ github.com/OctopusDeploy/go-octopusdeploy v1.2.1 h1:wfyln0AKOg74dBJM6V2hKHxskXQz github.com/OctopusDeploy/go-octopusdeploy v1.2.1/go.mod h1:WyBvcyhFPMULbZwFFWOmt6/irqrfZ/WqCy7ufa8/CGE= github.com/OctopusDeploy/go-octopusdeploy v1.3.0 h1:ZekYly62VzsHx7PHSSPI8bOKMNNz1DhlonIeWdPobO8= github.com/OctopusDeploy/go-octopusdeploy v1.3.0/go.mod h1:WyBvcyhFPMULbZwFFWOmt6/irqrfZ/WqCy7ufa8/CGE= +github.com/OctopusDeploy/go-octopusdeploy v1.4.0 h1:uTBRPoGcS3tN40LKQb70xq+m/hpKX1fExfLhGAAxHDk= +github.com/OctopusDeploy/go-octopusdeploy v1.4.0/go.mod h1:WyBvcyhFPMULbZwFFWOmt6/irqrfZ/WqCy7ufa8/CGE= github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8= github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= github.com/apparentlymart/go-cidr v1.0.0 h1:lGDvXx8Lv9QHjrAVP7jyzleG4F9+FkRhJcEsDFxeb8w= diff --git a/vendor/github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy/account.go b/vendor/github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy/account.go index bc8cbd743..72a358fe3 100644 --- a/vendor/github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy/account.go +++ b/vendor/github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy/account.go @@ -24,6 +24,7 @@ type Accounts struct { type Account struct { ID string `json:"Id"` + EnvironmentIDs []string `json:"EnvironmentIds"` Name string `json:"Name"` AccountType string `json:"AccountType"` SubscriptionNumber string `json:"SubscriptionNumber"` @@ -32,6 +33,7 @@ type Account struct { Password SensitiveValue `json:"Password"` TenantTags []string `json:"TenantTags,omitempty"` TenantedDeploymentParticipation string `json:"TenantedDeploymentParticipation"` + Token SensitiveValue `json:"Token,omitempty"` } func (t *Account) Validate() error { diff --git a/vendor/github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy/channels.go b/vendor/github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy/channels.go new file mode 100644 index 000000000..2a512ffca --- /dev/null +++ b/vendor/github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy/channels.go @@ -0,0 +1,160 @@ +package octopusdeploy + +import ( + "fmt" + + "github.com/dghubble/sling" + "gopkg.in/go-playground/validator.v9" +) + +type ChannelService struct { + sling *sling.Sling +} + +func NewChannelService(sling *sling.Sling) *ChannelService { + return &ChannelService{ + sling: sling, + } +} + +type Channels struct { + Items []Channel `json:"Items"` + PagedResults +} + +type Channel struct { + Description string `json:"Description"` + ID string `json:"Id,omitempty"` + IsDefault bool `json:"IsDefault"` + LifecycleID string `json:"LifecycleId"` + Name string `json:"Name"` + ProjectID string `json:"ProjectId"` + Rules []ChannelRule `json:"Rules,omitempty"` + TenantTags []string `json:"TenantedDeploymentMode,omitempty"` +} + +type ChannelRule struct { + // name of Package step(s) this rule applies to + Actions []string `json:"Actions,omitempty"` + + // Id + ID string `json:"Id,omitempty"` + + // Pre-release tag + Tag string `json:"Tag,omitempty"` + + //Use the NuGet or Maven versioning syntax (depending on the feed type) + //to specify the range of versions to include + VersionRange string `json:"VersionRange,omitempty"` +} + +func (d *Channels) Validate() error { + validate := validator.New() + + err := validate.Struct(d) + + if err != nil { + return err + } + + return nil +} + +func (s *ChannelService) Get(channelID string) (*Channel, error) { + path := fmt.Sprintf("channels/%s", channelID) + resp, err := apiGet(s.sling, new(Channel), path) + + if err != nil { + return nil, err + } + + return resp.(*Channel), nil +} + +func (s *ChannelService) GetAll() (*[]Channel, error) { + var ch []Channel + + path := "channel" + + loadNextPage := true + + for loadNextPage { + resp, err := apiGet(s.sling, new(Channels), path) + + if err != nil { + return nil, err + } + + r := resp.(*Channels) + + for _, item := range r.Items { + ch = append(ch, item) + } + + path, loadNextPage = LoadNextPage(r.PagedResults) + } + + return &ch, nil +} + +// Add adds a new channel +func (s *ChannelService) Add(channel *Channel) (*Channel, error) { + err := ValidateChannelValues(channel) + if err != nil { + return nil, err + } + + resp, err := apiAdd(s.sling, channel, new(Channel), "channels") + + if err != nil { + return nil, err + } + + return resp.(*Channel), nil +} + +// ValidateChannelValues checks the values of a Channel object to see if they are suitable for +// sending to Octopus Deploy. Used when adding or updating channels. +func ValidateChannelValues(Channel *Channel) error { + return ValidateMultipleProperties([]error{ + ValidateRequiredPropertyValue("Name", Channel.Name), + ValidateRequiredPropertyValue("ProjectID", Channel.ProjectID), + }) +} + +func NewChannel(name, description, projectID string) *Channel { + return &Channel{ + Name: name, + ProjectID: projectID, + Description: description, + } +} + +// Delete deletes an existing channel in Octopus Deploy +func (s *ChannelService) Delete(channelid string) error { + path := fmt.Sprintf("channels/%s", channelid) + err := apiDelete(s.sling, path) + + if err != nil { + return err + } + + return nil +} + +// Update updates an existing channel in Octopus Deploy +func (s *ChannelService) Update(channel *Channel) (*Channel, error) { + err := ValidateChannelValues(channel) + if err != nil { + return nil, err + } + + path := fmt.Sprintf("channels/%s", channel.ID) + resp, err := apiUpdate(s.sling, channel, new(Channel), path) + + if err != nil { + return nil, err + } + + return resp.(*Channel), nil +} diff --git a/vendor/github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy/machines.go b/vendor/github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy/machines.go index 800159d7e..e3a673b8f 100644 --- a/vendor/github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy/machines.go +++ b/vendor/github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy/machines.go @@ -42,15 +42,27 @@ type Machine struct { LastModifiedBy *string `json:"LastModifiedBy,omitempty"` } +type MachineEndpointAuthentication struct { + AccountID string `json:"AccountId"` + ClientCertificate string `json:"ClientCertificate"` + AuthenticationType string `json:"AuthenticationType"` +} + type MachineEndpoint struct { - ID string `json:"Id"` - CommunicationStyle string `json:"CommunicationStyle"` - ProxyID *string `json:"ProxyId"` - Thumbprint string `json:"Thumbprint"` - TentacleVersionDetails MachineTentacleVersionDetails `json:"TentacleVersionDetails"` - LastModifiedOn *string `json:"LastModifiedOn,omitempty"` - LastModifiedBy *string `json:"LastModifiedBy,omitempty"` - URI string `json:"Uri"` //This is not in the spec doc, but it shows up and needs to be kept in sync + ID string `json:"Id"` + CommunicationStyle string `json:"CommunicationStyle"` + ProxyID *string `json:"ProxyId"` + Thumbprint string `json:"Thumbprint"` + TentacleVersionDetails MachineTentacleVersionDetails `json:"TentacleVersionDetails"` + LastModifiedOn *string `json:"LastModifiedOn,omitempty"` + LastModifiedBy *string `json:"LastModifiedBy,omitempty"` + URI string `json:"Uri"` // This is not in the spec doc, but it shows up and needs to be kept in sync + ClusterCertificate string `json:"ClusterCertificate"` // Kubernetes (not in spec doc) + ClusterURL string `json:"ClusterUrl"` // Kubernetes (not in spec doc) + Namespace string `json:"Namespace"` // Kubernetes (not in spec doc) + SkipTLSVerification string `json:"SkipTlsVerification"` // Kubernetes (not in spec doc) + DefaultWorkerPoolID string `json:"DefaultWorkerPoolId"` + Authentication *MachineEndpointAuthentication `json:"Authentication"` } type MachineTentacleVersionDetails struct { @@ -130,6 +142,24 @@ func (s *MachineService) GetAll() (*[]Machine, error) { return &p, nil } +// GetByName gets an existing machine by its name in Octopus Deploy +func (s *MachineService) GetByName(machineName string) (*Machine, error) { + var found Machine + machines, err := s.GetAll() + + if err != nil { + return nil, err + } + + for _, machine := range *machines { + if machine.Name == machineName { + return &machine, nil + } + } + + return &found, fmt.Errorf("no machine found with name %s", machineName) +} + // Add creates a new machine in Octopus Deploy func (s *MachineService) Add(machine *Machine) (*Machine, error) { err := ValidateMachineValues(machine) diff --git a/vendor/github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy/octopusdeploy.go b/vendor/github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy/octopusdeploy.go index 82370295c..91d3ed36a 100644 --- a/vendor/github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy/octopusdeploy.go +++ b/vendor/github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy/octopusdeploy.go @@ -29,6 +29,7 @@ type Client struct { Interruption *InterruptionsService TagSet *TagSetService Space *SpaceService + Channel *ChannelService } // NewClient returns a new Client. @@ -55,6 +56,7 @@ func NewClient(httpClient *http.Client, octopusURL, octopusAPIKey string) *Clien Interruption: NewInterruptionService(base.New()), TagSet: NewTagSetService(base.New()), Space: NewSpaceService(base.New()), + Channel: NewChannelService(base.New()), } } @@ -79,6 +81,7 @@ func ForSpace(httpClient *http.Client, octopusURL, octopusAPIKey string, space * Lifecycle: NewLifecycleService(base.New()), LibraryVariableSet: NewLibraryVariableSetService(base.New()), TagSet: NewTagSetService(base.New()), + Channel: NewChannelService(base.New()), } } diff --git a/vendor/modules.txt b/vendor/modules.txt index 85b01c1b6..639179401 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,4 +1,4 @@ -# github.com/OctopusDeploy/go-octopusdeploy v1.3.0 +# github.com/OctopusDeploy/go-octopusdeploy v1.4.0 github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy # github.com/agext/levenshtein v1.2.1 github.com/agext/levenshtein