Skip to content
This repository was archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Do not pass around signing key when unnecessary
Browse files Browse the repository at this point in the history
The working checkout already holds the configuration for git, which
includes the key that should be used when doing signing operations with
git.

Default to the one in the configuration but leave the option open to
pass along a different key for specific operations.
  • Loading branch information
hiddeco committed Feb 14, 2019
1 parent 0bcef28 commit ccfeab6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
16 changes: 7 additions & 9 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (

"github.com/weaveworks/flux"
"github.com/weaveworks/flux/api"
"github.com/weaveworks/flux/api/v10"
"github.com/weaveworks/flux/api/v11"
"github.com/weaveworks/flux/api/v6"
"github.com/weaveworks/flux/api/v9"
v10 "github.com/weaveworks/flux/api/v10"
v11 "github.com/weaveworks/flux/api/v11"
v6 "github.com/weaveworks/flux/api/v6"
v9 "github.com/weaveworks/flux/api/v9"
"github.com/weaveworks/flux/cluster"
"github.com/weaveworks/flux/event"
"github.com/weaveworks/flux/git"
Expand Down Expand Up @@ -419,9 +419,8 @@ func (d *Daemon) updatePolicy(spec update.Spec, updates policy.Updates) updateFu
commitAuthor = spec.Cause.User
}
commitAction := git.CommitAction{
Author: commitAuthor,
Message: policyCommitMessage(updates, spec.Cause),
SigningKey: d.GitConfig.SigningKey,
Author: commitAuthor,
Message: policyCommitMessage(updates, spec.Cause),
}
if err := working.CommitAndPush(ctx, commitAction, &note{JobID: jobID, Spec: spec}); err != nil {
// On the chance pushing failed because it was not
Expand Down Expand Up @@ -465,9 +464,8 @@ func (d *Daemon) release(spec update.Spec, c release.Changes) updateFunc {
commitAuthor = spec.Cause.User
}
commitAction := git.CommitAction{
Author: commitAuthor,
Author: commitAuthor,
Message: commitMsg,
SigningKey: d.GitConfig.SigningKey,
}
if err := working.CommitAndPush(ctx, commitAction, &note{JobID: jobID, Spec: spec, Result: result}); err != nil {
// On the chance pushing failed because it was not
Expand Down
6 changes: 4 additions & 2 deletions git/gittest/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func TestSignedCommit(t *testing.T) {
defer gpgCleanup()

config := TestConfig
config.SigningKey = signingKey
config.GPGHomeDir = gpgHome
checkout, repo, cleanup := CheckoutWithConfig(t, config)
defer cleanup()
Expand All @@ -88,7 +89,7 @@ func TestSignedCommit(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

commitAction := git.CommitAction{Message: "Changed file", SigningKey: signingKey}
commitAction := git.CommitAction{Message: "Changed file"}
if err := checkout.CommitAndPush(ctx, commitAction, nil); err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -123,14 +124,15 @@ func TestSignedTag(t *testing.T) {
defer gpgCleanup()

config := TestConfig
config.SigningKey = signingKey
config.GPGHomeDir = gpgHome
checkout, _, cleanup := CheckoutWithConfig(t, config)
defer cleanup()

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

tagAction := git.TagAction{Revision: "HEAD", Message: "Sync pointer", SigningKey: signingKey}
tagAction := git.TagAction{Revision: "HEAD", Message: "Sync pointer"}
if err := checkout.MoveSyncTagAndPush(ctx, tagAction); err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 3 additions & 0 deletions git/working.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ func (c *Checkout) CommitAndPush(ctx context.Context, commitAction CommitAction,
}

commitAction.Message += c.config.SkipMessage
if commitAction.SigningKey == "" {
commitAction.SigningKey = c.config.SigningKey
}

if err := commit(ctx, c.dir, c.config.GPGHomeDir, commitAction); err != nil {
return err
Expand Down

0 comments on commit ccfeab6

Please sign in to comment.