gomod: update `go-tfe`

This commit is contained in:
Sander van Harmelen 2019-04-08 11:13:14 +02:00
parent ffcf9fc51b
commit 8a430113f6
14 changed files with 417 additions and 70 deletions

8
go.mod
View File

@ -52,11 +52,11 @@ require (
github.com/hashicorp/go-msgpack v0.0.0-20150518234257-fa3f63826f7c // indirect
github.com/hashicorp/go-multierror v1.0.0
github.com/hashicorp/go-plugin v0.0.0-20190322172744-52e1c4730856
github.com/hashicorp/go-retryablehttp v0.5.1
github.com/hashicorp/go-retryablehttp v0.5.2
github.com/hashicorp/go-rootcerts v1.0.0
github.com/hashicorp/go-sockaddr v0.0.0-20180320115054-6d291a969b86 // indirect
github.com/hashicorp/go-tfe v0.3.11
github.com/hashicorp/go-uuid v1.0.0
github.com/hashicorp/go-tfe v0.3.14
github.com/hashicorp/go-uuid v1.0.1
github.com/hashicorp/go-version v1.1.0
github.com/hashicorp/golang-lru v0.5.0 // indirect
github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f
@ -117,4 +117,6 @@ require (
google.golang.org/api v0.1.0
google.golang.org/grpc v1.18.0
gopkg.in/vmihailenco/msgpack.v2 v2.9.1 // indirect
labix.org/v2/mgo v0.0.0-20140701140051-000000000287 // indirect
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 // indirect
)

22
go.sum
View File

@ -179,20 +179,22 @@ github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uP
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
github.com/hashicorp/go-plugin v0.0.0-20190322172744-52e1c4730856 h1:FHiCaU46W1WoqApsaGGIKbNkhQ6v71hJrOf2INQMLUo=
github.com/hashicorp/go-plugin v0.0.0-20190322172744-52e1c4730856/go.mod h1:++UyYGoz3o5w9ZzAdZxtQKrWWP+iqPBn3cQptSMzBuY=
github.com/hashicorp/go-retryablehttp v0.5.1 h1:Vsx5XKPqPs3M6sM4U4GWyUqFS8aBiL9U5gkgvpkg4SE=
github.com/hashicorp/go-retryablehttp v0.5.1/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
github.com/hashicorp/go-retryablehttp v0.5.2 h1:AoISa4P4IsW0/m4T6St8Yw38gTl5GtBAgfkhYh1xAz4=
github.com/hashicorp/go-retryablehttp v0.5.2/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
github.com/hashicorp/go-rootcerts v1.0.0 h1:Rqb66Oo1X/eSV1x66xbDccZjhJigjg0+e82kpwzSwCI=
github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
github.com/hashicorp/go-safetemp v1.0.0 h1:2HR189eFNrjHQyENnQMMpCiBAsRxzbTMIgBhEyExpmo=
github.com/hashicorp/go-safetemp v1.0.0/go.mod h1:oaerMy3BhqiTbVye6QuFhFtIceqFoDHxNAB65b+Rj1I=
github.com/hashicorp/go-slug v0.2.0 h1:MVdZAkTmDsUi1AT+3NQDsn8n3ssnVSIHwiM6RcUHvE8=
github.com/hashicorp/go-slug v0.2.0/go.mod h1:+zDycQOzGqOqMW7Kn2fp9vz/NtqpMLQlgb9JUF+0km4=
github.com/hashicorp/go-slug v0.3.0 h1:L0c+AvH/J64iMNF4VqRaRku2DMTEuHioPVS7kMjWIU8=
github.com/hashicorp/go-slug v0.3.0/go.mod h1:I5tq5Lv0E2xcNXNkmx7BSfzi1PsJ2cNjs3cC3LwyhK8=
github.com/hashicorp/go-sockaddr v0.0.0-20180320115054-6d291a969b86 h1:7YOlAIO2YWnJZkQp7B5eFykaIY7C9JndqAFQyVV5BhM=
github.com/hashicorp/go-sockaddr v0.0.0-20180320115054-6d291a969b86/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
github.com/hashicorp/go-tfe v0.3.11 h1:PHw0f1XeriVkqBikhXgZm/t65GR/fEH1iUl/d/9qKbU=
github.com/hashicorp/go-tfe v0.3.11/go.mod h1:LHLchj07PCYgQqcyE5Sz+g4zrMNW+nALKbiSNTZedEs=
github.com/hashicorp/go-tfe v0.3.14 h1:1eWmq4RAICGufydNUWu7ahb0gtq24pN9jatD2FkdxdE=
github.com/hashicorp/go-tfe v0.3.14/go.mod h1:SuPHR+OcxvzBZNye7nGPfwZTEyd3rWPfLVbCgyZPezM=
github.com/hashicorp/go-uuid v1.0.0 h1:RS8zrF7PhGwyNPOtxSClXXj9HA8feRnJzgnI1RJCSnM=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1BE=
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-version v1.1.0 h1:bPIoEKD27tNdebFGGxxYwcL4nepeY4j1QP23PFRGzg0=
github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCOH9wdo=
@ -200,8 +202,6 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f h1:UdxlrJz4JOnY8W+DbLISwf2B8WXEolNRA8BGCwI9jws=
github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f/go.mod h1:oZtUIOe8dh44I2q6ScRibXws4Ajl+d+nod3AaR9vL5w=
github.com/hashicorp/hcl2 v0.0.0-20181208003705-670926858200/go.mod h1:ShfpTh661oAaxo7VcNxg0zcZW6jvMa7Moy2oFx7e5dE=
github.com/hashicorp/hcl2 v0.0.0-20190327223817-3fb4ed0d9260 h1:C3vhYEXk8ihs+Xvq093axRyYhfLERrZ6Uv5tfRw9yvw=
github.com/hashicorp/hcl2 v0.0.0-20190327223817-3fb4ed0d9260/go.mod h1:HtEzazM5AZ9fviNEof8QZB4T1Vz9UhHrGhnMPzl//Ek=
github.com/hashicorp/hcl2 v0.0.0-20190402200843-8b450a7d58f9 h1:zCITwiA0cog6aYr/a/McDHKtgsEpYxXvTIgugv5iu8o=
github.com/hashicorp/hcl2 v0.0.0-20190402200843-8b450a7d58f9/go.mod h1:HtEzazM5AZ9fviNEof8QZB4T1Vz9UhHrGhnMPzl//Ek=
github.com/hashicorp/hil v0.0.0-20190212112733-ab17b08d6590 h1:2yzhWGdgQUWZUCNK+AoO35V+HTsgEmcM4J9IkArh7PI=
@ -471,6 +471,8 @@ golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c h1:fqgJT0MGcGpPgpWU7VRdRjuArfcOvC4AoJmILihzhDg=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZenJ2O330aBsf7JfSUXmQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181030000716-a0a13e073c7b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
google.golang.org/api v0.0.0-20180910000450-7ca32eb868bf/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=
@ -512,5 +514,9 @@ grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJd
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
howett.net/plist v0.0.0-20181124034731-591f970eefbb/go.mod h1:vMygbs4qMhSZSc4lCUl2OEE+rDiIIJAIdR4m7MiMcm0=
labix.org/v2/mgo v0.0.0-20140701140051-000000000287 h1:L0cnkNl4TfAXzvdrqsYEmxOHOCv2p5I3taaReO8BWFs=
labix.org/v2/mgo v0.0.0-20140701140051-000000000287/go.mod h1:Lg7AYkt1uXJoR9oeSZ3W/8IXLdvOfIITgZnommstyz4=
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54=
launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM=
sourcegraph.com/sourcegraph/go-diff v0.5.0/go.mod h1:kuch7UrkMzY0X+p9CRK03kfuPQ2zzQcaEFbx8wA8rck=
sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4/go.mod h1:ketZ/q3QxT9HOBeFhu6RdvsftgpsbFHBF5Cas6cDKZ0=

View File

@ -36,7 +36,7 @@ import (
"strings"
"time"
"github.com/hashicorp/go-cleanhttp"
cleanhttp "github.com/hashicorp/go-cleanhttp"
)
var (
@ -81,6 +81,28 @@ func (r *Request) WithContext(ctx context.Context) *Request {
return r
}
// BodyBytes allows accessing the request body. It is an analogue to
// http.Request's Body variable, but it returns a copy of the underlying data
// rather than consuming it.
//
// This function is not thread-safe; do not call it at the same time as another
// call, or at the same time this request is being used with Client.Do.
func (r *Request) BodyBytes() ([]byte, error) {
if r.body == nil {
return nil, nil
}
body, err := r.body()
if err != nil {
return nil, err
}
buf := new(bytes.Buffer)
_, err = buf.ReadFrom(body)
if err != nil {
return nil, err
}
return buf.Bytes(), nil
}
// NewRequest creates a new wrapped request.
func NewRequest(method, url string, rawBody interface{}) (*Request, error) {
var err error

View File

@ -1 +1,3 @@
module github.com/hashicorp/go-slug
go 1.12

View File

@ -75,11 +75,20 @@ func packWalkFn(root, src, dst string, tarW *tar.Writer, meta *Meta, dereference
return nil
}
// Skip the .terraform directory, except for the modules subdirectory.
if strings.Contains(subpath, ".terraform") && info.Name() != ".terraform" {
if !strings.Contains(subpath, filepath.Clean(".terraform/modules")) {
return filepath.SkipDir
// Ignore the .terraform directory itself.
if info.IsDir() && info.Name() == ".terraform" {
return nil
}
// Ignore any files in the .terraform directory.
if !info.IsDir() && filepath.Dir(subpath) == ".terraform" {
return nil
}
// Skip .terraform subdirectories, except for the modules subdirectory.
if strings.HasPrefix(subpath, ".terraform"+string(filepath.Separator)) &&
!strings.HasPrefix(subpath, filepath.Clean(".terraform/modules")) {
return filepath.SkipDir
}
// Get the relative path from the initial root directory.

View File

@ -1,12 +1,13 @@
module github.com/hashicorp/go-tfe
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/go-querystring v1.0.0
github.com/hashicorp/go-cleanhttp v0.5.0
github.com/hashicorp/go-retryablehttp v0.5.1
github.com/hashicorp/go-slug v0.2.0
github.com/hashicorp/go-uuid v1.0.0
github.com/hashicorp/go-retryablehttp v0.5.2
github.com/hashicorp/go-slug v0.3.0
github.com/hashicorp/go-uuid v1.0.1
github.com/stretchr/testify v1.3.0
github.com/svanharmelen/jsonapi v0.0.0-20180618144545-0c0828c3f16d
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4
)

View File

@ -1,15 +1,17 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/hashicorp/go-cleanhttp v0.5.0 h1:wvCrVc9TjDls6+YGAF2hAifE1E5U1+b4tH6KdvN3Gig=
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-retryablehttp v0.5.1 h1:Vsx5XKPqPs3M6sM4U4GWyUqFS8aBiL9U5gkgvpkg4SE=
github.com/hashicorp/go-retryablehttp v0.5.1/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
github.com/hashicorp/go-slug v0.2.0 h1:MVdZAkTmDsUi1AT+3NQDsn8n3ssnVSIHwiM6RcUHvE8=
github.com/hashicorp/go-slug v0.2.0/go.mod h1:+zDycQOzGqOqMW7Kn2fp9vz/NtqpMLQlgb9JUF+0km4=
github.com/hashicorp/go-uuid v1.0.0 h1:RS8zrF7PhGwyNPOtxSClXXj9HA8feRnJzgnI1RJCSnM=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-retryablehttp v0.5.2 h1:AoISa4P4IsW0/m4T6St8Yw38gTl5GtBAgfkhYh1xAz4=
github.com/hashicorp/go-retryablehttp v0.5.2/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
github.com/hashicorp/go-slug v0.3.0 h1:L0c+AvH/J64iMNF4VqRaRku2DMTEuHioPVS7kMjWIU8=
github.com/hashicorp/go-slug v0.3.0/go.mod h1:I5tq5Lv0E2xcNXNkmx7BSfzi1PsJ2cNjs3cC3LwyhK8=
github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1BE=
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@ -17,5 +19,5 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/svanharmelen/jsonapi v0.0.0-20180618144545-0c0828c3f16d h1:Z4EH+5EffvBEhh37F0C0DnpklTMh00JOkjW5zK3ofBI=
github.com/svanharmelen/jsonapi v0.0.0-20180618144545-0c0828c3f16d/go.mod h1:BSTlc8jOjh0niykqEGVXOLXdi9o0r0kR8tCYiMvjFgw=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c h1:fqgJT0MGcGpPgpWU7VRdRjuArfcOvC4AoJmILihzhDg=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZenJ2O330aBsf7JfSUXmQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=

View File

@ -0,0 +1,294 @@
package tfe
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"time"
)
// Compile-time proof of interface implementation.
var _ NotificationConfigurations = (*notificationConfigurations)(nil)
// NotificationConfigurations describes all the Notification Configuration
// related methods that the Terraform Enterprise API supports.
//
// TFE API docs:
// https://www.terraform.io/docs/enterprise/api/notification-configurations.html
type NotificationConfigurations interface {
// List all the notification configurations within a workspace.
List(ctx context.Context, workspaceID string, options NotificationConfigurationListOptions) (*NotificationConfigurationList, error)
// Create a new notification configuration with the given options.
Create(ctx context.Context, workspaceID string, options NotificationConfigurationCreateOptions) (*NotificationConfiguration, error)
// Read a notification configuration by its ID.
Read(ctx context.Context, notificationConfigurationID string) (*NotificationConfiguration, error)
// Update an existing notification configuration.
Update(ctx context.Context, notificationConfigurationID string, options NotificationConfigurationUpdateOptions) (*NotificationConfiguration, error)
// Delete a notification configuration by its ID.
Delete(ctx context.Context, notificationConfigurationID string) error
// Verify a notification configuration by its ID.
Verify(ctx context.Context, notificationConfigurationID string) (*NotificationConfiguration, error)
}
// notificationConfigurations implements NotificationConfigurations.
type notificationConfigurations struct {
client *Client
}
// List of available notification triggers.
const (
NotificationTriggerCreated string = "run:created"
NotificationTriggerPlanning string = "run:planning"
NotificationTriggerNeedsAttention string = "run:needs_attention"
NotificationTriggerApplying string = "run:applying"
NotificationTriggerCompleted string = "run:completed"
NotificationTriggerErrored string = "run:errored"
)
// NotificationDestinationType represents the destination type of the
// notification configuration.
type NotificationDestinationType string
// List of available notification destination types.
const (
NotificationDestinationTypeSlack NotificationDestinationType = "slack"
NotificationDestinationTypeGeneric NotificationDestinationType = "generic"
)
// NotificationConfigurationList represents a list of Notification
// Configurations.
type NotificationConfigurationList struct {
*Pagination
Items []*NotificationConfiguration
}
// NotificationConfiguration represents a Notification Configuration.
type NotificationConfiguration struct {
ID string `jsonapi:"primary,notification-configurations"`
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
DeliveryResponses []*DeliveryResponse `jsonapi:"attr,delivery-responses"`
DestinationType NotificationDestinationType `jsonapi:"attr,destination-type"`
Enabled bool `jsonapi:"attr,enabled"`
Name string `jsonapi:"attr,name"`
Token string `jsonapi:"attr,token"`
Triggers []string `jsonapi:"attr,triggers"`
UpdatedAt time.Time `jsonapi:"attr,updated-at,iso8601"`
URL string `jsonapi:"attr,url"`
}
// DeliveryResponse represents a notification configuration delivery response.
type DeliveryResponse struct {
Body string `json:"body"`
Code int `json:"code"`
Headers http.Header `json:"headers"`
SentAt time.Time `json:"sent-at,iso8601"`
Successful bool `json:"successful"`
URL string `json:"url"`
}
// NotificationConfigurationListOptions represents the options for listing
// notification configurations.
type NotificationConfigurationListOptions struct {
ListOptions
}
// List all the notification configurations associated with a workspace.
func (s *notificationConfigurations) List(ctx context.Context, workspaceID string, options NotificationConfigurationListOptions) (*NotificationConfigurationList, error) {
if !validStringID(&workspaceID) {
return nil, errors.New("invalid value for workspace ID")
}
u := fmt.Sprintf("workspaces/%s/notification-configurations", url.QueryEscape(workspaceID))
req, err := s.client.newRequest("GET", u, options)
if err != nil {
return nil, err
}
ncl := &NotificationConfigurationList{}
err = s.client.do(ctx, req, ncl)
if err != nil {
return nil, err
}
return ncl, nil
}
// NotificationConfigurationCreateOptions represents the options for
// creating a new notification configuration.
type NotificationConfigurationCreateOptions struct {
// For internal use only!
ID string `jsonapi:"primary,notification-configurations"`
// The destination type of the notification configuration
DestinationType *NotificationDestinationType `jsonapi:"attr,destination-type"`
// Whether the notification configuration should be enabled or not
Enabled *bool `jsonapi:"attr,enabled"`
// The name of the notification configuration
Name *string `jsonapi:"attr,name"`
// The token of the notification configuration
Token *string `jsonapi:"attr,token,omitempty"`
// The destination type of the notification configuration
Triggers []string `jsonapi:"attr,triggers,omitempty"`
// The url of the notification configuration
URL *string `jsonapi:"attr,url"`
}
func (o NotificationConfigurationCreateOptions) valid() error {
if o.DestinationType == nil {
return errors.New("destination type is required")
}
if o.Enabled == nil {
return errors.New("enabled is required")
}
if !validString(o.Name) {
return errors.New("name is required")
}
if !validString(o.URL) {
return errors.New("url is required")
}
return nil
}
// Creates a notification configuration with the given options.
func (s *notificationConfigurations) Create(ctx context.Context, workspaceID string, options NotificationConfigurationCreateOptions) (*NotificationConfiguration, error) {
if !validStringID(&workspaceID) {
return nil, errors.New("invalid value for workspace ID")
}
if err := options.valid(); err != nil {
return nil, err
}
// Make sure we don't send a user provided ID.
options.ID = ""
u := fmt.Sprintf("workspaces/%s/notification-configurations", url.QueryEscape(workspaceID))
req, err := s.client.newRequest("POST", u, &options)
if err != nil {
return nil, err
}
nc := &NotificationConfiguration{}
err = s.client.do(ctx, req, nc)
if err != nil {
return nil, err
}
return nc, nil
}
// Read a notitification configuration by its ID.
func (s *notificationConfigurations) Read(ctx context.Context, notificationConfigurationID string) (*NotificationConfiguration, error) {
if !validStringID(&notificationConfigurationID) {
return nil, errors.New("invalid value for notification configuration ID")
}
u := fmt.Sprintf("notification-configurations/%s", url.QueryEscape(notificationConfigurationID))
req, err := s.client.newRequest("GET", u, nil)
if err != nil {
return nil, err
}
nc := &NotificationConfiguration{}
err = s.client.do(ctx, req, nc)
if err != nil {
return nil, err
}
return nc, nil
}
// NotificationConfigurationUpdateOptions represents the options for
// updating a existing notification configuration.
type NotificationConfigurationUpdateOptions struct {
// For internal use only!
ID string `jsonapi:"primary,notification-configurations"`
// Whether the notification configuration should be enabled or not
Enabled *bool `jsonapi:"attr,enabled,omitempty"`
// The name of the notification configuration
Name *string `jsonapi:"attr,name,omitempty"`
// The token of the notification configuration
Token *string `jsonapi:"attr,token,omitempty"`
// The destination type of the notification configuration
Triggers []string `jsonapi:"attr,triggers,omitempty"`
// The url of the notification configuration
URL *string `jsonapi:"attr,url,omitempty"`
}
// Updates a notification configuration with the given options.
func (s *notificationConfigurations) Update(ctx context.Context, notificationConfigurationID string, options NotificationConfigurationUpdateOptions) (*NotificationConfiguration, error) {
if !validStringID(&notificationConfigurationID) {
return nil, errors.New("invalid value for notification configuration ID")
}
// Make sure we don't send a user provided ID.
options.ID = ""
u := fmt.Sprintf("notification-configurations/%s", url.QueryEscape(notificationConfigurationID))
req, err := s.client.newRequest("PATCH", u, &options)
if err != nil {
return nil, err
}
nc := &NotificationConfiguration{}
err = s.client.do(ctx, req, nc)
if err != nil {
return nil, err
}
return nc, nil
}
// Delete a notifications configuration by its ID.
func (s *notificationConfigurations) Delete(ctx context.Context, notificationConfigurationID string) error {
if !validStringID(&notificationConfigurationID) {
return errors.New("invalid value for notification configuration ID")
}
u := fmt.Sprintf("notification-configurations/%s", url.QueryEscape(notificationConfigurationID))
req, err := s.client.newRequest("DELETE", u, nil)
if err != nil {
return err
}
return s.client.do(ctx, req, nil)
}
// Verifies a notification configuration by delivering a verification
// payload to the configured url.
func (s *notificationConfigurations) Verify(ctx context.Context, notificationConfigurationID string) (*NotificationConfiguration, error) {
if !validStringID(&notificationConfigurationID) {
return nil, errors.New("invalid value for notification configuration ID")
}
u := fmt.Sprintf(
"notification-configurations/%s/actions/verify", url.QueryEscape(notificationConfigurationID))
req, err := s.client.newRequest("POST", u, nil)
if err != nil {
return nil, err
}
nc := &NotificationConfiguration{}
err = s.client.do(ctx, req, nc)
if err != nil {
return nil, err
}
return nc, nil
}

View File

@ -112,6 +112,10 @@ type StateVersionCreateOptions struct {
// The base64 encoded state.
State *string `jsonapi:"attr,state"`
// Force can be set to skip certain validations. Wrong use
// of this flag can cause data loss, so USE WITH CAUTION!
Force *bool `jsonapi:"attr,force"`
// Specifies the run to associate the state with.
Run *Run `jsonapi:"relation,run,omitempty"`
}

View File

@ -106,6 +106,7 @@ type Client struct {
Applies Applies
ConfigurationVersions ConfigurationVersions
NotificationConfigurations NotificationConfigurations
OAuthClients OAuthClients
OAuthTokens OAuthTokens
Organizations Organizations
@ -194,6 +195,7 @@ func NewClient(cfg *Config) (*Client, error) {
// Create the services.
client.Applies = &applies{client: client}
client.ConfigurationVersions = &configurationVersions{client: client}
client.NotificationConfigurations = &notificationConfigurations{client: client}
client.OAuthClients = &oAuthClients{client: client}
client.OAuthTokens = &oAuthTokens{client: client}
client.Organizations = &organizations{client: client}
@ -297,6 +299,7 @@ func (c *Client) configureLimiter() error {
req.Header[k] = v
}
req.Header.Set("Accept", "application/vnd.api+json")
req.Header.Set("Authorization", "Bearer "+c.token)
// Make a single request to retrieve the rate limit headers.
resp, err := c.http.HTTPClient.Do(req)

View File

@ -35,6 +35,11 @@ func Int64(v int64) *int64 {
return &v
}
// NotificationDestination returns a pointer to the given notification configuration destination type
func NotificationDestination(v NotificationDestinationType) *NotificationDestinationType {
return &v
}
// ServiceProvider returns a pointer to the given service provider type.
func ServiceProvider(v ServiceProviderType) *ServiceProviderType {
return &v

View File

@ -110,7 +110,7 @@ type VariableCreateOptions struct {
Key *string `jsonapi:"attr,key"`
// The value of the variable.
Value *string `jsonapi:"attr,value"`
Value *string `jsonapi:"attr,value,omitempty"`
// Whether this is a Terraform or environment variable.
Category *CategoryType `jsonapi:"attr,category"`
@ -129,9 +129,6 @@ func (o VariableCreateOptions) valid() error {
if !validString(o.Key) {
return errors.New("key is required")
}
if !validString(o.Value) {
return errors.New("value is required")
}
if o.Category == nil {
return errors.New("category is required")
}

View File

@ -15,9 +15,11 @@ func GenerateRandomBytes(size int) ([]byte, error) {
return buf, nil
}
const uuidLen = 16
// GenerateUUID is used to generate a random UUID
func GenerateUUID() (string, error) {
buf, err := GenerateRandomBytes(16)
buf, err := GenerateRandomBytes(uuidLen)
if err != nil {
return "", err
}
@ -25,11 +27,11 @@ func GenerateUUID() (string, error) {
}
func FormatUUID(buf []byte) (string, error) {
if len(buf) != 16 {
return "", fmt.Errorf("wrong length byte slice (%d)", len(buf))
if buflen := len(buf); buflen != uuidLen {
return "", fmt.Errorf("wrong length byte slice (%d)", buflen)
}
return fmt.Sprintf("%08x-%04x-%04x-%04x-%12x",
return fmt.Sprintf("%x-%x-%x-%x-%x",
buf[0:4],
buf[4:6],
buf[6:8],
@ -38,16 +40,14 @@ func FormatUUID(buf []byte) (string, error) {
}
func ParseUUID(uuid string) ([]byte, error) {
if len(uuid) != 36 {
if len(uuid) != 2 * uuidLen + 4 {
return nil, fmt.Errorf("uuid string is wrong length")
}
hyph := []byte("-")
if uuid[8] != hyph[0] ||
uuid[13] != hyph[0] ||
uuid[18] != hyph[0] ||
uuid[23] != hyph[0] {
if uuid[8] != '-' ||
uuid[13] != '-' ||
uuid[18] != '-' ||
uuid[23] != '-' {
return nil, fmt.Errorf("uuid is improperly formatted")
}
@ -57,7 +57,7 @@ func ParseUUID(uuid string) ([]byte, error) {
if err != nil {
return nil, err
}
if len(ret) != 16 {
if len(ret) != uuidLen {
return nil, fmt.Errorf("decoded hex is the wrong length")
}

10
vendor/modules.txt vendored
View File

@ -282,17 +282,17 @@ github.com/hashicorp/go-multierror
# github.com/hashicorp/go-plugin v0.0.0-20190322172744-52e1c4730856
github.com/hashicorp/go-plugin
github.com/hashicorp/go-plugin/internal/plugin
# github.com/hashicorp/go-retryablehttp v0.5.1
# github.com/hashicorp/go-retryablehttp v0.5.2
github.com/hashicorp/go-retryablehttp
# github.com/hashicorp/go-rootcerts v1.0.0
github.com/hashicorp/go-rootcerts
# github.com/hashicorp/go-safetemp v1.0.0
github.com/hashicorp/go-safetemp
# github.com/hashicorp/go-slug v0.2.0
# github.com/hashicorp/go-slug v0.3.0
github.com/hashicorp/go-slug
# github.com/hashicorp/go-tfe v0.3.11
# github.com/hashicorp/go-tfe v0.3.14
github.com/hashicorp/go-tfe
# github.com/hashicorp/go-uuid v1.0.0
# github.com/hashicorp/go-uuid v1.0.1
github.com/hashicorp/go-uuid
# github.com/hashicorp/go-version v1.1.0
github.com/hashicorp/go-version
@ -522,7 +522,7 @@ golang.org/x/text/internal/language/compact
golang.org/x/text/internal/utf8internal
golang.org/x/text/runes
golang.org/x/text/internal/tag
# golang.org/x/time v0.0.0-20181108054448-85acf8d2951c
# golang.org/x/time v0.0.0-20190308202827-9d24e82272b4
golang.org/x/time/rate
# google.golang.org/api v0.1.0
google.golang.org/api/iterator