Skip to content

Commit

Permalink
Allow setting a target name to which credentials are synced
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Duchesne committed Jun 20, 2019
1 parent 018cc7d commit 1995888
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions credentials/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ func (credBase *Base) ShouldSync(targetName string, targetTags map[string]string
if credBase.NoSync {
return false
}
if credBase.TargetName != "" && credBase.TargetName != targetName {
return false
}

findMatch := func(match map[string]interface{}) bool {
for key, value := range match {
Expand Down
28 changes: 28 additions & 0 deletions credentials/credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ func TestShouldSyncCredentials(t *testing.T) {
creds: &Base{NoSync: true},
expected: false,
},
{
name: "Non matching target name",
targetName: "Target",
creds: &Base{TargetName: "Other target"},
expected: false,
},
{
name: "Matching target name",
targetName: "Target",
creds: &Base{TargetName: "Target"},
expected: true,
},
{
name: "No filter",
creds: &Base{},
Expand All @@ -47,6 +59,22 @@ func TestShouldSyncCredentials(t *testing.T) {
},
expected: true,
},
{
name: "Match but not target name",
creds: &Base{
TargetName: "Target",
TargetTags: targetTagsMatcher{
DoMatch: map[string]interface{}{
"MyFirstTag": "MyValue",
"MyTag": "MyValue",
},
}},
targetName: "Other",
targetTags: map[string]string{
"MyTag": "MyValue",
},
expected: false,
},
{
name: "Match List Item",
creds: &Base{TargetTags: targetTagsMatcher{
Expand Down

0 comments on commit 1995888

Please sign in to comment.