66 "encoding/json"
77 "fmt"
88 "io"
9- "io/ioutil"
109 "log"
1110 "net/http"
1211 "sort"
@@ -19,22 +18,22 @@ import (
1918
2019// Logger is an interface representing the Logger struct
2120type Logger interface {
22- Printf (format string , args ... interface {} )
21+ Printf (format string , args ... any )
2322}
2423
2524// DefaultLogger is a default struct, which satisfies the Logger interface
2625type DefaultLogger struct {}
2726
2827// Printf is a default Printf method
29- func (DefaultLogger ) Printf (format string , args ... interface {} ) {
28+ func (DefaultLogger ) Printf (format string , args ... any ) {
3029 log .Printf ("[DEBUG] " + format , args ... )
3130}
3231
3332// noopLogger is a default noop logger satisfies the Logger interface
3433type noopLogger struct {}
3534
3635// Printf is a default noop method
37- func (noopLogger ) Printf (format string , args ... interface {} ) {}
36+ func (noopLogger ) Printf (format string , args ... any ) {}
3837
3938// RoundTripper satisfies the http.RoundTripper interface and is used to
4039// customize the default http client RoundTripper
@@ -101,9 +100,7 @@ func (rt *RoundTripper) SetHeaders(headers http.Header) {
101100 newHeaders := make (http.Header , len (headers ))
102101 for k , v := range headers {
103102 s := make ([]string , len (v ))
104- for i , v := range v {
105- s [i ] = v
106- }
103+ copy (s , v )
107104 newHeaders [k ] = s
108105 }
109106
@@ -181,7 +178,7 @@ func (rt *RoundTripper) RoundTrip(request *http.Request) (*http.Response, error)
181178 // this is concurrency safe
182179 ort := rt .Rt
183180 if ort == nil {
184- return nil , fmt .Errorf ("Rt RoundTripper is nil, aborting" )
181+ return nil , fmt .Errorf ("Rt RoundTripper is nil, aborting" ) //nolint
185182 }
186183 response , err := ort .RoundTrip (request )
187184
@@ -232,7 +229,7 @@ func (rt *RoundTripper) logRequest(original io.ReadCloser, contentType string) (
232229 }
233230 rt .log ().Printf ("OpenStack Request Body: %s" , debugInfo )
234231
235- return ioutil .NopCloser (strings .NewReader (bs .String ())), nil
232+ return io .NopCloser (strings .NewReader (bs .String ())), nil
236233 }
237234
238235 rt .log ().Printf ("Not logging because OpenStack request body isn't JSON" )
@@ -259,7 +256,7 @@ func (rt *RoundTripper) logResponse(original io.ReadCloser, contentType string)
259256 rt .log ().Printf ("OpenStack Response Body: %s" , debugInfo )
260257 }
261258
262- return ioutil .NopCloser (strings .NewReader (bs .String ())), nil
259+ return io .NopCloser (strings .NewReader (bs .String ())), nil
263260 }
264261
265262 rt .log ().Printf ("Not logging because OpenStack response body isn't JSON" )
@@ -288,14 +285,14 @@ func (rt *RoundTripper) log() Logger {
288285// FormatJSON is a default function to pretty-format a JSON body.
289286// It will also mask known fields which contain sensitive information.
290287func FormatJSON (raw []byte ) (string , error ) {
291- var rawData interface {}
288+ var rawData any
292289
293290 err := json .Unmarshal (raw , & rawData )
294291 if err != nil {
295292 return string (raw ), fmt .Errorf ("unable to parse OpenStack JSON: %s" , err )
296293 }
297294
298- data , ok := rawData .(map [string ]interface {} )
295+ data , ok := rawData .(map [string ]any )
299296 if ! ok {
300297 pretty , err := json .MarshalIndent (rawData , "" , " " )
301298 if err != nil {
@@ -306,32 +303,32 @@ func FormatJSON(raw []byte) (string, error) {
306303 }
307304
308305 // Mask known password fields
309- if v , ok := data ["auth" ].(map [string ]interface {} ); ok {
306+ if v , ok := data ["auth" ].(map [string ]any ); ok {
310307 // v2 auth methods
311- if v , ok := v ["passwordCredentials" ].(map [string ]interface {} ); ok {
308+ if v , ok := v ["passwordCredentials" ].(map [string ]any ); ok {
312309 v ["password" ] = "***"
313310 }
314- if v , ok := v ["token" ].(map [string ]interface {} ); ok {
311+ if v , ok := v ["token" ].(map [string ]any ); ok {
315312 v ["id" ] = "***"
316313 }
317314 // v3 auth methods
318- if v , ok := v ["identity" ].(map [string ]interface {} ); ok {
319- if v , ok := v ["password" ].(map [string ]interface {} ); ok {
320- if v , ok := v ["user" ].(map [string ]interface {} ); ok {
315+ if v , ok := v ["identity" ].(map [string ]any ); ok {
316+ if v , ok := v ["password" ].(map [string ]any ); ok {
317+ if v , ok := v ["user" ].(map [string ]any ); ok {
321318 v ["password" ] = "***"
322319 }
323320 }
324- if v , ok := v ["application_credential" ].(map [string ]interface {} ); ok {
321+ if v , ok := v ["application_credential" ].(map [string ]any ); ok {
325322 v ["secret" ] = "***"
326323 }
327- if v , ok := v ["token" ].(map [string ]interface {} ); ok {
324+ if v , ok := v ["token" ].(map [string ]any ); ok {
328325 v ["id" ] = "***"
329326 }
330327 }
331328 }
332329
333330 // Mask EC2 access id and body hash
334- if v , ok := data ["credentials" ].(map [string ]interface {} ); ok {
331+ if v , ok := data ["credentials" ].(map [string ]any ); ok {
335332 var access string
336333 if s , ok := v ["access" ]; ok {
337334 access , _ = s .(string )
@@ -340,17 +337,17 @@ func FormatJSON(raw []byte) (string, error) {
340337 if _ , ok := v ["body_hash" ]; ok {
341338 v ["body_hash" ] = "***"
342339 }
343- if v , ok := v ["headers" ].(map [string ]interface {} ); ok {
340+ if v , ok := v ["headers" ].(map [string ]any ); ok {
344341 if _ , ok := v ["Authorization" ]; ok {
345342 if s , ok := v ["Authorization" ].(string ); ok {
346- v ["Authorization" ] = strings .Replace (s , access , "***" , - 1 )
343+ v ["Authorization" ] = strings .ReplaceAll (s , access , "***" )
347344 }
348345 }
349346 }
350347 }
351348
352349 // Ignore the huge catalog output
353- if v , ok := data ["token" ].(map [string ]interface {} ); ok {
350+ if v , ok := data ["token" ].(map [string ]any ); ok {
354351 if _ , ok := v ["catalog" ]; ok {
355352 v ["catalog" ] = "***"
356353 }
0 commit comments