From 042374e2d67fb750712481db4fb330d685ff7d34 Mon Sep 17 00:00:00 2001 From: Luca Di Maio Date: Wed, 13 Dec 2023 16:23:52 +0100 Subject: [PATCH] fix: move to gitcredentials package Signed-off-by: Luca Di Maio --- cmd/agent/workspace/setup_gpg.go | 11 +++++++---- pkg/gitcredentials/gitcredentials.go | 11 +++++++++++ pkg/gpg/gpg_forwarding.go | 13 ------------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/cmd/agent/workspace/setup_gpg.go b/cmd/agent/workspace/setup_gpg.go index 6c3f2c365..6de0621d6 100644 --- a/cmd/agent/workspace/setup_gpg.go +++ b/cmd/agent/workspace/setup_gpg.go @@ -5,6 +5,7 @@ import ( "encoding/base64" "github.com/loft-sh/devpod/cmd/flags" + "github.com/loft-sh/devpod/pkg/gitcredentials" "github.com/loft-sh/devpod/pkg/gpg" "github.com/loft-sh/log" "github.com/spf13/cobra" @@ -117,10 +118,12 @@ func (cmd *SetupGPGCmd) Run(ctx context.Context) error { return err } - logger.Debugf("Setup git signing key") - err = gpgConf.SetupGpgGitKey() - if err != nil { - return err + if gpgConf.GitKey != "" { + logger.Debugf("Setup git signing key") + err = gitcredentials.SetupGpgGitKey(gpgConf.GitKey) + if err != nil { + return err + } } return nil diff --git a/pkg/gitcredentials/gitcredentials.go b/pkg/gitcredentials/gitcredentials.go index 9ad794a1a..234ff6ab5 100644 --- a/pkg/gitcredentials/gitcredentials.go +++ b/pkg/gitcredentials/gitcredentials.go @@ -208,6 +208,17 @@ func GetCredentials(requestObj *GitCredentials) (*GitCredentials, error) { return Parse(string(stdout)) } +func SetupGpgGitKey(gitSignKey string) error { + gitConfigCmd := exec.Command("git", []string{"config", "--global", "user.signingKey", gitSignKey}...) + + out, err := gitConfigCmd.Output() + if err != nil { + return errors.Wrap(err, "git signkey: "+string(out)) + } + + return nil +} + func removeCredentialHelper(content string) string { scan := scanner.NewScanner(strings.NewReader(content)) diff --git a/pkg/gpg/gpg_forwarding.go b/pkg/gpg/gpg_forwarding.go index c39b03041..b8132eec4 100644 --- a/pkg/gpg/gpg_forwarding.go +++ b/pkg/gpg/gpg_forwarding.go @@ -89,19 +89,6 @@ func (g *GPGConf) ImportOwnerTrust() error { return gpgOwnerTrustCmd.Run() } -func (g *GPGConf) SetupGpgGitKey() error { - if g.GitKey != "" { - gitConfigCmd := exec.Command("git", []string{"config", "--global", "user.signingKey", g.GitKey}...) - - out, err := gitConfigCmd.Output() - if err != nil { - return fmt.Errorf("git signkey: %s", string(out)) - } - } - - return nil -} - func (g *GPGConf) SetupGpgConf() error { _, err := os.Stat(g.getConfigPath()) if err != nil {