From 2201e84101cb7f60d12b2c07abe5e17df43118fa Mon Sep 17 00:00:00 2001 From: Andrew Sauber Date: Thu, 27 Jun 2019 12:26:20 -0400 Subject: [PATCH] Support arbitrary root CAs * Update linodego * Use linodego internal http client --- Makefile | 27 +++++++++++++++++++++++---- go.mod | 4 ++-- go.sum | 4 ++-- pkg/linode-client/linode-client.go | 16 +++------------- 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index 4382fb38..4f451edf 100644 --- a/Makefile +++ b/Makefile @@ -20,24 +20,43 @@ REV=$(shell git describe --long --tags --dirty) export GO111MODULE=on -.PHONY: all linode clean linode-container - +.PHONY: all all: linode +.PHONY: vendor vendor: go mod vendor -test: - go test -v ./... -cover + +.PHONY: fmt +fmt: + go fmt ./... + +.PHONY: vet +vet: fmt go vet ./... + +.PHONY: test +test: vet + go test -v ./... -cover + +.PHONY: linode linode: vendor test CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-X main.vendorVersion=$(REV) -extldflags "-static"' -o _output/linode ./app/linode + +.PHONY: linode-container linode-container: linode docker build -t $(IMAGE_TAG) -f ./app/linode/Dockerfile . + +.PHONY: push push: linode-container #@echo "$$DOCKER_PASSWORD" | docker login -u "$$DOCKER_USERNAME" --password-stdin docker push $(IMAGE_TAG) + +.PHONY: verify verify: go mod verify + +.PHONY: clean clean: @GOOS=linux go clean -i -r -x ./... -rm -rf _output diff --git a/go.mod b/go.mod index b3842416..fd54982b 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/hashicorp/golang-lru v0.5.0 // indirect github.com/json-iterator/go v1.1.5 // indirect github.com/kubernetes-csi/csi-test v1.1.0 - github.com/linode/linodego v0.9.0 + github.com/linode/linodego v0.10.0 github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.1 // indirect @@ -36,7 +36,7 @@ require ( github.com/stretchr/testify v1.2.2 // indirect golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 // indirect golang.org/x/net v0.0.0-20181114220301-adae6a3d119a - golang.org/x/oauth2 v0.0.0-20181120190819-8f65e3013eba + golang.org/x/oauth2 v0.0.0-20181120190819-8f65e3013eba // indirect golang.org/x/time v0.0.0-20181108054448-85acf8d2951c // indirect google.golang.org/grpc v1.16.0 gopkg.in/inf.v0 v0.9.1 // indirect diff --git a/go.sum b/go.sum index 2b9816f0..d0089dfa 100644 --- a/go.sum +++ b/go.sum @@ -47,8 +47,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kubernetes-csi/csi-test v1.1.0 h1:a7CfGqhGDs0h7AZt1f6LTIUzBazcRf6eBdTUBXB4xE4= github.com/kubernetes-csi/csi-test v1.1.0/go.mod h1:YxJ4UiuPWIhMBkxUKY5c267DyA0uDZ/MtAimhx/2TA0= -github.com/linode/linodego v0.9.0 h1:FnWYh6myo4yuiRmui0rpU0TsCVwLbgX1L7/ibmFYenE= -github.com/linode/linodego v0.9.0/go.mod h1:cziNP7pbvE3mXIPneHj0oRY8L1WtGEIKlZ8LANE4eXA= +github.com/linode/linodego v0.10.0 h1:AMdb82HVgY8o3mjBXJcUv9B+fnJjfDMn2rNRGbX+jvM= +github.com/linode/linodego v0.10.0/go.mod h1:cziNP7pbvE3mXIPneHj0oRY8L1WtGEIKlZ8LANE4eXA= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= diff --git a/pkg/linode-client/linode-client.go b/pkg/linode-client/linode-client.go index f4c9f1fb..3e789699 100644 --- a/pkg/linode-client/linode-client.go +++ b/pkg/linode-client/linode-client.go @@ -3,10 +3,8 @@ package linodeclient import ( "context" "fmt" - "net/http" "github.com/linode/linodego" - "golang.org/x/oauth2" ) type LinodeClient interface { @@ -27,19 +25,11 @@ type LinodeClient interface { } func NewLinodeClient(token, uaPrefix string, url string) *linodego.Client { - tokenSource := oauth2.StaticTokenSource(&oauth2.Token{ - AccessToken: token, - }) - - oauth2Client := &http.Client{ - Transport: &oauth2.Transport{ - Source: tokenSource, - }, - } - ua := fmt.Sprintf("%s linodego/%s", uaPrefix, linodego.Version) - linodeClient := linodego.NewClient(oauth2Client) + // Use linodego built-in http client which supports setting root CA cert + linodeClient := linodego.NewClient(nil) linodeClient.SetUserAgent(ua) + linodeClient.SetToken(token) linodeClient.SetDebug(true) if url != "" {