Skip to content

Commit

Permalink
added reboot node ability and updated several outdated files
Browse files Browse the repository at this point in the history
  • Loading branch information
fvanmaldegem committed May 8, 2024
1 parent 9dc7354 commit b66b8fb
Show file tree
Hide file tree
Showing 31 changed files with 663 additions and 78 deletions.
6 changes: 3 additions & 3 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ stages:

analyze:lint:
stage: analyze
image: golangci/golangci-lint:v1.45
image: golangci/golangci-lint:v1.57
script:
- golangci-lint run -v
tags:
Expand All @@ -27,7 +27,7 @@ lint:golint:
lint:vet:
stage: lint
script:
- ci/vet.sh
- go vet ./...
tags:
- k8s-tbk

Expand All @@ -41,7 +41,7 @@ lint:modtidy:
test:go:
stage: test
script:
- ci/test.sh
- go test ./...
tags:
- k8s-tbk

Expand Down
47 changes: 42 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,58 @@ linters-settings:
goconst:
min-len: 3
min-occurrences: 2
depguard: {}
depguard:
rules:
Main:
files:
- "!**/internal/**/*.go"
- "$all"
- "!$test"
allow:
- "$gostd"
- github.com/transip/gotransip/v6
- github.com/transip/gotransip/v6/rest
- github.com/transip/gotransip/v6/repository
- github.com/transip/gotransip/v6/vps
Internal:
files:
- "**/internal/**/*.go"
allow:
- "$gostd"
- github.com/transip/gotransip/v6
- github.com/transip/gotransip/v6/rest
- github.com/transip/gotransip/v6/repository
- github.com/transip/gotransip/v6/vps
- github.com/stretchr/testify/assert
- github.com/stretchr/testify/require
Tests:
files:
- "$test"
allow:
- "$gostd"
- github.com/transip/gotransip/v6
- github.com/transip/gotransip/v6/rest
- github.com/transip/gotransip/v6/repository
- github.com/transip/gotransip/v6/ipaddress
- github.com/transip/gotransip/v6/vps
- github.com/transip/gotransip/v6/jwt
- github.com/transip/gotransip/v6/internal/testutil
- github.com/stretchr/testify/require
- github.com/stretchr/testify/assert


lll:
line-length: 160
nakedret:
max-func-lines: 10


linters:
enable:
- asciicheck
- bidichk
- bodyclose
- contextcheck
- deadcode
- decorder
- depguard
- dogsled
Expand All @@ -58,7 +97,6 @@ linters:
- gosimple
- govet
- grouper
- ifshort
- importas
- ineffassign
- lll
Expand All @@ -76,14 +114,12 @@ linters:
- rowserrcheck
- sqlclosecheck
- staticcheck
- structcheck
- stylecheck
- tenv
- typecheck
- unconvert
- unparam
- unused
- varcheck
- wastedassign
enable-all: false
disable-all: false
Expand All @@ -104,3 +140,4 @@ issues:
- path: mocks/*
linters:
- typecheck

9 changes: 5 additions & 4 deletions authenticator/authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"crypto/rand"
"errors"
"fmt"
"github.com/transip/gotransip/v6/jwt"
"github.com/transip/gotransip/v6/rest"
"io/ioutil"
"io"
"net/http"
"time"

"github.com/transip/gotransip/v6/jwt"
"github.com/transip/gotransip/v6/rest"
)

const (
Expand Down Expand Up @@ -164,7 +165,7 @@ func (a *Authenticator) requestNewToken() (jwt.Token, error) {
defer httpResponse.Body.Close()

// read entire response body
b, err := ioutil.ReadAll(httpResponse.Body)
b, err := io.ReadAll(httpResponse.Body)
if err != nil {
return jwt.Token{}, fmt.Errorf("error requesting token: %w", err)
}
Expand Down
13 changes: 7 additions & 6 deletions authenticator/authenticator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package authenticator
import (
"errors"
"fmt"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/transip/gotransip/v6/jwt"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/transip/gotransip/v6/jwt"
)

const amountOfNoncesToGet = 10
Expand Down Expand Up @@ -63,7 +64,7 @@ func TestAuthenticatorGetToken(t *testing.T) {
func TestRequestANewToken(t *testing.T) {
server := getMockServer(t)
defer server.Close()
key, err := ioutil.ReadFile("../testdata/signature.key")
key, err := os.ReadFile("../testdata/signature.key")
require.NoError(t, err)

authenticator := Authenticator{
Expand All @@ -84,7 +85,7 @@ func TestAuthenticationErrorIsReturned(t *testing.T) {
server := getFailedMockServer(t)
defer server.Close()

key, err := ioutil.ReadFile("../testdata/signature.key")
key, err := os.ReadFile("../testdata/signature.key")
require.NoError(t, err)

authenticator := Authenticator{
Expand Down
7 changes: 4 additions & 3 deletions authenticator/filetokencache.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package authenticator
import (
"encoding/json"
"fmt"
"github.com/transip/gotransip/v6/jwt"
"io/ioutil"
"io"
"os"
"sync"

"github.com/transip/gotransip/v6/jwt"
)

// cacheItem is one named item inside the filesystem cache
Expand Down Expand Up @@ -41,7 +42,7 @@ func NewFileTokenCache(path string) (*FileTokenCache, error) {
cache := FileTokenCache{File: file}

// try to read the File
fileContent, err := ioutil.ReadAll(file)
fileContent, err := io.ReadAll(file)
if err != nil {
return &FileTokenCache{}, fmt.Errorf("error reading cache File: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions authenticator/sign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package authenticator

import (
"encoding/json"
"io/ioutil"
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -11,7 +11,7 @@ import (

// See: https://api.transip.nl/v6/auth
func TestSignWithKey(t *testing.T) {
key, err := ioutil.ReadFile("../testdata/signature.key")
key, err := os.ReadFile("../testdata/signature.key")
require.NoError(t, err)

requestBody := &AuthRequest{
Expand Down
12 changes: 0 additions & 12 deletions ci/test.sh

This file was deleted.

12 changes: 0 additions & 12 deletions ci/vet.sh

This file was deleted.

30 changes: 18 additions & 12 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"

Expand Down Expand Up @@ -75,7 +74,7 @@ func newClient(config ClientConfiguration) (*client, error) {

if config.PrivateKeyReader != nil {
var err error
privateKeyBody, err = ioutil.ReadAll(config.PrivateKeyReader)
privateKeyBody, err = io.ReadAll(config.PrivateKeyReader)

if err != nil {
return &client{}, fmt.Errorf("error while reading private key: %w", err)
Expand Down Expand Up @@ -120,7 +119,7 @@ func newClient(config ClientConfiguration) (*client, error) {
// This method is used by all rest client methods, thus: 'get','post','put','delete'
// It uses the authenticator to get a token, either statically provided by the user or requested from the authentication server
// Then decodes the json response to a supplied interface
func (c *client) call(method rest.Method, request rest.Request, result interface{}) (rest.Response, error) {
func (c *client) call(method rest.Method, request rest.Request, result any) (rest.Response, error) {
token, err := c.authenticator.GetToken()
if err != nil {
return rest.Response{}, fmt.Errorf("could not get token from authenticator: %w", err)
Expand Down Expand Up @@ -150,7 +149,7 @@ func (c *client) call(method rest.Method, request rest.Request, result interface
bodyReader := io.LimitReader(httpResponse.Body, httpBodyLimit)

// read entire httpResponse body
b, err := ioutil.ReadAll(bodyReader)
b, err := io.ReadAll(bodyReader)
if err != nil {
return rest.Response{}, fmt.Errorf("error reading http response body: %w", err)
}
Expand All @@ -164,7 +163,7 @@ func (c *client) call(method rest.Method, request rest.Request, result interface
ContentLocation: contentLocation,
}

err = restResponse.ParseResponse(&result)
err = restResponse.ParseResponse(result)

return restResponse, err
}
Expand Down Expand Up @@ -195,45 +194,52 @@ func (c *client) Get(request rest.Request, responseObject interface{}) error {
// This method will create and execute a http Post request
// It expects no response, that is why it does not ask for a responseObject
func (c *client) Post(request rest.Request) error {
_, err := c.call(rest.PostMethod, request, nil)
var response any
_, err := c.call(rest.PostMethod, request, &response)
return err
}

// This method will create and execute a http Post request
// It expects a response
func (c *client) PostWithResponse(request rest.Request) (rest.Response, error) {
return c.call(rest.PostMethod, request, nil)
var response any
return c.call(rest.PostMethod, request, &response)
}

// This method will create and execute a http Put request
// It expects no response, that is why it does not ask for a responseObject
func (c *client) Put(request rest.Request) error {
_, err := c.call(rest.PutMethod, request, nil)
var response any
_, err := c.call(rest.PutMethod, request, &response)
return err
}

// This method will create and execute a http Put request
// It expects a response
func (c *client) PutWithResponse(request rest.Request) (rest.Response, error) {
return c.call(rest.PutMethod, request, nil)
var response any
return c.call(rest.PutMethod, request, &response)
}

// This method will create and execute a http Delete request
// It expects no response, that is why it does not ask for a responseObject
func (c *client) Delete(request rest.Request) error {
_, err := c.call(rest.DeleteMethod, request, nil)
var response any
_, err := c.call(rest.DeleteMethod, request, &response)
return err
}

// This method will create and execute a http Patch request
// It expects no response, that is why it does not ask for a responseObject
func (c *client) Patch(request rest.Request) error {
_, err := c.call(rest.PatchMethod, request, nil)
var response any
_, err := c.call(rest.PatchMethod, request, &response)
return err
}

// This method will create and execute a http Patch request
// It expects a response
func (c *client) PatchWithResponse(request rest.Request) (rest.Response, error) {
return c.call(rest.PatchMethod, request, nil)
var response any
return c.call(rest.PatchMethod, request, &response)
}
6 changes: 3 additions & 3 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package gotransip
import (
"bytes"
"errors"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"net/url"
Expand Down Expand Up @@ -74,7 +74,7 @@ func TestNewClient(t *testing.T) {
// Test if private key from path is read and passed to the authenticator
privateKeyFile, err := os.Open("testdata/signature.key")
require.NoError(t, err)
privateKeyBody, err := ioutil.ReadAll(privateKeyFile)
privateKeyBody, err := io.ReadAll(privateKeyFile)
require.NoError(t, err)

// Test that a tokencache is passed to the authenticator
Expand Down Expand Up @@ -218,7 +218,7 @@ func (m *mockServer) getHTTPServer() *httptest.Server {
if req.ContentLength != 0 {
// get the request body
// and check if the body matches the expected request body
body, err := ioutil.ReadAll(req.Body)
body, err := io.ReadAll(req.Body)
require.NoError(m.t, err)
assert.Equal(m.t, m.expectedRequest, string(body))
}
Expand Down
2 changes: 1 addition & 1 deletion configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

const (
libraryVersion = "6.23.0"
libraryVersion = "6.24.0"
defaultBasePath = "https://api.transip.nl/v6"
userAgent = "go-client-gotransip/" + libraryVersion
)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/kubernetes.go → examples/kubernetes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func main() {
}
for _, n := range nodepools {
fmt.Printf(
"\tNodePool: [description=%s, zone=%s, spec=%s, nodeCount=%s]\n",
"\tNodePool: [description=%s, zone=%s, spec=%s, nodeCount=%d]\n",
n.Description, n.AvailabilityZone, n.NodeSpec, n.DesiredNodeCount,
)
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit b66b8fb

Please sign in to comment.