diff --git a/cmd/rekor-cli/app/get.go b/cmd/rekor-cli/app/get.go index 836277658a21da540d8c6f03c05750965f983a85..ee1b1085ab479773059f9cc82e7abf3469c1928a 100644 --- a/cmd/rekor-cli/app/get.go +++ b/cmd/rekor-cli/app/get.go @@ -79,7 +79,7 @@ var getCmd = &cobra.Command{ } }, Run: format.WrapCmd(func(args []string) (interface{}, error) { - rekorClient, err := client.GetRekorClient(viper.GetString("rekor_server")) + rekorClient, err := client.GetRekorClient(viper.GetString("rekor_server"), client.WithUserAgent(UserAgent())) if err != nil { return nil, err } diff --git a/cmd/rekor-cli/app/log_info.go b/cmd/rekor-cli/app/log_info.go index 2efd79dd9697a08c5ac761b4352e9544c4a9495b..0bfc92530115af0cd70a16e9d3b88fa5ffa989bc 100644 --- a/cmd/rekor-cli/app/log_info.go +++ b/cmd/rekor-cli/app/log_info.go @@ -62,7 +62,7 @@ var logInfoCmd = &cobra.Command{ Long: `Prints info about the transparency log`, Run: format.WrapCmd(func(args []string) (interface{}, error) { serverURL := viper.GetString("rekor_server") - rekorClient, err := client.GetRekorClient(serverURL) + rekorClient, err := client.GetRekorClient(serverURL, client.WithUserAgent(UserAgent())) if err != nil { return nil, err } diff --git a/cmd/rekor-cli/app/log_proof.go b/cmd/rekor-cli/app/log_proof.go index c682d5b9366c29c2ebcf0546b5b58023c6f07ef5..cc2497c3f6e9c4775f315f534a4aa817726c8c33 100644 --- a/cmd/rekor-cli/app/log_proof.go +++ b/cmd/rekor-cli/app/log_proof.go @@ -72,7 +72,7 @@ var logProofCmd = &cobra.Command{ return nil }, Run: format.WrapCmd(func(args []string) (interface{}, error) { - rekorClient, err := client.GetRekorClient(viper.GetString("rekor_server")) + rekorClient, err := client.GetRekorClient(viper.GetString("rekor_server"), client.WithUserAgent(UserAgent())) if err != nil { return nil, err } diff --git a/cmd/rekor-cli/app/search.go b/cmd/rekor-cli/app/search.go index f742e06db8421f48a2be6809f70279916a998f5a..c9123e28cd8e149d12f6a9e8ffc48c78a3bcb932 100644 --- a/cmd/rekor-cli/app/search.go +++ b/cmd/rekor-cli/app/search.go @@ -96,7 +96,7 @@ var searchCmd = &cobra.Command{ }, Run: format.WrapCmd(func(args []string) (interface{}, error) { log := log.CliLogger - rekorClient, err := client.GetRekorClient(viper.GetString("rekor_server")) + rekorClient, err := client.GetRekorClient(viper.GetString("rekor_server"), client.WithUserAgent(UserAgent())) if err != nil { return nil, err } diff --git a/cmd/rekor-cli/app/timestamp.go b/cmd/rekor-cli/app/timestamp.go index 62b6e30269827a6c8e2b5bcbf3eac0fd76d42c60..816c16489cb68e2a552bd57d5c1fc29c0b41254a 100644 --- a/cmd/rekor-cli/app/timestamp.go +++ b/cmd/rekor-cli/app/timestamp.go @@ -139,7 +139,7 @@ var timestampCmd = &cobra.Command{ return nil }, Run: format.WrapCmd(func(args []string) (interface{}, error) { - rekorClient, err := client.GetRekorClient(viper.GetString("rekor_server")) + rekorClient, err := client.GetRekorClient(viper.GetString("rekor_server"), client.WithUserAgent(UserAgent())) if err != nil { return nil, err } diff --git a/cmd/rekor-cli/app/upload.go b/cmd/rekor-cli/app/upload.go index bbededf4eead9439decf7a752f64eaeb5b429699..c85b290593e259df7f5411bb5c3ff215075e64f5 100644 --- a/cmd/rekor-cli/app/upload.go +++ b/cmd/rekor-cli/app/upload.go @@ -73,7 +73,7 @@ var uploadCmd = &cobra.Command{ Long: `This command takes the public key, signature and URL of the release artifact and uploads it to the rekor server.`, Run: format.WrapCmd(func(args []string) (interface{}, error) { ctx := context.Background() - rekorClient, err := client.GetRekorClient(viper.GetString("rekor_server")) + rekorClient, err := client.GetRekorClient(viper.GetString("rekor_server"), client.WithUserAgent(UserAgent())) if err != nil { return nil, err } diff --git a/cmd/rekor-cli/app/useragent.go b/cmd/rekor-cli/app/useragent.go new file mode 100644 index 0000000000000000000000000000000000000000..983af143254659dc58e544be0ebeb35e40b51c0e --- /dev/null +++ b/cmd/rekor-cli/app/useragent.go @@ -0,0 +1,34 @@ +// +// Copyright 2022 The Sigstore Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package app + +import ( + "fmt" + "runtime" + + "sigs.k8s.io/release-utils/version" +) + +var ( + // uaString is meant to resemble the User-Agent sent by browsers with requests. + // See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent + uaString = fmt.Sprintf("rekor-cli/%s (%s; %s)", version.GetVersionInfo().GitVersion, runtime.GOOS, runtime.GOARCH) +) + +// UserAgent returns the User-Agent string which `rekor-cli` should send with HTTP requests. +func UserAgent() string { + return uaString +} diff --git a/cmd/rekor-cli/app/verify.go b/cmd/rekor-cli/app/verify.go index 76fbb9419e011c767dedcf4c228472fd8176dad4..f11d96222cd3c7b82a8ea4fc41bb4670f48eb354 100644 --- a/cmd/rekor-cli/app/verify.go +++ b/cmd/rekor-cli/app/verify.go @@ -87,7 +87,7 @@ var verifyCmd = &cobra.Command{ return nil }, Run: format.WrapCmd(func(args []string) (interface{}, error) { - rekorClient, err := client.GetRekorClient(viper.GetString("rekor_server")) + rekorClient, err := client.GetRekorClient(viper.GetString("rekor_server"), client.WithUserAgent(UserAgent())) if err != nil { return nil, err }