Skip to content
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

Add account name to pubsub and bigquery #699

Merged
merged 6 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/commands/logging/bigquery/bigquery_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ func listBigQueriesOK(i *fastly.ListBigQueriesInput) ([]*fastly.BigQuery, error)
Dataset: "raw-logs",
Table: "logs",
User: "[email protected]",
AccountName: "none",
SecretKey: "-----BEGIN RSA PRIVATE KEY-----MIIEogIBAAKCA",
Format: `%h %l %u %t "%r" %>s %b`,
Template: "%Y%m%d",
Expand All @@ -290,6 +291,7 @@ func listBigQueriesOK(i *fastly.ListBigQueriesInput) ([]*fastly.BigQuery, error)
Dataset: "analytics",
Table: "logs",
User: "[email protected]",
AccountName: "none",
SecretKey: "-----BEGIN RSA PRIVATE KEY-----MIIEogIBAAKCA",
Format: `%h %l %u %t "%r" %>s %b`,
Template: "%Y%m%d",
Expand Down Expand Up @@ -321,6 +323,7 @@ Version: 1
Name: logs
Format: %h %l %u %t "%r" %>s %b
User: [email protected]
Account name: none
Project ID: my-project
Dataset: raw-logs
Table: logs
Expand All @@ -335,6 +338,7 @@ Version: 1
Name: analytics
Format: %h %l %u %t "%r" %>s %b
User: [email protected]
Account name: none
Project ID: my-project
Dataset: analytics
Table: logs
Expand All @@ -354,6 +358,7 @@ func getBigQueryOK(i *fastly.GetBigQueryInput) (*fastly.BigQuery, error) {
Dataset: "raw-logs",
Table: "logs",
User: "[email protected]",
AccountName: "none",
SecretKey: "-----BEGIN RSA PRIVATE KEY-----MIIEogIBAAKCA",
Format: `%h %l %u %t "%r" %>s %b`,
Template: "%Y%m%d",
Expand All @@ -367,6 +372,7 @@ func getBigQueryError(i *fastly.GetBigQueryInput) (*fastly.BigQuery, error) {
}

var describeBigQueryOutput = "\n" + strings.TrimSpace(`
Account name: none
Dataset: raw-logs
Format: %h %l %u %t "%r" %>s %b
Format version: 0
Expand Down
49 changes: 25 additions & 24 deletions pkg/commands/logging/bigquery/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type CreateCommand struct {
ServiceVersion cmd.OptionalServiceVersion

// optional
AccountName cmd.OptionalString
AutoClone cmd.OptionalAutoClone
Dataset cmd.OptionalString
EndpointName cmd.OptionalString // Can't shadow cmd.Base method Name().
Expand Down Expand Up @@ -55,6 +56,7 @@ func NewCreateCommand(parent cmd.Registerer, globals *config.Data, data manifest
})

// optional
common.AccountName(c.CmdClause, &c.AccountName)
c.RegisterAutoCloneFlag(cmd.AutoCloneFlagOpts{
Action: c.AutoClone.Set,
Dst: &c.AutoClone.Value,
Expand Down Expand Up @@ -87,48 +89,47 @@ func NewCreateCommand(parent cmd.Registerer, globals *config.Data, data manifest

// ConstructInput transforms values parsed from CLI flags into an object to be used by the API client library.
func (c *CreateCommand) ConstructInput(serviceID string, serviceVersion int) (*fastly.CreateBigQueryInput, error) {
var input fastly.CreateBigQueryInput

input.ServiceID = serviceID
input.ServiceVersion = serviceVersion
if c.EndpointName.WasSet {
input.Name = &c.EndpointName.Value
input := fastly.CreateBigQueryInput{
ServiceID: serviceID,
ServiceVersion: serviceVersion,
}
if c.ProjectID.WasSet {
input.ProjectID = &c.ProjectID.Value

if c.AccountName.WasSet {
input.AccountName = &c.AccountName.Value
}
if c.Dataset.WasSet {
input.Dataset = &c.Dataset.Value
}
if c.User.WasSet {
input.User = &c.User.Value
}
if c.Table.WasSet {
input.Table = &c.Table.Value
}
if c.SecretKey.WasSet {
input.SecretKey = &c.SecretKey.Value
}

if c.Template.WasSet {
input.Template = &c.Template.Value
if c.EndpointName.WasSet {
input.Name = &c.EndpointName.Value
}

if c.Format.WasSet {
input.Format = &c.Format.Value
}

if c.FormatVersion.WasSet {
input.FormatVersion = &c.FormatVersion.Value
}

if c.Placement.WasSet {
input.Placement = &c.Placement.Value
}

if c.ProjectID.WasSet {
input.ProjectID = &c.ProjectID.Value
}
if c.ResponseCondition.WasSet {
input.ResponseCondition = &c.ResponseCondition.Value
}
if c.SecretKey.WasSet {
input.SecretKey = &c.SecretKey.Value
}
if c.Table.WasSet {
input.Table = &c.Table.Value
}
if c.Template.WasSet {
input.Template = &c.Template.Value
}
if c.User.WasSet {
input.User = &c.User.Value
}

return &input, nil
}
Expand Down
1 change: 1 addition & 0 deletions pkg/commands/logging/bigquery/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error {
}

lines := text.Lines{
"Account name": bq.AccountName,
"Dataset": bq.Dataset,
"Format version": bq.FormatVersion,
"Format": bq.Format,
Expand Down
1 change: 1 addition & 0 deletions pkg/commands/logging/bigquery/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error {
fmt.Fprintf(out, "\t\tName: %s\n", bq.Name)
fmt.Fprintf(out, "\t\tFormat: %s\n", bq.Format)
fmt.Fprintf(out, "\t\tUser: %s\n", bq.User)
fmt.Fprintf(out, "\t\tAccount name: %s\n", bq.AccountName)
fmt.Fprintf(out, "\t\tProject ID: %s\n", bq.ProjectID)
fmt.Fprintf(out, "\t\tDataset: %s\n", bq.Dataset)
fmt.Fprintf(out, "\t\tTable: %s\n", bq.Table)
Expand Down
67 changes: 31 additions & 36 deletions pkg/commands/logging/bigquery/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@ type UpdateCommand struct {
ServiceVersion cmd.OptionalServiceVersion

// optional
AccountName cmd.OptionalString
AutoClone cmd.OptionalAutoClone
Dataset cmd.OptionalString
Format cmd.OptionalString
FormatVersion cmd.OptionalInt
NewName cmd.OptionalString
Placement cmd.OptionalString
ProjectID cmd.OptionalString
Dataset cmd.OptionalString
Table cmd.OptionalString
User cmd.OptionalString
ResponseCondition cmd.OptionalString
SecretKey cmd.OptionalString
Table cmd.OptionalString
Template cmd.OptionalString
Placement cmd.OptionalString
ResponseCondition cmd.OptionalString
Format cmd.OptionalString
FormatVersion cmd.OptionalInt
User cmd.OptionalString
}

// NewUpdateCommand returns a usable command registered under the parent.
Expand All @@ -57,6 +58,7 @@ func NewUpdateCommand(parent cmd.Registerer, globals *config.Data, data manifest
})

// optional
common.AccountName(c.CmdClause, &c.AccountName)
c.RegisterAutoCloneFlag(cmd.AutoCloneFlagOpts{
Action: c.AutoClone.Set,
Dst: &c.AutoClone.Value,
Expand Down Expand Up @@ -95,49 +97,42 @@ func (c *UpdateCommand) ConstructInput(serviceID string, serviceVersion int) (*f
Name: c.EndpointName,
}

if c.NewName.WasSet {
input.NewName = &c.NewName.Value
}

if c.ProjectID.WasSet {
input.ProjectID = &c.ProjectID.Value
if c.AccountName.WasSet {
input.AccountName = &c.AccountName.Value
}

if c.Dataset.WasSet {
input.Dataset = &c.Dataset.Value
}

if c.Table.WasSet {
input.Table = &c.Table.Value
}

if c.User.WasSet {
input.User = &c.User.Value
}

if c.SecretKey.WasSet {
input.SecretKey = &c.SecretKey.Value
}

if c.Template.WasSet {
input.Template = &c.Template.Value
}

if c.Format.WasSet {
input.Format = &c.Format.Value
}

if c.FormatVersion.WasSet {
input.FormatVersion = &c.FormatVersion.Value
}

if c.ResponseCondition.WasSet {
input.ResponseCondition = &c.ResponseCondition.Value
if c.NewName.WasSet {
input.NewName = &c.NewName.Value
}

if c.Placement.WasSet {
input.Placement = &c.Placement.Value
}
if c.ProjectID.WasSet {
input.ProjectID = &c.ProjectID.Value
}
if c.ResponseCondition.WasSet {
input.ResponseCondition = &c.ResponseCondition.Value
}
if c.SecretKey.WasSet {
input.SecretKey = &c.SecretKey.Value
}
if c.Table.WasSet {
input.Table = &c.Table.Value
}
if c.Template.WasSet {
input.Template = &c.Template.Value
}
if c.User.WasSet {
input.User = &c.User.Value
}

return &input, nil
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/commands/logging/common/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import (
"github.com/fastly/kingpin"
)

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

// Format defines the format flag
func Format(cmd *kingpin.CmdClause, c *cmd.OptionalString) {
cmd.Flag("format", "Apache style log formatting. Your log must produce valid JSON").Action(c.Set).StringVar(&c.Value)
Expand Down
70 changes: 30 additions & 40 deletions pkg/commands/logging/gcs/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func NewCreateCommand(parent cmd.Registerer, globals *config.Data, data manifest
})

// optional
c.CmdClause.Flag("account-name", "The google account name used to obtain temporary credentials (default none)").Action(c.AccountName.Set).StringVar(&c.AccountName.Value)
common.AccountName(c.CmdClause, &c.AccountName)
c.RegisterAutoCloneFlag(cmd.AutoCloneFlagOpts{
Action: c.AutoClone.Set,
Dst: &c.AutoClone.Value,
Expand Down Expand Up @@ -96,21 +96,9 @@ func NewCreateCommand(parent cmd.Registerer, globals *config.Data, data manifest

// ConstructInput transforms values parsed from CLI flags into an object to be used by the API client library.
func (c *CreateCommand) ConstructInput(serviceID string, serviceVersion int) (*fastly.CreateGCSInput, error) {
var input fastly.CreateGCSInput

input.ServiceID = serviceID
input.ServiceVersion = serviceVersion
if c.EndpointName.WasSet {
input.Name = &c.EndpointName.Value
}
if c.Bucket.WasSet {
input.Bucket = &c.Bucket.Value
}
if c.User.WasSet {
input.User = &c.User.Value
}
if c.SecretKey.WasSet {
input.SecretKey = &c.SecretKey.Value
input := fastly.CreateGCSInput{
ServiceID: serviceID,
ServiceVersion: serviceVersion,
}

// The following blocks enforces the mutual exclusivity of the
Expand All @@ -119,48 +107,50 @@ func (c *CreateCommand) ConstructInput(serviceID string, serviceVersion int) (*f
return nil, fmt.Errorf("error parsing arguments: the --compression-codec flag is mutually exclusive with the --gzip-level flag")
}

if c.Path.WasSet {
input.Path = &c.Path.Value
if c.AccountName.WasSet {
input.AccountName = &c.AccountName.Value
}

if c.Period.WasSet {
input.Period = &c.Period.Value
if c.Bucket.WasSet {
input.Bucket = &c.Bucket.Value
}
if c.CompressionCodec.WasSet {
input.CompressionCodec = &c.CompressionCodec.Value
}
if c.EndpointName.WasSet {
input.Name = &c.EndpointName.Value
}

if c.Format.WasSet {
input.Format = &c.Format.Value
}

if c.FormatVersion.WasSet {
input.FormatVersion = &c.FormatVersion.Value
}

if c.GzipLevel.WasSet {
input.GzipLevel = &c.GzipLevel.Value
}

if c.ResponseCondition.WasSet {
input.ResponseCondition = &c.ResponseCondition.Value
}

if c.TimestampFormat.WasSet {
input.TimestampFormat = &c.TimestampFormat.Value
}

if c.MessageType.WasSet {
input.MessageType = &c.MessageType.Value
}

if c.Path.WasSet {
input.Path = &c.Path.Value
}
if c.Period.WasSet {
input.Period = &c.Period.Value
}
if c.Placement.WasSet {
input.Placement = &c.Placement.Value
}

if c.CompressionCodec.WasSet {
input.CompressionCodec = &c.CompressionCodec.Value
if c.ResponseCondition.WasSet {
input.ResponseCondition = &c.ResponseCondition.Value
}

if c.AccountName.WasSet {
input.AccountName = &c.AccountName.Value
if c.SecretKey.WasSet {
input.SecretKey = &c.SecretKey.Value
}
if c.TimestampFormat.WasSet {
input.TimestampFormat = &c.TimestampFormat.Value
}
if c.User.WasSet {
input.User = &c.User.Value
}

return &input, nil
Expand Down
Loading