Skip to content

Commit

Permalink
Merge pull request #698 from atc0005/fix-goconst-linting-errors
Browse files Browse the repository at this point in the history
Fix goconst linting errors
  • Loading branch information
atc0005 authored Nov 14, 2023
2 parents 05231a5 + 8a48504 commit 9147fe6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 31 deletions.
4 changes: 4 additions & 0 deletions internal/config/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ const (
ignoreExpiredRootCertificatesFlagHelp string = "Whether expired root certificates should be ignored."
)

// shorthandFlagSuffix is appended to short flag help text to emphasize that
// the flag is a shorthand version of a longer flag.
const shorthandFlagSuffix = " (shorthand)"

// Flag names for consistent references. Exported so that they're available
// from tests.
const (
Expand Down
42 changes: 21 additions & 21 deletions internal/config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,20 @@ func (c *Config) handleFlagsConfig(appType AppType) {
ignoreExpiredRootCertificatesFlagHelp,
)

flag.BoolVar(&c.VerboseOutput, VerboseFlagShort, defaultVerboseOutput, verboseOutputFlagHelp+" (shorthand)")
flag.BoolVar(&c.VerboseOutput, VerboseFlagShort, defaultVerboseOutput, verboseOutputFlagHelp+shorthandFlagSuffix)
flag.BoolVar(&c.VerboseOutput, VerboseFlagLong, defaultVerboseOutput, verboseOutputFlagHelp)

flag.BoolVar(&c.ListIgnoredValidationCheckResultErrors, ListIgnoredErrorsFlag, defaultListIgnoredValidationCheckResultErrors, listIgnoredErrorsFlagHelp)

flag.StringVar(&c.Filename, FilenameFlagLong, defaultFilename, filenameFlagHelp)

flag.StringVar(&c.Server, ServerFlagShort, defaultServer, serverFlagHelp+" (shorthand)")
flag.StringVar(&c.Server, ServerFlagShort, defaultServer, serverFlagHelp+shorthandFlagSuffix)
flag.StringVar(&c.Server, ServerFlagLong, defaultServer, serverFlagHelp)

flag.StringVar(&c.DNSName, DNSNameFlagShort, defaultDNSName, dnsNameFlagHelp+" (shorthand)")
flag.StringVar(&c.DNSName, DNSNameFlagShort, defaultDNSName, dnsNameFlagHelp+shorthandFlagSuffix)
flag.StringVar(&c.DNSName, DNSNameFlagLong, defaultDNSName, dnsNameFlagHelp)

flag.IntVar(&c.Port, PortFlagShort, defaultPort, portFlagHelp+" (shorthand)")
flag.IntVar(&c.Port, PortFlagShort, defaultPort, portFlagHelp+shorthandFlagSuffix)
flag.IntVar(&c.Port, PortFlagLong, defaultPort, portFlagHelp)

flag.Var(
Expand Down Expand Up @@ -135,19 +135,19 @@ func (c *Config) handleFlagsConfig(appType AppType) {

appDescription = "Used to generate a summary of certificate chain metadata and validation results for quick review."

flag.BoolVar(&c.VerboseOutput, VerboseFlagShort, defaultVerboseOutput, verboseOutputFlagHelp+" (shorthand)")
flag.BoolVar(&c.VerboseOutput, VerboseFlagShort, defaultVerboseOutput, verboseOutputFlagHelp+shorthandFlagSuffix)
flag.BoolVar(&c.VerboseOutput, VerboseFlagLong, defaultVerboseOutput, verboseOutputFlagHelp)

flag.StringVar(&c.Filename, FilenameFlagLong, defaultFilename, filenameFlagHelp)
flag.BoolVar(&c.EmitCertText, EmitCertTextFlagLong, defaultEmitCertText, emitCertTextFlagHelp)

flag.StringVar(&c.Server, ServerFlagShort, defaultServer, serverFlagHelp+" (shorthand)")
flag.StringVar(&c.Server, ServerFlagShort, defaultServer, serverFlagHelp+shorthandFlagSuffix)
flag.StringVar(&c.Server, ServerFlagLong, defaultServer, serverFlagHelp)

flag.StringVar(&c.DNSName, DNSNameFlagShort, defaultDNSName, dnsNameFlagHelp)
flag.StringVar(&c.DNSName, DNSNameFlagLong, defaultDNSName, dnsNameFlagHelp)

flag.IntVar(&c.Port, PortFlagShort, defaultPort, portFlagHelp+" (shorthand)")
flag.IntVar(&c.Port, PortFlagShort, defaultPort, portFlagHelp+shorthandFlagSuffix)
flag.IntVar(&c.Port, PortFlagLong, defaultPort, portFlagHelp)

case appType.Scanner:
Expand All @@ -164,56 +164,56 @@ func (c *Config) handleFlagsConfig(appType AppType) {
appDescription = "Scanner used for evaluating certificates in one or more given IP ranges or collection of name/FQDN values."

flag.IntVar(&c.timeoutPortScan, TimeoutPortScanFlagLong, defaultPortScanTimeout, timeoutPortScanFlagHelp)
flag.IntVar(&c.timeoutPortScan, TimeoutPortScanFlagShort, defaultPortScanTimeout, timeoutPortScanFlagHelp+" (shorthand)")
flag.IntVar(&c.timeoutPortScan, TimeoutPortScanFlagShort, defaultPortScanTimeout, timeoutPortScanFlagHelp+shorthandFlagSuffix)

flag.Var(&c.hosts, HostsFlagLong, hostsFlagHelp)
flag.Var(&c.hosts, HostsFlagAlt, hostsFlagHelp+" (alt name)")

flag.IntVar(&c.ScanRateLimit, ScanRateLimitFlagLong, defaultScanRateLimit, scanRateLimitFlagHelp)
flag.IntVar(&c.ScanRateLimit, ScanRateLimitFlagShort, defaultScanRateLimit, scanRateLimitFlagHelp+" (shorthand)")
flag.IntVar(&c.ScanRateLimit, ScanRateLimitFlagShort, defaultScanRateLimit, scanRateLimitFlagHelp+shorthandFlagSuffix)

flag.IntVar(&c.timeoutAppInactivity, AppTimeoutFlagLong, defaultAppTimeout, timeoutAppInactivityFlagHelp)
flag.IntVar(&c.timeoutAppInactivity, AppTimeoutFlagShort, defaultAppTimeout, timeoutAppInactivityFlagHelp+" (shorthand)")
flag.IntVar(&c.timeoutAppInactivity, AppTimeoutFlagShort, defaultAppTimeout, timeoutAppInactivityFlagHelp+shorthandFlagSuffix)

flag.Var(&c.portsList, PortsFlagLong, portsListFlagHelp)
flag.Var(&c.portsList, PortsFlagShort, portsListFlagHelp+" (shorthand)")
flag.Var(&c.portsList, PortsFlagShort, portsListFlagHelp+shorthandFlagSuffix)

flag.BoolVar(&c.ShowPortScanResults, ShowPortScanResultsFlagLong, defaultShowPortScanResults, showPortScanResultsFlagHelp)
flag.BoolVar(&c.ShowPortScanResults, ShowPortScanResultsFlagShort, defaultShowPortScanResults, showPortScanResultsFlagHelp+" (shorthand)")
flag.BoolVar(&c.ShowPortScanResults, ShowPortScanResultsFlagShort, defaultShowPortScanResults, showPortScanResultsFlagHelp+shorthandFlagSuffix)

flag.BoolVar(&c.ShowHostsWithClosedPorts, ShowHostsWithClosedPortsFlagLong, defaultShowHostsWithClosedPorts, showHostsWithClosedPortsFlagHelp)
flag.BoolVar(&c.ShowHostsWithClosedPorts, ShowHostsWithClosedPortsFlagShort, defaultShowHostsWithClosedPorts, showHostsWithClosedPortsFlagHelp+" (shorthand)")
flag.BoolVar(&c.ShowHostsWithClosedPorts, ShowHostsWithClosedPortsFlagShort, defaultShowHostsWithClosedPorts, showHostsWithClosedPortsFlagHelp+shorthandFlagSuffix)

flag.BoolVar(&c.ShowHostsWithValidCerts, ShowHostsWithValidCertsFlagLong, defaultShowHostsWithValidCerts, showHostsWithValidCertsFlagHelp)
flag.BoolVar(&c.ShowHostsWithValidCerts, ShowHostsWithValidCertsFlagShort, defaultShowHostsWithValidCerts, showHostsWithValidCertsFlagHelp+" (shorthand)")
flag.BoolVar(&c.ShowHostsWithValidCerts, ShowHostsWithValidCertsFlagShort, defaultShowHostsWithValidCerts, showHostsWithValidCertsFlagHelp+shorthandFlagSuffix)

flag.BoolVar(&c.ShowValidCerts, ShowValidCertsFlagLong, defaultShowValidCerts, showValidCertsFlagHelp)
flag.BoolVar(&c.ShowValidCerts, ShowValidCertsFlagShort, defaultShowValidCerts, showValidCertsFlagHelp+" (shorthand)")
flag.BoolVar(&c.ShowValidCerts, ShowValidCertsFlagShort, defaultShowValidCerts, showValidCertsFlagHelp+shorthandFlagSuffix)

flag.BoolVar(&c.ShowOverview, ShowOverviewFlagLong, defaultShowOverview, showOverviewFlagHelp)
flag.BoolVar(&c.ShowOverview, ShowOverviewFlagShort, defaultShowOverview, showOverviewFlagHelp+" (shorthand)")
flag.BoolVar(&c.ShowOverview, ShowOverviewFlagShort, defaultShowOverview, showOverviewFlagHelp+shorthandFlagSuffix)

}

// Shared flags for all application type

flag.Var(&c.SANsEntries, SANsEntriesFlagShort, sansEntriesFlagHelp+" (shorthand)")
flag.Var(&c.SANsEntries, SANsEntriesFlagShort, sansEntriesFlagHelp+shorthandFlagSuffix)
flag.Var(&c.SANsEntries, SANsEntriesFlagLong, sansEntriesFlagHelp)

flag.IntVar(&c.AgeWarning, AgeWarningFlagShort, defaultCertExpireAgeWarning, certExpireAgeWarningFlagHelp+" (shorthand)")
flag.IntVar(&c.AgeWarning, AgeWarningFlagShort, defaultCertExpireAgeWarning, certExpireAgeWarningFlagHelp+shorthandFlagSuffix)
flag.IntVar(&c.AgeWarning, AgeWarningFlagLong, defaultCertExpireAgeWarning, certExpireAgeWarningFlagHelp)

flag.IntVar(&c.AgeCritical, AgeCriticalFlagShort, defaultCertExpireAgeCritical, certExpireAgeCriticalFlagHelp+" (shorthand)")
flag.IntVar(&c.AgeCritical, AgeCriticalFlagShort, defaultCertExpireAgeCritical, certExpireAgeCriticalFlagHelp+shorthandFlagSuffix)
flag.IntVar(&c.AgeCritical, AgeCriticalFlagLong, defaultCertExpireAgeCritical, certExpireAgeCriticalFlagHelp)

flag.IntVar(&c.timeout, TimeoutFlagShort, defaultConnectTimeout, timeoutConnectFlagHelp+" (shorthand)")
flag.IntVar(&c.timeout, TimeoutFlagShort, defaultConnectTimeout, timeoutConnectFlagHelp+shorthandFlagSuffix)
flag.IntVar(&c.timeout, TimeoutFlagLong, defaultConnectTimeout, timeoutConnectFlagHelp)

flag.StringVar(
&c.LoggingLevel,
LogLevelFlagShort,
defaultLogLevel,
supportedValuesFlagHelpText(logLevelFlagHelp, supportedLogLevels())+" (shorthand)",
supportedValuesFlagHelpText(logLevelFlagHelp, supportedLogLevels())+shorthandFlagSuffix,
)
flag.StringVar(
&c.LoggingLevel,
Expand Down
6 changes: 2 additions & 4 deletions internal/config/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ func (c Config) validate(appType AppType) error {
for _, specifiedKeyword := range c.ignoreValidationResults {
if !textutils.InList(specifiedKeyword, supportedValidationKeywords, true) {
return fmt.Errorf(
"invalid ignore validation results keyword specified;"+
" got %v, expected one of %v",
"invalid ignore validation results keyword specified; got %v, expected one of %v",
specifiedKeyword,
supportedValidationKeywords,
)
Expand All @@ -84,8 +83,7 @@ func (c Config) validate(appType AppType) error {
for _, specifiedKeyword := range c.applyValidationResults {
if !textutils.InList(specifiedKeyword, supportedValidationKeywords, true) {
return fmt.Errorf(
"invalid apply validation results keyword specified;"+
" got %v, expected one of %v",
"invalid apply validation results keyword specified; got %v, expected one of %v",
specifiedKeyword,
supportedValidationKeywords,
)
Expand Down
9 changes: 3 additions & 6 deletions internal/netutils/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,7 @@ func ExpandHost(hostPattern string) (HostPattern, error) {
num, err := strconv.Atoi(halves[0])
if err != nil {
return HostPattern{}, fmt.Errorf(
"octet %q of IP pattern %q invalid; "+
"non-numeric values present: %w",
"octet %q of IP pattern %q invalid; non-numeric values present: %w",
octets[octIdx],
hostPattern,
ErrUnrecognizedIPRange,
Expand All @@ -449,8 +448,7 @@ func ExpandHost(hostPattern string) (HostPattern, error) {
rangeStart, err := strconv.Atoi(halves[0])
if err != nil {
return HostPattern{}, fmt.Errorf(
"octet %q of IP pattern %q invalid; "+
"non-numeric values present: %w",
"octet %q of IP pattern %q invalid; non-numeric values present: %w",
octets[octIdx],
hostPattern,
ErrUnrecognizedIPRange,
Expand All @@ -460,8 +458,7 @@ func ExpandHost(hostPattern string) (HostPattern, error) {
rangeEnd, err := strconv.Atoi(halves[1])
if err != nil {
return HostPattern{}, fmt.Errorf(
"octet %q of IP pattern %q invalid; "+
"non-numeric values present: %w",
"octet %q of IP pattern %q invalid; non-numeric values present: %w",
octets[octIdx],
hostPattern,
ErrUnrecognizedIPRange,
Expand Down

0 comments on commit 9147fe6

Please sign in to comment.