44 "encoding/base64"
55 "encoding/json"
66 "fmt"
7- "io/ioutil"
87 "net/http"
98 "net/url"
109 "strings"
@@ -32,7 +31,7 @@ func CheckForOldCouchbaseCapellaVersion(hostname, username, password string) (is
3231 return false , err
3332 }
3433 defer resp .Body .Close ()
35- body , err := ioutil .ReadAll (resp .Body )
34+ body , err := io .ReadAll (resp .Body )
3635 if err != nil {
3736 return false , err
3837 }
@@ -65,7 +64,7 @@ func getRootCAfromCouchbaseCapella(url string) (Base64pemCA string, err error) {
6564 return "" , err
6665 }
6766 defer resp .Body .Close ()
68- body , err := ioutil .ReadAll (resp .Body )
67+ body , err := io .ReadAll (resp .Body )
6968 if err != nil {
7069 return "" , err
7170 }
@@ -136,7 +135,7 @@ func checkBucketReady(address, username, password, bucket string) (err error) {
136135 return err
137136 }
138137 defer resp .Body .Close ()
139- body , err := ioutil .ReadAll (resp .Body )
138+ body , err := io .ReadAll (resp .Body )
140139 if err != nil {
141140 return err
142141 }
@@ -268,7 +267,7 @@ func NewCapellaClient(baseUrl string, accessKey string, secretKey string) *Capel
268267}
269268
270269func Unmarshal (body io.Reader , v interface {}) error {
271- rb , err := ioutil .ReadAll (body )
270+ rb , err := io .ReadAll (body )
272271 if err != nil {
273272 return err
274273 }
@@ -302,8 +301,13 @@ func CreateCapellaDbCredUser(baseUrl string, cloudAPIclustersEndPoint string, ac
302301
303302 ep := c .baseURL + cloudAPIclustersEndPoint + "/users"
304303 resp , err := c .sendRequest (http .MethodPost , ep , string (data ))
305- if resp != nil && resp .StatusCode != http .StatusCreated {
304+ if err != nil {
305+ return err
306+ }
307+ if resp != nil {
306308 defer resp .Body .Close ()
309+ }
310+ if resp != nil && resp .StatusCode != http .StatusCreated {
307311 // obfuscate password in the log
308312 obfData := fmt .Sprintf ("{\" name\" :\" %s\" , \" password\" :\" [password]\" , \" access\" :%v}" , username , string (adata ))
309313 b , err1 := io .ReadAll (resp .Body )
@@ -314,9 +318,6 @@ func CreateCapellaDbCredUser(baseUrl string, cloudAPIclustersEndPoint string, ac
314318 return fmt .Errorf ("failed during capella user creation, response = %s, ep = %s, user = %v, payload = %v, access=%s, secret=%s" ,
315319 string (b ), ep , username , obfData , accessKey , secretKey )
316320 }
317- if err != nil {
318- return err
319- }
320321
321322 return nil
322323}
@@ -356,7 +357,7 @@ func UpdateCapellaDbCredUser(baseUrl string, cloudAPIclustersEndPoint string, ac
356357 }
357358 defer resp .Body .Close ()
358359
359- body , err := ioutil .ReadAll (resp .Body )
360+ body , err := io .ReadAll (resp .Body )
360361 if err != nil {
361362 return "" , fmt .Errorf ("failed during capella user id fetch unmarshal, response = %v, ep = %s, error=%v" ,
362363 resp , ep , err )
@@ -381,13 +382,16 @@ func DeleteCapellaDbCredUser(baseUrl string, cloudAPIclustersEndPoint string, ac
381382 }
382383 ep := c .baseURL + cloudAPIclustersEndPoint + "/users/" + userId
383384 resp , err := c .sendRequest (http .MethodDelete , ep , "" )
384- if resp != nil && resp .StatusCode != http .StatusNoContent {
385- return fmt .Errorf ("failed during capella user deletion, response = %v, ep = %s" ,
386- resp , ep )
387- }
388385 if err != nil {
389386 return err
390387 }
388+ if resp == nil {
389+ return fmt .Errorf ("failed during capella user deletion, response is nil, ep = %s" , ep )
390+ }
391+ if resp .StatusCode != http .StatusNoContent {
392+ return fmt .Errorf ("failed during capella user deletion, response = %v, ep = %s" ,
393+ resp , ep )
394+ }
391395 return nil
392396}
393397
@@ -439,7 +443,7 @@ func getDbCredId(baseUrl string, cloudAPIclustersEndPoint string, accessKey stri
439443 } else {
440444 defer resp .Body .Close ()
441445
442- body , err := ioutil .ReadAll (resp .Body )
446+ body , err := io .ReadAll (resp .Body )
443447 if err != nil {
444448 return dbUserId , fmt .Errorf ("failed during capella user id fetch unmarshal, response = %v, ep = %s, error=%v" ,
445449 resp , ep , err )
0 commit comments