Skip to content

Commit 860f88a

Browse files
authored
Refactored for general code and log messages cleanup (#2)
1 parent f206120 commit 860f88a

2 files changed

Lines changed: 2 additions & 57 deletions

File tree

connection_producer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type couchbaseCapellaDBConnectionProducer struct {
4343

4444
func (c *couchbaseCapellaDBConnectionProducer) secretValues() map[string]string {
4545
return map[string]string{
46-
c.Password: "{{password}}",
46+
c.Password: "[password]",
4747
c.Username: "[username]",
4848
}
4949
}

couchbasecapella.go

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
package couchbasecapella
22

33
import (
4-
"bytes"
54
"context"
6-
"encoding/json"
75
"fmt"
8-
"net/http"
9-
"os"
106
"strings"
117
"time"
128

@@ -91,7 +87,6 @@ func (c *CouchbaseCapellaDB) Initialize(ctx context.Context, req dbplugin.Initia
9187
Config: req.Config,
9288
}
9389

94-
c.logger.Info(fmt.Sprintf("Initialize, resp=%v", resp))
9590
return resp, nil
9691
}
9792

@@ -118,53 +113,10 @@ func (c *CouchbaseCapellaDB) NewUser(ctx context.Context, req dbplugin.NewUserRe
118113
return resp, nil
119114
}
120115

121-
func callVaultAPI(method, path string, requestData map[string]interface{}, responseData interface{}) error {
122-
vaultAddr := os.Getenv("VAULT_ADDR")
123-
if len(vaultAddr) == 0 {
124-
vaultAddr = "http://127.0.0.1:8200"
125-
}
126-
vaultToken := os.Getenv("VAULT_TOKEN")
127-
if len(vaultToken) == 0 {
128-
vaultToken = os.Getenv("VAULT_DEV_ROOT_TOKEN_ID")
129-
if len(vaultToken) == 0 {
130-
vaultToken = "root"
131-
}
132-
}
133-
url := fmt.Sprintf("%s/v1/%s", vaultAddr, path)
134-
reqData, err := json.Marshal(requestData)
135-
if err != nil {
136-
return err
137-
}
138-
139-
logger.Info(fmt.Sprintf("Attempting HTTP : %s %s", method, url))
140-
req, err := http.NewRequest(method, url, bytes.NewBuffer(reqData))
141-
if err != nil {
142-
return err
143-
}
144-
req.Header.Add("X-Vault-Token", vaultToken)
145-
146-
client := http.Client{}
147-
defer client.CloseIdleConnections()
148-
resp, err := client.Do(req)
149-
if err != nil {
150-
return err
151-
}
152-
defer resp.Body.Close()
153-
154-
if responseData != nil {
155-
if err := json.NewDecoder(resp.Body).Decode(&responseData); err != nil {
156-
return err
157-
}
158-
}
159-
160-
return nil
161-
}
162-
163116
func (c *CouchbaseCapellaDB) UpdateUser(ctx context.Context, req dbplugin.UpdateUserRequest) (dbplugin.UpdateUserResponse, error) {
164117
if req.Password != nil {
165118
newpassword := req.Password.NewPassword
166-
pwd, err := c.changeUserPassword(ctx, req.Username, newpassword)
167-
c.logger.Info("after change pwd=%v", pwd)
119+
_, err := c.changeUserPassword(ctx, req.Username, newpassword)
168120
return dbplugin.UpdateUserResponse{}, err
169121
}
170122
return dbplugin.UpdateUserResponse{}, nil
@@ -192,9 +144,6 @@ func newUser(ctx context.Context, c *couchbaseCapellaDBConnectionProducer, usern
192144
statements = append(statements, defaultCouchbaseCapellaUserRole)
193145
}
194146

195-
c.logger.Info(fmt.Sprintf("%s :: %s :: %s :: %s :: %s :: %s", c.CloudAPIBaseURL, c.CloudAPIClustersPath, c.Username, c.Password,
196-
username, req.Password))
197-
198147
err := CreateCapellaDbCredUser(c.CloudAPIBaseURL, c.CloudAPIClustersPath, c.Username, c.Password,
199148
username, req.Password, statements[0])
200149
if err != nil {
@@ -208,13 +157,9 @@ func (c *CouchbaseCapellaDB) changeUserPassword(ctx context.Context, username, p
208157
// Don't let anyone write the config while we're using it
209158
c.RLock()
210159
defer c.RUnlock()
211-
c.logger.Info(fmt.Sprintf("%s :: %s :: %s :: %s :: %s :: %s", c.CloudAPIBaseURL, c.CloudAPIClustersPath, c.Username, c.Password,
212-
username, password))
213160
pwd, err := UpdateCapellaDbCredUser(c.CloudAPIBaseURL, c.CloudAPIClustersPath, c.Username, c.Password,
214161
username, password)
215162

216-
c.logger.Info(fmt.Sprintf("changeUserPassword, new password: %s", pwd))
217-
c.logger.Info(fmt.Sprintf("changeUserPassword, after change secretValues %v", c.secretValues()))
218163
if err != nil {
219164
return pwd, err
220165
}

0 commit comments

Comments
 (0)