-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support sasl kafka endpoint options in Fastly CLI #161
Changes from 3 commits
6d6a0d3
5bf4ebc
7a16ab8
3015eff
34e3558
2530b04
4485587
8c0f4da
ecd0124
83f13a3
0fd5778
6f48f1d
d256350
8849e39
9e05949
8585157
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
|
@@ -61,14 +68,19 @@ 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) | ||
kellymclaughlin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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) | ||
kellymclaughlin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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) | ||
kellymclaughlin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
c.CmdClause.Flag("username", "SASL authentication username. Required if --auth-method is specified.").Action(c.User.Set).StringVar(&c.User.Value) | ||
kellymclaughlin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
c.CmdClause.Flag("password", "SASL authentication password. Required if --auth-method is specified.").Action(c.Password.Set).StringVar(&c.Password.Value) | ||
kellymclaughlin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return &c | ||
} | ||
|
||
// 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 { | ||
kellymclaughlin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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) | ||
} | ||
kellymclaughlin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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) | ||
} | ||
kellymclaughlin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
if !c.UseSASL.Value && (c.AuthMethod.Value != "" || c.User.Value != "" || c.Password.Value != "") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Disregard the following, but it was a thought that crossed my mind. I based my final judgement on how thought - Is this block really necessary? In other words isn't this safe to just accept, but not do anything with these values since the values are only set in the above block? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question. It's not necessary. The reason I added this was trying avoid unexpected results and unnecessary debugging. My reasoning was if a user gives the auth method, username, or password they probably meant to enable SASL and by accepting the invalid set of options we've possibly added to the confusion. The hope is by enforcing this at creation time we're saving them and possibly ourselves some time. Happy to remove it though if you think it's not worth it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is probably worth giving the user feedback when the options they used make no sense. My $0.02 it should stay. The more Go Way to do it would be to move this invalid case as far up in the function as possible. |
||
return nil, fmt.Errorf("the --auth-method, --username, and --password options are only valid when the --use-sasl flag is specified") | ||
} | ||
|
||
return &input, nil | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kellymclaughlin I just pulled your branch and ran
make all
and found that thego.sum
was updated for me to remove the v1.16.0 dependency. Are you OK to update this PR with that change?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Integralist Ok, I've pushed that change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @kellymclaughlin - just to let you know that Patrick and I are still chipping away at the Go-Fastly v2 merge/release (things got complicated 😬) but we expect to have it finished today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 It looks like something has changed in the last day or so on the Github side with setting environment variables for the CI actions and it's now causing the checks to fail. Let me know if you would like me to try to run that down for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we had to fix that here: https://github.com/fastly/terraform-provider-fastly/pull/340/files#diff-15c806aa509538190832852f439e9921a23bec2da81f95ed0e4bf13c14e5b160R55