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

Set rekor-cli User-Agent header on requests #684

Merged
merged 1 commit into from
Feb 18, 2022
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
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