Skip to content

Commit

Permalink
fix: resolve revive linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Integralist committed Jun 15, 2023
1 parent 2d29467 commit 217c264
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 50 deletions.
67 changes: 34 additions & 33 deletions pkg/commands/logging/common/flags.go
Original file line number Diff line number Diff line change
@@ -1,86 +1,87 @@
package common

import (
"github.com/fastly/cli/pkg/cmd"
"github.com/fastly/kingpin"

"github.com/fastly/cli/pkg/cmd"
)

// AccountName defines the account-name flag.
func AccountName(cmd *kingpin.CmdClause, c *cmd.OptionalString) {
cmd.Flag("account-name", "The google account name used to obtain temporary credentials (default none)").Action(c.Set).StringVar(&c.Value)
func AccountName(command *kingpin.CmdClause, c *cmd.OptionalString) {
command.Flag("account-name", "The google account name used to obtain temporary credentials (default none)").Action(c.Set).StringVar(&c.Value)
}

// Format defines the format flag
func Format(cmd *kingpin.CmdClause, c *cmd.OptionalString) {
cmd.Flag("format", "Apache style log formatting. Your log must produce valid JSON").Action(c.Set).StringVar(&c.Value)
func Format(command *kingpin.CmdClause, c *cmd.OptionalString) {
command.Flag("format", "Apache style log formatting. Your log must produce valid JSON").Action(c.Set).StringVar(&c.Value)
}

// GzipLevel defines the gzip flag
func GzipLevel(cmd *kingpin.CmdClause, c *cmd.OptionalInt) {
cmd.Flag("gzip-level", "What level of GZIP encoding to have when dumping logs (default 0, no compression)").Action(c.Set).IntVar(&c.Value)
func GzipLevel(command *kingpin.CmdClause, c *cmd.OptionalInt) {
command.Flag("gzip-level", "What level of GZIP encoding to have when dumping logs (default 0, no compression)").Action(c.Set).IntVar(&c.Value)
}

// Path defines the path flag
func Path(cmd *kingpin.CmdClause, c *cmd.OptionalString) {
cmd.Flag("path", "The path to upload logs to").Action(c.Set).StringVar(&c.Value)
func Path(command *kingpin.CmdClause, c *cmd.OptionalString) {
command.Flag("path", "The path to upload logs to").Action(c.Set).StringVar(&c.Value)
}

// MessageType defines the path flag
func MessageType(cmd *kingpin.CmdClause, c *cmd.OptionalString) {
cmd.Flag("message-type", "How the message should be formatted. One of: classic (default), loggly, logplex or blank").Action(c.Set).StringVar(&c.Value)
func MessageType(command *kingpin.CmdClause, c *cmd.OptionalString) {
command.Flag("message-type", "How the message should be formatted. One of: classic (default), loggly, logplex or blank").Action(c.Set).StringVar(&c.Value)
}

// Period defines the period flag
func Period(cmd *kingpin.CmdClause, c *cmd.OptionalInt) {
cmd.Flag("period", "How frequently log files are finalized so they can be available for reading (in seconds, default 3600)").Action(c.Set).IntVar(&c.Value)
func Period(command *kingpin.CmdClause, c *cmd.OptionalInt) {
command.Flag("period", "How frequently log files are finalized so they can be available for reading (in seconds, default 3600)").Action(c.Set).IntVar(&c.Value)
}

// FormatVersion defines the format-version flag
func FormatVersion(cmd *kingpin.CmdClause, c *cmd.OptionalInt) {
cmd.Flag("format-version", "The version of the custom logging format used for the configured endpoint. Can be either 2 (the default, version 2 log format) or 1 (the version 1 log format). The logging call gets placed by default in vcl_log if format_version is set to 2 and in vcl_deliver if format_version is set to 1").Action(c.Set).IntVar(&c.Value)
func FormatVersion(command *kingpin.CmdClause, c *cmd.OptionalInt) {
command.Flag("format-version", "The version of the custom logging format used for the configured endpoint. Can be either 2 (the default, version 2 log format) or 1 (the version 1 log format). The logging call gets placed by default in vcl_log if format_version is set to 2 and in vcl_deliver if format_version is set to 1").Action(c.Set).IntVar(&c.Value)
}

// CompressionCodec defines the compression-codec flag
func CompressionCodec(cmd *kingpin.CmdClause, c *cmd.OptionalString) {
cmd.Flag("compression-codec", `The codec used for compression of your logs. Valid values are zstd, snappy, and gzip. If the specified codec is "gzip", gzip_level will default to 3. To specify a different level, leave compression_codec blank and explicitly set the level using gzip_level. Specifying both compression_codec and gzip_level in the same API request will result in an error.`).Action(c.Set).StringVar(&c.Value)
func CompressionCodec(command *kingpin.CmdClause, c *cmd.OptionalString) {
command.Flag("compression-codec", `The codec used for compression of your logs. Valid values are zstd, snappy, and gzip. If the specified codec is "gzip", gzip_level will default to 3. To specify a different level, leave compression_codec blank and explicitly set the level using gzip_level. Specifying both compression_codec and gzip_level in the same API request will result in an error.`).Action(c.Set).StringVar(&c.Value)
}

// Placement defines the placement flag
func Placement(cmd *kingpin.CmdClause, c *cmd.OptionalString) {
cmd.Flag("placement", "Where in the generated VCL the logging call should be placed, overriding any format_version default. Can be none or waf_debug. This field is not required and has no default value").Action(c.Set).StringVar(&c.Value)
func Placement(command *kingpin.CmdClause, c *cmd.OptionalString) {
command.Flag("placement", "Where in the generated VCL the logging call should be placed, overriding any format_version default. Can be none or waf_debug. This field is not required and has no default value").Action(c.Set).StringVar(&c.Value)
}

// ResponseCondition defines the response-condition flag
func ResponseCondition(cmd *kingpin.CmdClause, c *cmd.OptionalString) {
cmd.Flag("response-condition", "The name of an existing condition in the configured endpoint, or leave blank to always execute").Action(c.Set).StringVar(&c.Value)
func ResponseCondition(command *kingpin.CmdClause, c *cmd.OptionalString) {
command.Flag("response-condition", "The name of an existing condition in the configured endpoint, or leave blank to always execute").Action(c.Set).StringVar(&c.Value)
}

// TimestampFormat defines the timestamp-format flag
func TimestampFormat(cmd *kingpin.CmdClause, c *cmd.OptionalString) {
cmd.Flag("timestamp-format", `strftime specified timestamp formatting (default "%Y-%m-%dT%H:%M:%S.000")`).Action(c.Set).StringVar(&c.Value)
func TimestampFormat(command *kingpin.CmdClause, c *cmd.OptionalString) {
command.Flag("timestamp-format", `strftime specified timestamp formatting (default "%Y-%m-%dT%H:%M:%S.000")`).Action(c.Set).StringVar(&c.Value)
}

// PublicKey defines the public-key flag
func PublicKey(cmd *kingpin.CmdClause, c *cmd.OptionalString) {
cmd.Flag("public-key", "A PGP public key that Fastly will use to encrypt your log files before writing them to disk").Action(c.Set).StringVar(&c.Value)
func PublicKey(command *kingpin.CmdClause, c *cmd.OptionalString) {
command.Flag("public-key", "A PGP public key that Fastly will use to encrypt your log files before writing them to disk").Action(c.Set).StringVar(&c.Value)
}

// TLSCACert defines the tls-ca-cert flag
func TLSCACert(cmd *kingpin.CmdClause, c *cmd.OptionalString) {
cmd.Flag("tls-ca-cert", "A secure certificate to authenticate the server with. Must be in PEM format").Action(c.Set).StringVar(&c.Value)
func TLSCACert(command *kingpin.CmdClause, c *cmd.OptionalString) {
command.Flag("tls-ca-cert", "A secure certificate to authenticate the server with. Must be in PEM format").Action(c.Set).StringVar(&c.Value)
}

// TLSHostname defines the tls-hostname flag
func TLSHostname(cmd *kingpin.CmdClause, c *cmd.OptionalString) {
cmd.Flag("tls-hostname", "Used during the TLS handshake to validate the certificate").Action(c.Set).StringVar(&c.Value)
func TLSHostname(command *kingpin.CmdClause, c *cmd.OptionalString) {
command.Flag("tls-hostname", "Used during the TLS handshake to validate the certificate").Action(c.Set).StringVar(&c.Value)
}

// TLSClientCert defines the tls-client-cert flag
func TLSClientCert(cmd *kingpin.CmdClause, c *cmd.OptionalString) {
cmd.Flag("tls-client-cert", "The client certificate used to make authenticated requests. Must be in PEM format").Action(c.Set).StringVar(&c.Value)
func TLSClientCert(command *kingpin.CmdClause, c *cmd.OptionalString) {
command.Flag("tls-client-cert", "The client certificate used to make authenticated requests. Must be in PEM format").Action(c.Set).StringVar(&c.Value)
}

// TLSClientKey defines the tls-client-key flag
func TLSClientKey(cmd *kingpin.CmdClause, c *cmd.OptionalString) {
cmd.Flag("tls-client-key", "The client private key used to make authenticated requests. Must be in PEM format").Action(c.Set).StringVar(&c.Value)
func TLSClientKey(command *kingpin.CmdClause, c *cmd.OptionalString) {
command.Flag("tls-client-key", "The client private key used to make authenticated requests. Must be in PEM format").Action(c.Set).StringVar(&c.Value)
}
14 changes: 8 additions & 6 deletions pkg/commands/logging/s3/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"fmt"
"io"

"github.com/fastly/go-fastly/v8/fastly"

"github.com/fastly/cli/pkg/cmd"
"github.com/fastly/cli/pkg/commands/logging/common"
"github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/global"
"github.com/fastly/cli/pkg/manifest"
"github.com/fastly/cli/pkg/text"
"github.com/fastly/go-fastly/v8/fastly"
)

// CreateCommand calls the Fastly API to create an Amazon S3 logging endpoint.
Expand Down Expand Up @@ -126,14 +127,15 @@ func (c *CreateCommand) ConstructInput(serviceID string, serviceVersion int) (*f
// SecretKey or the IAMRole is required, but they are mutually
// exclusive. The kingpin library lacks a way to express this constraint
// via the flag specification API so we enforce it manually here.
if !c.AccessKey.WasSet && !c.SecretKey.WasSet && !c.IAMRole.WasSet {
switch {
case !c.AccessKey.WasSet && !c.SecretKey.WasSet && !c.IAMRole.WasSet:
return nil, fmt.Errorf("error parsing arguments: the --access-key and --secret-key flags or the --iam-role flag must be provided")
} else if (c.AccessKey.WasSet || c.SecretKey.WasSet) && c.IAMRole.WasSet {
case (c.AccessKey.WasSet || c.SecretKey.WasSet) && c.IAMRole.WasSet:
// Enforce mutual exclusion
return nil, fmt.Errorf("error parsing arguments: the --access-key and --secret-key flags are mutually exclusive with the --iam-role flag")
} else if c.AccessKey.WasSet && !c.SecretKey.WasSet {
case c.AccessKey.WasSet && !c.SecretKey.WasSet:
return nil, fmt.Errorf("error parsing arguments: required flag --secret-key not provided")
} else if !c.AccessKey.WasSet && c.SecretKey.WasSet {
case !c.AccessKey.WasSet && c.SecretKey.WasSet:
return nil, fmt.Errorf("error parsing arguments: required flag --access-key not provided")
}

Expand Down Expand Up @@ -250,7 +252,7 @@ func ValidateRedundancy(val string) (redundancy fastly.S3Redundancy, err error)
default:
err = fmt.Errorf("unknown redundancy: " + val)
}
return
return redundancy, err
}

// Exec invokes the application logic for the command.
Expand Down
2 changes: 1 addition & 1 deletion pkg/text/lines.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// Lines is the struct that is used by PrintLines
type Lines map[string]interface{}
type Lines map[string]any

// PrintLines pretty prints a Lines struct with one item per line.
// The map is sorted before printing and a newline is added at the beginning
Expand Down
5 changes: 3 additions & 2 deletions pkg/text/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
"strings"
"syscall"

"github.com/fastly/cli/pkg/sync"
"github.com/mitchellh/go-wordwrap"
"golang.org/x/term"

"github.com/fastly/cli/pkg/sync"
)

// DefaultTextWidth is the width that should be passed to Wrap for most
Expand Down Expand Up @@ -111,7 +112,7 @@ func IsStdin(r io.Reader) bool {
// IsTTY returns true if fd is a terminal. When used in combination
// with IsStdin, it can be used to determine whether standard input
// is being piped data (i.e. IsStdin == true && IsTTY == false).
// Provide STDOUT as a way to determine whether formating and/or
// Provide STDOUT as a way to determine whether formatting and/or
// prompting is acceptable output.
func IsTTY(fd any) bool {
if s, ok := fd.(*sync.Writer); ok {
Expand Down
16 changes: 8 additions & 8 deletions scripts/go-test-cache/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import (
)

const (
BUF_SIZE = 65536
BASE_DATE = 1684178360
TIME_FORMAT = "2006-01-02 15:04:05"
bufSize = 65536
baseDate = 1684178360
timeFormat = "2006-01-02 15:04:05"
)

func main() {
Expand Down Expand Up @@ -55,7 +55,7 @@ func main() {

modTime := getModifiedTime(sha1Hash)

log.Printf("Setting modified time of file %s to %s\n", relPath, modTime.Format(TIME_FORMAT))
log.Printf("Setting modified time of file %s to %s\n", relPath, modTime.Format(timeFormat))
err = os.Chtimes(filePath, modTime, modTime)
if err != nil {
return err
Expand All @@ -75,8 +75,8 @@ func main() {
for _, dirPath := range allDirs {
relPath, _ := filepath.Rel(repoRoot, dirPath)

log.Printf("Setting modified time of directory %s to %s\n", relPath, time.Unix(BASE_DATE, 0).Format(TIME_FORMAT))
err := os.Chtimes(dirPath, time.Unix(BASE_DATE, 0), time.Unix(BASE_DATE, 0))
log.Printf("Setting modified time of directory %s to %s\n", relPath, time.Unix(baseDate, 0).Format(timeFormat))
err := os.Chtimes(dirPath, time.Unix(baseDate, 0), time.Unix(baseDate, 0))
if err != nil {
log.Fatal("Error:", err)
}
Expand All @@ -93,7 +93,7 @@ func getFileSHA1(filePath string) (string, error) {
defer file.Close()

hash := sha1.New()
if _, err := io.CopyBuffer(hash, file, make([]byte, BUF_SIZE)); err != nil {
if _, err := io.CopyBuffer(hash, file, make([]byte, bufSize)); err != nil {
return "", err
}

Expand All @@ -109,6 +109,6 @@ func getModifiedTime(sha1Hash string) time.Time {
lastFiveValue = (lastFiveValue << 8) + int64(b)
}

modTime := BASE_DATE - (lastFiveValue % 10000)
modTime := baseDate - (lastFiveValue % 10000)
return time.Unix(modTime, 0)
}

0 comments on commit 217c264

Please sign in to comment.