From 6d6a0d33b471c48bc1f3fa3aa23272447f8e569a Mon Sep 17 00:00:00 2001 From: Kelly L McLaughlin Date: Mon, 26 Oct 2020 15:52:42 -0600 Subject: [PATCH 01/12] Support sasl kafka endpoint options in Fastly CLI --- pkg/logging/kafka/create.go | 52 +++- pkg/logging/kafka/describe.go | 5 + pkg/logging/kafka/kafka_integration_test.go | 70 ++++- pkg/logging/kafka/kafka_test.go | 327 +++++++++++++++++++- pkg/logging/kafka/list.go | 5 + pkg/logging/kafka/update.go | 81 +++++ 6 files changed, 531 insertions(+), 9 deletions(-) diff --git a/pkg/logging/kafka/create.go b/pkg/logging/kafka/create.go index 47b5335ed..d694b1b6d 100644 --- a/pkg/logging/kafka/create.go +++ b/pkg/logging/kafka/create.go @@ -1,6 +1,7 @@ package kafka import ( + "fmt" "io" "github.com/fastly/cli/pkg/common" @@ -34,6 +35,12 @@ type CreateCommand struct { FormatVersion common.OptionalUint Placement common.OptionalString ResponseCondition common.OptionalString + ParseLogKeyvals common.OptionalBool + RequestMaxBytes common.OptionalUint + UseSASL common.OptionalBool + AuthMethod common.OptionalString + User common.OptionalString + Password common.OptionalString } // NewCreateCommand returns a usable command registered under the parent. @@ -52,7 +59,7 @@ func NewCreateCommand(parent common.Registerer, globals *config.Data) *CreateCom c.CmdClause.Flag("compression-codec", "The codec used for compression of your logs. One of: gzip, snappy, lz4").Action(c.CompressionCodec.Set).StringVar(&c.CompressionCodec.Value) c.CmdClause.Flag("required-acks", "The Number of acknowledgements a leader must receive before a write is considered successful. One of: 1 (default) One server needs to respond. 0 No servers need to respond. -1 Wait for all in-sync replicas to respond").Action(c.RequiredACKs.Set).StringVar(&c.RequiredACKs.Value) - c.CmdClause.Flag("use-tls", "Whether to use TLS for secure logging. Can be either true or false").Action(c.UseTLS.Set).BoolVar(&c.UseTLS.Value) + c.CmdClause.Flag("use-tls", "Whether to use TLS for secure logging.").Action(c.UseTLS.Set).BoolVar(&c.UseTLS.Value) c.CmdClause.Flag("tls-ca-cert", "A secure certificate to authenticate the server with. Must be in PEM format").Action(c.TLSCACert.Set).StringVar(&c.TLSCACert.Value) c.CmdClause.Flag("tls-client-cert", "The client certificate used to make authenticated requests. Must be in PEM format").Action(c.TLSClientCert.Set).StringVar(&c.TLSClientCert.Value) c.CmdClause.Flag("tls-client-key", "The client private key used to make authenticated requests. Must be in PEM format").Action(c.TLSClientKey.Set).StringVar(&c.TLSClientKey.Value) @@ -61,6 +68,12 @@ func NewCreateCommand(parent common.Registerer, globals *config.Data) *CreateCom c.CmdClause.Flag("format-version", "The version of the custom logging format used for the configured endpoint. Can be either 2 (default) or 1").Action(c.FormatVersion.Set).UintVar(&c.FormatVersion.Value) c.CmdClause.Flag("placement", "Where in the generated VCL the logging call should be placed, overriding any format_version default. Can be none or waf_debug").Action(c.Placement.Set).StringVar(&c.Placement.Value) c.CmdClause.Flag("response-condition", "The name of an existing condition in the configured endpoint, or leave blank to always execute").Action(c.ResponseCondition.Set).StringVar(&c.ResponseCondition.Value) + c.CmdClause.Flag("parse-log-keyvals", "Parse key-value pairs within the log format.").Action(c.ParseLogKeyvals.Set).BoolVar(&c.ParseLogKeyvals.Value) + c.CmdClause.Flag("max-batch-size", "The maximum size of the log batch in bytes").Action(c.RequestMaxBytes.Set).UintVar(&c.RequestMaxBytes.Value) + c.CmdClause.Flag("use-sasl", "Enable SASL authentication. Requires --auth-method, --username, and --password to be specified.").Action(c.UseSASL.Set).BoolVar(&c.UseSASL.Value) + c.CmdClause.Flag("auth-method", "SASL authentication method. Valid values are: plain, scram-sha-256, scram-sha-512").Action(c.AuthMethod.Set).StringVar(&c.AuthMethod.Value) + c.CmdClause.Flag("username", "SASL authentication username. Required if --auth-method is specified.").Action(c.User.Set).StringVar(&c.User.Value) + c.CmdClause.Flag("password", "SASL authentication password. Required if --auth-method is specified.").Action(c.Password.Set).StringVar(&c.Password.Value) return &c } @@ -68,7 +81,6 @@ func NewCreateCommand(parent common.Registerer, globals *config.Data) *CreateCom // createInput transforms values parsed from CLI flags into an object to be used by the API client library. func (c *CreateCommand) createInput() (*fastly.CreateKafkaInput, error) { var input fastly.CreateKafkaInput - serviceID, source := c.manifest.ServiceID() if source == manifest.SourceUndefined { return nil, errors.ErrNoServiceID @@ -124,6 +136,42 @@ func (c *CreateCommand) createInput() (*fastly.CreateKafkaInput, error) { input.Placement = fastly.String(c.Placement.Value) } + if c.ParseLogKeyvals.Valid { + input.ParseLogKeyvals = fastly.CBool(c.ParseLogKeyvals.Value) + } + + if c.RequestMaxBytes.Valid { + input.RequestMaxBytes = fastly.Uint(c.RequestMaxBytes.Value) + } + + if c.UseSASL.Valid && c.UseSASL.Value { + if c.AuthMethod.Value == "" || c.User.Value == "" || c.Password.Value == "" { + return nil, fmt.Errorf("the --auth-method, --username, and --password flags must be present when using the --use-sasl flag") + + } + + if c.AuthMethod.Value != "plain" && + c.AuthMethod.Value != "scram-sha-256" && + c.AuthMethod.Value != "scram-sha-512" { + + return nil, fmt.Errorf("invalid SASL authentication method: %s. Valid values are plain, scram-sha-256, and scram-sha-512", c.AuthMethod.Value) + } + + input.AuthMethod = fastly.String(c.AuthMethod.Value) + + if c.User.Valid { + input.User = fastly.String(c.User.Value) + } + + if c.Password.Valid { + input.Password = fastly.String(c.Password.Value) + } + } + + if !c.UseSASL.Value && (c.AuthMethod.Value != "" || c.User.Value != "" || c.Password.Value != "") { + return nil, fmt.Errorf("the --auth-method, --username, and --password options are only valid when the --use-sasl flag is specified") + } + return &input, nil } diff --git a/pkg/logging/kafka/describe.go b/pkg/logging/kafka/describe.go index 7c4cf0cfe..8e705677b 100644 --- a/pkg/logging/kafka/describe.go +++ b/pkg/logging/kafka/describe.go @@ -59,6 +59,11 @@ func (c *DescribeCommand) Exec(in io.Reader, out io.Writer) error { fmt.Fprintf(out, "Format version: %d\n", kafka.FormatVersion) fmt.Fprintf(out, "Response condition: %s\n", kafka.ResponseCondition) fmt.Fprintf(out, "Placement: %s\n", kafka.Placement) + fmt.Fprintf(out, "Parse log key-values: %t\n", kafka.ParseLogKeyvals) + fmt.Fprintf(out, "Max batch size: %d\n", kafka.RequestMaxBytes) + fmt.Fprintf(out, "SASL authentication method: %s\n", kafka.AuthMethod) + fmt.Fprintf(out, "SASL authentication username: %s\n", kafka.User) + fmt.Fprintf(out, "SASL authentication password: %s\n", kafka.Password) return nil } diff --git a/pkg/logging/kafka/kafka_integration_test.go b/pkg/logging/kafka/kafka_integration_test.go index 67407bd16..88397960e 100644 --- a/pkg/logging/kafka/kafka_integration_test.go +++ b/pkg/logging/kafka/kafka_integration_test.go @@ -32,7 +32,7 @@ func TestKafkaCreate(t *testing.T) { wantError: "error parsing arguments: required flag --brokers not provided", }, { - args: []string{"logging", "kafka", "create", "--service-id", "123", "--version", "1", "--name", "log", "--topic", "logs", "--brokers", "127.0.0.1,127.0.0.2"}, + args: []string{"logging", "kafka", "create", "--service-id", "123", "--version", "1", "--name", "log", "--topic", "logs", "--brokers", "127.0.0.1,127.0.0.2", "--parse-log-keyvals", "--max-batch-size", "1024", "--use-sasl", "--auth-method", "plain", "--username", "user", "--password", "password"}, api: mock.API{CreateKafkaFn: createKafkaOK}, wantOutput: "Created Kafka logging endpoint log (service 123 version 1)", }, @@ -194,6 +194,14 @@ func TestKafkaUpdate(t *testing.T) { }, wantOutput: "Updated Kafka logging endpoint log (service 123 version 1)", }, + { + args: []string{"logging", "kafka", "update", "--service-id", "123", "--version", "1", "--name", "logs", "--new-name", "log", "--parse-log-keyvals", "--max-batch-size", "1024", "--use-sasl", "--auth-method", "plain", "--username", "user", "--password", "password"}, + api: mock.API{ + GetKafkaFn: getKafkaOK, + UpdateKafkaFn: updateKafkaSASL, + }, + wantOutput: "Updated Kafka logging endpoint log (service 123 version 1)", + }, } { t.Run(strings.Join(testcase.args, " "), func(t *testing.T) { var ( @@ -275,6 +283,11 @@ func createKafkaOK(i *fastly.CreateKafkaInput) (*fastly.Kafka, error) { TLSClientCert: "-----BEGIN CERTIFICATE-----bar", TLSClientKey: "-----BEGIN PRIVATE KEY-----bar", FormatVersion: 2, + ParseLogKeyvals: true, + RequestMaxBytes: 1024, + AuthMethod: "plain", + User: "user", + Password: "password", }, nil } @@ -301,6 +314,11 @@ func listKafkasOK(i *fastly.ListKafkasInput) ([]*fastly.Kafka, error) { TLSClientCert: "-----BEGIN CERTIFICATE-----bar", TLSClientKey: "-----BEGIN PRIVATE KEY-----bar", FormatVersion: 2, + ParseLogKeyvals: false, + RequestMaxBytes: 0, + AuthMethod: "", + User: "", + Password: "", }, { ServiceID: i.Service, @@ -319,6 +337,11 @@ func listKafkasOK(i *fastly.ListKafkasInput) ([]*fastly.Kafka, error) { ResponseCondition: "Prevent default logging", Format: `%h %l %u %t "%r" %>s %b`, FormatVersion: 2, + ParseLogKeyvals: false, + RequestMaxBytes: 0, + AuthMethod: "", + User: "", + Password: "", }, }, nil } @@ -355,6 +378,11 @@ Version: 1 Format version: 2 Response condition: Prevent default logging Placement: none + Parse log key-values: false + Max batch size: 0 + SASL authentication method: `+` + SASL authentication username: `+` + SASL authentication password: `+` Kafka 2/2 Service ID: 123 Version: 1 @@ -372,7 +400,12 @@ Version: 1 Format version: 2 Response condition: Prevent default logging Placement: none -`) + "\n\n" + Parse log key-values: false + Max batch size: 0 + SASL authentication method: `+` + SASL authentication username: `+` + SASL authentication password:`+` +`) + " \n\n" func getKafkaOK(i *fastly.GetKafkaInput) (*fastly.Kafka, error) { return &fastly.Kafka{ @@ -416,7 +449,12 @@ Format: %h %l %u %t "%r" %>s %b Format version: 2 Response condition: Prevent default logging Placement: none -`) + "\n" +Parse log key-values: false +Max batch size: 0 +SASL authentication method: `+` +SASL authentication username: `+` +SASL authentication password:`+` +`) + " \n" func updateKafkaOK(i *fastly.UpdateKafkaInput) (*fastly.Kafka, error) { return &fastly.Kafka{ @@ -439,6 +477,32 @@ func updateKafkaOK(i *fastly.UpdateKafkaInput) (*fastly.Kafka, error) { }, nil } +func updateKafkaSASL(i *fastly.UpdateKafkaInput) (*fastly.Kafka, error) { + return &fastly.Kafka{ + ServiceID: i.Service, + Version: i.Version, + Name: "log", + ResponseCondition: "Prevent default logging", + Format: `%h %l %u %t "%r" %>s %b`, + Topic: "logs", + Brokers: "127.0.0.1,127.0.0.2", + RequiredACKs: "-1", + CompressionCodec: "zippy", + UseTLS: true, + Placement: "none", + TLSCACert: "-----BEGIN CERTIFICATE-----foo", + TLSHostname: "127.0.0.1,127.0.0.2", + TLSClientCert: "-----BEGIN CERTIFICATE-----bar", + TLSClientKey: "-----BEGIN PRIVATE KEY-----bar", + FormatVersion: 2, + ParseLogKeyvals: true, + RequestMaxBytes: 1024, + AuthMethod: "plain", + User: "user", + Password: "password", + }, nil +} + func updateKafkaError(i *fastly.UpdateKafkaInput) (*fastly.Kafka, error) { return nil, errTest } diff --git a/pkg/logging/kafka/kafka_test.go b/pkg/logging/kafka/kafka_test.go index e8000c4ee..f0ebf7cc6 100644 --- a/pkg/logging/kafka/kafka_test.go +++ b/pkg/logging/kafka/kafka_test.go @@ -58,6 +58,71 @@ func TestCreateKafkaInput(t *testing.T) { want: nil, wantError: errors.ErrNoServiceID.Error(), }, + { + name: "verify SASL fields", + cmd: createCommandSASL("scram-sha-512", "user1", "12345"), + want: &fastly.CreateKafkaInput{ + Service: "123", + Version: 2, + Name: fastly.String("log"), + Topic: fastly.String("logs"), + Brokers: fastly.String("127.0.0.1,127.0.0.2"), + ParseLogKeyvals: fastly.CBool(true), + RequestMaxBytes: fastly.Uint(11111), + AuthMethod: fastly.String("scram-sha-512"), + User: fastly.String("user1"), + Password: fastly.String("12345"), + }, + }, + { + name: "verify SASL validation: invalid auth method", + cmd: createCommandSASL("bad-auth-type", "user", "password"), + want: nil, + wantError: "invalid SASL authentication method: bad-auth-type. Valid values are plain, scram-sha-256, and scram-sha-512", + }, + { + name: "verify SASL validation: missing username", + cmd: createCommandSASL("scram-sha-256", "", "password"), + want: nil, + wantError: "the --auth-method, --username, and --password flags must be present when using the --use-sasl flag", + }, + { + name: "verify SASL validation: missing password", + cmd: createCommandSASL("plain", "user", ""), + want: nil, + wantError: "the --auth-method, --username, and --password flags must be present when using the --use-sasl flag", + }, + { + name: "verify SASL validation: username with no auth method or password", + cmd: createCommandSASL("", "user1", ""), + want: nil, + wantError: "the --auth-method, --username, and --password flags must be present when using the --use-sasl flag", + }, + { + name: "verify SASL validation: password with no auth method", + cmd: createCommandSASL("", "", "password"), + want: nil, + wantError: "the --auth-method, --username, and --password flags must be present when using the --use-sasl flag", + }, + + { + name: "verify SASL validation: no SASL, but auth-method given", + cmd: createCommandNoSASL("scram-sha-256", "", ""), + want: nil, + wantError: "the --auth-method, --username, and --password options are only valid when the --use-sasl flag is specified", + }, + { + name: "verify SASL validation: no SASL, but username with given", + cmd: createCommandNoSASL("", "user1", ""), + want: nil, + wantError: "the --auth-method, --username, and --password options are only valid when the --use-sasl flag is specified", + }, + { + name: "verify SASL validation: no SASL, but password given", + cmd: createCommandNoSASL("", "", "password"), + want: nil, + wantError: "the --auth-method, --username, and --password options are only valid when the --use-sasl flag is specified", + }, } { t.Run(testcase.name, func(t *testing.T) { have, err := testcase.cmd.createInput() @@ -97,6 +162,11 @@ func TestUpdateKafkaInput(t *testing.T) { TLSClientCert: fastly.String("new10"), TLSClientKey: fastly.String("new11"), TLSHostname: fastly.String("new12"), + ParseLogKeyvals: fastly.CBool(false), + RequestMaxBytes: fastly.Uint(22222), + AuthMethod: fastly.String("plain"), + User: fastly.String("new13"), + Password: fastly.String("new14"), }, }, { @@ -121,6 +191,11 @@ func TestUpdateKafkaInput(t *testing.T) { TLSHostname: fastly.String("example.com"), TLSClientCert: fastly.String("-----BEGIN CERTIFICATE-----bar"), TLSClientKey: fastly.String("-----BEGIN PRIVATE KEY-----bar"), + ParseLogKeyvals: fastly.CBool(false), + RequestMaxBytes: fastly.Uint(11111), + AuthMethod: fastly.String(""), + User: fastly.String(""), + Password: fastly.String(""), }, }, { @@ -129,6 +204,113 @@ func TestUpdateKafkaInput(t *testing.T) { want: nil, wantError: errors.ErrNoServiceID.Error(), }, + { + name: "verify SASL fields", + api: mock.API{GetKafkaFn: getKafkaOK}, + cmd: updateCommandSASL("scram-sha-512", "user1", "12345"), + want: &fastly.UpdateKafkaInput{ + Service: "123", + Version: 2, + Name: "log", + NewName: fastly.String("log"), + Topic: fastly.String("logs"), + Brokers: fastly.String("127.0.0.1,127.0.0.2"), + RequiredACKs: fastly.String("-1"), + UseTLS: fastly.CBool(true), + CompressionCodec: fastly.String("zippy"), + Format: fastly.String(`%h %l %u %t "%r" %>s %b`), + FormatVersion: fastly.Uint(2), + ResponseCondition: fastly.String("Prevent default logging"), + Placement: fastly.String("none"), + TLSCACert: fastly.String("-----BEGIN CERTIFICATE-----foo"), + TLSHostname: fastly.String("example.com"), + TLSClientCert: fastly.String("-----BEGIN CERTIFICATE-----bar"), + TLSClientKey: fastly.String("-----BEGIN PRIVATE KEY-----bar"), + ParseLogKeyvals: fastly.CBool(true), + RequestMaxBytes: fastly.Uint(11111), + AuthMethod: fastly.String("scram-sha-512"), + User: fastly.String("user1"), + Password: fastly.String("12345"), + }, + }, + { + name: "verify disabling SASL", + api: mock.API{GetKafkaFn: getKafkaSASL}, + cmd: updateCommandNoSASL(), + want: &fastly.UpdateKafkaInput{ + Service: "123", + Version: 2, + Name: "log", + NewName: fastly.String("log"), + Topic: fastly.String("logs"), + Brokers: fastly.String("127.0.0.1,127.0.0.2"), + RequiredACKs: fastly.String("-1"), + UseTLS: fastly.CBool(true), + CompressionCodec: fastly.String("zippy"), + Format: fastly.String(`%h %l %u %t "%r" %>s %b`), + FormatVersion: fastly.Uint(2), + ResponseCondition: fastly.String("Prevent default logging"), + Placement: fastly.String("none"), + TLSCACert: fastly.String("-----BEGIN CERTIFICATE-----foo"), + TLSHostname: fastly.String("example.com"), + TLSClientCert: fastly.String("-----BEGIN CERTIFICATE-----bar"), + TLSClientKey: fastly.String("-----BEGIN PRIVATE KEY-----bar"), + ParseLogKeyvals: fastly.CBool(true), + RequestMaxBytes: fastly.Uint(11111), + AuthMethod: fastly.String(""), + User: fastly.String(""), + Password: fastly.String(""), + }, + }, + { + name: "verify SASL validation: enable and disable key-value log parsing", + api: mock.API{GetKafkaFn: getKafkaOK}, + cmd: updateCommandConflictingParseLogKeyvals(), + want: nil, + wantError: "--parse-key-logvals and --no-parse-key-logvals are mutually exclusive", + }, + { + name: "verify SASL validation: enable and disable SASL", + api: mock.API{GetKafkaFn: getKafkaOK}, + cmd: updateCommandEnableAndDisableSASL(), + want: nil, + wantError: "--use-sasl and --disable-sasl are mutually exclusive", + }, + { + name: "verify SASL validation: invalid auth method", + api: mock.API{GetKafkaFn: getKafkaOK}, + cmd: updateCommandSASL("bad-auth-type", "user", "password"), + want: nil, + wantError: "invalid SASL authentication method: bad-auth-type. Valid values are plain, scram-sha-256, and scram-sha-512", + }, + { + name: "verify SASL validation: missing username", + api: mock.API{GetKafkaFn: getKafkaOK}, + cmd: updateCommandSASL("scram-sha-256", "", "password"), + want: nil, + wantError: "the --auth-method, --username, and --password flags must be present when using the --use-sasl flag", + }, + { + name: "verify SASL validation: missing password", + api: mock.API{GetKafkaFn: getKafkaOK}, + cmd: updateCommandSASL("plain", "user", ""), + want: nil, + wantError: "the --auth-method, --username, and --password flags must be present when using the --use-sasl flag", + }, + { + name: "verify SASL validation: username with no auth method", + api: mock.API{GetKafkaFn: getKafkaOK}, + cmd: updateCommandSASL("", "user1", ""), + want: nil, + wantError: "the --auth-method, --username, and --password flags must be present when using the --use-sasl flag", + }, + { + name: "verify SASL validation: password with no auth method", + api: mock.API{GetKafkaFn: getKafkaOK}, + cmd: updateCommandSASL("", "", "password"), + want: nil, + wantError: "the --auth-method, --username, and --password flags must be present when using the --use-sasl flag", + }, } { t.Run(testcase.name, func(t *testing.T) { testcase.cmd.Base.Globals.Client = testcase.api @@ -171,6 +353,38 @@ func createCommandAll() *CreateCommand { } } +func createCommandSASL(authMethod, user, password string) *CreateCommand { + return &CreateCommand{ + manifest: manifest.Data{Flag: manifest.Flag{ServiceID: "123"}}, + EndpointName: "log", + Version: 2, + Topic: "logs", + Brokers: "127.0.0.1,127.0.0.2", + ParseLogKeyvals: common.OptionalBool{Optional: common.Optional{Valid: true}, Value: true}, + RequestMaxBytes: common.OptionalUint{Optional: common.Optional{Valid: true}, Value: 11111}, + UseSASL: common.OptionalBool{Optional: common.Optional{Valid: true}, Value: true}, + AuthMethod: common.OptionalString{Optional: common.Optional{Valid: true}, Value: authMethod}, + User: common.OptionalString{Optional: common.Optional{Valid: true}, Value: user}, + Password: common.OptionalString{Optional: common.Optional{Valid: true}, Value: password}, + } +} + +func createCommandNoSASL(authMethod, user, password string) *CreateCommand { + return &CreateCommand{ + manifest: manifest.Data{Flag: manifest.Flag{ServiceID: "123"}}, + EndpointName: "log", + Version: 2, + Topic: "logs", + Brokers: "127.0.0.1,127.0.0.2", + ParseLogKeyvals: common.OptionalBool{Optional: common.Optional{Valid: true}, Value: true}, + RequestMaxBytes: common.OptionalUint{Optional: common.Optional{Valid: true}, Value: 11111}, + UseSASL: common.OptionalBool{Optional: common.Optional{Valid: true}, Value: false}, + AuthMethod: common.OptionalString{Optional: common.Optional{Valid: true}, Value: authMethod}, + User: common.OptionalString{Optional: common.Optional{Valid: true}, Value: user}, + Password: common.OptionalString{Optional: common.Optional{Valid: true}, Value: password}, + } +} + func createCommandMissingServiceID() *CreateCommand { res := createCommandAll() res.manifest = manifest.Data{} @@ -179,10 +393,12 @@ func createCommandMissingServiceID() *CreateCommand { func updateCommandNoUpdates() *UpdateCommand { return &UpdateCommand{ - Base: common.Base{Globals: &config.Data{Client: nil}}, - manifest: manifest.Data{Flag: manifest.Flag{ServiceID: "123"}}, - EndpointName: "log", - Version: 2, + Base: common.Base{Globals: &config.Data{Client: nil}}, + manifest: manifest.Data{Flag: manifest.Flag{ServiceID: "123"}}, + EndpointName: "log", + Version: 2, + ParseLogKeyvals: common.OptionalBool{Optional: common.Optional{Valid: true}, Value: false}, + RequestMaxBytes: common.OptionalUint{Optional: common.Optional{Valid: true}, Value: 11111}, } } @@ -206,6 +422,78 @@ func updateCommandAll() *UpdateCommand { TLSClientCert: common.OptionalString{Optional: common.Optional{Valid: true}, Value: "new10"}, TLSClientKey: common.OptionalString{Optional: common.Optional{Valid: true}, Value: "new11"}, TLSHostname: common.OptionalString{Optional: common.Optional{Valid: true}, Value: "new12"}, + ParseLogKeyvals: common.OptionalBool{Optional: common.Optional{Valid: true}, Value: false}, + RequestMaxBytes: common.OptionalUint{Optional: common.Optional{Valid: true}, Value: 22222}, + UseSASL: common.OptionalBool{Optional: common.Optional{Valid: true}, Value: true}, + AuthMethod: common.OptionalString{Optional: common.Optional{Valid: true}, Value: "plain"}, + User: common.OptionalString{Optional: common.Optional{Valid: true}, Value: "new13"}, + Password: common.OptionalString{Optional: common.Optional{Valid: true}, Value: "new14"}, + } +} + +func updateCommandSASL(authMethod, user, password string) *UpdateCommand { + return &UpdateCommand{ + Base: common.Base{Globals: &config.Data{Client: nil}}, + manifest: manifest.Data{Flag: manifest.Flag{ServiceID: "123"}}, + EndpointName: "log", + Version: 2, + Topic: common.OptionalString{Optional: common.Optional{Valid: true}, Value: "logs"}, + Brokers: common.OptionalString{Optional: common.Optional{Valid: true}, Value: "127.0.0.1,127.0.0.2"}, + ParseLogKeyvals: common.OptionalBool{Optional: common.Optional{Valid: true}, Value: true}, + RequestMaxBytes: common.OptionalUint{Optional: common.Optional{Valid: true}, Value: 11111}, + UseSASL: common.OptionalBool{Optional: common.Optional{Valid: true}, Value: true}, + AuthMethod: common.OptionalString{Optional: common.Optional{Valid: true}, Value: authMethod}, + User: common.OptionalString{Optional: common.Optional{Valid: true}, Value: user}, + Password: common.OptionalString{Optional: common.Optional{Valid: true}, Value: password}, + } +} + +func updateCommandNoSASL() *UpdateCommand { + return &UpdateCommand{ + Base: common.Base{Globals: &config.Data{Client: nil}}, + manifest: manifest.Data{Flag: manifest.Flag{ServiceID: "123"}}, + EndpointName: "log", + Version: 2, + Topic: common.OptionalString{Optional: common.Optional{Valid: true}, Value: "logs"}, + Brokers: common.OptionalString{Optional: common.Optional{Valid: true}, Value: "127.0.0.1,127.0.0.2"}, + ParseLogKeyvals: common.OptionalBool{Optional: common.Optional{Valid: true}, Value: true}, + RequestMaxBytes: common.OptionalUint{Optional: common.Optional{Valid: true}, Value: 11111}, + UseSASL: common.OptionalBool{Optional: common.Optional{Valid: false}, Value: false}, + DisableSASL: common.OptionalBool{Optional: common.Optional{Valid: true}, Value: true}, + AuthMethod: common.OptionalString{Optional: common.Optional{Valid: false}, Value: ""}, + User: common.OptionalString{Optional: common.Optional{Valid: false}, Value: ""}, + Password: common.OptionalString{Optional: common.Optional{Valid: false}, Value: ""}, + } +} + +func updateCommandEnableAndDisableSASL() *UpdateCommand { + return &UpdateCommand{ + Base: common.Base{Globals: &config.Data{Client: nil}}, + manifest: manifest.Data{Flag: manifest.Flag{ServiceID: "123"}}, + EndpointName: "log", + Version: 2, + Topic: common.OptionalString{Optional: common.Optional{Valid: true}, Value: "logs"}, + Brokers: common.OptionalString{Optional: common.Optional{Valid: true}, Value: "127.0.0.1,127.0.0.2"}, + ParseLogKeyvals: common.OptionalBool{Optional: common.Optional{Valid: true}, Value: true}, + RequestMaxBytes: common.OptionalUint{Optional: common.Optional{Valid: true}, Value: 11111}, + UseSASL: common.OptionalBool{Optional: common.Optional{Valid: true}, Value: true}, + DisableSASL: common.OptionalBool{Optional: common.Optional{Valid: true}, Value: true}, + AuthMethod: common.OptionalString{Optional: common.Optional{Valid: false}, Value: ""}, + User: common.OptionalString{Optional: common.Optional{Valid: false}, Value: ""}, + Password: common.OptionalString{Optional: common.Optional{Valid: false}, Value: ""}, + } +} + +func updateCommandConflictingParseLogKeyvals() *UpdateCommand { + return &UpdateCommand{ + Base: common.Base{Globals: &config.Data{Client: nil}}, + manifest: manifest.Data{Flag: manifest.Flag{ServiceID: "123"}}, + EndpointName: "log", + Version: 2, + Topic: common.OptionalString{Optional: common.Optional{Valid: true}, Value: "logs"}, + Brokers: common.OptionalString{Optional: common.Optional{Valid: true}, Value: "127.0.0.1,127.0.0.2"}, + ParseLogKeyvals: common.OptionalBool{Optional: common.Optional{Valid: true}, Value: true}, + NoParseLogKeyvals: common.OptionalBool{Optional: common.Optional{Valid: true}, Value: true}, } } @@ -233,5 +521,36 @@ func getKafkaOK(i *fastly.GetKafkaInput) (*fastly.Kafka, error) { TLSHostname: "example.com", TLSClientCert: "-----BEGIN CERTIFICATE-----bar", TLSClientKey: "-----BEGIN PRIVATE KEY-----bar", + ParseLogKeyvals: false, + RequestMaxBytes: 0, + AuthMethod: "", + User: "", + Password: "", + }, nil +} + +func getKafkaSASL(i *fastly.GetKafkaInput) (*fastly.Kafka, error) { + return &fastly.Kafka{ + ServiceID: i.Service, + Version: i.Version, + Name: "log", + Brokers: "127.0.0.1,127.0.0.2", + Topic: "logs", + RequiredACKs: "-1", + UseTLS: true, + CompressionCodec: "zippy", + Format: `%h %l %u %t "%r" %>s %b`, + FormatVersion: 2, + ResponseCondition: "Prevent default logging", + Placement: "none", + TLSCACert: "-----BEGIN CERTIFICATE-----foo", + TLSHostname: "example.com", + TLSClientCert: "-----BEGIN CERTIFICATE-----bar", + TLSClientKey: "-----BEGIN PRIVATE KEY-----bar", + ParseLogKeyvals: false, + RequestMaxBytes: 0, + AuthMethod: "plain", + User: "user", + Password: "password", }, nil } diff --git a/pkg/logging/kafka/list.go b/pkg/logging/kafka/list.go index ab689ceb4..b85305da0 100644 --- a/pkg/logging/kafka/list.go +++ b/pkg/logging/kafka/list.go @@ -73,6 +73,11 @@ func (c *ListCommand) Exec(in io.Reader, out io.Writer) error { fmt.Fprintf(out, "\t\tFormat version: %d\n", kafka.FormatVersion) fmt.Fprintf(out, "\t\tResponse condition: %s\n", kafka.ResponseCondition) fmt.Fprintf(out, "\t\tPlacement: %s\n", kafka.Placement) + fmt.Fprintf(out, "\t\tParse log key-values: %t\n", kafka.ParseLogKeyvals) + fmt.Fprintf(out, "\t\tMax batch size: %d\n", kafka.RequestMaxBytes) + fmt.Fprintf(out, "\t\tSASL authentication method: %s\n", kafka.AuthMethod) + fmt.Fprintf(out, "\t\tSASL authentication username: %s\n", kafka.User) + fmt.Fprintf(out, "\t\tSASL authentication password: %s\n", kafka.Password) } fmt.Fprintln(out) diff --git a/pkg/logging/kafka/update.go b/pkg/logging/kafka/update.go index bb11225e8..f20d0ad82 100644 --- a/pkg/logging/kafka/update.go +++ b/pkg/logging/kafka/update.go @@ -1,6 +1,7 @@ package kafka import ( + "fmt" "io" "github.com/fastly/cli/pkg/common" @@ -36,6 +37,14 @@ type UpdateCommand struct { FormatVersion common.OptionalUint Placement common.OptionalString ResponseCondition common.OptionalString + ParseLogKeyvals common.OptionalBool + NoParseLogKeyvals common.OptionalBool + RequestMaxBytes common.OptionalUint + UseSASL common.OptionalBool + DisableSASL common.OptionalBool + AuthMethod common.OptionalString + User common.OptionalString + Password common.OptionalString } // NewUpdateCommand returns a usable command registered under the parent. @@ -64,6 +73,14 @@ func NewUpdateCommand(parent common.Registerer, globals *config.Data) *UpdateCom c.CmdClause.Flag("format-version", "The version of the custom logging format used for the configured endpoint. Can be either 2 (default) or 1").Action(c.FormatVersion.Set).UintVar(&c.FormatVersion.Value) c.CmdClause.Flag("placement", "Where in the generated VCL the logging call should be placed, overriding any format_version default. Can be none or waf_debug").Action(c.Placement.Set).StringVar(&c.Placement.Value) c.CmdClause.Flag("response-condition", "The name of an existing condition in the configured endpoint, or leave blank to always execute").Action(c.ResponseCondition.Set).StringVar(&c.ResponseCondition.Value) + c.CmdClause.Flag("parse-log-keyvals", "Parse key-value pairs within the log format.").Action(c.ParseLogKeyvals.Set).BoolVar(&c.ParseLogKeyvals.Value) + c.CmdClause.Flag("no-parse-log-keyvals", "Disable parsing of key-value pairs within the log format.").Action(c.NoParseLogKeyvals.Set).BoolVar(&c.NoParseLogKeyvals.Value) + c.CmdClause.Flag("max-batch-size", "The maximum size of the log batch in bytes").Action(c.RequestMaxBytes.Set).UintVar(&c.RequestMaxBytes.Value) + c.CmdClause.Flag("use-sasl", "Enable SASL authentication. Requires --auth-method, --username, and --password to be specified.").Action(c.UseSASL.Set).BoolVar(&c.UseSASL.Value) + c.CmdClause.Flag("disable-sasl", "Disable SASL authentication.").Action(c.DisableSASL.Set).BoolVar(&c.DisableSASL.Value) + c.CmdClause.Flag("auth-method", "SASL authentication method. Valid values are: plain, scram-sha-256, scram-sha-512.").Action(c.AuthMethod.Set).StringVar(&c.AuthMethod.Value) + c.CmdClause.Flag("username", "SASL authentication username. Required if --auth-method is specified.").Action(c.User.Set).StringVar(&c.User.Value) + c.CmdClause.Flag("password", "SASL authentication password. Required if --auth-method is specified.").Action(c.Password.Set).StringVar(&c.Password.Value) return &c } @@ -102,6 +119,11 @@ func (c *UpdateCommand) createInput() (*fastly.UpdateKafkaInput, error) { TLSHostname: fastly.String(kafka.TLSHostname), TLSClientCert: fastly.String(kafka.TLSClientCert), TLSClientKey: fastly.String(kafka.TLSClientKey), + ParseLogKeyvals: fastly.CBool(kafka.ParseLogKeyvals), + RequestMaxBytes: fastly.Uint(kafka.RequestMaxBytes), + AuthMethod: fastly.String(kafka.AuthMethod), + User: fastly.String(kafka.User), + Password: fastly.String(kafka.Password), } if c.NewName.Valid { @@ -160,6 +182,65 @@ func (c *UpdateCommand) createInput() (*fastly.UpdateKafkaInput, error) { input.Placement = fastly.String(c.Placement.Value) } + if c.ParseLogKeyvals.Valid && c.NoParseLogKeyvals.Valid { + return nil, fmt.Errorf("--parse-key-logvals and --no-parse-key-logvals are mutually exclusive") + } + + if c.ParseLogKeyvals.Valid { + input.ParseLogKeyvals = fastly.CBool(c.ParseLogKeyvals.Value) + } + + if c.RequestMaxBytes.Valid { + input.RequestMaxBytes = fastly.Uint(c.RequestMaxBytes.Value) + } + + if c.UseSASL.Valid && c.DisableSASL.Valid { + return nil, fmt.Errorf("--use-sasl and --disable-sasl are mutually exclusive") + } + + if c.DisableSASL.Valid && c.DisableSASL.Value { + input.AuthMethod = fastly.String("") + input.User = fastly.String("") + input.Password = fastly.String("") + } + + if c.UseSASL.Valid && c.UseSASL.Value { + if c.AuthMethod.Value == "" || c.User.Value == "" || c.Password.Value == "" { + return nil, fmt.Errorf("the --auth-method, --username, and --password flags must be present when using the --use-sasl flag") + + } + + if c.AuthMethod.Value != "plain" && + c.AuthMethod.Value != "scram-sha-256" && + c.AuthMethod.Value != "scram-sha-512" { + + return nil, fmt.Errorf("invalid SASL authentication method: %s. Valid values are plain, scram-sha-256, and scram-sha-512", c.AuthMethod.Value) + } + + input.AuthMethod = fastly.String(c.AuthMethod.Value) + + if c.User.Valid { + input.User = fastly.String(c.User.Value) + } + + if c.Password.Valid { + input.Password = fastly.String(c.Password.Value) + } + } + + if !c.UseSASL.Value && (c.AuthMethod.Value != "" || c.User.Value != "" || c.Password.Value != "") { + if c.AuthMethod.Value != "" { + fmt.Printf("AuthMethod: %s\n", c.AuthMethod.Value) + } + if c.User.Value != "" { + fmt.Printf("AuthMethod: %s\n", c.User.Value) + } + if c.Password.Value != "" { + fmt.Printf("AuthMethod: %s\n", c.Password.Value) + } + return nil, fmt.Errorf("the --auth-method, --username, and --password options are only valid when the --use-sasl flag is specified") + } + return &input, nil } From 5bf4ebc603a9b3a7061cc9fc2443d332ed8ca7ff Mon Sep 17 00:00:00 2001 From: Kelly L McLaughlin Date: Wed, 28 Oct 2020 15:21:49 -0600 Subject: [PATCH 02/12] Bump the go-fastly version to pull in kafka SASL changes --- go.mod | 2 +- go.sum | 20 ++++++++++++++++++++ pkg/app/run_test.go | 27 +++++++++++++++++++++++++++ pkg/logging/kafka/create.go | 2 +- 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 69ae35dbf..3d92a22ef 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect github.com/blang/semver v3.5.1+incompatible github.com/dustinkirkland/golang-petname v0.0.0-20191129215211-8e5a1ed0cff0 - github.com/fastly/go-fastly v1.16.0 + github.com/fastly/go-fastly v1.18.0 github.com/fatih/color v1.7.0 github.com/frankban/quicktest v1.5.0 // indirect github.com/google/go-cmp v0.3.1 diff --git a/go.sum b/go.sum index 161e10aab..4d032946d 100644 --- a/go.sum +++ b/go.sum @@ -32,6 +32,8 @@ github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= github.com/fastly/go-fastly v1.16.0 h1:RMHvkzZ52J60+jSPK+6BLodIsx4OBlaoB18XmL7C0+Y= github.com/fastly/go-fastly v1.16.0/go.mod h1:jILbTQnU/K/7XHQNzQWd1O7hbXIcp6dKrxfRWqU6xfk= +github.com/fastly/go-fastly v1.18.0 h1:fyVq/142VTFz5ZkNE5d57K+NkTmtwxt2K2Mh5sV5scg= +github.com/fastly/go-fastly v1.18.0/go.mod h1:fwYSSnZ6zEClwRS65T0f57Yh83Tc4gL12GgttQwJZfA= github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ= @@ -56,6 +58,7 @@ github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO github.com/google/jsonapi v0.0.0-20170708005851-46d3ced04344/go.mod h1:XSx4m2SziAqk9DXY9nz659easTq4q6TyrpYd9tHSm0g= github.com/google/jsonapi v0.0.0-20200226002910-c8283f632fb7 h1:aQ4kMXDAmP9IRIZHcSKB2orXHGwGiSxH4PX1BzKHR50= github.com/google/jsonapi v0.0.0-20200226002910-c8283f632fb7/go.mod h1:XSx4m2SziAqk9DXY9nz659easTq4q6TyrpYd9tHSm0g= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/hashicorp/go-cleanhttp v0.0.0-20170211013415-3573b8b52aa7/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM= github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= @@ -66,6 +69,7 @@ github.com/kennygrant/sanitize v1.2.4 h1:gN25/otpP5vAsO2djbMhF/LQX6R7+O1TB4yv8Nz github.com/kennygrant/sanitize v1.2.4/go.mod h1:LGsjYYtgxbetdg5owWB2mpgUL6e2nfw2eObZ0u0qvak= github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd h1:Coekwdh0v2wtGp9Gmz1Ze3eVRAWJMLokvN3QjdzCHLY= github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.9.2 h1:LfVyl+ZlLlLDeQ/d2AqfGIIH4qEDu0Ed2S5GyhCWIWY= github.com/klauspost/compress v1.9.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= @@ -107,6 +111,7 @@ github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/segmentio/textio v1.2.0 h1:Ug4IkV3kh72juJbG8azoSBlgebIbUUxVNrfFcKHfTSQ= github.com/segmentio/textio v1.2.0/go.mod h1:+Rb7v0YVODP+tK5F7FD9TCkV7gOYx9IgLHWiqtvY8ag= github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= @@ -124,22 +129,29 @@ github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70 github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4= github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo= github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc= golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4= golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -156,6 +168,12 @@ golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200624163319-25775e59acb7/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c h1:vTxShRUnK60yd8DZU+f95p1zSLj814+5CuEh7NjF2/Y= gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c/go.mod h1:3HH7i1SgMqlzxCcBmUHW657sD4Kvv9sC3HpL3YukzwA= @@ -164,6 +182,7 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/src-d/go-billy.v4 v4.3.2 h1:0SQA1pRztfTFx2miS8sA97XvooFeNOmvUenF4o0EcVg= gopkg.in/src-d/go-billy.v4 v4.3.2/go.mod h1:nDjArDMp+XMs1aFAESLRjfGSgfvoYN0hDfzEk0GjC98= gopkg.in/src-d/go-git-fixtures.v3 v3.5.0 h1:ivZFOIltbce2Mo8IjzUHAFoq/IylO9WHhNOAJK+LsJg= @@ -178,3 +197,4 @@ gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= diff --git a/pkg/app/run_test.go b/pkg/app/run_test.go index ac3e2985f..db891bc11 100644 --- a/pkg/app/run_test.go +++ b/pkg/app/run_test.go @@ -2564,6 +2564,18 @@ COMMANDS The name of an existing condition in the configured endpoint, or leave blank to always execute + --parse-log-keyvals Parse key-value pairs within the log format. + --max-batch-size=MAX-BATCH-SIZE + The maximum size of the log batch in bytes + --use-sasl Enable SASL authentication. Requires + --auth-method, --username, and --password to + be specified. + --auth-method=AUTH-METHOD SASL authentication method. Valid values are: + plain, scram-sha-256, scram-sha-512 + --username=USERNAME SASL authentication username. Required if + --auth-method is specified. + --password=PASSWORD SASL authentication password. Required if + --auth-method is specified. logging kafka list --version=VERSION [] List Kafka endpoints on a Fastly service version @@ -2627,6 +2639,21 @@ COMMANDS The name of an existing condition in the configured endpoint, or leave blank to always execute + --parse-log-keyvals Parse key-value pairs within the log format. + --no-parse-log-keyvals Disable parsing of key-value pairs within the + log format. + --max-batch-size=MAX-BATCH-SIZE + The maximum size of the log batch in bytes + --use-sasl Enable SASL authentication. Requires + --auth-method, --username, and --password to + be specified. + --disable-sasl Disable SASL authentication. + --auth-method=AUTH-METHOD SASL authentication method. Valid values are: + plain, scram-sha-256, scram-sha-512. + --username=USERNAME SASL authentication username. Required if + --auth-method is specified. + --password=PASSWORD SASL authentication password. Required if + --auth-method is specified. logging kafka delete --version=VERSION --name=NAME [] Delete a Kafka logging endpoint on a Fastly service version diff --git a/pkg/logging/kafka/create.go b/pkg/logging/kafka/create.go index d694b1b6d..1db13f7ef 100644 --- a/pkg/logging/kafka/create.go +++ b/pkg/logging/kafka/create.go @@ -59,7 +59,7 @@ func NewCreateCommand(parent common.Registerer, globals *config.Data) *CreateCom c.CmdClause.Flag("compression-codec", "The codec used for compression of your logs. One of: gzip, snappy, lz4").Action(c.CompressionCodec.Set).StringVar(&c.CompressionCodec.Value) c.CmdClause.Flag("required-acks", "The Number of acknowledgements a leader must receive before a write is considered successful. One of: 1 (default) One server needs to respond. 0 No servers need to respond. -1 Wait for all in-sync replicas to respond").Action(c.RequiredACKs.Set).StringVar(&c.RequiredACKs.Value) - c.CmdClause.Flag("use-tls", "Whether to use TLS for secure logging.").Action(c.UseTLS.Set).BoolVar(&c.UseTLS.Value) + c.CmdClause.Flag("use-tls", "Whether to use TLS for secure logging. Can be either true or false").Action(c.UseTLS.Set).BoolVar(&c.UseTLS.Value) c.CmdClause.Flag("tls-ca-cert", "A secure certificate to authenticate the server with. Must be in PEM format").Action(c.TLSCACert.Set).StringVar(&c.TLSCACert.Value) c.CmdClause.Flag("tls-client-cert", "The client certificate used to make authenticated requests. Must be in PEM format").Action(c.TLSClientCert.Set).StringVar(&c.TLSClientCert.Value) c.CmdClause.Flag("tls-client-key", "The client private key used to make authenticated requests. Must be in PEM format").Action(c.TLSClientKey.Set).StringVar(&c.TLSClientKey.Value) From 3015eff2d7e098778a240b7a23645dff32cdbe6c Mon Sep 17 00:00:00 2001 From: Kelly L McLaughlin Date: Thu, 29 Oct 2020 13:55:28 -0600 Subject: [PATCH 03/12] Updates based on review feedback * Use NegatableBoolVar instead of two explicit flags * Use EnumVar for --auth-method to restrict valid input values * Remove some unnecessary test formatting * Remove obsolete test cases --- pkg/logging/kafka/create.go | 9 +-- pkg/logging/kafka/kafka_integration_test.go | 18 +++--- pkg/logging/kafka/kafka_test.go | 61 +-------------------- pkg/logging/kafka/update.go | 25 +-------- 4 files changed, 14 insertions(+), 99 deletions(-) diff --git a/pkg/logging/kafka/create.go b/pkg/logging/kafka/create.go index 1db13f7ef..0b1801a6d 100644 --- a/pkg/logging/kafka/create.go +++ b/pkg/logging/kafka/create.go @@ -71,7 +71,7 @@ func NewCreateCommand(parent common.Registerer, globals *config.Data) *CreateCom c.CmdClause.Flag("parse-log-keyvals", "Parse key-value pairs within the log format.").Action(c.ParseLogKeyvals.Set).BoolVar(&c.ParseLogKeyvals.Value) c.CmdClause.Flag("max-batch-size", "The maximum size of the log batch in bytes").Action(c.RequestMaxBytes.Set).UintVar(&c.RequestMaxBytes.Value) c.CmdClause.Flag("use-sasl", "Enable SASL authentication. Requires --auth-method, --username, and --password to be specified.").Action(c.UseSASL.Set).BoolVar(&c.UseSASL.Value) - c.CmdClause.Flag("auth-method", "SASL authentication method. Valid values are: plain, scram-sha-256, scram-sha-512").Action(c.AuthMethod.Set).StringVar(&c.AuthMethod.Value) + c.CmdClause.Flag("auth-method", "SASL authentication method. Valid values are plain, scram-sha-256, and scram-sha-512.").Action(c.AuthMethod.Set).HintOptions("plain", "scram-sha-256", "scram-sha-512").EnumVar(&c.AuthMethod.Value, "plain", "scram-sha-256", "scram-sha-512") c.CmdClause.Flag("username", "SASL authentication username. Required if --auth-method is specified.").Action(c.User.Set).StringVar(&c.User.Value) c.CmdClause.Flag("password", "SASL authentication password. Required if --auth-method is specified.").Action(c.Password.Set).StringVar(&c.Password.Value) @@ -150,13 +150,6 @@ func (c *CreateCommand) createInput() (*fastly.CreateKafkaInput, error) { } - if c.AuthMethod.Value != "plain" && - c.AuthMethod.Value != "scram-sha-256" && - c.AuthMethod.Value != "scram-sha-512" { - - return nil, fmt.Errorf("invalid SASL authentication method: %s. Valid values are plain, scram-sha-256, and scram-sha-512", c.AuthMethod.Value) - } - input.AuthMethod = fastly.String(c.AuthMethod.Value) if c.User.Valid { diff --git a/pkg/logging/kafka/kafka_integration_test.go b/pkg/logging/kafka/kafka_integration_test.go index 88397960e..e59c4a89e 100644 --- a/pkg/logging/kafka/kafka_integration_test.go +++ b/pkg/logging/kafka/kafka_integration_test.go @@ -380,9 +380,9 @@ Version: 1 Placement: none Parse log key-values: false Max batch size: 0 - SASL authentication method: `+` - SASL authentication username: `+` - SASL authentication password: `+` + SASL authentication method: + SASL authentication username: + SASL authentication password: Kafka 2/2 Service ID: 123 Version: 1 @@ -402,9 +402,9 @@ Version: 1 Placement: none Parse log key-values: false Max batch size: 0 - SASL authentication method: `+` - SASL authentication username: `+` - SASL authentication password:`+` + SASL authentication method: + SASL authentication username: + SASL authentication password: `) + " \n\n" func getKafkaOK(i *fastly.GetKafkaInput) (*fastly.Kafka, error) { @@ -451,9 +451,9 @@ Response condition: Prevent default logging Placement: none Parse log key-values: false Max batch size: 0 -SASL authentication method: `+` -SASL authentication username: `+` -SASL authentication password:`+` +SASL authentication method: +SASL authentication username: +SASL authentication password: `) + " \n" func updateKafkaOK(i *fastly.UpdateKafkaInput) (*fastly.Kafka, error) { diff --git a/pkg/logging/kafka/kafka_test.go b/pkg/logging/kafka/kafka_test.go index f0ebf7cc6..8404186ee 100644 --- a/pkg/logging/kafka/kafka_test.go +++ b/pkg/logging/kafka/kafka_test.go @@ -74,12 +74,6 @@ func TestCreateKafkaInput(t *testing.T) { Password: fastly.String("12345"), }, }, - { - name: "verify SASL validation: invalid auth method", - cmd: createCommandSASL("bad-auth-type", "user", "password"), - want: nil, - wantError: "invalid SASL authentication method: bad-auth-type. Valid values are plain, scram-sha-256, and scram-sha-512", - }, { name: "verify SASL validation: missing username", cmd: createCommandSASL("scram-sha-256", "", "password"), @@ -262,27 +256,6 @@ func TestUpdateKafkaInput(t *testing.T) { Password: fastly.String(""), }, }, - { - name: "verify SASL validation: enable and disable key-value log parsing", - api: mock.API{GetKafkaFn: getKafkaOK}, - cmd: updateCommandConflictingParseLogKeyvals(), - want: nil, - wantError: "--parse-key-logvals and --no-parse-key-logvals are mutually exclusive", - }, - { - name: "verify SASL validation: enable and disable SASL", - api: mock.API{GetKafkaFn: getKafkaOK}, - cmd: updateCommandEnableAndDisableSASL(), - want: nil, - wantError: "--use-sasl and --disable-sasl are mutually exclusive", - }, - { - name: "verify SASL validation: invalid auth method", - api: mock.API{GetKafkaFn: getKafkaOK}, - cmd: updateCommandSASL("bad-auth-type", "user", "password"), - want: nil, - wantError: "invalid SASL authentication method: bad-auth-type. Valid values are plain, scram-sha-256, and scram-sha-512", - }, { name: "verify SASL validation: missing username", api: mock.API{GetKafkaFn: getKafkaOK}, @@ -458,45 +431,13 @@ func updateCommandNoSASL() *UpdateCommand { Brokers: common.OptionalString{Optional: common.Optional{Valid: true}, Value: "127.0.0.1,127.0.0.2"}, ParseLogKeyvals: common.OptionalBool{Optional: common.Optional{Valid: true}, Value: true}, RequestMaxBytes: common.OptionalUint{Optional: common.Optional{Valid: true}, Value: 11111}, - UseSASL: common.OptionalBool{Optional: common.Optional{Valid: false}, Value: false}, - DisableSASL: common.OptionalBool{Optional: common.Optional{Valid: true}, Value: true}, - AuthMethod: common.OptionalString{Optional: common.Optional{Valid: false}, Value: ""}, - User: common.OptionalString{Optional: common.Optional{Valid: false}, Value: ""}, - Password: common.OptionalString{Optional: common.Optional{Valid: false}, Value: ""}, - } -} - -func updateCommandEnableAndDisableSASL() *UpdateCommand { - return &UpdateCommand{ - Base: common.Base{Globals: &config.Data{Client: nil}}, - manifest: manifest.Data{Flag: manifest.Flag{ServiceID: "123"}}, - EndpointName: "log", - Version: 2, - Topic: common.OptionalString{Optional: common.Optional{Valid: true}, Value: "logs"}, - Brokers: common.OptionalString{Optional: common.Optional{Valid: true}, Value: "127.0.0.1,127.0.0.2"}, - ParseLogKeyvals: common.OptionalBool{Optional: common.Optional{Valid: true}, Value: true}, - RequestMaxBytes: common.OptionalUint{Optional: common.Optional{Valid: true}, Value: 11111}, - UseSASL: common.OptionalBool{Optional: common.Optional{Valid: true}, Value: true}, - DisableSASL: common.OptionalBool{Optional: common.Optional{Valid: true}, Value: true}, + UseSASL: common.OptionalBool{Optional: common.Optional{Valid: true}, Value: false}, AuthMethod: common.OptionalString{Optional: common.Optional{Valid: false}, Value: ""}, User: common.OptionalString{Optional: common.Optional{Valid: false}, Value: ""}, Password: common.OptionalString{Optional: common.Optional{Valid: false}, Value: ""}, } } -func updateCommandConflictingParseLogKeyvals() *UpdateCommand { - return &UpdateCommand{ - Base: common.Base{Globals: &config.Data{Client: nil}}, - manifest: manifest.Data{Flag: manifest.Flag{ServiceID: "123"}}, - EndpointName: "log", - Version: 2, - Topic: common.OptionalString{Optional: common.Optional{Valid: true}, Value: "logs"}, - Brokers: common.OptionalString{Optional: common.Optional{Valid: true}, Value: "127.0.0.1,127.0.0.2"}, - ParseLogKeyvals: common.OptionalBool{Optional: common.Optional{Valid: true}, Value: true}, - NoParseLogKeyvals: common.OptionalBool{Optional: common.Optional{Valid: true}, Value: true}, - } -} - func updateCommandMissingServiceID() *UpdateCommand { res := updateCommandAll() res.manifest = manifest.Data{} diff --git a/pkg/logging/kafka/update.go b/pkg/logging/kafka/update.go index f20d0ad82..99a71395d 100644 --- a/pkg/logging/kafka/update.go +++ b/pkg/logging/kafka/update.go @@ -38,10 +38,8 @@ type UpdateCommand struct { Placement common.OptionalString ResponseCondition common.OptionalString ParseLogKeyvals common.OptionalBool - NoParseLogKeyvals common.OptionalBool RequestMaxBytes common.OptionalUint UseSASL common.OptionalBool - DisableSASL common.OptionalBool AuthMethod common.OptionalString User common.OptionalString Password common.OptionalString @@ -73,12 +71,10 @@ func NewUpdateCommand(parent common.Registerer, globals *config.Data) *UpdateCom c.CmdClause.Flag("format-version", "The version of the custom logging format used for the configured endpoint. Can be either 2 (default) or 1").Action(c.FormatVersion.Set).UintVar(&c.FormatVersion.Value) c.CmdClause.Flag("placement", "Where in the generated VCL the logging call should be placed, overriding any format_version default. Can be none or waf_debug").Action(c.Placement.Set).StringVar(&c.Placement.Value) c.CmdClause.Flag("response-condition", "The name of an existing condition in the configured endpoint, or leave blank to always execute").Action(c.ResponseCondition.Set).StringVar(&c.ResponseCondition.Value) - c.CmdClause.Flag("parse-log-keyvals", "Parse key-value pairs within the log format.").Action(c.ParseLogKeyvals.Set).BoolVar(&c.ParseLogKeyvals.Value) - c.CmdClause.Flag("no-parse-log-keyvals", "Disable parsing of key-value pairs within the log format.").Action(c.NoParseLogKeyvals.Set).BoolVar(&c.NoParseLogKeyvals.Value) + c.CmdClause.Flag("parse-log-keyvals", "Parse key-value pairs within the log format.").Action(c.ParseLogKeyvals.Set).NegatableBoolVar(&c.ParseLogKeyvals.Value) c.CmdClause.Flag("max-batch-size", "The maximum size of the log batch in bytes").Action(c.RequestMaxBytes.Set).UintVar(&c.RequestMaxBytes.Value) c.CmdClause.Flag("use-sasl", "Enable SASL authentication. Requires --auth-method, --username, and --password to be specified.").Action(c.UseSASL.Set).BoolVar(&c.UseSASL.Value) - c.CmdClause.Flag("disable-sasl", "Disable SASL authentication.").Action(c.DisableSASL.Set).BoolVar(&c.DisableSASL.Value) - c.CmdClause.Flag("auth-method", "SASL authentication method. Valid values are: plain, scram-sha-256, scram-sha-512.").Action(c.AuthMethod.Set).StringVar(&c.AuthMethod.Value) + c.CmdClause.Flag("auth-method", "SASL authentication method. Valid values are plain, scram-sha-256, and scram-sha-512.").Action(c.AuthMethod.Set).HintOptions("plain", "scram-sha-256", "scram-sha-512").EnumVar(&c.AuthMethod.Value, "plain", "scram-sha-256", "scram-sha-512") c.CmdClause.Flag("username", "SASL authentication username. Required if --auth-method is specified.").Action(c.User.Set).StringVar(&c.User.Value) c.CmdClause.Flag("password", "SASL authentication password. Required if --auth-method is specified.").Action(c.Password.Set).StringVar(&c.Password.Value) @@ -182,10 +178,6 @@ func (c *UpdateCommand) createInput() (*fastly.UpdateKafkaInput, error) { input.Placement = fastly.String(c.Placement.Value) } - if c.ParseLogKeyvals.Valid && c.NoParseLogKeyvals.Valid { - return nil, fmt.Errorf("--parse-key-logvals and --no-parse-key-logvals are mutually exclusive") - } - if c.ParseLogKeyvals.Valid { input.ParseLogKeyvals = fastly.CBool(c.ParseLogKeyvals.Value) } @@ -194,11 +186,7 @@ func (c *UpdateCommand) createInput() (*fastly.UpdateKafkaInput, error) { input.RequestMaxBytes = fastly.Uint(c.RequestMaxBytes.Value) } - if c.UseSASL.Valid && c.DisableSASL.Valid { - return nil, fmt.Errorf("--use-sasl and --disable-sasl are mutually exclusive") - } - - if c.DisableSASL.Valid && c.DisableSASL.Value { + if c.UseSASL.Valid && !c.UseSASL.Value { input.AuthMethod = fastly.String("") input.User = fastly.String("") input.Password = fastly.String("") @@ -210,13 +198,6 @@ func (c *UpdateCommand) createInput() (*fastly.UpdateKafkaInput, error) { } - if c.AuthMethod.Value != "plain" && - c.AuthMethod.Value != "scram-sha-256" && - c.AuthMethod.Value != "scram-sha-512" { - - return nil, fmt.Errorf("invalid SASL authentication method: %s. Valid values are plain, scram-sha-256, and scram-sha-512", c.AuthMethod.Value) - } - input.AuthMethod = fastly.String(c.AuthMethod.Value) if c.User.Valid { From 34e3558b432bd016709ba3b55b633be218d22ca5 Mon Sep 17 00:00:00 2001 From: Kelly L McLaughlin Date: Thu, 29 Oct 2020 14:13:59 -0600 Subject: [PATCH 04/12] Clean up help output so run_test passes --- pkg/app/run_test.go | 7 ++----- pkg/logging/kafka/create.go | 2 +- pkg/logging/kafka/update.go | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/pkg/app/run_test.go b/pkg/app/run_test.go index 9553ed8ca..fbda5ccc5 100644 --- a/pkg/app/run_test.go +++ b/pkg/app/run_test.go @@ -2640,17 +2640,14 @@ COMMANDS The name of an existing condition in the configured endpoint, or leave blank to always execute - --parse-log-keyvals Parse key-value pairs within the log format. - --no-parse-log-keyvals Disable parsing of key-value pairs within the - log format. + --[no-]parse-log-keyvals Parse key-value pairs within the log format. --max-batch-size=MAX-BATCH-SIZE The maximum size of the log batch in bytes --use-sasl Enable SASL authentication. Requires --auth-method, --username, and --password to be specified. - --disable-sasl Disable SASL authentication. --auth-method=AUTH-METHOD SASL authentication method. Valid values are: - plain, scram-sha-256, scram-sha-512. + plain, scram-sha-256, scram-sha-512 --username=USERNAME SASL authentication username. Required if --auth-method is specified. --password=PASSWORD SASL authentication password. Required if diff --git a/pkg/logging/kafka/create.go b/pkg/logging/kafka/create.go index 0b1801a6d..237871359 100644 --- a/pkg/logging/kafka/create.go +++ b/pkg/logging/kafka/create.go @@ -71,7 +71,7 @@ func NewCreateCommand(parent common.Registerer, globals *config.Data) *CreateCom c.CmdClause.Flag("parse-log-keyvals", "Parse key-value pairs within the log format.").Action(c.ParseLogKeyvals.Set).BoolVar(&c.ParseLogKeyvals.Value) c.CmdClause.Flag("max-batch-size", "The maximum size of the log batch in bytes").Action(c.RequestMaxBytes.Set).UintVar(&c.RequestMaxBytes.Value) c.CmdClause.Flag("use-sasl", "Enable SASL authentication. Requires --auth-method, --username, and --password to be specified.").Action(c.UseSASL.Set).BoolVar(&c.UseSASL.Value) - c.CmdClause.Flag("auth-method", "SASL authentication method. Valid values are plain, scram-sha-256, and scram-sha-512.").Action(c.AuthMethod.Set).HintOptions("plain", "scram-sha-256", "scram-sha-512").EnumVar(&c.AuthMethod.Value, "plain", "scram-sha-256", "scram-sha-512") + c.CmdClause.Flag("auth-method", "SASL authentication method. Valid values are: plain, scram-sha-256, scram-sha-512").Action(c.AuthMethod.Set).HintOptions("plain", "scram-sha-256", "scram-sha-512").EnumVar(&c.AuthMethod.Value, "plain", "scram-sha-256", "scram-sha-512") c.CmdClause.Flag("username", "SASL authentication username. Required if --auth-method is specified.").Action(c.User.Set).StringVar(&c.User.Value) c.CmdClause.Flag("password", "SASL authentication password. Required if --auth-method is specified.").Action(c.Password.Set).StringVar(&c.Password.Value) diff --git a/pkg/logging/kafka/update.go b/pkg/logging/kafka/update.go index 99a71395d..57ef98415 100644 --- a/pkg/logging/kafka/update.go +++ b/pkg/logging/kafka/update.go @@ -74,7 +74,7 @@ func NewUpdateCommand(parent common.Registerer, globals *config.Data) *UpdateCom c.CmdClause.Flag("parse-log-keyvals", "Parse key-value pairs within the log format.").Action(c.ParseLogKeyvals.Set).NegatableBoolVar(&c.ParseLogKeyvals.Value) c.CmdClause.Flag("max-batch-size", "The maximum size of the log batch in bytes").Action(c.RequestMaxBytes.Set).UintVar(&c.RequestMaxBytes.Value) c.CmdClause.Flag("use-sasl", "Enable SASL authentication. Requires --auth-method, --username, and --password to be specified.").Action(c.UseSASL.Set).BoolVar(&c.UseSASL.Value) - c.CmdClause.Flag("auth-method", "SASL authentication method. Valid values are plain, scram-sha-256, and scram-sha-512.").Action(c.AuthMethod.Set).HintOptions("plain", "scram-sha-256", "scram-sha-512").EnumVar(&c.AuthMethod.Value, "plain", "scram-sha-256", "scram-sha-512") + c.CmdClause.Flag("auth-method", "SASL authentication method. Valid values are: plain, scram-sha-256, scram-sha-512").Action(c.AuthMethod.Set).HintOptions("plain", "scram-sha-256", "scram-sha-512").EnumVar(&c.AuthMethod.Value, "plain", "scram-sha-256", "scram-sha-512") c.CmdClause.Flag("username", "SASL authentication username. Required if --auth-method is specified.").Action(c.User.Set).StringVar(&c.User.Value) c.CmdClause.Flag("password", "SASL authentication password. Required if --auth-method is specified.").Action(c.Password.Set).StringVar(&c.Password.Value) From 448558764d19fd69c669527905a25a9172c6191e Mon Sep 17 00:00:00 2001 From: Kelly L McLaughlin Date: Mon, 9 Nov 2020 09:27:28 -0700 Subject: [PATCH 05/12] Move failure cases up in functions per code review --- pkg/logging/kafka/create.go | 29 ++++++++++++++--------------- pkg/logging/kafka/update.go | 37 ++++++++++++++----------------------- 2 files changed, 28 insertions(+), 38 deletions(-) diff --git a/pkg/logging/kafka/create.go b/pkg/logging/kafka/create.go index 237871359..d8ab10874 100644 --- a/pkg/logging/kafka/create.go +++ b/pkg/logging/kafka/create.go @@ -86,6 +86,14 @@ func (c *CreateCommand) createInput() (*fastly.CreateKafkaInput, error) { return nil, errors.ErrNoServiceID } + if c.UseSASL.Valid && c.UseSASL.Value && (c.AuthMethod.Value == "" || c.User.Value == "" || c.Password.Value == "") { + return nil, fmt.Errorf("the --auth-method, --username, and --password flags must be present when using the --use-sasl flag") + } + + if !c.UseSASL.Value && (c.AuthMethod.Value != "" || c.User.Value != "" || c.Password.Value != "") { + return nil, fmt.Errorf("the --auth-method, --username, and --password options are only valid when the --use-sasl flag is specified") + } + input.Service = serviceID input.Version = c.Version input.Name = fastly.String(c.EndpointName) @@ -144,25 +152,16 @@ func (c *CreateCommand) createInput() (*fastly.CreateKafkaInput, error) { input.RequestMaxBytes = fastly.Uint(c.RequestMaxBytes.Value) } - if c.UseSASL.Valid && c.UseSASL.Value { - if c.AuthMethod.Value == "" || c.User.Value == "" || c.Password.Value == "" { - return nil, fmt.Errorf("the --auth-method, --username, and --password flags must be present when using the --use-sasl flag") - - } - + if c.AuthMethod.Valid { input.AuthMethod = fastly.String(c.AuthMethod.Value) + } - if c.User.Valid { - input.User = fastly.String(c.User.Value) - } - - if c.Password.Valid { - input.Password = fastly.String(c.Password.Value) - } + if c.User.Valid { + input.User = fastly.String(c.User.Value) } - if !c.UseSASL.Value && (c.AuthMethod.Value != "" || c.User.Value != "" || c.Password.Value != "") { - return nil, fmt.Errorf("the --auth-method, --username, and --password options are only valid when the --use-sasl flag is specified") + if c.Password.Valid { + input.Password = fastly.String(c.Password.Value) } return &input, nil diff --git a/pkg/logging/kafka/update.go b/pkg/logging/kafka/update.go index 57ef98415..39da8780e 100644 --- a/pkg/logging/kafka/update.go +++ b/pkg/logging/kafka/update.go @@ -97,6 +97,14 @@ func (c *UpdateCommand) createInput() (*fastly.UpdateKafkaInput, error) { return nil, err } + if c.UseSASL.Valid && c.UseSASL.Value && (c.AuthMethod.Value == "" || c.User.Value == "" || c.Password.Value == "") { + return nil, fmt.Errorf("the --auth-method, --username, and --password flags must be present when using the --use-sasl flag") + } + + if !c.UseSASL.Value && (c.AuthMethod.Value != "" || c.User.Value != "" || c.Password.Value != "") { + return nil, fmt.Errorf("the --auth-method, --username, and --password options are only valid when the --use-sasl flag is specified") + } + input := fastly.UpdateKafkaInput{ Service: kafka.ServiceID, Version: kafka.Version, @@ -192,34 +200,17 @@ func (c *UpdateCommand) createInput() (*fastly.UpdateKafkaInput, error) { input.Password = fastly.String("") } - if c.UseSASL.Valid && c.UseSASL.Value { - if c.AuthMethod.Value == "" || c.User.Value == "" || c.Password.Value == "" { - return nil, fmt.Errorf("the --auth-method, --username, and --password flags must be present when using the --use-sasl flag") - - } - + if c.AuthMethod.Valid { input.AuthMethod = fastly.String(c.AuthMethod.Value) - if c.User.Valid { - input.User = fastly.String(c.User.Value) - } + } - if c.Password.Valid { - input.Password = fastly.String(c.Password.Value) - } + if c.User.Valid { + input.User = fastly.String(c.User.Value) } - if !c.UseSASL.Value && (c.AuthMethod.Value != "" || c.User.Value != "" || c.Password.Value != "") { - if c.AuthMethod.Value != "" { - fmt.Printf("AuthMethod: %s\n", c.AuthMethod.Value) - } - if c.User.Value != "" { - fmt.Printf("AuthMethod: %s\n", c.User.Value) - } - if c.Password.Value != "" { - fmt.Printf("AuthMethod: %s\n", c.Password.Value) - } - return nil, fmt.Errorf("the --auth-method, --username, and --password options are only valid when the --use-sasl flag is specified") + if c.Password.Valid { + input.Password = fastly.String(c.Password.Value) } return &input, nil From ecd01247b0177c6ff915d53421809f5c644307f6 Mon Sep 17 00:00:00 2001 From: Kelly L McLaughlin Date: Mon, 9 Nov 2020 09:47:32 -0700 Subject: [PATCH 06/12] Remove some extraneous whitespace in Kafka test cases --- pkg/logging/kafka/kafka_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/logging/kafka/kafka_test.go b/pkg/logging/kafka/kafka_test.go index 8404186ee..7b11f21e7 100644 --- a/pkg/logging/kafka/kafka_test.go +++ b/pkg/logging/kafka/kafka_test.go @@ -78,25 +78,25 @@ func TestCreateKafkaInput(t *testing.T) { name: "verify SASL validation: missing username", cmd: createCommandSASL("scram-sha-256", "", "password"), want: nil, - wantError: "the --auth-method, --username, and --password flags must be present when using the --use-sasl flag", + wantError: "the --auth-method, --username, and --password flags must be present when using the --use-sasl flag", }, { name: "verify SASL validation: missing password", cmd: createCommandSASL("plain", "user", ""), want: nil, - wantError: "the --auth-method, --username, and --password flags must be present when using the --use-sasl flag", + wantError: "the --auth-method, --username, and --password flags must be present when using the --use-sasl flag", }, { name: "verify SASL validation: username with no auth method or password", cmd: createCommandSASL("", "user1", ""), want: nil, - wantError: "the --auth-method, --username, and --password flags must be present when using the --use-sasl flag", + wantError: "the --auth-method, --username, and --password flags must be present when using the --use-sasl flag", }, { name: "verify SASL validation: password with no auth method", cmd: createCommandSASL("", "", "password"), want: nil, - wantError: "the --auth-method, --username, and --password flags must be present when using the --use-sasl flag", + wantError: "the --auth-method, --username, and --password flags must be present when using the --use-sasl flag", }, { @@ -261,28 +261,28 @@ func TestUpdateKafkaInput(t *testing.T) { api: mock.API{GetKafkaFn: getKafkaOK}, cmd: updateCommandSASL("scram-sha-256", "", "password"), want: nil, - wantError: "the --auth-method, --username, and --password flags must be present when using the --use-sasl flag", + wantError: "the --auth-method, --username, and --password flags must be present when using the --use-sasl flag", }, { name: "verify SASL validation: missing password", api: mock.API{GetKafkaFn: getKafkaOK}, cmd: updateCommandSASL("plain", "user", ""), want: nil, - wantError: "the --auth-method, --username, and --password flags must be present when using the --use-sasl flag", + wantError: "the --auth-method, --username, and --password flags must be present when using the --use-sasl flag", }, { name: "verify SASL validation: username with no auth method", api: mock.API{GetKafkaFn: getKafkaOK}, cmd: updateCommandSASL("", "user1", ""), want: nil, - wantError: "the --auth-method, --username, and --password flags must be present when using the --use-sasl flag", + wantError: "the --auth-method, --username, and --password flags must be present when using the --use-sasl flag", }, { name: "verify SASL validation: password with no auth method", api: mock.API{GetKafkaFn: getKafkaOK}, cmd: updateCommandSASL("", "", "password"), want: nil, - wantError: "the --auth-method, --username, and --password flags must be present when using the --use-sasl flag", + wantError: "the --auth-method, --username, and --password flags must be present when using the --use-sasl flag", }, } { t.Run(testcase.name, func(t *testing.T) { From 0fd57788f9e1f68466752709a06a63b94eed01d5 Mon Sep 17 00:00:00 2001 From: Kelly McLaughlin Date: Tue, 10 Nov 2020 08:33:09 -0700 Subject: [PATCH 07/12] Apply suggestions from code review Remove periods from flag descriptions Co-authored-by: Patrick Hamann --- pkg/logging/kafka/create.go | 8 ++++---- pkg/logging/kafka/update.go | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/logging/kafka/create.go b/pkg/logging/kafka/create.go index d8ab10874..dd66f3610 100644 --- a/pkg/logging/kafka/create.go +++ b/pkg/logging/kafka/create.go @@ -68,12 +68,12 @@ func NewCreateCommand(parent common.Registerer, globals *config.Data) *CreateCom c.CmdClause.Flag("format-version", "The version of the custom logging format used for the configured endpoint. Can be either 2 (default) or 1").Action(c.FormatVersion.Set).UintVar(&c.FormatVersion.Value) c.CmdClause.Flag("placement", "Where in the generated VCL the logging call should be placed, overriding any format_version default. Can be none or waf_debug").Action(c.Placement.Set).StringVar(&c.Placement.Value) c.CmdClause.Flag("response-condition", "The name of an existing condition in the configured endpoint, or leave blank to always execute").Action(c.ResponseCondition.Set).StringVar(&c.ResponseCondition.Value) - c.CmdClause.Flag("parse-log-keyvals", "Parse key-value pairs within the log format.").Action(c.ParseLogKeyvals.Set).BoolVar(&c.ParseLogKeyvals.Value) + c.CmdClause.Flag("parse-log-keyvals", "Parse key-value pairs within the log format").Action(c.ParseLogKeyvals.Set).BoolVar(&c.ParseLogKeyvals.Value) c.CmdClause.Flag("max-batch-size", "The maximum size of the log batch in bytes").Action(c.RequestMaxBytes.Set).UintVar(&c.RequestMaxBytes.Value) - c.CmdClause.Flag("use-sasl", "Enable SASL authentication. Requires --auth-method, --username, and --password to be specified.").Action(c.UseSASL.Set).BoolVar(&c.UseSASL.Value) + c.CmdClause.Flag("use-sasl", "Enable SASL authentication. Requires --auth-method, --username, and --password to be specified").Action(c.UseSASL.Set).BoolVar(&c.UseSASL.Value) c.CmdClause.Flag("auth-method", "SASL authentication method. Valid values are: plain, scram-sha-256, scram-sha-512").Action(c.AuthMethod.Set).HintOptions("plain", "scram-sha-256", "scram-sha-512").EnumVar(&c.AuthMethod.Value, "plain", "scram-sha-256", "scram-sha-512") - c.CmdClause.Flag("username", "SASL authentication username. Required if --auth-method is specified.").Action(c.User.Set).StringVar(&c.User.Value) - c.CmdClause.Flag("password", "SASL authentication password. Required if --auth-method is specified.").Action(c.Password.Set).StringVar(&c.Password.Value) + c.CmdClause.Flag("username", "SASL authentication username. Required if --auth-method is specified").Action(c.User.Set).StringVar(&c.User.Value) + c.CmdClause.Flag("password", "SASL authentication password. Required if --auth-method is specified").Action(c.Password.Set).StringVar(&c.Password.Value) return &c } diff --git a/pkg/logging/kafka/update.go b/pkg/logging/kafka/update.go index 39da8780e..a8113774b 100644 --- a/pkg/logging/kafka/update.go +++ b/pkg/logging/kafka/update.go @@ -71,12 +71,12 @@ func NewUpdateCommand(parent common.Registerer, globals *config.Data) *UpdateCom c.CmdClause.Flag("format-version", "The version of the custom logging format used for the configured endpoint. Can be either 2 (default) or 1").Action(c.FormatVersion.Set).UintVar(&c.FormatVersion.Value) c.CmdClause.Flag("placement", "Where in the generated VCL the logging call should be placed, overriding any format_version default. Can be none or waf_debug").Action(c.Placement.Set).StringVar(&c.Placement.Value) c.CmdClause.Flag("response-condition", "The name of an existing condition in the configured endpoint, or leave blank to always execute").Action(c.ResponseCondition.Set).StringVar(&c.ResponseCondition.Value) - c.CmdClause.Flag("parse-log-keyvals", "Parse key-value pairs within the log format.").Action(c.ParseLogKeyvals.Set).NegatableBoolVar(&c.ParseLogKeyvals.Value) + c.CmdClause.Flag("parse-log-keyvals", "Parse key-value pairs within the log format").Action(c.ParseLogKeyvals.Set).NegatableBoolVar(&c.ParseLogKeyvals.Value) c.CmdClause.Flag("max-batch-size", "The maximum size of the log batch in bytes").Action(c.RequestMaxBytes.Set).UintVar(&c.RequestMaxBytes.Value) - c.CmdClause.Flag("use-sasl", "Enable SASL authentication. Requires --auth-method, --username, and --password to be specified.").Action(c.UseSASL.Set).BoolVar(&c.UseSASL.Value) + c.CmdClause.Flag("use-sasl", "Enable SASL authentication. Requires --auth-method, --username, and --password to be specified").Action(c.UseSASL.Set).BoolVar(&c.UseSASL.Value) c.CmdClause.Flag("auth-method", "SASL authentication method. Valid values are: plain, scram-sha-256, scram-sha-512").Action(c.AuthMethod.Set).HintOptions("plain", "scram-sha-256", "scram-sha-512").EnumVar(&c.AuthMethod.Value, "plain", "scram-sha-256", "scram-sha-512") - c.CmdClause.Flag("username", "SASL authentication username. Required if --auth-method is specified.").Action(c.User.Set).StringVar(&c.User.Value) - c.CmdClause.Flag("password", "SASL authentication password. Required if --auth-method is specified.").Action(c.Password.Set).StringVar(&c.Password.Value) + c.CmdClause.Flag("username", "SASL authentication username. Required if --auth-method is specified").Action(c.User.Set).StringVar(&c.User.Value) + c.CmdClause.Flag("password", "SASL authentication password. Required if --auth-method is specified").Action(c.Password.Set).StringVar(&c.Password.Value) return &c } From 6f48f1d8cfde4c7da99edcd9e0dffbef13d34449 Mon Sep 17 00:00:00 2001 From: Kelly L McLaughlin Date: Tue, 10 Nov 2020 08:40:43 -0700 Subject: [PATCH 08/12] Update the app help test to remove periods from kafka flag descriptions --- pkg/app/run_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/app/run_test.go b/pkg/app/run_test.go index fbda5ccc5..b41adb86b 100644 --- a/pkg/app/run_test.go +++ b/pkg/app/run_test.go @@ -2565,18 +2565,18 @@ COMMANDS The name of an existing condition in the configured endpoint, or leave blank to always execute - --parse-log-keyvals Parse key-value pairs within the log format. + --parse-log-keyvals Parse key-value pairs within the log format --max-batch-size=MAX-BATCH-SIZE The maximum size of the log batch in bytes --use-sasl Enable SASL authentication. Requires --auth-method, --username, and --password to - be specified. + be specified --auth-method=AUTH-METHOD SASL authentication method. Valid values are: plain, scram-sha-256, scram-sha-512 --username=USERNAME SASL authentication username. Required if - --auth-method is specified. + --auth-method is specified --password=PASSWORD SASL authentication password. Required if - --auth-method is specified. + --auth-method is specified logging kafka list --version=VERSION [] List Kafka endpoints on a Fastly service version @@ -2640,18 +2640,18 @@ COMMANDS The name of an existing condition in the configured endpoint, or leave blank to always execute - --[no-]parse-log-keyvals Parse key-value pairs within the log format. + --[no-]parse-log-keyvals Parse key-value pairs within the log format --max-batch-size=MAX-BATCH-SIZE The maximum size of the log batch in bytes --use-sasl Enable SASL authentication. Requires --auth-method, --username, and --password to - be specified. + be specified --auth-method=AUTH-METHOD SASL authentication method. Valid values are: plain, scram-sha-256, scram-sha-512 --username=USERNAME SASL authentication username. Required if - --auth-method is specified. + --auth-method is specified --password=PASSWORD SASL authentication password. Required if - --auth-method is specified. + --auth-method is specified logging kafka delete --version=VERSION --name=NAME [] Delete a Kafka logging endpoint on a Fastly service version From d25635053f057d49532c6308f0c89257b6660ded Mon Sep 17 00:00:00 2001 From: Kelly L McLaughlin Date: Tue, 17 Nov 2020 07:56:10 -0700 Subject: [PATCH 09/12] go.sum file cleanup --- go.sum | 2 -- 1 file changed, 2 deletions(-) diff --git a/go.sum b/go.sum index 5770de0bb..db813ba8a 100644 --- a/go.sum +++ b/go.sum @@ -30,8 +30,6 @@ github.com/dustinkirkland/golang-petname v0.0.0-20191129215211-8e5a1ed0cff0 h1:9 github.com/dustinkirkland/golang-petname v0.0.0-20191129215211-8e5a1ed0cff0/go.mod h1:V+Qd57rJe8gd4eiGzZyg4h54VLHmYVVw54iMnlAMrF8= github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg= github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= -github.com/fastly/go-fastly v1.16.0 h1:RMHvkzZ52J60+jSPK+6BLodIsx4OBlaoB18XmL7C0+Y= -github.com/fastly/go-fastly v1.16.0/go.mod h1:jILbTQnU/K/7XHQNzQWd1O7hbXIcp6dKrxfRWqU6xfk= github.com/fastly/go-fastly v1.18.0 h1:fyVq/142VTFz5ZkNE5d57K+NkTmtwxt2K2Mh5sV5scg= github.com/fastly/go-fastly v1.18.0/go.mod h1:fwYSSnZ6zEClwRS65T0f57Yh83Tc4gL12GgttQwJZfA= github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= From 8849e39bbc6f7433e4a460fe5e1d649648184d2d Mon Sep 17 00:00:00 2001 From: Kelly L McLaughlin Date: Tue, 17 Nov 2020 09:03:55 -0700 Subject: [PATCH 10/12] Update how GOPATH is set in pr_test github action file --- .github/workflows/pr_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr_test.yml b/.github/workflows/pr_test.yml index 1910c992b..063954476 100644 --- a/.github/workflows/pr_test.yml +++ b/.github/workflows/pr_test.yml @@ -13,7 +13,7 @@ jobs: - name: Set GOPATH # Temporary fix, see: https://github.com/actions/setup-go/issues/14 run: | - echo "::set-env name=GOPATH::$(go env GOPATH)" + echo "GOPATH=$GITHUB_WORKSPACE/go" >> $GITHUB_ENV echo "::add-path::$(go env GOPATH)/bin" shell: bash - name: Restore cache From 9e0594921def49adc8e2bf7a83c4342952e1b271 Mon Sep 17 00:00:00 2001 From: Kelly L McLaughlin Date: Tue, 17 Nov 2020 09:26:14 -0700 Subject: [PATCH 11/12] Update how PATH is set in pr_test github action file --- .github/workflows/pr_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr_test.yml b/.github/workflows/pr_test.yml index 063954476..91e73fc8b 100644 --- a/.github/workflows/pr_test.yml +++ b/.github/workflows/pr_test.yml @@ -14,7 +14,7 @@ jobs: # Temporary fix, see: https://github.com/actions/setup-go/issues/14 run: | echo "GOPATH=$GITHUB_WORKSPACE/go" >> $GITHUB_ENV - echo "::add-path::$(go env GOPATH)/bin" + echo "$(go env GOPATH)/bin" >> $GITHUB_PATH shell: bash - name: Restore cache id: cache From 858515789338d23285159c91d460448c4428becd Mon Sep 17 00:00:00 2001 From: Kelly L McLaughlin Date: Tue, 17 Nov 2020 09:36:48 -0700 Subject: [PATCH 12/12] Update how PATH and GOPATH are set for tests in pr_test action file --- .github/workflows/pr_test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr_test.yml b/.github/workflows/pr_test.yml index 91e73fc8b..e2eb94e78 100644 --- a/.github/workflows/pr_test.yml +++ b/.github/workflows/pr_test.yml @@ -69,8 +69,8 @@ jobs: - name: Set GOPATH # Temporary fix, see: https://github.com/actions/setup-go/issues/14 run: | - echo "::set-env name=GOPATH::$(go env GOPATH)" - echo "::add-path::$(go env GOPATH)/bin" + echo "GOPATH=$GITHUB_WORKSPACE/go" >> $GITHUB_ENV + echo "$(go env GOPATH)/bin" >> $GITHUB_PATH - name: Restore cache uses: actions/cache@v1 with: