Skip to content

Commit be02c46

Browse files
authored
Merge pull request #86 from sylabs/impl-user-agent
Add user-agent to library and build-clients
2 parents c940d9e + adca20e commit be02c46

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

cmd/scs-build/build.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func executeBuildCmd(cmd *cobra.Command, args []string) error {
9898
LibraryRef: libraryRef,
9999
SkipTLSVerify: v.GetBool(keySkipTLSVerify),
100100
Force: v.GetBool(keyForceOverwrite),
101+
UserAgent: fmt.Sprintf("scs-build/%v", version),
101102
})
102103
if err != nil {
103104
fmt.Fprintf(os.Stderr, "Application init error: %v\n", err)

internal/app/buildclient/client.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Config struct {
2929
SkipTLSVerify bool
3030
LibraryRef string
3131
Force bool
32+
UserAgent string
3233
}
3334

3435
// App represents the application instance
@@ -77,7 +78,7 @@ func New(ctx context.Context, cfg *Config) (*App, error) {
7778
}
7879

7980
// Initialize build & library clients
80-
if app.buildClient, app.libraryClient, err = getClients(ctx, cfg.SkipTLSVerify, feURL, cfg.AuthToken); err != nil {
81+
if app.buildClient, app.libraryClient, err = getClients(ctx, cfg.SkipTLSVerify, feURL, cfg.AuthToken, cfg.UserAgent); err != nil {
8182
return nil, fmt.Errorf("error initializing client(s): %w", err)
8283
}
8384
return app, nil
@@ -118,7 +119,7 @@ func getFrontendURL(r *library.Ref, urlOverride string) (string, error) {
118119
}
119120

120121
// getClients returns initialized clients for remote build and cloud library
121-
func getClients(ctx context.Context, skipVerify bool, endpoint, authToken string) (*build.Client, *library.Client, error) {
122+
func getClients(ctx context.Context, skipVerify bool, endpoint, authToken, userAgent string) (*build.Client, *library.Client, error) {
122123
feCfg, err := endpoints.GetFrontendConfig(ctx, skipVerify, endpoint)
123124
if err != nil {
124125
return nil, nil, err
@@ -132,6 +133,7 @@ func getClients(ctx context.Context, skipVerify bool, endpoint, authToken string
132133
BaseURL: feCfg.BuildAPI.URI,
133134
AuthToken: authToken,
134135
HTTPClient: &http.Client{Transport: tr},
136+
UserAgent: userAgent,
135137
})
136138
if err != nil {
137139
return nil, nil, fmt.Errorf("error initializing build client: %w", err)
@@ -141,6 +143,7 @@ func getClients(ctx context.Context, skipVerify bool, endpoint, authToken string
141143
BaseURL: feCfg.LibraryAPI.URI,
142144
AuthToken: authToken,
143145
HTTPClient: &http.Client{Transport: tr},
146+
UserAgent: userAgent,
144147
})
145148
if err != nil {
146149
return nil, nil, fmt.Errorf("error initializing library client: %w", err)

0 commit comments

Comments
 (0)