Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

- uses: actions/setup-go@v5
with:
go-version: '1.13'
go-version: '1.26'

- name: Setup
run: |
Expand Down
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ lint:
@./bin/golangci-lint run

tools:
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.24.0
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.57.0
@scripts/install-swagger.sh

.PHONY: build gen gen-native gen-m1 test testapi test-integration fmt fmtcheck lint tools
16 changes: 16 additions & 0 deletions aptible/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aptible

import (
"fmt"
"net/http"
"os"
"regexp"
"strings"
Expand All @@ -12,6 +13,17 @@ import (
"github.com/go-openapi/strfmt"
)

type userAgentTransport struct {
wrapped http.RoundTripper
userAgent string
}

func (t *userAgentTransport) RoundTrip(req *http.Request) (*http.Response, error) {
req = req.Clone(req.Context())
req.Header.Set("User-Agent", t.userAgent)
return t.wrapped.RoundTrip(req)
}

type Client struct {
Client *deploy.DeployAPIV1
Token runtime.ClientAuthInfoWriter
Expand All @@ -31,6 +43,10 @@ func SetUpClient() (*Client, error) {
deploy.DefaultSchemes)
rt.Consumers["application/hal+json"] = runtime.JSONConsumer()
rt.Producers["application/hal+json"] = runtime.JSONProducer()
rt.Transport = &userAgentTransport{
wrapped: http.DefaultTransport,
userAgent: userAgent(),
}
client := deploy.New(rt, strfmt.Default)

token, err := GetToken()
Expand Down
3 changes: 2 additions & 1 deletion aptible/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ type Database struct {
}

// DBUpdates - struct to define what operations you contain your DB update to. Add values to this struct
// to eventually pass it around for consumption by the go sdk
//
// to eventually pass it around for consumption by the go sdk
type DBUpdates struct {
ContainerSize int64
DiskSize int64
Expand Down
6 changes: 3 additions & 3 deletions aptible/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (c *Client) CreateEndpoint(service Service, attrs EndpointCreateAttrs) (End
request.ContainerPort = attrs.ContainerPort
}

if *attrs.Type != "http_proxy_protocol" && *attrs.Type != "http" && *attrs.Type != "grpc" {
if *attrs.Type != "http" && *attrs.Type != "grpc" {
request.ContainerPorts = attrs.ContainerPorts
}

Expand Down Expand Up @@ -280,7 +280,7 @@ func (c *Client) DeleteEndpoint(endpointID int64) error {
func GetEndpointType(t string) (string, error) {
switch t {
case "HTTPS", "https":
return "http_proxy_protocol", nil
return "http", nil
case "TCP", "tcp":
return "tcp", nil
case "TLS", "tls":
Expand All @@ -295,7 +295,7 @@ func GetEndpointType(t string) (string, error) {

func GetHumanReadableEndpointType(t string) (string, error) {
switch t {
case "http_proxy_protocol":
case "http_proxy_protocol", "http":
return "https", nil
case "tcp":
return "tcp", nil
Expand Down
4 changes: 1 addition & 3 deletions aptible/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"net/http"
"os"
"path/filepath"

"github.com/mitchellh/go-homedir"
)

// loginWithUsernameAndPassword - specifically requests APTIBLE_AUTH_ROOT_URL for token with a username/password
Expand Down Expand Up @@ -88,7 +86,7 @@ func GetToken() (string, error) {
return token, nil
}

home, err := homedir.Dir()
home, err := os.UserHomeDir()
if err != nil {
return "", fmt.Errorf("Your token is invalid. Are you logged in? Error: %v", err.Error())
}
Expand Down
3 changes: 0 additions & 3 deletions aptible/tokens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"os"
"path/filepath"
"testing"

"github.com/mitchellh/go-homedir"
)

func mockEnv(envVar, value string) func() {
Expand Down Expand Up @@ -39,7 +37,6 @@ func TestGetTokenEnv(t *testing.T) {
}

func TestGetToken(t *testing.T) {
homedir.DisableCache = true
tmpHome, err := ioutil.TempDir(os.TempDir(), "go-deploy")
if err != nil {
t.Error("Failed to create the temp directory", err)
Expand Down
21 changes: 21 additions & 0 deletions aptible/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package aptible

import "runtime/debug"

func version() string {
if info, ok := debug.ReadBuildInfo(); ok {
for _, dep := range info.Deps {
if dep.Path == "github.com/aptible/go-deploy" {
return dep.Version
}
}
if info.Main.Path == "github.com/aptible/go-deploy" {
return info.Main.Version
}
}
return "unknown"
}

func userAgent() string {
return "aptible/go-deploy/" + version()
}
18 changes: 18 additions & 0 deletions aptible/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package aptible

import "testing"

func TestVersion(t *testing.T) {
v := version()
if v == "unknown" {
t.Errorf("version() returned %q", v)
}
}

func TestUserAgent(t *testing.T) {
ua := userAgent()
expected := "aptible/go-deploy/" + version()
if ua != expected {
t.Errorf("userAgent() = %q, want %q", ua, expected)
}
}
3 changes: 2 additions & 1 deletion client/operations/delete_accounts_id_parameters.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions client/operations/delete_accounts_id_responses.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion client/operations/delete_apps_id_parameters.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions client/operations/delete_apps_id_responses.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion client/operations/delete_certificates_id_parameters.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions client/operations/delete_certificates_id_responses.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion client/operations/delete_configurations_id_parameters.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions client/operations/delete_configurations_id_responses.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion client/operations/delete_databases_id_parameters.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions client/operations/delete_databases_id_responses.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion client/operations/delete_log_drains_id_parameters.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions client/operations/delete_log_drains_id_responses.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion client/operations/delete_permissions_id_parameters.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading