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

update gitSecret feature to handle git.Export #2429

Merged
merged 2 commits into from
Sep 26, 2019
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/fluxd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,6 @@ func main() {
SigningKey: *gitSigningKey,
SetAuthor: *gitSetAuthor,
SkipMessage: *gitSkipMessage,
GitSecret: *gitSecret,
}

repo := git.NewRepo(gitRemote, git.PollInterval(*gitPollInterval), git.Timeout(*gitTimeout), git.Branch(*gitBranch), git.IsReadOnly(*gitReadonly))
Expand Down Expand Up @@ -694,6 +693,7 @@ func main() {
JobStatusCache: &job.StatusCache{Size: 100},
Logger: log.With(logger, "component", "daemon"),
ManifestGenerationEnabled: *manifestGeneration,
GitSecretEnabled: *gitSecret,
LoopVars: &daemon.LoopVars{
SyncInterval: *syncInterval,
SyncState: syncProvider,
Expand Down
11 changes: 11 additions & 0 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type Daemon struct {
EventWriter event.EventWriter
Logger log.Logger
ManifestGenerationEnabled bool
GitSecretEnabled bool
// bookkeeping
*LoopVars
}
Expand Down Expand Up @@ -659,6 +660,11 @@ func (d *Daemon) WithWorkingClone(ctx context.Context, fn func(*git.Checkout) er
return err
}
defer co.Clean()
if d.GitSecretEnabled {
if err := co.SecretUnseal(ctx); err != nil {
return err
}
}
return fn(co)
}

Expand All @@ -675,6 +681,11 @@ func (d *Daemon) WithReadonlyClone(ctx context.Context, fn func(*git.Export) err
return err
}
defer co.Clean()
if d.GitSecretEnabled {
if err := co.SecretUnseal(ctx); err != nil {
return err
}
}
return fn(co)
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/daemon/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ func (d *Daemon) Sync(ctx context.Context, started time.Time, newRevision string
cancel()
defer working.Clean()

// Unseal any secrets if enabled
if d.GitSecretEnabled {
ctxt, cancel := context.WithTimeout(ctx, d.GitTimeout)
if err := working.SecretUnseal(ctxt); err != nil {
return err
}
cancel()
}

// Retrieve change set of commits we need to sync
c, err := getChangeSet(ctx, ratchet, newRevision, d.Repo, d.GitTimeout, d.GitConfig.Paths)
if err != nil {
Expand Down
11 changes: 8 additions & 3 deletions pkg/git/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,17 @@ func (r *Repo) Export(ctx context.Context, ref string) (*Export, error) {
return &Export{dir}, nil
}

// SecretUnseal unseals git secrets in the clone.
func (e *Export) SecretUnseal(ctx context.Context) error {
return secretUnseal(ctx, e.Dir())
}

// ChangedFiles does a git diff listing changed files
func (c *Export) ChangedFiles(ctx context.Context, sinceRef string, paths []string) ([]string, error) {
list, err := changed(ctx, c.Dir(), sinceRef, paths)
func (e *Export) ChangedFiles(ctx context.Context, sinceRef string, paths []string) ([]string, error) {
list, err := changed(ctx, e.Dir(), sinceRef, paths)
if err == nil {
for i, file := range list {
list[i] = filepath.Join(c.Dir(), file)
list[i] = filepath.Join(e.Dir(), file)
}
}
return list, err
Expand Down
6 changes: 5 additions & 1 deletion pkg/git/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ func mirror(ctx context.Context, workingDir, repoURL string) (path string, err e

func checkout(ctx context.Context, workingDir, ref string) error {
args := []string{"checkout", ref, "--"}
return execGitCmd(ctx, args, gitCmdConfig{dir: workingDir})
err := execGitCmd(ctx, args, gitCmdConfig{dir: workingDir})
if err != nil {
return err
}
return nil
}

func add(ctx context.Context, workingDir, path string) error {
Expand Down
7 changes: 0 additions & 7 deletions pkg/git/working.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ type Config struct {
SigningKey string
SetAuthor bool
SkipMessage string
GitSecret bool
}

// Checkout is a local working clone of the remote repo. It is
Expand Down Expand Up @@ -101,12 +100,6 @@ func (r *Repo) Clone(ctx context.Context, conf Config) (*Checkout, error) {
}
r.mu.RUnlock()

if conf.GitSecret {
if err := secretUnseal(ctx, repoDir); err != nil {
return nil, err
}
}

return &Checkout{
Export: &Export{dir: repoDir},
upstream: upstream,
Expand Down