Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cone version to user agent info #114

Merged
merged 5 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/cone/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ func main() {
// Notify the channel for specified signals
signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM)

ctx, cancel := context.WithCancel(context.Background())
ctx := context.WithValue(context.Background(), client.VersionKey, version)
ctx, cancel := context.WithCancel(ctx)

go func() {
// Block until a signal is received
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (

require (
github.com/conductorone/baton-sdk v0.2.35
github.com/conductorone/conductorone-sdk-go v1.22.0
github.com/conductorone/conductorone-sdk-go v1.23.0
github.com/pterm/pterm v0.12.62
github.com/toqueteos/webbrowser v1.2.0
github.com/xhit/go-str2duration/v2 v2.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/conductorone/baton-sdk v0.2.35 h1:aSdNvlM5HMti8WdhotrXTHWs+b+BmSqMxtGwsSUFxjY=
github.com/conductorone/baton-sdk v0.2.35/go.mod h1:hmd/Oz3DPIKD+9QmkusZaA18ZoiinnTDdrxh2skcdUc=
github.com/conductorone/conductorone-sdk-go v1.22.0 h1:sz9nz/85YZ0pJ/U3b63QEzE3WMSz6HuCjRTi/kb3mbU=
github.com/conductorone/conductorone-sdk-go v1.22.0/go.mod h1:vr3946WqFYEpOuIGy/TqXkarhhCzHSKsmXXsxCmeIj8=
github.com/conductorone/conductorone-sdk-go v1.23.0 h1:xRWsFNztcFEx4w+e1RRNbUyKaXzrIXk8htASQMAE39g=
github.com/conductorone/conductorone-sdk-go v1.23.0/go.mod h1:vr3946WqFYEpOuIGy/TqXkarhhCzHSKsmXXsxCmeIj8=
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=
github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
Expand Down
12 changes: 12 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"context"
"fmt"
"net/http"
"net/url"
"strconv"
Expand All @@ -16,6 +17,10 @@ import (

const ConeClientID = "2RGdOS94VDferT9e80mdgntl36K"

type contextKey string

const VersionKey contextKey = "version"

type client struct {
httpClient *http.Client
clientName string
Expand Down Expand Up @@ -132,9 +137,16 @@ func New(
}
c.baseURL = &apiURL

var version = "dev"

if v := ctx.Value(VersionKey).(string); v != "" {
version = v
}

c.sdk = sdk.New(
sdk.WithClient(uclient),
sdk.WithServerURL(apiURL.String()),
sdk.WithExtraUserAgent(fmt.Sprintf("cone/%s", version)),
)

return c, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"crypto/tls"
"errors"
"fmt"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -33,6 +34,12 @@ func WithTenant(input string) (SDKOption, error) {
return func(api *ConductoroneAPI) {}, nil
}

func WithExtraUserAgent(userAgent string) SDKOption {
return func(sdk *ConductoroneAPI) {
sdk.sdkConfiguration.UserAgent = fmt.Sprintf("%s %s", userAgent, sdk.sdkConfiguration.UserAgent)
}
}

type CustomSDKOption func(*CustomOptions)

func WithTenantCustom(input string) (CustomSDKOption, error) {
Expand Down
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ github.com/cenkalti/backoff/v4
github.com/conductorone/baton-sdk/pb/c1/connector/v2
github.com/conductorone/baton-sdk/pkg/crypto/providers
github.com/conductorone/baton-sdk/pkg/crypto/providers/jwk
# github.com/conductorone/conductorone-sdk-go v1.22.0
# github.com/conductorone/conductorone-sdk-go v1.23.0
## explicit; go 1.21
github.com/conductorone/conductorone-sdk-go
github.com/conductorone/conductorone-sdk-go/internal/hooks
Expand Down
Loading