Skip to content

Commit

Permalink
Set CDK-CLIENT header to improve analytics (#30)
Browse files Browse the repository at this point in the history
* Set CDK-CLIENT header to improve analytics

* Add version in CDK-CLIENT header
  • Loading branch information
gbecan authored Apr 15, 2024
1 parent 06aba51 commit d96e740
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
goversion: "${{ env.GO_VERSION }}"
ldflags: -X 'github.com/conduktor/ctl/cmd.version=${{ github.event.release.tag_name }}' -X 'github.com/conduktor/ctl/cmd.hash=${{ github.sha }}'
ldflags: -X 'github.com/conduktor/ctl/utils.version=${{ github.event.release.tag_name }}' -X 'github.com/conduktor/ctl/utils.hash=${{ github.sha }}'
project_path: "./"
binary_name: "conduktor"

Expand Down
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Client struct {
}

func Make(token string, baseUrl string, debug bool, key, cert string) (*Client, error) {
restyClient := resty.New().SetDebug(debug).SetHeader("Authorization", "Bearer "+token)
restyClient := resty.New().SetDebug(debug).SetHeader("Authorization", "Bearer "+token).SetHeader("CDK-CLIENT", "CLI/"+utils.GetConduktorVersion())
if (key == "" && cert != "") || (key != "" && cert == "") {
return nil, fmt.Errorf("key and cert must be provided together")
} else if key != "" && cert != "" {
Expand Down
10 changes: 7 additions & 3 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func TestApplyShouldWork(t *testing.T) {
"http://baseUrl/public/v1/topic",
nil,
httpmock.HeaderIs("Authorization", "Bearer "+token).
And(httpmock.HeaderIs("CDK-CLIENT", "CLI/unknown")).
And(httpmock.BodyContainsBytes(topic.Json)),
responder,
)
Expand Down Expand Up @@ -141,7 +142,8 @@ func TestGetShouldWork(t *testing.T) {
"GET",
"http://baseUrl/public/v1/application",
nil,
httpmock.HeaderIs("Authorization", "Bearer "+token),
httpmock.HeaderIs("Authorization", "Bearer "+token).
And(httpmock.HeaderIs("CDK-CLIENT", "CLI/unknown")),
responder,
)

Expand Down Expand Up @@ -262,7 +264,8 @@ func TestDescribeShouldWork(t *testing.T) {
"GET",
"http://baseUrl/public/v1/application/yo",
nil,
httpmock.HeaderIs("Authorization", "Bearer "+token),
httpmock.HeaderIs("Authorization", "Bearer "+token).
And(httpmock.HeaderIs("CDK-CLIENT", "CLI/unknown")),
responder,
)

Expand Down Expand Up @@ -322,7 +325,8 @@ func TestDeleteShouldWork(t *testing.T) {
"DELETE",
"http://baseUrl/public/v1/application/yo",
nil,
httpmock.HeaderIs("Authorization", "Bearer "+token),
httpmock.HeaderIs("Authorization", "Bearer "+token).
And(httpmock.HeaderIs("CDK-CLIENT", "CLI/unknown")),
responder,
)

Expand Down
6 changes: 2 additions & 4 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@ package cmd

import (
"fmt"
"github.com/conduktor/ctl/utils"
"github.com/spf13/cobra"
)

var version = "unknown"
var hash = "unknown"

// versionCmd represents the apply command
var versionCmd = &cobra.Command{
Use: "version",
Short: "Display the version of conduktor",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Version: %s\nHash: %s\n", version, hash)
fmt.Printf("Version: %s\nHash: %s\n", utils.GetConduktorVersion(), utils.GetConduktorHash())
},
}

Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . ./
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-X 'github.com/conduktor/ctl/cmd.version=$version' -X 'github.com/conduktor/ctl/cmd.hash=$hash'" -o /conduktor . && rm -rf /app
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-X 'github.com/conduktor/ctl/utils.version=$version' -X 'github.com/conduktor/ctl/utils.hash=$hash'" -o /conduktor . && rm -rf /app
CMD ["/bin/conduktor"]

FROM alpine:3.19
Expand Down
12 changes: 12 additions & 0 deletions utils/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package utils

var version = "unknown"
var hash = "unknown"

func GetConduktorVersion() string {
return version
}

func GetConduktorHash() string {
return hash
}

0 comments on commit d96e740

Please sign in to comment.