Skip to content

Commit

Permalink
APPS-1181 Fix read password from credentials (#175)
Browse files Browse the repository at this point in the history
fix read password
  • Loading branch information
korotkov-aerospike authored Mar 28, 2024
1 parent f585c9c commit c1889f6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions pkg/model/aerospike_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ func (c *AerospikeCluster) GetPassword() *string {
return password
}

if c.Credentials != nil && c.Credentials.Password != nil {
c.pwd.Store(c.Credentials.Password)
return c.Credentials.Password
}

if c.Credentials == nil || c.Credentials.PasswordPath == nil {
slog.Warn("No credentials provided to read password")
return nil
Expand Down
14 changes: 11 additions & 3 deletions pkg/model/aerospike_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func TestAerospikeCluster_GetPassword(t *testing.T) {
credentials: &Credentials{
User: nil,
PasswordPath: ptr.String(passwordPath),
AuthMode: nil,
},
expectedPassword: ptr.String("password"),
expectedErr: false,
Expand All @@ -38,7 +37,6 @@ func TestAerospikeCluster_GetPassword(t *testing.T) {
credentials: &Credentials{
User: nil,
PasswordPath: ptr.String("not-existing.txt"),
AuthMode: nil,
},
expectedPassword: nil,
expectedErr: true,
Expand Down Expand Up @@ -82,7 +80,6 @@ func TestAerospikeCluster_GetPasswordCaching(t *testing.T) {
Credentials: &Credentials{
User: nil,
PasswordPath: ptr.String(passwordPath),
AuthMode: nil,
},
}

Expand All @@ -96,6 +93,17 @@ func TestAerospikeCluster_GetPasswordCaching(t *testing.T) {
passwordAfterCache := cluster.GetPassword()
assert.Equal(t, password, passwordAfterCache)
}
func TestAerospikeCluster_GetPasswordFromCredentials(t *testing.T) {
cluster := &AerospikeCluster{
Credentials: &Credentials{
User: nil,
Password: ptr.String("password"),
},
}

password := cluster.GetPassword()
assert.Equal(t, ptr.String("password"), password)
}

func createValidFile() {
text := []byte("password")
Expand Down

0 comments on commit c1889f6

Please sign in to comment.