Skip to content

Commit

Permalink
fix: move to gitcredentials package
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Di Maio <luca.dimaio1@gmail.com>
  • Loading branch information
89luca89 committed Dec 13, 2023
1 parent fead677 commit 042374e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
11 changes: 7 additions & 4 deletions cmd/agent/workspace/setup_gpg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions pkg/gitcredentials/gitcredentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
13 changes: 0 additions & 13 deletions pkg/gpg/gpg_forwarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 042374e

Please sign in to comment.