Skip to content

Commit

Permalink
OCM-10455 | feat: Add a user agent config
Browse files Browse the repository at this point in the history
This is needed by arbitrary services which use the client
package to communicate with ocm / rosa.

Signed-off-by: Ahmed Abdalla <aabdelre@redhat.com>
  • Loading branch information
devguyio committed Aug 16, 2024
1 parent 94e13ba commit 3880654
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type Config struct {
Scopes []string `json:"scopes,omitempty" doc:"OpenID scope."`
TokenURL string `json:"token_url,omitempty" doc:"OpenID token URL."`
URL string `json:"url,omitempty" doc:"URL of the API gateway."`
UserAgent string `json:"user_agent,omitempty" doc:"OCM clients UserAgent. Default value is used if not set."`
FedRAMP bool `json:"fedramp,omitempty" doc:"Indicates FedRAMP."`
}

Expand Down
1 change: 1 addition & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var _ = Describe("Config", Ordered, func() {
"scopes": "OpenID scope.",
"token_url": "OpenID token URL.",
"url": "URL of the API gateway.",
"user_agent": "OCM clients UserAgent. Default value is used if not set.",
"fedramp": "Indicates FedRAMP.",
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ const Version = "1.2.45"
// Build contains the short Git SHA of the CLI at the point it was build. Set via `-ldflags` at build time
var Build = "local"

const UserAgent = "ROSACLI"
const DefaultUserAgent = "ROSACLI"
7 changes: 6 additions & 1 deletion pkg/ocm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ func (b *ClientBuilder) Build() (result *Client, err error) {
// values in the configuration, so that default values won't be overridden:
builder := sdk.NewConnectionBuilder()
builder.Logger(logger)
builder.Agent(info.UserAgent + "/" + info.Version + " " + sdk.DefaultAgent)

userAgent := info.DefaultUserAgent
if b.cfg.UserAgent != "" {
userAgent = b.cfg.UserAgent
}
builder.Agent(userAgent + "/" + info.Version + " " + sdk.DefaultAgent)
if b.cfg.TokenURL != "" {
builder.TokenURL(b.cfg.TokenURL)
}
Expand Down

0 comments on commit 3880654

Please sign in to comment.