Skip to content

Commit

Permalink
actual fix
Browse files Browse the repository at this point in the history
Signed-off-by: razzle <harry@razzle.cloud>
  • Loading branch information
Noxsios committed Mar 14, 2024
1 parent 1ec8849 commit 810902d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 55 deletions.
3 changes: 1 addition & 2 deletions src/pkg/interactive/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/defenseunicorns/zarf/src/pkg/utils"
"github.com/defenseunicorns/zarf/src/types"
"github.com/pterm/pterm"
)

// SelectOptionalComponent prompts to confirm optional components
Expand Down Expand Up @@ -76,7 +75,7 @@ func SelectChoiceGroup(componentGroup []types.ZarfComponent) types.ZarfComponent
Options: options,
}

pterm.Println()
fmt.Fprintln(message.LogWriter)

if err := survey.AskOne(prompt, &chosen); err != nil {
message.Fatalf(nil, lang.PkgDeployErrComponentSelectionCanceled, err.Error())
Expand Down
28 changes: 14 additions & 14 deletions src/pkg/message/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package message

import (
"fmt"
"os"
"io"
"strings"

"github.com/defenseunicorns/zarf/src/config"
Expand All @@ -31,8 +31,8 @@ func PrintCredentialTable(state *types.ZarfState, componentsToDeploy []types.Dep
componentsToDeploy = []types.DeployedComponent{{Name: "logging"}, {Name: "git-server"}}
}

// Set output to os.Stderr to avoid creds being printed in logs
pterm.SetDefaultOutput(os.Stderr)
// Set output to only LogWriter (default is os.Stderr) to avoid creds being printed in logs
pterm.SetDefaultOutput(LogWriter)

loginData := [][]string{}
if state.RegistryInfo.InternalRegistry {
Expand Down Expand Up @@ -63,8 +63,8 @@ func PrintCredentialTable(state *types.ZarfState, componentsToDeploy []types.Dep
}

// Restore the log file if it was specified
if !config.SkipLogFile {
UseLogFile()
if !config.SkipLogFile && logFile != nil {
pterm.SetDefaultOutput(io.MultiWriter(LogWriter, logFile))
}
}

Expand Down Expand Up @@ -96,8 +96,8 @@ func PrintComponentCredential(state *types.ZarfState, componentName string) {

// PrintCredentialUpdates displays credentials that will be updated
func PrintCredentialUpdates(oldState *types.ZarfState, newState *types.ZarfState, services []string) {
// Set output to os.Stderr to avoid creds being printed in logs
pterm.SetDefaultOutput(os.Stderr)
// Set output to only LogWriter (default is os.Stderr) to avoid creds being printed in logs
pterm.SetDefaultOutput(LogWriter)

for _, service := range services {

Expand All @@ -108,7 +108,7 @@ func PrintCredentialUpdates(oldState *types.ZarfState, newState *types.ZarfState
oR := oldState.RegistryInfo
nR := newState.RegistryInfo
Title("Registry", "the information used to interact with Zarf's container image registry")
pterm.Println()
fmt.Fprintln(LogWriter)
pterm.Printfln(" %s: %s", pterm.Bold.Sprint("URL Address"), compareStrings(oR.Address, nR.Address, false))
pterm.Printfln(" %s: %s", pterm.Bold.Sprint("Push Username"), compareStrings(oR.PushUsername, nR.PushUsername, false))
pterm.Printfln(" %s: %s", pterm.Bold.Sprint("Push Password"), compareStrings(oR.PushPassword, nR.PushPassword, true))
Expand All @@ -118,7 +118,7 @@ func PrintCredentialUpdates(oldState *types.ZarfState, newState *types.ZarfState
oG := oldState.GitServer
nG := newState.GitServer
Title("Git Server", "the information used to interact with Zarf's GitOps Git Server")
pterm.Println()
fmt.Fprintln(LogWriter)
pterm.Printfln(" %s: %s", pterm.Bold.Sprint("URL Address"), compareStrings(oG.Address, nG.Address, false))
pterm.Printfln(" %s: %s", pterm.Bold.Sprint("Push Username"), compareStrings(oG.PushUsername, nG.PushUsername, false))
pterm.Printfln(" %s: %s", pterm.Bold.Sprint("Push Password"), compareStrings(oG.PushPassword, nG.PushPassword, true))
Expand All @@ -128,26 +128,26 @@ func PrintCredentialUpdates(oldState *types.ZarfState, newState *types.ZarfState
oA := oldState.ArtifactServer
nA := newState.ArtifactServer
Title("Artifact Server", "the information used to interact with Zarf's Artifact Server")
pterm.Println()
fmt.Fprintln(LogWriter)
pterm.Printfln(" %s: %s", pterm.Bold.Sprint("URL Address"), compareStrings(oA.Address, nA.Address, false))
pterm.Printfln(" %s: %s", pterm.Bold.Sprint("Push Username"), compareStrings(oA.PushUsername, nA.PushUsername, false))
pterm.Printfln(" %s: %s", pterm.Bold.Sprint("Push Token"), compareStrings(oA.PushToken, nA.PushToken, true))
case AgentKey:
oT := oldState.AgentTLS
nT := newState.AgentTLS
Title("Agent TLS", "the certificates used to connect to Zarf's Agent")
pterm.Println()
fmt.Fprintln(LogWriter)
pterm.Printfln(" %s: %s", pterm.Bold.Sprint("Certificate Authority"), compareStrings(string(oT.CA), string(nT.CA), true))
pterm.Printfln(" %s: %s", pterm.Bold.Sprint("Public Certificate"), compareStrings(string(oT.Cert), string(nT.Cert), true))
pterm.Printfln(" %s: %s", pterm.Bold.Sprint("Private Key"), compareStrings(string(oT.Key), string(nT.Key), true))
}
}

pterm.Println()
fmt.Fprintln(LogWriter)

// Restore the log file if it was specified
if !config.SkipLogFile {
UseLogFile()
if !config.SkipLogFile && logFile != nil {
pterm.SetDefaultOutput(io.MultiWriter(LogWriter, logFile))
}
}

Expand Down
16 changes: 0 additions & 16 deletions src/pkg/message/generic.go

This file was deleted.

34 changes: 13 additions & 21 deletions src/pkg/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,13 @@ func UseLogFile() {
ts := time.Now().Format("2006-01-02-15-04-05")

var err error
if logFile != nil {
// Use the existing log file if logFile is set
LogWriter = io.MultiWriter(os.Stderr, logFile)
pterm.SetDefaultOutput(LogWriter)
if logFile, err = os.CreateTemp("./logs", fmt.Sprintf("zarf-%s-*.log", ts)); err != nil {
WarnErr(err, "Error saving a log file to a temporary directory")
} else {
// Try to create a temp log file if one hasn't been made already
if logFile, err = os.CreateTemp("", fmt.Sprintf("zarf-%s-*.log", ts)); err != nil {
WarnErr(err, "Error saving a log file to a temporary directory")
} else {
useLogFile = true
LogWriter = io.MultiWriter(os.Stderr, logFile)
pterm.SetDefaultOutput(LogWriter)
message := fmt.Sprintf("Saving log file to %s", logFile.Name())
Note(message)
}
useLogFile = true
pterm.SetDefaultOutput(io.MultiWriter(LogWriter, logFile))
message := fmt.Sprintf("Saving log file to %s", logFile.Name())
Note(message)
}
}

Expand Down Expand Up @@ -162,7 +154,7 @@ func Warn(message string) {
// Warnf prints a warning message with a given format.
func Warnf(format string, a ...any) {
message := Paragraphn(TermWidth-10, format, a...)
pterm.Println()
fmt.Fprintln(LogWriter)
pterm.Warning.Println(message)
}

Expand Down Expand Up @@ -223,7 +215,7 @@ func Question(text string) {

// Questionf prints a user prompt description message with a given format.
func Questionf(format string, a ...any) {
pterm.Println()
fmt.Fprintln(LogWriter)
message := Paragraph(format, a...)
pterm.FgLightGreen.Println(message)
}
Expand All @@ -235,7 +227,7 @@ func Note(text string) {

// Notef prints a note message with a given format.
func Notef(format string, a ...any) {
pterm.Println()
fmt.Fprintln(LogWriter)
message := Paragraphn(TermWidth-7, format, a...)
notePrefix := pterm.PrefixPrinter{
MessageStyle: &pterm.ThemeDefault.InfoMessageStyle,
Expand All @@ -259,7 +251,7 @@ func HeaderInfof(format string, a ...any) {
message := Truncate(fmt.Sprintf(format, a...), TermWidth, false)
// Ensure the text is consistent for the header width
padding := TermWidth - len(message)
pterm.Println()
fmt.Fprintln(LogWriter)
pterm.DefaultHeader.
WithBackgroundStyle(pterm.NewStyle(pterm.BgDarkGray)).
WithTextStyle(pterm.NewStyle(pterm.FgLightWhite)).
Expand All @@ -269,8 +261,8 @@ func HeaderInfof(format string, a ...any) {

// HorizontalRule prints a white horizontal rule to separate the terminal
func HorizontalRule() {
pterm.Println()
pterm.Println(RuleLine)
fmt.Fprintln(LogWriter)
fmt.Fprintln(LogWriter, RuleLine)
}

// JSONValue prints any value as JSON.
Expand Down Expand Up @@ -322,7 +314,7 @@ func Truncate(text string, length int, invert bool) string {

// Table prints a padded table containing the specified header and data
func Table(header []string, data [][]string) {
pterm.Println()
fmt.Fprintln(LogWriter)

// To avoid side effects make copies of the header and data before adding padding
headerCopy := make([]string, len(header))
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/packager/interactive.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

func (p *Packager) confirmAction(stage string) (confirm bool) {

pterm.Println()
fmt.Fprintln(message.LogWriter)
message.HeaderInfof("📦 PACKAGE DEFINITION")
utils.ColorPrintYAML(p.cfg.Pkg, p.getPackageYAMLHints(stage), true)

Expand Down
2 changes: 1 addition & 1 deletion src/pkg/utils/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func ColorPrintYAML(data any, hints map[string]string, spaceRootLists bool) {
outputYAML = ansiRegex.ReplaceAllString(outputYAML, "")
}

pterm.Println()
fmt.Fprintln(message.LogWriter)
pterm.Println(outputYAML)
}

Expand Down

0 comments on commit 810902d

Please sign in to comment.