package app import ( "fmt" "io" "gitea.maximumdirect.net/eric/distributor/internal/config" ) func writeSecretConflictWarnings(w io.Writer, conflicts []config.SecretConflict) error { return writeWarnings(w, secretConflictWarnings(conflicts)) } func secretConflictWarnings(conflicts []config.SecretConflict) []OutputWarning { warnings := make([]OutputWarning, 0, len(conflicts)) for _, conflict := range conflicts { warnings = append(warnings, OutputWarning{ Message: fmt.Sprintf("secret %s ignored because the real environment already has that variable", conflict.Name), }) } return warnings } func writeSSHWarnings(w io.Writer, pipeline config.Pipeline) error { return writeWarnings(w, sshWarnings(pipeline)) } func sshWarnings(pipeline config.Pipeline) []OutputWarning { var warnings []OutputWarning if pipeline.Source.Backend == config.BackendSSH && pipeline.Source.SSH.HostKeyPolicy == config.HostKeyPolicyOff { warnings = append(warnings, OutputWarning{ Message: fmt.Sprintf("pipeline=%s source host_key_policy=off disables SSH host key checking", pipeline.ID), }) } for _, destination := range pipeline.Destinations { if destination.Backend == config.BackendSSH && destination.SSH.HostKeyPolicy == config.HostKeyPolicyOff { warnings = append(warnings, OutputWarning{ Message: fmt.Sprintf("pipeline=%s destination=%s host_key_policy=off disables SSH host key checking", pipeline.ID, destination.ID), }) } } return warnings } func writeWarnings(w io.Writer, warnings []OutputWarning) error { if w == nil { return nil } for _, warning := range warnings { if _, err := fmt.Fprintf(w, "Warning: %s\n", warning.Message); err != nil { return err } } return nil }