Skip to content

Commit

Permalink
release 0.0.17
Browse files Browse the repository at this point in the history
- added cache control headers to requests
- return ErrSystemNotReady for Connection refused and 502, also always
  reset the client's compatibility error property when versionCheck is called
  so that it always queries the backend.
- bumped semver to 3.2.1
  • Loading branch information
rschmied committed Apr 25, 2023
1 parent 877d99f commit 3aed91e
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 51 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

Lists the changes in the gocmlclient package.

## Version 0.0.17

- added cache control headers to requests
- return ErrSystemNotReady for Connection refused and 502, also always
reset the client's compatibility error property when versionCheck is called
so that it always queries the backend.
- bumped semver to 3.2.1

## Version 0.0.16

- added new API endpoints for groups and users
Expand Down
24 changes: 21 additions & 3 deletions apiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
"io"
"log"
"net/http"
"strings"
"sync/atomic"
"syscall"
)

const (
Expand Down Expand Up @@ -39,6 +41,10 @@ func (c *Client) apiRequest(ctx context.Context, method string, path string, dat
setTokenHeader(req, c.apiToken)
}
req.Header.Set("Accept", contentType)
req.Header.Set("Cache-Control", "no-cache, no-store, must-revalidate")
req.Header.Set("Pragma", "no-cache")
req.Header.Set("Expires", "0")
req.Header.Set("Conenction", "close")
if data != nil {
req.Header.Set("Content-Type", contentType)
}
Expand Down Expand Up @@ -71,6 +77,9 @@ retry:
}
res, err := c.httpClient.Do(req)
if err != nil {
if errors.Is(err, syscall.ECONNREFUSED) {
return nil, ErrSystemNotReady
}
return nil, err
}
defer res.Body.Close()
Expand Down Expand Up @@ -99,11 +108,20 @@ retry:
c.state.set(stateAuthenticated)
goto retry
}
if res.StatusCode == http.StatusOK || res.StatusCode == http.StatusNoContent || res.StatusCode == http.StatusCreated {
switch res.StatusCode {
case http.StatusOK:
fallthrough
case http.StatusNoContent:
fallthrough
case http.StatusCreated:
return body, err
} else {
return nil, fmt.Errorf("status: %d, %s", res.StatusCode, body)
case http.StatusBadGateway:
return nil, ErrSystemNotReady
}
return nil, fmt.Errorf(
"status: %d, %s",
res.StatusCode, strings.TrimSpace(string(body)),
)
}

/* technically, only jsonGet and jsonPost need the depth as they are the only
Expand Down
2 changes: 1 addition & 1 deletion auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func TestClient_token_auth(t *testing.T) {
t.Error("not all data in mock client consumed")
}
if tt.wantErr {
assert.EqualError(t, err, tt.errstr)
assert.ErrorContains(t, err, tt.errstr)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/rschmied/gocmlclient
go 1.19

require (
github.com/Masterminds/semver/v3 v3.2.0
github.com/Masterminds/semver/v3 v3.2.1
github.com/rschmied/mockresponder v1.0.4
github.com/stretchr/testify v1.8.2
golang.org/x/sync v0.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/Masterminds/semver/v3 v3.2.0 h1:3MEsd0SM6jqZojhjLWWeBY+Kcjy9i6MQAeY7YgDP83g=
github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
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=
Expand Down
3 changes: 2 additions & 1 deletion system.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ func versionError(got string) error {

func (c *Client) versionCheck(ctx context.Context, depth int32) error {

c.compatibilityErr = nil
sv := systemVersion{}
if err := c.jsonGet(ctx, systeminfoAPI, &sv, depth); err != nil {
return err
return fmt.Errorf("system info error %d (%w)", depth, err)
}

if !sv.Ready {
Expand Down
3 changes: 0 additions & 3 deletions vendor/github.com/Masterminds/semver/v3/.golangci.yml

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

17 changes: 5 additions & 12 deletions vendor/github.com/Masterminds/semver/v3/Makefile

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

22 changes: 18 additions & 4 deletions vendor/github.com/Masterminds/semver/v3/README.md

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

19 changes: 19 additions & 0 deletions vendor/github.com/Masterminds/semver/v3/SECURITY.md

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

2 changes: 1 addition & 1 deletion vendor/github.com/Masterminds/semver/v3/constraints.go

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

22 changes: 0 additions & 22 deletions vendor/github.com/Masterminds/semver/v3/fuzz.go

This file was deleted.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# github.com/Masterminds/semver/v3 v3.2.0
# github.com/Masterminds/semver/v3 v3.2.1
## explicit; go 1.18
github.com/Masterminds/semver/v3
# github.com/davecgh/go-spew v1.1.1
Expand Down

0 comments on commit 3aed91e

Please sign in to comment.