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

Commit

Permalink
fix dst overwrite
Browse files Browse the repository at this point in the history
  • Loading branch information
raffis committed Feb 16, 2021
1 parent e4fa820 commit 51d6bdd
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions controllers/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,19 @@ type VaultWriter interface {
}

// ApplySecret applies the desired secret to vault
func (h *VaultHandler) Write(writer VaultWriter, data map[string]interface{}) (bool, error) {
func (h *VaultHandler) Write(writer VaultWriter, srcData map[string]interface{}) (bool, error) {
var writeBack bool

// Ignore error if there is no path at the destination
dstData, err := h.Read(writer.GetPath())
data, err := h.Read(writer.GetPath())
if err != nil && err != ErrPathNotFound {
return writeBack, err
}

// If no field mapping is configured all fields get mapped with their source field name
mapping := writer.GetFieldMapping()
if len(mapping) == 0 {
for k, _ := range data {
for k, _ := range srcData {
mapping = append(mapping, v1beta1.FieldMapping{
Name: k,
})
Expand All @@ -174,12 +174,12 @@ func (h *VaultHandler) Write(writer VaultWriter, data map[string]interface{}) (b
h.logger.Info("applying fields to vault", "srcField", srcField, "dstField", dstField, "dstPath", writer.GetPath())

// If k8s secret field does not exists return an error
srcValue, ok := data[srcField]
srcValue, ok := srcData[srcField]
if !ok {
return writeBack, ErrFieldNotAvailable
}

_, existingField := dstData[dstField]
_, existingField := data[dstField]

switch {
case !existingField:
Expand Down

0 comments on commit 51d6bdd

Please sign in to comment.