Skip to content

Commit ca1cea0

Browse files
authored
feat(logging/scalyr): add project-id (#1166)
* build: bump go-fastly to 9.2.0 * feat(logging/scalyr): add project-id * fix(logging/scalyr): test
1 parent 09d98dd commit ca1cea0

File tree

10 files changed

+45
-17
lines changed

10 files changed

+45
-17
lines changed

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ require (
2727
)
2828

2929
require (
30-
github.com/fastly/go-fastly/v9 v9.0.1
30+
github.com/fastly/go-fastly/v9 v9.2.0
3131
github.com/hashicorp/cap v0.5.0
3232
github.com/kennygrant/sanitize v1.2.4
3333
github.com/mholt/archiver v3.1.1+incompatible

Diff for: go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5/go.mod h1:qssHWj6
2323
github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY=
2424
github.com/dustinkirkland/golang-petname v0.0.0-20191129215211-8e5a1ed0cff0 h1:90Ly+6UfUypEF6vvvW5rQIv9opIL8CbmW9FT20LDQoY=
2525
github.com/dustinkirkland/golang-petname v0.0.0-20191129215211-8e5a1ed0cff0/go.mod h1:V+Qd57rJe8gd4eiGzZyg4h54VLHmYVVw54iMnlAMrF8=
26-
github.com/fastly/go-fastly/v9 v9.0.1 h1:964+VZGeEd6SMuJBGcdfdpBnS5631PT3lSHGPYq2KOU=
27-
github.com/fastly/go-fastly/v9 v9.0.1/go.mod h1:5w2jgJBZqQEebOwM/rRg7wutAcpDTziiMYWb/6qdM7U=
26+
github.com/fastly/go-fastly/v9 v9.2.0 h1:+tCE/5LV0fa9bMuIBKx5Xtc4N/dTlRjB02b3bSddRv4=
27+
github.com/fastly/go-fastly/v9 v9.2.0/go.mod h1:5w2jgJBZqQEebOwM/rRg7wutAcpDTziiMYWb/6qdM7U=
2828
github.com/fastly/kingpin v2.1.12-0.20191105091915-95d230a53780+incompatible h1:FhrXlfhgGCS+uc6YwyiFUt04alnjpoX7vgDKJxS6Qbk=
2929
github.com/fastly/kingpin v2.1.12-0.20191105091915-95d230a53780+incompatible/go.mod h1:U8UynVoU1SQaqD2I4ZqgYd5lx3A1ipQYn4aSt2Y5h6c=
3030
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=

Diff for: pkg/commands/compute/init_test.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"errors"
66
"io"
7+
"net/http"
78
"os"
89
"path/filepath"
910
"strings"
@@ -13,6 +14,7 @@ import (
1314
"github.com/fastly/cli/pkg/config"
1415
"github.com/fastly/cli/pkg/global"
1516
"github.com/fastly/cli/pkg/manifest"
17+
"github.com/fastly/cli/pkg/mock"
1618
"github.com/fastly/cli/pkg/testutil"
1719
)
1820

@@ -42,6 +44,8 @@ func TestInit(t *testing.T) {
4244
name string
4345
args []string
4446
configFile config.File
47+
httpClientRes []*http.Response
48+
httpClientErr []error
4549
manifest string
4650
wantFiles []string
4751
unwantedFiles []string
@@ -54,7 +58,17 @@ func TestInit(t *testing.T) {
5458
{
5559
name: "broken endpoint",
5660
args: args("compute init --from https://example.com/i-dont-exist"),
57-
wantError: "failed to get package: 404 Not Found",
61+
wantError: "failed to get package: Not Found",
62+
httpClientRes: []*http.Response{
63+
{
64+
Body: io.NopCloser(strings.NewReader("")),
65+
Status: http.StatusText(http.StatusNotFound),
66+
StatusCode: http.StatusNotFound,
67+
},
68+
},
69+
httpClientErr: []error{
70+
nil,
71+
},
5872
},
5973
{
6074
name: "name prompt",
@@ -364,6 +378,10 @@ func TestInit(t *testing.T) {
364378
opts := testutil.MockGlobalData(testcase.args, &stdout)
365379
opts.Config = testcase.configFile
366380

381+
if testcase.httpClientRes != nil || testcase.httpClientErr != nil {
382+
opts.HTTPClient = mock.HTMLClient(testcase.httpClientRes, testcase.httpClientErr)
383+
}
384+
367385
// we need to define stdin as the init process prompts the user multiple
368386
// times, but we don't need to provide any values as all our prompts will
369387
// fallback to default values if the input is unrecognised.

Diff for: pkg/commands/logging/scalyr/create.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type CreateCommand struct {
3131
Placement argparser.OptionalString
3232
Region argparser.OptionalString
3333
ResponseCondition argparser.OptionalString
34+
ProjectID argparser.OptionalString
3435
}
3536

3637
// NewCreateCommand returns a usable command registered under the parent.
@@ -60,6 +61,7 @@ func NewCreateCommand(parent argparser.Registerer, g *global.Data) *CreateComman
6061
common.Format(c.CmdClause, &c.Format)
6162
common.FormatVersion(c.CmdClause, &c.FormatVersion)
6263
common.Placement(c.CmdClause, &c.Placement)
64+
c.CmdClause.Flag("project-id", "The name of the logfile field sent to Scalyr").Action(c.ProjectID.Set).StringVar(&c.ProjectID.Value)
6365
c.CmdClause.Flag("region", "The region that log data will be sent to. One of US or EU. Defaults to US if undefined").Action(c.Region.Set).StringVar(&c.Region.Value)
6466
common.ResponseCondition(c.CmdClause, &c.ResponseCondition)
6567
c.RegisterFlag(argparser.StringFlagOpts{
@@ -89,26 +91,24 @@ func (c *CreateCommand) ConstructInput(serviceID string, serviceVersion int) (*f
8991
if c.Token.WasSet {
9092
input.Token = &c.Token.Value
9193
}
92-
9394
if c.Region.WasSet {
9495
input.Region = &c.Region.Value
9596
}
96-
9797
if c.Format.WasSet {
9898
input.Format = &c.Format.Value
9999
}
100-
101100
if c.FormatVersion.WasSet {
102101
input.FormatVersion = &c.FormatVersion.Value
103102
}
104-
105103
if c.ResponseCondition.WasSet {
106104
input.ResponseCondition = &c.ResponseCondition.Value
107105
}
108-
109106
if c.Placement.WasSet {
110107
input.Placement = &c.Placement.Value
111108
}
109+
if c.ProjectID.WasSet {
110+
input.ProjectID = &c.ProjectID.Value
111+
}
112112

113113
return &input, nil
114114
}

Diff for: pkg/commands/logging/scalyr/describe.go

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error {
9797
"Format": fastly.ToValue(o.Format),
9898
"Name": fastly.ToValue(o.Name),
9999
"Placement": fastly.ToValue(o.Placement),
100+
"Project ID": fastly.ToValue(o.ProjectID),
100101
"Region": fastly.ToValue(o.Region),
101102
"Response condition": fastly.ToValue(o.ResponseCondition),
102103
"Token": fastly.ToValue(o.Token),

Diff for: pkg/commands/logging/scalyr/list.go

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error {
118118
fmt.Fprintf(out, "\t\tFormat version: %d\n", fastly.ToValue(scalyr.FormatVersion))
119119
fmt.Fprintf(out, "\t\tResponse condition: %s\n", fastly.ToValue(scalyr.ResponseCondition))
120120
fmt.Fprintf(out, "\t\tPlacement: %s\n", fastly.ToValue(scalyr.Placement))
121+
fmt.Fprintf(out, "\t\tProject ID: %s\n", fastly.ToValue(scalyr.ProjectID))
121122
}
122123
fmt.Fprintln(out)
123124

Diff for: pkg/commands/logging/scalyr/scalyr_integration_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ func listScalyrsOK(i *fastly.ListScalyrsInput) ([]*fastly.Scalyr, error) {
332332
FormatVersion: fastly.ToPointer(2),
333333
ResponseCondition: fastly.ToPointer("Prevent default logging"),
334334
Placement: fastly.ToPointer("none"),
335+
ProjectID: fastly.ToPointer("example-project"),
335336
},
336337
{
337338
ServiceID: fastly.ToPointer(i.ServiceID),
@@ -343,6 +344,7 @@ func listScalyrsOK(i *fastly.ListScalyrsInput) ([]*fastly.Scalyr, error) {
343344
FormatVersion: fastly.ToPointer(2),
344345
ResponseCondition: fastly.ToPointer("Prevent default logging"),
345346
Placement: fastly.ToPointer("none"),
347+
ProjectID: fastly.ToPointer("example-project"),
346348
},
347349
}, nil
348350
}
@@ -374,6 +376,7 @@ Version: 1
374376
Format version: 2
375377
Response condition: Prevent default logging
376378
Placement: none
379+
Project ID: example-project
377380
Scalyr 2/2
378381
Service ID: 123
379382
Version: 1
@@ -384,6 +387,7 @@ Version: 1
384387
Format version: 2
385388
Response condition: Prevent default logging
386389
Placement: none
390+
Project ID: example-project
387391
`) + "\n\n"
388392

389393
func getScalyrOK(i *fastly.GetScalyrInput) (*fastly.Scalyr, error) {
@@ -397,6 +401,7 @@ func getScalyrOK(i *fastly.GetScalyrInput) (*fastly.Scalyr, error) {
397401
FormatVersion: fastly.ToPointer(2),
398402
ResponseCondition: fastly.ToPointer("Prevent default logging"),
399403
Placement: fastly.ToPointer("none"),
404+
ProjectID: fastly.ToPointer("example-project"),
400405
}, nil
401406
}
402407

@@ -409,6 +414,7 @@ Format: %h %l %u %t "%r" %>s %b
409414
Format version: 2
410415
Name: logs
411416
Placement: none
417+
Project ID: example-project
412418
Region: US
413419
Response condition: Prevent default logging
414420
Service ID: 123

Diff for: pkg/commands/logging/scalyr/scalyr_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func TestCreateScalyrInput(t *testing.T) {
4646
Format: fastly.ToPointer(`%h %l %u %t "%r" %>s %b`),
4747
ResponseCondition: fastly.ToPointer("Prevent default logging"),
4848
Placement: fastly.ToPointer("none"),
49+
ProjectID: fastly.ToPointer("example-project"),
4950
},
5051
},
5152
{
@@ -128,6 +129,7 @@ func TestUpdateScalyrInput(t *testing.T) {
128129
ResponseCondition: fastly.ToPointer("new4"),
129130
Placement: fastly.ToPointer("new5"),
130131
Region: fastly.ToPointer("new6"),
132+
ProjectID: fastly.ToPointer("new7"),
131133
},
132134
},
133135
{
@@ -251,6 +253,7 @@ func createCommandAll() *scalyr.CreateCommand {
251253
FormatVersion: argparser.OptionalInt{Optional: argparser.Optional{WasSet: true}, Value: 2},
252254
ResponseCondition: argparser.OptionalString{Optional: argparser.Optional{WasSet: true}, Value: "Prevent default logging"},
253255
Placement: argparser.OptionalString{Optional: argparser.Optional{WasSet: true}, Value: "none"},
256+
ProjectID: argparser.OptionalString{Optional: argparser.Optional{WasSet: true}, Value: "example-project"},
254257
}
255258
}
256259

@@ -330,6 +333,7 @@ func updateCommandAll() *scalyr.UpdateCommand {
330333
ResponseCondition: argparser.OptionalString{Optional: argparser.Optional{WasSet: true}, Value: "new4"},
331334
Placement: argparser.OptionalString{Optional: argparser.Optional{WasSet: true}, Value: "new5"},
332335
Region: argparser.OptionalString{Optional: argparser.Optional{WasSet: true}, Value: "new6"},
336+
ProjectID: argparser.OptionalString{Optional: argparser.Optional{WasSet: true}, Value: "new7"},
333337
}
334338
}
335339

Diff for: pkg/commands/logging/scalyr/update.go

+5-8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type UpdateCommand struct {
3232
Region argparser.OptionalString
3333
ResponseCondition argparser.OptionalString
3434
Placement argparser.OptionalString
35+
ProjectID argparser.OptionalString
3536
}
3637

3738
// NewUpdateCommand returns a usable command registered under the parent.
@@ -62,6 +63,7 @@ func NewUpdateCommand(parent argparser.Registerer, g *global.Data) *UpdateComman
6263
common.FormatVersion(c.CmdClause, &c.FormatVersion)
6364
c.CmdClause.Flag("new-name", "New name of the Scalyr logging object").Action(c.NewName.Set).StringVar(&c.NewName.Value)
6465
common.Placement(c.CmdClause, &c.Placement)
66+
c.CmdClause.Flag("project-id", "The name of the logfile field sent to Scalyr").Action(c.ProjectID.Set).StringVar(&c.ProjectID.Value)
6567
c.CmdClause.Flag("region", "The region that log data will be sent to. One of US or EU. Defaults to US if undefined").Action(c.Region.Set).StringVar(&c.Region.Value)
6668
common.ResponseCondition(c.CmdClause, &c.ResponseCondition)
6769
c.RegisterFlag(argparser.StringFlagOpts{
@@ -86,35 +88,30 @@ func (c *UpdateCommand) ConstructInput(serviceID string, serviceVersion int) (*f
8688
ServiceVersion: serviceVersion,
8789
Name: c.EndpointName,
8890
}
89-
9091
if c.NewName.WasSet {
9192
input.NewName = &c.NewName.Value
9293
}
93-
9494
if c.Format.WasSet {
9595
input.Format = &c.Format.Value
9696
}
97-
9897
if c.FormatVersion.WasSet {
9998
input.FormatVersion = &c.FormatVersion.Value
10099
}
101-
102100
if c.Token.WasSet {
103101
input.Token = &c.Token.Value
104102
}
105-
106103
if c.Region.WasSet {
107104
input.Region = &c.Region.Value
108105
}
109-
110106
if c.ResponseCondition.WasSet {
111107
input.ResponseCondition = &c.ResponseCondition.Value
112108
}
113-
114109
if c.Placement.WasSet {
115110
input.Placement = &c.Placement.Value
116111
}
117-
112+
if c.ProjectID.WasSet {
113+
input.ProjectID = &c.ProjectID.Value
114+
}
118115
return &input, nil
119116
}
120117

Diff for: pkg/mock/client.go

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func (c HTTPClient) Get(p string, _ *fastly.RequestOptions) (*http.Response, err
4141

4242
// Do mocks a HTTP Client Do operation.
4343
func (c HTTPClient) Do(r *http.Request) (*http.Response, error) {
44+
fmt.Printf("r.URL: %#v\n", r.URL.String())
4445
fmt.Printf("r: %#v\n", r)
4546
c.Index++
4647
return c.Responses[c.Index], c.Errors[c.Index]

0 commit comments

Comments
 (0)