Skip to content

Commit 8627008

Browse files
authored
merge 1.7.0 to main
2 parents 768e198 + 4304b49 commit 8627008

File tree

73 files changed

+2512
-1626
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+2512
-1626
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
# v1.7.0
2+
3+
## Features
4+
5+
### CLI
6+
7+
- `stores import csv`: supports interactive credential input, as well as input via flags and environmental
8+
variables. [docs](docs/kfutil_stores_import_csv.md)
9+
10+
## Fixes
11+
12+
### CLI
13+
14+
- `stores import csv`: providing a `Password(/StorePassword)` does not crash CLI.
15+
- `stores import csv`: results CSV retains input header ordering.
16+
- `stores import csv`: Handle `BOM` characters in an input CSV file.
17+
- `store-types create`: URL encode `-b` parameter when passed.
18+
- `store-types create`: Initialize logger before fetching store-type definitions.
19+
- `stores rot`: Re-enabled and improved logging.
20+
121
# v1.6.2
222

323
## Fixes

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,10 @@ set of defined certificates are present in each store that meets a certain set o
298298
299299
```bash
300300
echo "Generating cert template file certs_template.csv"
301-
kfutil stores rot generate-template-rot --type certs
301+
kfutil stores rot generate-template --type certs
302302
# edit the certs_template.csv file
303303
echo "Generating stores template file stores_template.csv"
304-
kfutil stores rot generate-template-rot --type stores
304+
kfutil stores rot generate-template --type stores
305305
# edit the stores_template.csv file
306306
kfutil stores rot audit --add-certs certs_template.csv --stores stores_template.csv #This will audit the stores and generate a report file
307307
# review/edit the report file generated `rot_audit.csv`
@@ -317,7 +317,7 @@ For full documentation, see [stores rot generate template](docs/kfutil_stores_ro
317317
This will write the file `certs_template.csv` to the current directory.
318318
319319
```bash
320-
kfutil stores generate-template-rot --type certs
320+
kfutil stores rot generate-template --type certs
321321
```
322322
323323
#### Generate Certificate Store List Template
@@ -327,7 +327,7 @@ For full documentation, see [stores rot generate template](docs/kfutil_stores_ro
327327
This will write the file `stores_template.csv` to the current directory. For full documentation
328328
329329
```bash
330-
kfutil stores generate-template-rot --type stores
330+
kfutil stores rot generate-template --type stores
331331
```
332332
333333
#### Run Root of Trust Audit

cmd/constants.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,14 @@ const (
3030
FlagGitRef = "git-ref"
3131
FlagGitRepo = "repo"
3232
FlagFromFile = "from-file"
33-
DebugFuncEnter = "entered: %s"
34-
DebugFuncExit = "exiting: %s"
35-
DebugFuncCall = "calling: %s"
33+
DebugFuncEnter = "entered:"
34+
DebugFuncExit = "exiting:"
35+
DebugFuncCall = "calling:"
3636
MinHttpTimeout = 3
37+
38+
EnvStoresImportCSVServerUsername = "KFUTIL_CSV_SERVER_USERNAME"
39+
EnvStoresImportCSVServerPassword = "KFUTIL_CSV_SERVER_PASSWORD"
40+
EnvStoresImportCSVStorePassword = "KFUTIL_CSV_STORE_PASSWORD"
3741
)
3842

3943
var ProviderTypeChoices = []string{

cmd/helpers.go

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ import (
2323
"net/http"
2424
"os"
2525
"path/filepath"
26+
"slices"
2627
"strconv"
2728
"time"
2829

2930
"github.com/google/uuid"
3031
"github.com/rs/zerolog"
3132
"github.com/rs/zerolog/log"
3233
"github.com/spf13/cobra"
33-
34-
stdlog "log"
34+
//stdlog "log"
3535
)
3636

3737
func boolToPointer(b bool) *bool {
@@ -132,7 +132,7 @@ func csvToMap(filename string) ([]map[string]string, error) {
132132

133133
// Populate the map with data from the row
134134
for i, column := range header {
135-
rowMap[column] = row[i]
135+
rowMap[column] = stripAllBOMs(row[i])
136136
}
137137

138138
// Append the map to the data slice
@@ -190,12 +190,23 @@ func informDebug(debugFlag bool) {
190190
}
191191

192192
func initLogger() {
193-
stdlog.SetOutput(io.Discard)
194-
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
195-
zerolog.SetGlobalLevel(zerolog.Disabled) // default to disabled
196-
log.Logger = log.With().Caller().Logger()
193+
// Configure zerolog to include caller information
194+
log.Logger = log.With().Caller().Logger().Output(
195+
zerolog.ConsoleWriter{
196+
Out: os.Stdout,
197+
TimeFormat: time.RFC3339,
198+
FormatCaller: func(caller interface{}) string {
199+
if c, ok := caller.(string); ok {
200+
return c // This will include the full file path and line number
201+
}
202+
return ""
203+
},
204+
},
205+
)
197206
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339})
198207

208+
initStdLogger()
209+
199210
}
200211

201212
func intToPointer(i int) *int {
@@ -282,27 +293,32 @@ func logGlobals() {
282293

283294
}
284295

285-
func mapToCSV(data []map[string]string, filename string) error {
286-
file, err := os.Create(filename)
287-
if err != nil {
288-
return err
296+
func mapToCSV(data []map[string]string, filename string, inputHeader []string) error {
297+
file, fErr := os.Create(filename)
298+
if fErr != nil {
299+
return fErr
289300
}
290301
defer file.Close()
291302

292303
writer := csv.NewWriter(file)
293304
defer writer.Flush()
294305

295306
// Write the header using keys from the first map
296-
var header []string
297-
if len(data) > 0 {
307+
var header = inputHeader
308+
if len(header) <= 0 && len(data) > 0 {
298309
for key := range data[0] {
299-
header = append(header, key)
300-
}
301-
if err := writer.Write(header); err != nil {
302-
return err
310+
header = append(header, stripAllBOMs(key))
303311
}
304312
}
305313

314+
errorColFound := slices.Contains(header, "Errors")
315+
if !errorColFound {
316+
header = append(header, "Errors")
317+
}
318+
if hErr := writer.Write(header); hErr != nil {
319+
return hErr
320+
}
321+
306322
// Write map data to CSV
307323
for _, row := range data {
308324
var record []string

cmd/logging.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package cmd
2+
3+
import (
4+
"strings"
5+
6+
"github.com/rs/zerolog/log"
7+
)
8+
9+
// zerologWriter implements io.Writer and forwards standard log output to zerolog
10+
type zerologWriter struct{}
11+
12+
func (w zerologWriter) Write(p []byte) (n int, err error) {
13+
// Clean up the log message (remove timestamp, etc.)
14+
msg := string(p)
15+
msg = strings.TrimSpace(msg)
16+
17+
// Check if it's a debug message
18+
if strings.Contains(msg, "[DEBUG]") {
19+
msg = strings.Replace(msg, "[DEBUG]", "", 1)
20+
log.Debug().Msg(strings.TrimSpace(msg))
21+
} else if strings.Contains(msg, "[ERROR]") {
22+
msg = strings.Replace(msg, "[ERROR]", "", 1)
23+
log.Error().Msg(strings.TrimSpace(msg))
24+
} else if strings.Contains(msg, "[INFO]") {
25+
msg = strings.Replace(msg, "[INFO]", "", 1)
26+
log.Info().Msg(strings.TrimSpace(msg))
27+
28+
} else if strings.Contains(msg, "[WARN]") {
29+
msg = strings.Replace(msg, "[WARN]", "", 1)
30+
log.Warn().Msg(strings.TrimSpace(msg))
31+
32+
} else if strings.Contains(msg, "[FATAL]") {
33+
msg = strings.Replace(msg, "[FATAL]", "", 1)
34+
log.Fatal().Msg(strings.TrimSpace(msg))
35+
36+
} else if strings.Contains(msg, "[TRACE]") {
37+
msg = strings.Replace(msg, "[TRACE]", "", 1)
38+
log.Trace().Msg(strings.TrimSpace(msg))
39+
} else {
40+
// Default to info level
41+
log.Info().Msg(msg)
42+
}
43+
44+
return len(p), nil
45+
}

cmd/login.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ package cmd
1717
import (
1818
"bufio"
1919
"fmt"
20-
"io"
21-
stdlog "log"
2220
"os"
2321
"path"
2422
"strings"
@@ -70,7 +68,7 @@ WARNING: This will write the environmental credentials to disk and will be store
7068
if debugErr != nil {
7169
return debugErr
7270
}
73-
stdlog.SetOutput(io.Discard)
71+
//stdlog.SetOutput(io.Discard)
7472
informDebug(debugFlag)
7573
logGlobals()
7674

@@ -237,14 +235,32 @@ WARNING: This will write the environmental credentials to disk and will be store
237235
}
238236

239237
if authType == "oauth" {
240-
log.Debug().Msg("attempting to authenticate via OAuth")
238+
log.Debug().
239+
Str("profile", profile).
240+
Str("configFile", configFile).
241+
Str("host", outputServer.Host).
242+
Str("authType", authType).
243+
Str("accessToken", hashSecretValue(kfcOAuth.AccessToken)).
244+
Str("clientID", kfcOAuth.ClientID).
245+
Str("clientSecret", hashSecretValue(kfcOAuth.ClientSecret)).
246+
Str("apiPath", kfcOAuth.CommandAPIPath).
247+
Msg("attempting to authenticate via OAuth")
241248
aErr := kfcOAuth.Authenticate()
242249
if aErr != nil {
243250
log.Error().Err(aErr)
244251
return aErr
245252
}
246253
} else if authType == "basic" {
247-
log.Debug().Msg("attempting to authenticate via Basic Auth")
254+
log.Debug().
255+
Str("profile", profile).
256+
Str("configFile", configFile).
257+
Str("host", outputServer.Host).
258+
Str("authType", authType).
259+
Str("username", kfcBasicAuth.Username).
260+
Str("domain", kfcBasicAuth.Domain).
261+
Str("password", hashSecretValue(kfcBasicAuth.Password)).
262+
Str("apiPath", kfcBasicAuth.CommandAPIPath).
263+
Msg("attempting to authenticate via Basic Auth")
248264
aErr := kfcBasicAuth.Authenticate()
249265
if aErr != nil {
250266
log.Error().Err(aErr)

cmd/logout.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ package cmd
1616

1717
import (
1818
"fmt"
19-
"io"
20-
stdlog "log"
2119
"os"
2220

2321
"github.com/Keyfactor/keyfactor-auth-client-go/auth_providers"
@@ -39,7 +37,7 @@ var logoutCmd = &cobra.Command{
3937
if debugErr != nil {
4038
return debugErr
4139
}
42-
stdlog.SetOutput(io.Discard)
40+
//stdlog.SetOutput(io.Discard)
4341
informDebug(debugFlag)
4442

4543
logGlobals()

0 commit comments

Comments
 (0)