Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
53f8344
fix(stores): `stores import` providing a `Password(/StorePassword)` d…
spbsoluble Apr 24, 2025
b66dedd
chore(deps): Update all explicit imports to latest.
spbsoluble Apr 24, 2025
3c12667
feat(stores): `import csv` add support for credential input via flags…
spbsoluble Apr 24, 2025
de21e90
chore(docs): Regenerate docs.
spbsoluble Apr 24, 2025
8d1e6a2
feat(stores): `import csv` supports ENV credentials.
spbsoluble Apr 28, 2025
197fd75
chore(docs): Regenerate CLI docs
spbsoluble Apr 28, 2025
8d1b82f
chore(docs): Update CHANGELOG.md
spbsoluble Apr 28, 2025
be591a2
chore(docs): Update `stores import csv` top level synopsis with crede…
spbsoluble Apr 28, 2025
b10de54
chore(docs): Update `stores import csv` top level synopsis with mappi…
spbsoluble Apr 29, 2025
436c6ea
fix(stores): When creating a store don't log the request.
spbsoluble May 7, 2025
b498ac6
fix(cli): Escape git branch refs for online store-type lookups.
spbsoluble May 7, 2025
04d84bd
chore(docs): Update CHANGELOG.md
spbsoluble May 7, 2025
8a1c308
fix(cli): `stores import csv` strip all `BOM`s from payload.
spbsoluble May 7, 2025
c126d75
fix(cli): `stores import csv` strip all `BOM`s from payload.
spbsoluble May 7, 2025
63634b5
fix(cli): `stores rot` re-enabled and logging updated.
spbsoluble May 14, 2025
d438dd2
fix(cli): `stores import` don't output create requests in debug logs.
spbsoluble May 14, 2025
0c05396
chore(docs): Update CHANGELOG.md
spbsoluble May 14, 2025
d4381eb
fix(logging): Function enter/exit messages no longer contain a `%s`.
spbsoluble Jun 4, 2025
0ae8be1
feat(logging): Capture imported library logs and redirect to zerolog
spbsoluble Jun 4, 2025
7a5f6f8
fix(core): Output auth config params before calling `Authenticate()`
spbsoluble Jun 4, 2025
da67c27
chore(deps): Bump go version to `1.24` and update all direct imports
spbsoluble Jun 6, 2025
2b122c9
chore(docs): Add docs for `stores import csv` inventory headers
spbsoluble Jun 17, 2025
210719a
chore(docs): Update `stores import csv` docs to use product doc verbi…
spbsoluble Jun 17, 2025
6d30681
chore(docs): Fix root-of-trust template commands on top level README.md
spbsoluble Jun 18, 2025
4304b49
Merge pull request #271 from Keyfactor/ab#70785
doebrowsk Jul 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# v1.7.0

## Features

### CLI

- `stores import csv`: supports interactive credential input, as well as input via flags and environmental
variables. [docs](docs/kfutil_stores_import_csv.md)

## Fixes

### CLI

- `stores import csv`: providing a `Password(/StorePassword)` does not crash CLI.
- `stores import csv`: results CSV retains input header ordering.
- `stores import csv`: Handle `BOM` characters in an input CSV file.
- `store-types create`: URL encode `-b` parameter when passed.
- `store-types create`: Initialize logger before fetching store-type definitions.
- `stores rot`: Re-enabled and improved logging.

# v1.6.2

## Fixes
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,10 @@ set of defined certificates are present in each store that meets a certain set o

```bash
echo "Generating cert template file certs_template.csv"
kfutil stores rot generate-template-rot --type certs
kfutil stores rot generate-template --type certs
# edit the certs_template.csv file
echo "Generating stores template file stores_template.csv"
kfutil stores rot generate-template-rot --type stores
kfutil stores rot generate-template --type stores
# edit the stores_template.csv file
kfutil stores rot audit --add-certs certs_template.csv --stores stores_template.csv #This will audit the stores and generate a report file
# review/edit the report file generated `rot_audit.csv`
Expand All @@ -317,7 +317,7 @@ For full documentation, see [stores rot generate template](docs/kfutil_stores_ro
This will write the file `certs_template.csv` to the current directory.

```bash
kfutil stores generate-template-rot --type certs
kfutil stores rot generate-template --type certs
```

#### Generate Certificate Store List Template
Expand All @@ -327,7 +327,7 @@ For full documentation, see [stores rot generate template](docs/kfutil_stores_ro
This will write the file `stores_template.csv` to the current directory. For full documentation

```bash
kfutil stores generate-template-rot --type stores
kfutil stores rot generate-template --type stores
```

#### Run Root of Trust Audit
Expand Down
10 changes: 7 additions & 3 deletions cmd/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ const (
FlagGitRef = "git-ref"
FlagGitRepo = "repo"
FlagFromFile = "from-file"
DebugFuncEnter = "entered: %s"
DebugFuncExit = "exiting: %s"
DebugFuncCall = "calling: %s"
DebugFuncEnter = "entered:"
DebugFuncExit = "exiting:"
DebugFuncCall = "calling:"
MinHttpTimeout = 3

EnvStoresImportCSVServerUsername = "KFUTIL_CSV_SERVER_USERNAME"
EnvStoresImportCSVServerPassword = "KFUTIL_CSV_SERVER_PASSWORD"
EnvStoresImportCSVStorePassword = "KFUTIL_CSV_STORE_PASSWORD"
)

var ProviderTypeChoices = []string{
Expand Down
50 changes: 33 additions & 17 deletions cmd/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ import (
"net/http"
"os"
"path/filepath"
"slices"
"strconv"
"time"

"github.com/google/uuid"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"

stdlog "log"
//stdlog "log"
)

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

// Populate the map with data from the row
for i, column := range header {
rowMap[column] = row[i]
rowMap[column] = stripAllBOMs(row[i])
}

// Append the map to the data slice
Expand Down Expand Up @@ -190,12 +190,23 @@ func informDebug(debugFlag bool) {
}

func initLogger() {
stdlog.SetOutput(io.Discard)
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
zerolog.SetGlobalLevel(zerolog.Disabled) // default to disabled
log.Logger = log.With().Caller().Logger()
// Configure zerolog to include caller information
log.Logger = log.With().Caller().Logger().Output(
zerolog.ConsoleWriter{
Out: os.Stdout,
TimeFormat: time.RFC3339,
FormatCaller: func(caller interface{}) string {
if c, ok := caller.(string); ok {
return c // This will include the full file path and line number
}
return ""
},
},
)
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339})

initStdLogger()

}

func intToPointer(i int) *int {
Expand Down Expand Up @@ -282,27 +293,32 @@ func logGlobals() {

}

func mapToCSV(data []map[string]string, filename string) error {
file, err := os.Create(filename)
if err != nil {
return err
func mapToCSV(data []map[string]string, filename string, inputHeader []string) error {
file, fErr := os.Create(filename)
if fErr != nil {
return fErr
}
defer file.Close()

writer := csv.NewWriter(file)
defer writer.Flush()

// Write the header using keys from the first map
var header []string
if len(data) > 0 {
var header = inputHeader
if len(header) <= 0 && len(data) > 0 {
for key := range data[0] {
header = append(header, key)
}
if err := writer.Write(header); err != nil {
return err
header = append(header, stripAllBOMs(key))
}
}

errorColFound := slices.Contains(header, "Errors")
if !errorColFound {
header = append(header, "Errors")
}
if hErr := writer.Write(header); hErr != nil {
return hErr
}

// Write map data to CSV
for _, row := range data {
var record []string
Expand Down
45 changes: 45 additions & 0 deletions cmd/logging.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package cmd

import (
"strings"

"github.com/rs/zerolog/log"
)

// zerologWriter implements io.Writer and forwards standard log output to zerolog
type zerologWriter struct{}

func (w zerologWriter) Write(p []byte) (n int, err error) {
// Clean up the log message (remove timestamp, etc.)
msg := string(p)
msg = strings.TrimSpace(msg)

// Check if it's a debug message
if strings.Contains(msg, "[DEBUG]") {
msg = strings.Replace(msg, "[DEBUG]", "", 1)
log.Debug().Msg(strings.TrimSpace(msg))
} else if strings.Contains(msg, "[ERROR]") {
msg = strings.Replace(msg, "[ERROR]", "", 1)
log.Error().Msg(strings.TrimSpace(msg))
} else if strings.Contains(msg, "[INFO]") {
msg = strings.Replace(msg, "[INFO]", "", 1)
log.Info().Msg(strings.TrimSpace(msg))

} else if strings.Contains(msg, "[WARN]") {
msg = strings.Replace(msg, "[WARN]", "", 1)
log.Warn().Msg(strings.TrimSpace(msg))

} else if strings.Contains(msg, "[FATAL]") {
msg = strings.Replace(msg, "[FATAL]", "", 1)
log.Fatal().Msg(strings.TrimSpace(msg))

} else if strings.Contains(msg, "[TRACE]") {
msg = strings.Replace(msg, "[TRACE]", "", 1)
log.Trace().Msg(strings.TrimSpace(msg))
} else {
// Default to info level
log.Info().Msg(msg)
}

return len(p), nil
}
26 changes: 21 additions & 5 deletions cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ package cmd
import (
"bufio"
"fmt"
"io"
stdlog "log"
"os"
"path"
"strings"
Expand Down Expand Up @@ -70,7 +68,7 @@ WARNING: This will write the environmental credentials to disk and will be store
if debugErr != nil {
return debugErr
}
stdlog.SetOutput(io.Discard)
//stdlog.SetOutput(io.Discard)
informDebug(debugFlag)
logGlobals()

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

if authType == "oauth" {
log.Debug().Msg("attempting to authenticate via OAuth")
log.Debug().
Str("profile", profile).
Str("configFile", configFile).
Str("host", outputServer.Host).
Str("authType", authType).
Str("accessToken", hashSecretValue(kfcOAuth.AccessToken)).
Str("clientID", kfcOAuth.ClientID).
Str("clientSecret", hashSecretValue(kfcOAuth.ClientSecret)).
Str("apiPath", kfcOAuth.CommandAPIPath).
Msg("attempting to authenticate via OAuth")
aErr := kfcOAuth.Authenticate()
if aErr != nil {
log.Error().Err(aErr)
return aErr
}
} else if authType == "basic" {
log.Debug().Msg("attempting to authenticate via Basic Auth")
log.Debug().
Str("profile", profile).
Str("configFile", configFile).
Str("host", outputServer.Host).
Str("authType", authType).
Str("username", kfcBasicAuth.Username).
Str("domain", kfcBasicAuth.Domain).
Str("password", hashSecretValue(kfcBasicAuth.Password)).
Str("apiPath", kfcBasicAuth.CommandAPIPath).
Msg("attempting to authenticate via Basic Auth")
aErr := kfcBasicAuth.Authenticate()
if aErr != nil {
log.Error().Err(aErr)
Expand Down
4 changes: 1 addition & 3 deletions cmd/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ package cmd

import (
"fmt"
"io"
stdlog "log"
"os"

"github.com/Keyfactor/keyfactor-auth-client-go/auth_providers"
Expand All @@ -39,7 +37,7 @@ var logoutCmd = &cobra.Command{
if debugErr != nil {
return debugErr
}
stdlog.SetOutput(io.Discard)
//stdlog.SetOutput(io.Discard)
informDebug(debugFlag)

logGlobals()
Expand Down
Loading
Loading