Skip to content

Commit d866b43

Browse files
use the first rid, and set user agent
1 parent 843cd59 commit d866b43

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ GOTEST=$(GOCMD) test
44
GOVET=$(GOCMD) vet
55
BINARY_NAME=pure-fa-om-exporter
66
MODULE_NAME=purestorage/fa-openmetrics-exporter
7+
UserAgentBase=Pure_FA_OpenMetrics_exporter
78
VERSION?=1.0.18
89
SERVICE_PORT?=9490
910
DOCKER_REGISTRY?= quay.io/purestorage/
@@ -26,11 +27,11 @@ init:
2627

2728
build: ## Build project and put the output binary in out/bin/
2829
mkdir -p out/bin
29-
CGO_ENABLED=0 GO111MODULE=on $(GOCMD) build -a -mod=readonly -tags 'netgo osusergo static_build' -ldflags="-X 'main.version=v$(VERSION)' -X 'purestorage/fa-openmetrics-exporter/internal/rest-client.UserAgentVersion=$(VERSION)'" -o out/bin/$(BINARY_NAME) cmd/fa-om-exporter/main.go
30+
CGO_ENABLED=0 GO111MODULE=on $(GOCMD) build -a -mod=readonly -tags 'netgo osusergo static_build' -ldflags="-X 'main.version=v$(VERSION)' -X 'purestorage/fa-openmetrics-exporter/internal/rest-client.UserAgentVersion=$(VERSION)' -X 'purestorage/fa-openmetrics-exporter/internal/rest-client.FARestUserAgentBase=$(UserAgentBase)'" -o out/bin/$(BINARY_NAME) cmd/fa-om-exporter/main.go
3031

3132
build-with-vendor: ## Build project using the vendor directory and put the output binary in out/bin/
3233
mkdir -p out/bin
33-
CGO_ENABLED=0 GO111MODULE=on $(GOCMD) build -a -mod=vendor -tags 'netgo osusergo static_build' -ldflags="-X 'main.version=v$(VERSION)' -X 'purestorage/fa-openmetrics-exporter/internal/rest-client.UserAgentVersion=$(VERSION)'" -o out/bin/$(BINARY_NAME) cmd/fa-om-exporter/main.go
34+
CGO_ENABLED=0 GO111MODULE=on $(GOCMD) build -a -mod=vendor -tags 'netgo osusergo static_build' -ldflags="-X 'main.version=v$(VERSION)' -X 'purestorage/fa-openmetrics-exporter/internal/rest-client.UserAgentVersion=$(VERSION)' -X 'purestorage/fa-openmetrics-exporter/internal/rest-client.FARestUserAgentBase=$(UserAgentBase)'" -o out/bin/$(BINARY_NAME) cmd/fa-om-exporter/main.go
3435

3536
clean: ## Remove build related file
3637
rm -fr ./bin

build/docker/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
FROM golang:alpine as build
22
ARG VERSION=1.0.18
3+
ARG UserAgentBase=Pure_FA_OpenMetrics_exporter
34

45
WORKDIR /usr/src/app
56

@@ -9,7 +10,7 @@ RUN go mod download && go mod verify
910

1011
COPY . .
1112

12-
RUN CGO_ENABLED=1 go build -mod=readonly -a -tags 'netgo osusergo static_build' -ldflags="-X 'main.version=v$VERSION' -X 'purestorage/fa-openmetrics-exporter/internal/rest-client.UserAgentVersion=$VERSION'" -v -o /usr/local/bin/pure-fa-om-exporter cmd/fa-om-exporter/main.go
13+
RUN CGO_ENABLED=1 go build -mod=readonly -a -tags 'netgo osusergo static_build' -ldflags="-X 'main.version=v$VERSION' -X 'purestorage/fa-openmetrics-exporter/internal/rest-client.FARestUserAgentBase=$UserAgentBase' -X 'purestorage/fa-openmetrics-exporter/internal/rest-client.UserAgentVersion=$VERSION'" -v -o /usr/local/bin/pure-fa-om-exporter cmd/fa-om-exporter/main.go
1314

1415

1516
# alpine is used here as it seems to be the minimal image that passes quay.io vulnerability scan

internal/rest-client/flasharray_client.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import (
99

1010
var UserAgentVersion string = "development"
1111

12-
var FARestUserAgent string = "Pure_FA_OpenMetrics_exporter/" + UserAgentVersion
12+
var FARestUserAgentBase string = "Dev_Pure_FA_OpenMetrics_exporter"
13+
14+
var FARestUserAgent string = FARestUserAgentBase + "/" + UserAgentVersion
1315

1416
type Client interface {
1517
GetAlerts(filter string) *AlertsList
@@ -56,6 +58,7 @@ func NewRestClient(endpoint string, apitoken string, apiversion string, uagent s
5658
"Content-Type": "application/json",
5759
"Accept": "application/json",
5860
"X-Request-ID": fa.XRequestID,
61+
"User-Agent": FARestUserAgent + " (" + uagent + ")",
5962
})
6063
if debug {
6164
fa.RestClient.SetDebug(true)
@@ -86,7 +89,9 @@ func NewRestClient(endpoint string, apitoken string, apiversion string, uagent s
8689
} else {
8790
fa.ApiVersion = apiversion
8891
}
92+
fa.XRequestID = res.Header().Get("X-Request-ID")
8993
fa.RestClient.SetBaseURL("https://" + endpoint + "/api/" + fa.ApiVersion)
94+
fa.RestClient.SetHeader("X-Request-ID", fa.XRequestID)
9095
res, err = fa.RestClient.R().
9196
SetHeader("api-token", apitoken).
9297
Post("/login")
@@ -98,13 +103,8 @@ func NewRestClient(endpoint string, apitoken string, apiversion string, uagent s
98103
fa.Error = errors.New("failed to login to FlashArray, check API Token")
99104
return fa
100105
}
101-
//Get the X-Auth-Token and the X-Request-ID from the HTTP Response Headers (FA will reply with the same X-Request-ID, if provided, otherwise it will generate one.)
102106
fa.XAuthToken = res.Header().Get("x-auth-token")
103-
fa.XRequestID = res.Header().Get("X-Request-ID")
104-
fa.RestClient.SetHeader("User-Agent", FARestUserAgent+" ("+uagent+")")
105-
//Set the X-Auth-Token and the X-Request-ID from the HTTP Response Headers
106107
fa.RestClient.SetHeader("x-auth-token", fa.XAuthToken)
107-
fa.RestClient.SetHeader("X-Request-ID", fa.XRequestID)
108108
return fa
109109
}
110110

0 commit comments

Comments
 (0)