6
6
"encoding/json"
7
7
"fmt"
8
8
"io"
9
- "io/ioutil"
10
9
"log"
11
10
"net/http"
12
11
"sort"
@@ -19,22 +18,22 @@ import (
19
18
20
19
// Logger is an interface representing the Logger struct
21
20
type Logger interface {
22
- Printf (format string , args ... interface {} )
21
+ Printf (format string , args ... any )
23
22
}
24
23
25
24
// DefaultLogger is a default struct, which satisfies the Logger interface
26
25
type DefaultLogger struct {}
27
26
28
27
// Printf is a default Printf method
29
- func (DefaultLogger ) Printf (format string , args ... interface {} ) {
28
+ func (DefaultLogger ) Printf (format string , args ... any ) {
30
29
log .Printf ("[DEBUG] " + format , args ... )
31
30
}
32
31
33
32
// noopLogger is a default noop logger satisfies the Logger interface
34
33
type noopLogger struct {}
35
34
36
35
// Printf is a default noop method
37
- func (noopLogger ) Printf (format string , args ... interface {} ) {}
36
+ func (noopLogger ) Printf (format string , args ... any ) {}
38
37
39
38
// RoundTripper satisfies the http.RoundTripper interface and is used to
40
39
// customize the default http client RoundTripper
@@ -101,9 +100,7 @@ func (rt *RoundTripper) SetHeaders(headers http.Header) {
101
100
newHeaders := make (http.Header , len (headers ))
102
101
for k , v := range headers {
103
102
s := make ([]string , len (v ))
104
- for i , v := range v {
105
- s [i ] = v
106
- }
103
+ copy (s , v )
107
104
newHeaders [k ] = s
108
105
}
109
106
@@ -181,7 +178,7 @@ func (rt *RoundTripper) RoundTrip(request *http.Request) (*http.Response, error)
181
178
// this is concurrency safe
182
179
ort := rt .Rt
183
180
if ort == nil {
184
- return nil , fmt .Errorf ("Rt RoundTripper is nil, aborting" )
181
+ return nil , fmt .Errorf ("Rt RoundTripper is nil, aborting" ) //nolint
185
182
}
186
183
response , err := ort .RoundTrip (request )
187
184
@@ -232,7 +229,7 @@ func (rt *RoundTripper) logRequest(original io.ReadCloser, contentType string) (
232
229
}
233
230
rt .log ().Printf ("OpenStack Request Body: %s" , debugInfo )
234
231
235
- return ioutil .NopCloser (strings .NewReader (bs .String ())), nil
232
+ return io .NopCloser (strings .NewReader (bs .String ())), nil
236
233
}
237
234
238
235
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)
259
256
rt .log ().Printf ("OpenStack Response Body: %s" , debugInfo )
260
257
}
261
258
262
- return ioutil .NopCloser (strings .NewReader (bs .String ())), nil
259
+ return io .NopCloser (strings .NewReader (bs .String ())), nil
263
260
}
264
261
265
262
rt .log ().Printf ("Not logging because OpenStack response body isn't JSON" )
@@ -288,14 +285,14 @@ func (rt *RoundTripper) log() Logger {
288
285
// FormatJSON is a default function to pretty-format a JSON body.
289
286
// It will also mask known fields which contain sensitive information.
290
287
func FormatJSON (raw []byte ) (string , error ) {
291
- var rawData interface {}
288
+ var rawData any
292
289
293
290
err := json .Unmarshal (raw , & rawData )
294
291
if err != nil {
295
292
return string (raw ), fmt .Errorf ("unable to parse OpenStack JSON: %s" , err )
296
293
}
297
294
298
- data , ok := rawData .(map [string ]interface {} )
295
+ data , ok := rawData .(map [string ]any )
299
296
if ! ok {
300
297
pretty , err := json .MarshalIndent (rawData , "" , " " )
301
298
if err != nil {
@@ -306,32 +303,32 @@ func FormatJSON(raw []byte) (string, error) {
306
303
}
307
304
308
305
// Mask known password fields
309
- if v , ok := data ["auth" ].(map [string ]interface {} ); ok {
306
+ if v , ok := data ["auth" ].(map [string ]any ); ok {
310
307
// v2 auth methods
311
- if v , ok := v ["passwordCredentials" ].(map [string ]interface {} ); ok {
308
+ if v , ok := v ["passwordCredentials" ].(map [string ]any ); ok {
312
309
v ["password" ] = "***"
313
310
}
314
- if v , ok := v ["token" ].(map [string ]interface {} ); ok {
311
+ if v , ok := v ["token" ].(map [string ]any ); ok {
315
312
v ["id" ] = "***"
316
313
}
317
314
// 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 {
321
318
v ["password" ] = "***"
322
319
}
323
320
}
324
- if v , ok := v ["application_credential" ].(map [string ]interface {} ); ok {
321
+ if v , ok := v ["application_credential" ].(map [string ]any ); ok {
325
322
v ["secret" ] = "***"
326
323
}
327
- if v , ok := v ["token" ].(map [string ]interface {} ); ok {
324
+ if v , ok := v ["token" ].(map [string ]any ); ok {
328
325
v ["id" ] = "***"
329
326
}
330
327
}
331
328
}
332
329
333
330
// 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 {
335
332
var access string
336
333
if s , ok := v ["access" ]; ok {
337
334
access , _ = s .(string )
@@ -340,17 +337,17 @@ func FormatJSON(raw []byte) (string, error) {
340
337
if _ , ok := v ["body_hash" ]; ok {
341
338
v ["body_hash" ] = "***"
342
339
}
343
- if v , ok := v ["headers" ].(map [string ]interface {} ); ok {
340
+ if v , ok := v ["headers" ].(map [string ]any ); ok {
344
341
if _ , ok := v ["Authorization" ]; ok {
345
342
if s , ok := v ["Authorization" ].(string ); ok {
346
- v ["Authorization" ] = strings .Replace (s , access , "***" , - 1 )
343
+ v ["Authorization" ] = strings .ReplaceAll (s , access , "***" )
347
344
}
348
345
}
349
346
}
350
347
}
351
348
352
349
// 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 {
354
351
if _ , ok := v ["catalog" ]; ok {
355
352
v ["catalog" ] = "***"
356
353
}
0 commit comments