Skip to content

Commit

Permalink
Set rekor-cli User-Agent header on requests (#684)
Browse files Browse the repository at this point in the history
This sets the User-Agent header to match the format used in cosign of

rekor-cli/vX.Y.Z (OS) (ARCH)

Signed-off-by: Bob Callaway <bob.callaway@gmail.com>
  • Loading branch information
bobcallaway authored Feb 18, 2022
1 parent 520c328 commit 057b017
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/rekor-cli/app/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/rekor-cli/app/log_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/rekor-cli/app/log_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/rekor-cli/app/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/rekor-cli/app/timestamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/rekor-cli/app/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
34 changes: 34 additions & 0 deletions cmd/rekor-cli/app/useragent.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion cmd/rekor-cli/app/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 057b017

Please sign in to comment.