Skip to content

Commit

Permalink
Bit of refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
Otávio Fernandes committed Mar 30, 2019
1 parent 50ece29 commit 5f33701
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions pkg/vault-handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,16 @@ func (h *Handler) Upload(manifest *Manifest) error {
uploadPerPath := make(map[string]map[string]interface{})
logger := h.logger.WithField("action", "upload")

if err = h.loop(logger, manifest, func(logger *log.Entry, group, vaultPath string, data SecretData) error {
fn := func(logger *log.Entry, group, vaultPath string, data SecretData) error {
var err error

logger.Info("Handling file")
file := NewFile(group, &data, []byte{})

if err = file.Read(h.config.InputDir); err != nil {
logger.Error("error on reading file", err)
return err
}

if data.Zip {
if err = file.Zip(); err != nil {
logger.Error("error on zipping payload", err)
Expand All @@ -62,7 +63,9 @@ func (h *Handler) Upload(manifest *Manifest) error {
uploadPerPath[vaultPath][data.Name] = string(file.Payload())

return nil
}); err != nil {
}

if err = h.loop(logger, manifest, fn); err != nil {
return err
}

Expand All @@ -78,12 +81,11 @@ func (h *Handler) Upload(manifest *Manifest) error {

// Download files from vault based on manifest.
func (h *Handler) Download(manifest *Manifest) error {
var err error

logger := h.logger.WithField("action", "download")

return h.loop(logger, manifest, func(logger *log.Entry, group, vaultPath string, data SecretData) error {
fn := func(logger *log.Entry, group, vaultPath string, data SecretData) error {
var payload []byte
var err error

vaultPath = h.composeVaultPath(data, vaultPath)
logger = logger.WithField("vaultPath", vaultPath)
Expand All @@ -104,7 +106,9 @@ func (h *Handler) Download(manifest *Manifest) error {

logger.Info("Persisting in file-system")
return h.persist(file)
})
}

return h.loop(logger, manifest, fn)
}

// loop execute the primary manifest item loop, yielding informed method.
Expand Down

0 comments on commit 5f33701

Please sign in to comment.