Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Breaking:

### Enhancements:
- feat(logging): Add support for 'CompressionCodec' and 'GzipLevel' attribute to the HTTPS endpoint.

### Bug fixes:

Expand Down
18 changes: 18 additions & 0 deletions pkg/commands/logging/https/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package https

import (
"context"
"fmt"
"io"

"github.com/fastly/go-fastly/v11/fastly"
Expand All @@ -27,10 +28,12 @@ type CreateCommand struct {

// Optional.
AutoClone argparser.OptionalAutoClone
CompressionCodec argparser.OptionalString
ContentType argparser.OptionalString
EndpointName argparser.OptionalString // Can't shadow argparser.Base method Name().
Format argparser.OptionalString
FormatVersion argparser.OptionalInt
GzipLevel argparser.OptionalInt
HeaderName argparser.OptionalString
HeaderValue argparser.OptionalString
JSONFormat argparser.OptionalString
Expand Down Expand Up @@ -72,8 +75,10 @@ func NewCreateCommand(parent argparser.Registerer, g *global.Data) *CreateComman
Dst: &c.AutoClone.Value,
})
c.CmdClause.Flag("content-type", "Content type of the header sent with the request").Action(c.ContentType.Set).StringVar(&c.ContentType.Value)
common.CompressionCodec(c.CmdClause, &c.CompressionCodec)
common.Format(c.CmdClause, &c.Format)
common.FormatVersion(c.CmdClause, &c.FormatVersion)
common.GzipLevel(c.CmdClause, &c.GzipLevel)
c.CmdClause.Flag("header-name", "Name of the custom header sent with the request").Action(c.HeaderName.Set).StringVar(&c.HeaderName.Value)
c.CmdClause.Flag("header-value", "Value of the custom header sent with the request").Action(c.HeaderValue.Set).StringVar(&c.HeaderValue.Value)
c.CmdClause.Flag("json-format", "Enforces valid JSON formatting for log entries. Can be disabled 0, array of json (wraps JSON log batches in an array) 1, or newline delimited json (places each JSON log entry onto a new line in a batch) 2").Action(c.JSONFormat.Set).StringVar(&c.JSONFormat.Value)
Expand Down Expand Up @@ -108,6 +113,12 @@ func NewCreateCommand(parent argparser.Registerer, g *global.Data) *CreateComman
func (c *CreateCommand) ConstructInput(serviceID string, serviceVersion int) (*fastly.CreateHTTPSInput, error) {
var input fastly.CreateHTTPSInput

// The following blocks enforces the mutual exclusivity of the
// CompressionCodec and GzipLevel flags.
if c.CompressionCodec.WasSet && c.GzipLevel.WasSet {
return nil, fmt.Errorf("error parsing arguments: the --compression-codec flag is mutually exclusive with the --gzip-level flag")
}

input.ServiceID = serviceID
if c.EndpointName.WasSet {
input.Name = &c.EndpointName.Value
Expand All @@ -117,9 +128,16 @@ func (c *CreateCommand) ConstructInput(serviceID string, serviceVersion int) (*f
}
input.ServiceVersion = serviceVersion

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

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

if c.HeaderName.WasSet {
input.HeaderName = &c.HeaderName.Value
Expand Down
2 changes: 2 additions & 0 deletions pkg/commands/logging/https/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error {
}

lines := text.Lines{
"Compression codec": fastly.ToValue(o.CompressionCodec),
"Content type": fastly.ToValue(o.ContentType),
"Format version": fastly.ToValue(o.FormatVersion),
"Format": fastly.ToValue(o.Format),
"GZip level": fastly.ToValue(o.GzipLevel),
"Header name": fastly.ToValue(o.HeaderName),
"Header value": fastly.ToValue(o.HeaderValue),
"JSON format": fastly.ToValue(o.JSONFormat),
Expand Down
24 changes: 24 additions & 0 deletions pkg/commands/logging/https/https_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ func TestHTTPSCreate(t *testing.T) {
},
wantError: errTest.Error(),
},
{
args: args("logging https create --service-id 123 --version 1 --name log --url example.com --compression-codec zstd --gzip-level 9 --autoclone"),
api: mock.API{
ListVersionsFn: testutil.ListVersions,
CloneVersionFn: testutil.CloneVersionResult(4),
},
wantError: "error parsing arguments: the --compression-codec flag is mutually exclusive with the --gzip-level flag",
},
}
for testcaseIdx := range scenarios {
testcase := &scenarios[testcaseIdx]
Expand Down Expand Up @@ -284,7 +292,9 @@ func createHTTPSOK(_ context.Context, i *fastly.CreateHTTPSInput) (*fastly.HTTPS
URL: fastly.ToPointer("example.com"),
RequestMaxEntries: fastly.ToPointer(2),
RequestMaxBytes: fastly.ToPointer(2),
CompressionCodec: fastly.ToPointer(""),
ContentType: fastly.ToPointer("application/json"),
GzipLevel: fastly.ToPointer(0),
HeaderName: fastly.ToPointer("name"),
HeaderValue: fastly.ToPointer("value"),
Method: fastly.ToPointer(http.MethodGet),
Expand Down Expand Up @@ -314,7 +324,9 @@ func listHTTPSsOK(_ context.Context, i *fastly.ListHTTPSInput) ([]*fastly.HTTPS,
URL: fastly.ToPointer("example.com"),
RequestMaxEntries: fastly.ToPointer(2),
RequestMaxBytes: fastly.ToPointer(2),
CompressionCodec: fastly.ToPointer(""),
ContentType: fastly.ToPointer("application/json"),
GzipLevel: fastly.ToPointer(0),
HeaderName: fastly.ToPointer("name"),
HeaderValue: fastly.ToPointer("value"),
Method: fastly.ToPointer(http.MethodGet),
Expand All @@ -337,7 +349,9 @@ func listHTTPSsOK(_ context.Context, i *fastly.ListHTTPSInput) ([]*fastly.HTTPS,
URL: fastly.ToPointer("analytics.example.com"),
RequestMaxEntries: fastly.ToPointer(2),
RequestMaxBytes: fastly.ToPointer(2),
CompressionCodec: fastly.ToPointer(""),
ContentType: fastly.ToPointer("application/json"),
GzipLevel: fastly.ToPointer(0),
HeaderName: fastly.ToPointer("name"),
HeaderValue: fastly.ToPointer("value"),
Method: fastly.ToPointer(http.MethodGet),
Expand Down Expand Up @@ -376,7 +390,9 @@ Version: 1
Version: 1
Name: logs
URL: example.com
Compression codec:
Content type: application/json
GZip level: 0
Header name: name
Header value: value
Method: GET
Expand All @@ -398,7 +414,9 @@ Version: 1
Version: 1
Name: analytics
URL: analytics.example.com
Compression codec:
Content type: application/json
GZip level: 0
Header name: name
Header value: value
Method: GET
Expand Down Expand Up @@ -427,7 +445,9 @@ func getHTTPSOK(_ context.Context, i *fastly.GetHTTPSInput) (*fastly.HTTPS, erro
URL: fastly.ToPointer("example.com"),
RequestMaxEntries: fastly.ToPointer(2),
RequestMaxBytes: fastly.ToPointer(2),
CompressionCodec: fastly.ToPointer(""),
ContentType: fastly.ToPointer("application/json"),
GzipLevel: fastly.ToPointer(0),
HeaderName: fastly.ToPointer("name"),
HeaderValue: fastly.ToPointer("value"),
Method: fastly.ToPointer(http.MethodGet),
Expand All @@ -448,9 +468,11 @@ func getHTTPSError(_ context.Context, _ *fastly.GetHTTPSInput) (*fastly.HTTPS, e
}

var describeHTTPSOutput = "\n" + strings.TrimSpace(`
Compression codec:
Content type: application/json
Format: %h %l %u %t "%r" %>s %b
Format version: 2
GZip level: 0
Header name: name
Header value: value
JSON format: 1
Expand Down Expand Up @@ -481,7 +503,9 @@ func updateHTTPSOK(_ context.Context, i *fastly.UpdateHTTPSInput) (*fastly.HTTPS
URL: fastly.ToPointer("example.com"),
RequestMaxEntries: fastly.ToPointer(2),
RequestMaxBytes: fastly.ToPointer(2),
CompressionCodec: fastly.ToPointer(""),
ContentType: fastly.ToPointer("application/json"),
GzipLevel: fastly.ToPointer(7),
HeaderName: fastly.ToPointer("name"),
HeaderValue: fastly.ToPointer("value"),
Method: fastly.ToPointer(http.MethodGet),
Expand Down
3 changes: 3 additions & 0 deletions pkg/commands/logging/https/https_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func TestCreateHTTPSInput(t *testing.T) {
MessageType: fastly.ToPointer("classic"),
FormatVersion: fastly.ToPointer(2),
ProcessingRegion: fastly.ToPointer("eu"),
CompressionCodec: fastly.ToPointer("zstd"),
},
},
{
Expand Down Expand Up @@ -288,6 +289,7 @@ func createCommandAll() *https.CreateCommand {
TLSClientCert: argparser.OptionalString{Optional: argparser.Optional{WasSet: true}, Value: "-----BEGIN CERTIFICATE-----bar"},
TLSClientKey: argparser.OptionalString{Optional: argparser.Optional{WasSet: true}, Value: "-----BEGIN PRIVATE KEY-----bar"},
ProcessingRegion: argparser.OptionalString{Optional: argparser.Optional{WasSet: true}, Value: "eu"},
CompressionCodec: argparser.OptionalString{Optional: argparser.Optional{WasSet: true}, Value: "zstd"},
}
}

Expand Down Expand Up @@ -379,6 +381,7 @@ func updateCommandAll() *https.UpdateCommand {
MessageType: argparser.OptionalString{Optional: argparser.Optional{WasSet: true}, Value: "new15"},
FormatVersion: argparser.OptionalInt{Optional: argparser.Optional{WasSet: true}, Value: 3},
ProcessingRegion: argparser.OptionalString{Optional: argparser.Optional{WasSet: true}, Value: "eu"},
CompressionCodec: argparser.OptionalString{Optional: argparser.Optional{WasSet: true}, Value: "zstd"},
}
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/commands/logging/https/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error {
fmt.Fprintf(out, "\t\tVersion: %d\n", fastly.ToValue(https.ServiceVersion))
fmt.Fprintf(out, "\t\tName: %s\n", fastly.ToValue(https.Name))
fmt.Fprintf(out, "\t\tURL: %s\n", fastly.ToValue(https.URL))
fmt.Fprintf(out, "\t\tCompression codec: %s\n", fastly.ToValue(https.CompressionCodec))
fmt.Fprintf(out, "\t\tContent type: %s\n", fastly.ToValue(https.ContentType))
fmt.Fprintf(out, "\t\tGZip level: %d\n", fastly.ToValue(https.GzipLevel))
fmt.Fprintf(out, "\t\tHeader name: %s\n", fastly.ToValue(https.HeaderName))
fmt.Fprintf(out, "\t\tHeader value: %s\n", fastly.ToValue(https.HeaderValue))
fmt.Fprintf(out, "\t\tMethod: %s\n", fastly.ToValue(https.Method))
Expand Down
2 changes: 2 additions & 0 deletions pkg/commands/logging/https/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ type UpdateCommand struct {

// Optional.
AutoClone argparser.OptionalAutoClone
CompressionCodec argparser.OptionalString
ContentType argparser.OptionalString
Format argparser.OptionalString
FormatVersion argparser.OptionalInt
GzipLevel argparser.OptionalInt
HeaderName argparser.OptionalString
HeaderValue argparser.OptionalString
JSONFormat argparser.OptionalString
Expand Down
Loading