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

Ensure all relevant 'create' input fields are using pointers. #382

Merged
merged 51 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
29c397a
ACLs
Integralist Nov 3, 2022
b92b4e9
ERLs
Integralist Nov 3, 2022
04e170a
Loggly
Integralist Nov 4, 2022
5961426
SFTP
Integralist Nov 4, 2022
f9d489a
FTP
Integralist Nov 4, 2022
7c31282
S3
Integralist Nov 4, 2022
01aff1f
Azure Blob Storage
Integralist Nov 4, 2022
dcf619d
Datadog
Integralist Nov 4, 2022
a3d80ac
LogShuttle
Integralist Nov 4, 2022
a4220b7
Papertrail
Integralist Nov 4, 2022
41cc747
GCS
Integralist Nov 4, 2022
607a938
HTTPS
Integralist Nov 4, 2022
b9089f1
Honeycomb
Integralist Nov 4, 2022
fd52cbb
Elasticsearch
Integralist Nov 4, 2022
b986419
Gzip
Integralist Nov 4, 2022
89be1b4
NewRelic
Integralist Nov 4, 2022
5381c11
Logentries
Integralist Nov 4, 2022
8f2ef3b
Splunk
Integralist Nov 4, 2022
256b7e4
Digital Ocean
Integralist Nov 4, 2022
3800696
Sumologic
Integralist Nov 4, 2022
cfa1743
Heroku
Integralist Nov 4, 2022
b8f13e8
Syslog
Integralist Nov 4, 2022
98bf48d
Kafka
Integralist Nov 4, 2022
91945a3
Scalyr
Integralist Nov 4, 2022
562dbbd
Kinesis
Integralist Nov 4, 2022
21aab93
OpenStack
Integralist Nov 4, 2022
ec37b2a
BigQuery
Integralist Nov 4, 2022
3147f10
Cloudfiles
Integralist Nov 4, 2022
2ef225c
Headers
Integralist Nov 4, 2022
59c3f33
Backend
Integralist Nov 4, 2022
87ac220
Directors
Integralist Nov 4, 2022
c709f72
Server
Integralist Nov 4, 2022
2e62b91
Domains
Integralist Nov 4, 2022
c0e0be2
PubSub
Integralist Nov 4, 2022
bd977c3
Versions
Integralist Nov 4, 2022
d204bc4
Services
Integralist Nov 4, 2022
935c066
User
Integralist Nov 4, 2022
98cf1b1
Health checks
Integralist Nov 7, 2022
53b615f
VCL
Integralist Nov 7, 2022
963e563
VCL Snippets
Integralist Nov 7, 2022
0b57c95
Conditions
Integralist Nov 7, 2022
e14d396
ACL Entries
Integralist Nov 7, 2022
a91ba80
Pools
Integralist Nov 7, 2022
f1a7d05
Response Objects
Integralist Nov 7, 2022
75ec167
Cache Settings
Integralist Nov 7, 2022
a0fe2b2
Request Settings
Integralist Nov 7, 2022
0b6b220
Service Authorizations
Integralist Nov 7, 2022
171cd7d
Object Store
Integralist Nov 7, 2022
a7087d1
Dictionaries
Integralist Nov 7, 2022
c5d2f77
Dictionary Item
Integralist Nov 7, 2022
a87439d
Token
Integralist Nov 7, 2022
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
Prev Previous commit
Next Next commit
Conditions
  • Loading branch information
Integralist committed Nov 7, 2022
commit 0b57c95aaba8d1cf8d96c29a90a147cb892a5bea
46 changes: 19 additions & 27 deletions fastly/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func (c *Client) ListConditions(i *ListConditionsInput) ([]*Condition, error) {
if i.ServiceID == "" {
return nil, ErrMissingServiceID
}

if i.ServiceVersion == 0 {
return nil, ErrMissingServiceVersion
}
Expand All @@ -75,25 +74,24 @@ func (c *Client) ListConditions(i *ListConditionsInput) ([]*Condition, error) {
// CreateConditionInput is used as input to the CreateCondition function.
type CreateConditionInput struct {
// Name is the name of the condition.
Name string `url:"name,omitempty"`
Name *string `url:"name,omitempty"`
// Priority is a numeric string. Priority determines execution order. Lower numbers execute first.
Priority *int `url:"priority,omitempty"`
// ServiceID is the ID of the service (required).
ServiceID string
ServiceID string `url:"-"`
// ServiceVersion is the specific configuration version (required).
ServiceVersion int
ServiceVersion int `url:"-"`
// Statement is a conditional expression in VCL used to determine if the condition is met.
Statement string `url:"statement,omitempty"`
Statement *string `url:"statement,omitempty"`
// Type is the type of the condition (REQUEST, CACHE, RESPONSE, PREFETCH).
Type string `url:"type,omitempty"`
Type *string `url:"type,omitempty"`
}

// CreateCondition creates a new resource.
func (c *Client) CreateCondition(i *CreateConditionInput) (*Condition, error) {
if i.ServiceID == "" {
return nil, ErrMissingServiceID
}

if i.ServiceVersion == 0 {
return nil, ErrMissingServiceVersion
}
Expand All @@ -114,7 +112,7 @@ func (c *Client) CreateCondition(i *CreateConditionInput) (*Condition, error) {

// GetConditionInput is used as input to the GetCondition function.
type GetConditionInput struct {
// Name is the name of the condition to fetch.
// Name is the name of the condition to fetch (required).
Name string
// ServiceID is the ID of the service (required).
ServiceID string
Expand All @@ -124,18 +122,16 @@ type GetConditionInput struct {

// GetCondition retrieves the specified resource.
func (c *Client) GetCondition(i *GetConditionInput) (*Condition, error) {
if i.Name == "" {
return nil, ErrMissingName
}
if i.ServiceID == "" {
return nil, ErrMissingServiceID
}

if i.ServiceVersion == 0 {
return nil, ErrMissingServiceVersion
}

if i.Name == "" {
return nil, ErrMissingName
}

path := fmt.Sprintf("/service/%s/version/%d/condition/%s", i.ServiceID, i.ServiceVersion, url.PathEscape(i.Name))
resp, err := c.Get(path, nil)
if err != nil {
Expand All @@ -154,14 +150,14 @@ func (c *Client) GetCondition(i *GetConditionInput) (*Condition, error) {
type UpdateConditionInput struct {
// Comment is a freeform descriptive note.
Comment *string `url:"comment,omitempty"`
// Name is the name of the condition to update.
Name string
// Name is the name of the condition to update (required).
Name string `url:"-"`
// Priority is a numeric string. Priority determines execution order. Lower numbers execute first.
Priority *int `url:"priority,omitempty"`
// ServiceID is the ID of the service (required).
ServiceID string
ServiceID string `url:"-"`
// ServiceVersion is the specific configuration version (required).
ServiceVersion int
ServiceVersion int `url:"-"`
// Statement is a conditional expression in VCL used to determine if the condition is met.
Statement *string `url:"statement,omitempty"`
// Type is the type of the condition (REQUEST, CACHE, RESPONSE, PREFETCH).
Expand All @@ -170,18 +166,16 @@ type UpdateConditionInput struct {

// UpdateCondition updates the specified resource.
func (c *Client) UpdateCondition(i *UpdateConditionInput) (*Condition, error) {
if i.Name == "" {
return nil, ErrMissingName
}
if i.ServiceID == "" {
return nil, ErrMissingServiceID
}

if i.ServiceVersion == 0 {
return nil, ErrMissingServiceVersion
}

if i.Name == "" {
return nil, ErrMissingName
}

path := fmt.Sprintf("/service/%s/version/%d/condition/%s", i.ServiceID, i.ServiceVersion, url.PathEscape(i.Name))
resp, err := c.PutForm(path, i, nil)
if err != nil {
Expand All @@ -208,18 +202,16 @@ type DeleteConditionInput struct {

// DeleteCondition deletes the specified resource.
func (c *Client) DeleteCondition(i *DeleteConditionInput) error {
if i.Name == "" {
return ErrMissingName
}
if i.ServiceID == "" {
return ErrMissingServiceID
}

if i.ServiceVersion == 0 {
return ErrMissingServiceVersion
}

if i.Name == "" {
return ErrMissingName
}

path := fmt.Sprintf("/service/%s/version/%d/condition/%s", i.ServiceID, i.ServiceVersion, url.PathEscape(i.Name))
resp, err := c.Delete(path, nil)
if err != nil {
Expand Down
63 changes: 33 additions & 30 deletions fastly/condition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ func TestClient_Conditions(t *testing.T) {
condition, err = c.CreateCondition(&CreateConditionInput{
ServiceID: testServiceID,
ServiceVersion: tv.Number,
Name: "test/condition",
Statement: "req.url~+\"index.html\"",
Type: "REQUEST",
Name: String("test/condition"),
Statement: String("req.url~+\"index.html\""),
Type: String("REQUEST"),
Priority: Int(1),
})
})
Expand Down Expand Up @@ -161,81 +161,84 @@ func TestClient_CreateCondition_validation(t *testing.T) {

func TestClient_GetCondition_validation(t *testing.T) {
var err error

_, err = testClient.GetCondition(&GetConditionInput{
ServiceID: "",
ServiceID: "foo",
ServiceVersion: 1,
})
if err != ErrMissingServiceID {
if err != ErrMissingName {
t.Errorf("bad error: %s", err)
}

_, err = testClient.GetCondition(&GetConditionInput{
ServiceID: "foo",
ServiceVersion: 0,
Name: "test",
ServiceVersion: 1,
})
if err != ErrMissingServiceVersion {
if err != ErrMissingServiceID {
t.Errorf("bad error: %s", err)
}

_, err = testClient.GetCondition(&GetConditionInput{
ServiceID: "foo",
ServiceVersion: 1,
Name: "",
Name: "test",
ServiceID: "foo",
})
if err != ErrMissingName {
if err != ErrMissingServiceVersion {
t.Errorf("bad error: %s", err)
}
}

func TestClient_UpdateCondition_validation(t *testing.T) {
var err error

_, err = testClient.UpdateCondition(&UpdateConditionInput{
ServiceID: "",
ServiceID: "foo",
ServiceVersion: 1,
})
if err != ErrMissingServiceID {
if err != ErrMissingName {
t.Errorf("bad error: %s", err)
}

_, err = testClient.UpdateCondition(&UpdateConditionInput{
ServiceID: "foo",
ServiceVersion: 0,
Name: "test",
ServiceVersion: 1,
})
if err != ErrMissingServiceVersion {
if err != ErrMissingServiceID {
t.Errorf("bad error: %s", err)
}

_, err = testClient.UpdateCondition(&UpdateConditionInput{
ServiceID: "foo",
ServiceVersion: 1,
Name: "",
Name: "test",
ServiceID: "foo",
})
if err != ErrMissingName {
if err != ErrMissingServiceVersion {
t.Errorf("bad error: %s", err)
}
}

func TestClient_DeleteCondition_validation(t *testing.T) {
var err error

err = testClient.DeleteCondition(&DeleteConditionInput{
ServiceID: "",
ServiceID: "foo",
ServiceVersion: 1,
})
if err != ErrMissingServiceID {
if err != ErrMissingName {
t.Errorf("bad error: %s", err)
}

err = testClient.DeleteCondition(&DeleteConditionInput{
ServiceID: "foo",
ServiceVersion: 0,
Name: "test",
ServiceVersion: 1,
})
if err != ErrMissingServiceVersion {
if err != ErrMissingServiceID {
t.Errorf("bad error: %s", err)
}

err = testClient.DeleteCondition(&DeleteConditionInput{
ServiceID: "foo",
ServiceVersion: 1,
Name: "",
Name: "test",
ServiceID: "foo",
})
if err != ErrMissingName {
if err != ErrMissingServiceVersion {
t.Errorf("bad error: %s", err)
}
}
6 changes: 3 additions & 3 deletions fastly/fastly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,9 @@ func createTestWAFCondition(t *testing.T, fixture, serviceID, name string, servi
condition, err = c.CreateCondition(&CreateConditionInput{
ServiceID: serviceID,
ServiceVersion: serviceNumber,
Name: name,
Statement: "req.url~+\"index.html\"",
Type: "PREFETCH", // This must be a prefetch condition
Name: String(name),
Statement: String("req.url~+\"index.html\""),
Type: String("PREFETCH"), // This must be a prefetch condition
Priority: Int(1),
})
})
Expand Down
16 changes: 8 additions & 8 deletions fastly/fixtures/conditions/cleanup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ interactions:
form: {}
headers:
User-Agent:
- FastlyGo/5.1.2 (+github.com/fastly/go-fastly; go1.17.3)
url: https://api.fastly.com/service/7i6HN3TK9wS159v2gPAZ8A/version/74/condition/test%2Fcondition
- FastlyGo/6.8.0 (+github.com/fastly/go-fastly; go1.16.15)
url: https://api.fastly.com/service/7i6HN3TK9wS159v2gPAZ8A/version/89/condition/test%2Fcondition
method: DELETE
response:
body: '{"msg":"Record not found","detail":"Couldn''t find Condition ''{ deleted
=\u003e 0000-00-00 00:00:00, name =\u003e test/condition, service =\u003e 7i6HN3TK9wS159v2gPAZ8A,
version =\u003e 74 }''"}'
version =\u003e 89 }''"}'
headers:
Accept-Ranges:
- bytes
Expand All @@ -21,11 +21,11 @@ interactions:
Content-Type:
- application/json
Date:
- Fri, 26 Nov 2021 07:13:27 GMT
- Mon, 07 Nov 2022 12:32:13 GMT
Fastly-Ratelimit-Remaining:
- "4989"
- "9979"
Fastly-Ratelimit-Reset:
- "1637913600"
- "1667826000"
Status:
- 404 Not Found
Strict-Transport-Security:
Expand All @@ -39,9 +39,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-slwdc9037-CONTROL-SLWDC, cache-tyo11952-TYO
- cache-control-cp-aws-us-east-1-prod-5-CONTROL-AWS, cache-man4136-MAN
X-Timer:
- S1637910808.571039,VS0,VE278
- S1667824333.179726,VS0,VE328
status: 404 Not Found
code: 404
duration: ""
22 changes: 9 additions & 13 deletions fastly/fixtures/conditions/create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
version: 1
interactions:
- request:
body: ServiceID=7i6HN3TK9wS159v2gPAZ8A&ServiceVersion=74&name=test%2Fcondition&priority=1&statement=req.url~%2B%22index.html%22&type=REQUEST
body: name=test%2Fcondition&priority=1&statement=req.url~%2B%22index.html%22&type=REQUEST
form:
ServiceID:
- 7i6HN3TK9wS159v2gPAZ8A
ServiceVersion:
- "74"
name:
- test/condition
priority:
Expand All @@ -20,11 +16,11 @@ interactions:
Content-Type:
- application/x-www-form-urlencoded
User-Agent:
- FastlyGo/5.1.2 (+github.com/fastly/go-fastly; go1.17.3)
url: https://api.fastly.com/service/7i6HN3TK9wS159v2gPAZ8A/version/74/condition
- FastlyGo/6.8.0 (+github.com/fastly/go-fastly; go1.16.15)
url: https://api.fastly.com/service/7i6HN3TK9wS159v2gPAZ8A/version/89/condition
method: POST
response:
body: '{"name":"test/condition","priority":"1","statement":"req.url~+\"index.html\"","type":"REQUEST","service_id":"7i6HN3TK9wS159v2gPAZ8A","version":"74","comment":"","deleted_at":null,"created_at":"2021-11-26T07:13:25Z","updated_at":"2021-11-26T07:13:25Z"}'
body: '{"name":"test/condition","priority":"1","statement":"req.url~+\"index.html\"","type":"REQUEST","service_id":"7i6HN3TK9wS159v2gPAZ8A","version":"89","deleted_at":null,"created_at":"2022-11-07T12:32:11Z","comment":"","updated_at":"2022-11-07T12:32:11Z"}'
headers:
Accept-Ranges:
- bytes
Expand All @@ -33,11 +29,11 @@ interactions:
Content-Type:
- application/json
Date:
- Fri, 26 Nov 2021 07:13:25 GMT
- Mon, 07 Nov 2022 12:32:11 GMT
Fastly-Ratelimit-Remaining:
- "4992"
- "9982"
Fastly-Ratelimit-Reset:
- "1637913600"
- "1667826000"
Status:
- 200 OK
Strict-Transport-Security:
Expand All @@ -51,9 +47,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-slwdc9036-CONTROL-SLWDC, cache-tyo11952-TYO
- cache-control-cp-aws-us-east-1-prod-1-CONTROL-AWS, cache-man4136-MAN
X-Timer:
- S1637910805.308884,VS0,VE640
- S1667824332.511453,VS0,VE323
status: 200 OK
code: 200
duration: ""
Loading