Skip to content

Commit ea7d534

Browse files
Session Auth Token Refresh and V3 Client Cache (#166)
* Add logic for session refresh in prism-go-client Also add WithUserAgent ClientOption for v3 client constructor. * Add a cache for v3 clients * Address review comments - Add omitempty tags to all properties - run gofumpt on files - remove extraneous print statements - Update retry logic * Fix build failures - Add custom yaml linter config - Fix otherbuild related issues * Address review comments
1 parent 8724a6b commit ea7d534

File tree

13 files changed

+466
-139
lines changed

13 files changed

+466
-139
lines changed

.github/workflows/build-lint-test.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ jobs:
1818
- name: Setup Go
1919
uses: actions/setup-go@v5
2020
with:
21-
go-version: '^1.18'
22-
23-
- name: Install dependencies
24-
run: make vendor
21+
go-version: '^1.21'
2522

2623
- name: Check build
2724
run: make build
@@ -45,4 +42,3 @@ jobs:
4542

4643
- name: Codecov
4744
uses: codecov/[email protected]
48-

CHANGELOG.md

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased]
88
### Added
99
- Added support for v4 client creation.
10-
11-
### Added
1210
- Added support for getting information about an AZ given a uuid.
13-
14-
### Added
1511
- Added support for getting a projection of attributes of entities using the 'groups' API endpoint.
16-
17-
### Added
1812
- Added support for creating, deleting, listing, and getting the status of recovery plan jobs.
19-
20-
### Changed
21-
- Change the MetaService interface methods to take context.Context as a parameter
22-
- Local environment provider now fetches port from `NUTANIX_PORT` environment variable
23-
24-
### Added
2513
- Add optional function options for the NewKarbonAPIClient constructor
2614
- Add ClusterRegistration interface in karbon package
2715
- Add ClusterRegistration SetInfo and Cluster Addon SetInfo APIs
28-
29-
### Added
3016
- Added support for specifying volume groups by category in a recovery plan create request.
3117
- Added support for specifying primary and recovery clusters in a recovery plan.
18+
- Added WithUserAgent client option for v3 client constructor.
19+
- Added Cache for v3 Clients in v3 package.
20+
21+
### Changed
22+
- Change the MetaService interface methods to take context.Context as a parameter
23+
- Local environment provider now fetches port from `NUTANIX_PORT` environment variable
24+
- Add logic to internal.Client for auto retry once after refreshing auth cookie on a 401 response in case of session auth.
3225

3326
## [0.3.4] - 2022-11-24
3427
### Changed

Makefile

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ WHITE := $(shell tput -Txterm setaf 7)
1111
CYAN := $(shell tput -Txterm setaf 6)
1212
RESET := $(shell tput -Txterm sgr0)
1313

14-
.PHONY: all test build vendor
14+
.PHONY: all test build
1515

1616
all: help
1717

1818
## Build:
19-
build: vendor ## Build your project and put the output binary in bin/
19+
build: ## Build your project and put the output binary in bin/
2020
mkdir -p bin
21-
GO111MODULE=on $(GOCMD) build -mod vendor -o bin/$(BINARY_NAME) .
21+
$(GOCMD) build -o bin/$(BINARY_NAME) .
2222

23-
# go-get-tool will 'go get' any package $2 and install it to $1.
23+
# go-get-tool will 'go install' any package $2 and install it to $1.
2424
# originally copied from kubebuilder
2525
define go-get-tool
2626
@[ -f $(1) ] || { \
@@ -46,7 +46,7 @@ CONTROLLER_GEN := $(TOOLS_BIN_DIR)/$(CONTROLLER_GEN_BIN)
4646
CRD_OPTIONS ?= "crd:crdVersions=v1"
4747

4848
$(CONTROLLER_GEN): $(TOOLS_BIN_DIR)
49-
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.6.1)
49+
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.14.0)
5050

5151
KEPLOY_VER := v0.7.12
5252
KEPLOY_BIN := server-$(KEPLOY_VER)
@@ -72,13 +72,10 @@ clean: ## Remove build related file
7272
rm -fr ./bin vendor hack/tools/bin
7373
rm -f ./junit-report.xml checkstyle-report.xml ./coverage.xml ./profile.cov yamllint-checkstyle.xml
7474

75-
vendor: ## Copy of all packages needed to support builds and tests in the vendor directory
76-
$(GOCMD) mod vendor
77-
7875
## Test:
7976
test: run-keploy ## Run the tests of the project
8077
ifeq ($(EXPORT_RESULT), true)
81-
GO111MODULE=off go get -u github.com/jstemmer/go-junit-report
78+
go install github.com/jstemmer/go-junit-report
8279
$(eval OUTPUT_OPTIONS = | tee /dev/tty | go-junit-report -set-exit-code > junit-report.xml)
8380
endif
8481
$(GOTEST) -v -race ./... $(OUTPUT_OPTIONS)
@@ -88,26 +85,25 @@ coverage: run-keploy ## Run the tests of the project and export the coverage
8885
$(GOTEST) -cover -covermode=count -coverprofile=profile.cov ./...
8986
$(GOCMD) tool cover -func profile.cov
9087
ifeq ($(EXPORT_RESULT), true)
91-
GO111MODULE=off go get -u github.com/AlekSi/gocov-xml
92-
GO111MODULE=off go get -u github.com/axw/gocov/gocov
88+
go install github.com/AlekSi/gocov-xml
89+
go install github.com/axw/gocov/gocov
9390
gocov convert profile.cov | gocov-xml > coverage.xml
9491
endif
9592
@$(MAKE) stop-keploy
9693

97-
9894
## Lint:
9995
lint: lint-go lint-yaml lint-kubebuilder ## Run all available linters
10096

10197
lint-go: ## Use golintci-lint on your project
10298
$(eval OUTPUT_OPTIONS = $(shell [ "${EXPORT_RESULT}" == "true" ] && echo "--out-format checkstyle ./... | tee /dev/tty > checkstyle-report.xml" || echo "" ))
103-
docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:latest-alpine golangci-lint run --enable gofmt --fix --enable gofumpt --deadline=300s $(OUTPUT_OPTIONS)
99+
docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:latest-alpine golangci-lint run --enable gofmt --fix --enable gofumpt $(OUTPUT_OPTIONS)
104100

105101
lint-yaml: ## Use yamllint on the yaml file of your projects
106102
ifeq ($(EXPORT_RESULT), true)
107-
GO111MODULE=off go get -u github.com/thomaspoignant/yamllint-checkstyle
103+
go install github.com/thomaspoignant/yamllint-checkstyle
108104
$(eval OUTPUT_OPTIONS = | tee /dev/tty | yamllint-checkstyle > yamllint-checkstyle.xml)
109105
endif
110-
docker run --rm -it -v $(shell pwd):/data cytopia/yamllint -d relaxed -f parsable $(shell git ls-files '*.yml' '*.yaml') $(OUTPUT_OPTIONS)
106+
docker run --rm -it -v $(shell pwd):/data cytopia/yamllint -c yamllint-config.yaml -f parsable $(shell git ls-files '*.yml' '*.yaml') $(OUTPUT_OPTIONS)
111107

112108
.PHONY: lint-kubebuilder
113109
lint-kubebuilder: $(CONTROLLER_GEN) ## Lint Kubebuilder annotations by generating objects and checking if it is successful

environment/types/types.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ var ErrNotFound = fmt.Errorf("environment key not found")
1818
// the underlying infrastructure.
1919
type ApiCredentials struct {
2020
// Username for basic authentication
21-
Username string
21+
Username string `json:"username,omitempty"`
2222
// Password for basic authentication
23-
Password string
23+
Password string `json:"password,omitempty"`
2424
// KeyPair is JSON-encoded key pair for TLS client authentication
25-
KeyPair string
25+
KeyPair string `json:"keyPair,omitempty"`
2626
}
2727

2828
// ManagementEndpoint specifies API endpoint used for interacting with underlying
@@ -31,14 +31,14 @@ type ManagementEndpoint struct {
3131
// ApiCredentials embedded into endpoint
3232
ApiCredentials
3333
// Address is URL of management endpoint
34-
Address *url.URL
34+
Address *url.URL `json:"address,omitempty"`
3535
// Whether to authenticate TLS endpoint in case of HTTPS as transport.
3636
// HTTPS is used for encryption independent of this setting. An
3737
// unauthenticated TLS endpoint is prone to man-in-the-middle attacks.
38-
Insecure bool
38+
Insecure bool `json:"insecure,omitempty"`
3939
// AdditionalTrustBundle is a PEM-encoded certificate bundle to be used
4040
// in addition to system trust store
41-
AdditionalTrustBundle string
41+
AdditionalTrustBundle string `json:"additionalTrustBundle,omitempty"`
4242
}
4343

4444
// Topology is a map of topological domains to topological segments.

go.mod

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@ require (
2626
)
2727

2828
require (
29+
bitbucket.org/creachadair/shell v0.0.6 // indirect
2930
github.com/99designs/gqlgen v0.15.1 // indirect
31+
github.com/AlekSi/gocov-xml v1.1.0 // indirect
3032
github.com/PaesslerAG/gval v1.0.0 // indirect
3133
github.com/agnivade/levenshtein v1.1.1 // indirect
3234
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de // indirect
35+
github.com/axw/gocov v1.1.0 // indirect
36+
github.com/bitfield/script v0.18.0 // indirect
3337
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
3438
github.com/creasty/defaults v1.5.2 // indirect
3539
github.com/davecgh/go-spew v1.1.1 // indirect
@@ -55,6 +59,7 @@ require (
5559
github.com/hashicorp/golang-lru v0.5.4 // indirect
5660
github.com/josharian/intern v1.0.0 // indirect
5761
github.com/json-iterator/go v1.1.12 // indirect
62+
github.com/jstemmer/go-junit-report v1.0.0 // indirect
5863
github.com/k0kubun/pp/v3 v3.1.0 // indirect
5964
github.com/klauspost/compress v1.15.1 // indirect
6065
github.com/leodido/go-urn v1.2.1 // indirect
@@ -70,6 +75,7 @@ require (
7075
github.com/pmezard/go-difflib v1.0.0 // indirect
7176
github.com/russross/blackfriday/v2 v2.1.0 // indirect
7277
github.com/sirupsen/logrus v1.9.0 // indirect
78+
github.com/thomaspoignant/yamllint-checkstyle v1.0.2 // indirect
7379
github.com/tidwall/gjson v1.14.0 // indirect
7480
github.com/tidwall/match v1.1.1 // indirect
7581
github.com/tidwall/pretty v1.2.0 // indirect

go.sum

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
bitbucket.org/creachadair/shell v0.0.6 h1:reJflDbKqnlnqb4Oo2pQ1/BqmY/eCWcNGHrIUO8qIzc=
2+
bitbucket.org/creachadair/shell v0.0.6/go.mod h1:8Qqi/cYk7vPnsOePHroKXDJYmb5x7ENhtiFtfZq8K+M=
13
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
24
github.com/99designs/gqlgen v0.15.1 h1:48bRXecwlCNTa/n2bMSp2rQsXNxwZ54QHbiULNf78ec=
35
github.com/99designs/gqlgen v0.15.1/go.mod h1:nbeSjFkqphIqpZsYe1ULVz0yfH8hjpJdJIQoX/e0G2I=
6+
github.com/AlekSi/gocov-xml v1.1.0 h1:iElWGi7s/MuL8/d8WDtI2fOAsN3ap9x8nK5RrAhaDng=
7+
github.com/AlekSi/gocov-xml v1.1.0/go.mod h1:g1dRVOCHjKkMtlPfW6BokJ/qxoeZ1uPNAK7A/ii3CUo=
48
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
59
github.com/PaesslerAG/gval v1.0.0 h1:GEKnRwkWDdf9dOmKcNrar9EA1bz1z9DqPIO1+iLzhd8=
610
github.com/PaesslerAG/gval v1.0.0/go.mod h1:y/nm5yEyTeX6av0OfKJNp9rBNj2XrGhAf5+v24IBN1I=
@@ -17,8 +21,12 @@ github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de h1:FxWPpzIjnTlhP
1721
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de/go.mod h1:DCaWoUhZrYW9p1lxo/cm8EmUOOzAPSEZNGF2DK1dJgw=
1822
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q=
1923
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE=
24+
github.com/axw/gocov v1.1.0 h1:y5U1krExoJDlb/kNtzxyZQmNRprFOFCutWbNjcQvmVM=
25+
github.com/axw/gocov v1.1.0/go.mod h1:H9G4tivgdN3pYSSVrTFBr6kGDCmAkgbJhtxFzAvgcdw=
2026
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
2127
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
28+
github.com/bitfield/script v0.18.0 h1:F4sg0y06aVb8/rLOpa2RoPXq3aob+oIQP3Xo4tT3c2I=
29+
github.com/bitfield/script v0.18.0/go.mod h1:YGjrl5cZB++zV0DD8/tZmekyjaMDm4UMjatdA84FGj0=
2230
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
2331
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
2432
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
@@ -119,6 +127,8 @@ github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8Hm
119127
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
120128
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
121129
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
130+
github.com/jstemmer/go-junit-report v1.0.0 h1:8X1gzZpR+nVQLAht+L/foqOeX2l9DTZoaIPbEQHxsds=
131+
github.com/jstemmer/go-junit-report v1.0.0/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
122132
github.com/k0kubun/pp/v3 v3.1.0 h1:ifxtqJkRZhw3h554/z/8zm6AAbyO4LLKDlA5eV+9O8Q=
123133
github.com/k0kubun/pp/v3 v3.1.0/go.mod h1:vIrP5CF0n78pKHm2Ku6GVerpZBJvscg48WepUYEk2gw=
124134
github.com/keploy/go-sdk v0.7.2 h1:mvvjDRciMSFTgOF/KIGz38ElJZKkM1WlniaHseaPhpo=
@@ -217,6 +227,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
217227
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
218228
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
219229
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
230+
github.com/thomaspoignant/yamllint-checkstyle v1.0.2 h1:mGgEeBgZhGZ5GUYv1pMEydyh1itMorUaVXmd1xld588=
231+
github.com/thomaspoignant/yamllint-checkstyle v1.0.2/go.mod h1:hfra2golykYl9vaU4GuCbtiQTgNJ5zGpjT9ztxC1MnQ=
220232
github.com/tidwall/gjson v1.14.0 h1:6aeJ0bzojgWLa82gDQHcx3S0Lr/O51I9bJ5nv6JFx5w=
221233
github.com/tidwall/gjson v1.14.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
222234
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
@@ -343,6 +355,7 @@ golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3
343355
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
344356
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
345357
golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
358+
golang.org/x/tools v0.0.0-20190617190820-da514acc4774/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
346359
golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
347360
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
348361
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=

0 commit comments

Comments
 (0)