Skip to content

Commit 0c2d71e

Browse files
authored
Check user namespace before using the default one (#726)
1 parent 090e4e6 commit 0c2d71e

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

pkg/api/v1/project/integration.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package project
22

33
import (
4-
"strings"
5-
64
"go.mongodb.org/atlas/mongodbatlas"
75

86
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/common"
@@ -84,7 +82,7 @@ func (i Integration) ToAtlas(c client.Client, defaultNS string) (result *mongodb
8482
return
8583
}
8684

87-
*target, err = passwordField.ReadPassword(c, defaultNS)
85+
*target, err = passwordField.ReadPassword(c, getNamespace(passwordField.Namespace, defaultNS))
8886
storeError(err, errors)
8987
}
9088

@@ -117,6 +115,13 @@ func storeError(err error, errors *[]error) {
117115
}
118116
}
119117

120-
func RemoveStarsFromString(str string) string {
121-
return strings.ReplaceAll(str, "*", "")
118+
// getNamespace returns first non-empty namespace from the list
119+
func getNamespace(namespaces ...string) string {
120+
for _, namespace := range namespaces {
121+
if namespace != "" {
122+
return namespace
123+
}
124+
}
125+
126+
return ""
122127
}

test/e2e/integration_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func integrationCycle(data *model.TestDataProvider, key string) {
106106

107107
dog, err := atlasClient.GetIntegrationbyType(data.Project.ID(), integrationType)
108108
Expect(err).ShouldNot(HaveOccurred())
109-
Expect(strings.HasSuffix(key, project.RemoveStarsFromString(dog.APIKey))).Should(BeTrue())
109+
Expect(strings.HasSuffix(key, removeStarsFromString(dog.APIKey))).Should(BeTrue())
110110
})
111111

112112
By("Delete integration", func() {
@@ -138,3 +138,7 @@ func GetProjectIntegrationStatus(testData *model.TestDataProvider) string {
138138
}
139139
return ""
140140
}
141+
142+
func removeStarsFromString(str string) string {
143+
return strings.ReplaceAll(str, "*", "")
144+
}

0 commit comments

Comments
 (0)