From 14f7d2ce1819132d0bf369c7296b601b49a392dc Mon Sep 17 00:00:00 2001 From: Jimmi Dyson Date: Mon, 31 Jul 2023 11:04:57 +0100 Subject: [PATCH] feat: Add mindthegap to useragent (#476) --- cmd/mindthegap/create/imagebundle/image_bundle.go | 8 +++++++- cmd/mindthegap/push/bundle/bundle.go | 10 ++++++++-- cmd/mindthegap/utils/useragent.go | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 cmd/mindthegap/utils/useragent.go diff --git a/cmd/mindthegap/create/imagebundle/image_bundle.go b/cmd/mindthegap/create/imagebundle/image_bundle.go index 5b1c1054..89f43aab 100644 --- a/cmd/mindthegap/create/imagebundle/image_bundle.go +++ b/cmd/mindthegap/create/imagebundle/image_bundle.go @@ -23,6 +23,7 @@ import ( "github.com/mesosphere/mindthegap/archive" "github.com/mesosphere/mindthegap/cleanup" + "github.com/mesosphere/mindthegap/cmd/mindthegap/utils" "github.com/mesosphere/mindthegap/config" "github.com/mesosphere/mindthegap/docker/registry" "github.com/mesosphere/mindthegap/images" @@ -133,7 +134,11 @@ func NewCommand(out output.Output) *cobra.Command { tr.CloseIdleConnections() } }() - destRemoteOpts := []remote.Option{remote.WithTransport(destTLSRoundTripper), remote.WithContext(egCtx)} + destRemoteOpts := []remote.Option{ + remote.WithTransport(destTLSRoundTripper), + remote.WithContext(egCtx), + remote.WithUserAgent(utils.Useragent()), + } out.StartOperationWithProgress(pullGauge) @@ -165,6 +170,7 @@ func NewCommand(out output.Output) *cobra.Command { remote.WithTransport(sourceTLSRoundTripper), remote.WithAuthFromKeychain(keychain), remote.WithContext(egCtx), + remote.WithUserAgent(utils.Useragent()), } platformsStrings := make([]string, 0, len(platforms)) diff --git a/cmd/mindthegap/push/bundle/bundle.go b/cmd/mindthegap/push/bundle/bundle.go index 370f28af..3dd19863 100644 --- a/cmd/mindthegap/push/bundle/bundle.go +++ b/cmd/mindthegap/push/bundle/bundle.go @@ -107,7 +107,10 @@ func NewCommand(out output.Output, bundleCmdName string) *cobra.Command { out.Error(err, "error configuring TLS for source registry") os.Exit(2) } - sourceRemoteOpts := []remote.Option{remote.WithTransport(sourceTLSRoundTripper)} + sourceRemoteOpts := []remote.Option{ + remote.WithTransport(sourceTLSRoundTripper), + remote.WithUserAgent(utils.Useragent()), + } destTLSRoundTripper, err := httputils.TLSConfiguredRoundTripper( remote.DefaultTransport, @@ -119,7 +122,10 @@ func NewCommand(out output.Output, bundleCmdName string) *cobra.Command { out.Error(err, "error configuring TLS for destination registry") os.Exit(2) } - destRemoteOpts := []remote.Option{remote.WithTransport(destTLSRoundTripper)} + destRemoteOpts := []remote.Option{ + remote.WithTransport(destTLSRoundTripper), + remote.WithUserAgent(utils.Useragent()), + } var destNameOpts []name.Option if flags.SkipTLSVerify(destRegistrySkipTLSVerify, &destRegistryURI) { diff --git a/cmd/mindthegap/utils/useragent.go b/cmd/mindthegap/utils/useragent.go new file mode 100644 index 00000000..bc239b0d --- /dev/null +++ b/cmd/mindthegap/utils/useragent.go @@ -0,0 +1,14 @@ +// Copyright 2023 D2iQ, Inc. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +package utils + +import ( + "fmt" + + "github.com/mesosphere/dkp-cli-runtime/core/cmd/version" +) + +func Useragent() string { + return fmt.Sprintf("mindthegap/%s", version.GetVersion().GitVersion) +}