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 relevant logging endpoints have their token marked as required #355

Merged
merged 3 commits into from
Jul 20, 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
8 changes: 8 additions & 0 deletions fastly/datadog.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ func (c *Client) CreateDatadog(i *CreateDatadogInput) (*Datadog, error) {
return nil, ErrMissingServiceVersion
}

if i.Token == "" {
return nil, ErrMissingToken
}

path := fmt.Sprintf("/service/%s/version/%d/logging/datadog", i.ServiceID, i.ServiceVersion)
resp, err := c.PostForm(path, i, nil)
if err != nil {
Expand Down Expand Up @@ -180,6 +184,10 @@ func (c *Client) UpdateDatadog(i *UpdateDatadogInput) (*Datadog, error) {
return nil, ErrMissingName
}

if i.Token != nil && *i.Token == "" {
return nil, ErrTokenEmpty
}

path := fmt.Sprintf("/service/%s/version/%d/logging/datadog/%s", i.ServiceID, i.ServiceVersion, url.PathEscape(i.Name))
resp, err := c.PutForm(path, i, nil)
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions fastly/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ func NewFieldError(kind string) *FieldError {
}
}

const emptyTokenInvalid string = "the token value cannot be empty"

// ErrTokenEmpty is an error that is returned when an input struct
// specifies an "Token" key value which the user has set to an empty string.
var ErrTokenEmpty = NewFieldError("Token").Message(emptyTokenInvalid)

const batchModifyMaxExceeded string = "batch modify maximum operations exceeded"

// ErrMaxExceededEntries is an error that is returned when an input struct
Expand Down Expand Up @@ -269,6 +275,10 @@ var ErrNotImplemented = errors.New("not implemented")
// already enabled for a service.
var ErrManagedLoggingEnabled = errors.New("managed logging already enabled")

// ErrMissingToken is an error that is returned when an input struct
// requires a "Token" key, but one was not set.
var ErrMissingToken = NewFieldError("Token")

// Ensure HTTPError is, in fact, an error.
var _ error = (*HTTPError)(nil)

Expand Down
8 changes: 8 additions & 0 deletions fastly/honeycomb.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ func (c *Client) CreateHoneycomb(i *CreateHoneycombInput) (*Honeycomb, error) {
return nil, ErrMissingServiceVersion
}

if i.Token == "" {
return nil, ErrMissingToken
}

path := fmt.Sprintf("/service/%s/version/%d/logging/honeycomb", i.ServiceID, i.ServiceVersion)
resp, err := c.PostForm(path, i, nil)
if err != nil {
Expand Down Expand Up @@ -180,6 +184,10 @@ func (c *Client) UpdateHoneycomb(i *UpdateHoneycombInput) (*Honeycomb, error) {
return nil, ErrMissingName
}

if i.Token != nil && *i.Token == "" {
return nil, ErrTokenEmpty
}

path := fmt.Sprintf("/service/%s/version/%d/logging/honeycomb/%s", i.ServiceID, i.ServiceVersion, url.PathEscape(i.Name))
resp, err := c.PutForm(path, i, nil)
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions fastly/newrelic.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ func (c *Client) CreateNewRelic(i *CreateNewRelicInput) (*NewRelic, error) {
return nil, ErrMissingServiceVersion
}

if i.Token == "" {
return nil, ErrMissingToken
}

path := fmt.Sprintf("/service/%s/version/%d/logging/newrelic", i.ServiceID, i.ServiceVersion)
resp, err := c.PostForm(path, i, nil)
if err != nil {
Expand Down Expand Up @@ -180,6 +184,10 @@ func (c *Client) UpdateNewRelic(i *UpdateNewRelicInput) (*NewRelic, error) {
return nil, ErrMissingName
}

if i.Token != nil && *i.Token == "" {
return nil, ErrTokenEmpty
}

path := fmt.Sprintf("/service/%s/version/%d/logging/newrelic/%s", i.ServiceID, i.ServiceVersion, url.PathEscape(i.Name))
resp, err := c.PutForm(path, i, nil)
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions fastly/scalyr.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ func (c *Client) CreateScalyr(i *CreateScalyrInput) (*Scalyr, error) {
return nil, ErrMissingServiceVersion
}

if i.Token == "" {
return nil, ErrMissingToken
}

path := fmt.Sprintf("/service/%s/version/%d/logging/scalyr", i.ServiceID, i.ServiceVersion)
resp, err := c.PostForm(path, i, nil)
if err != nil {
Expand Down Expand Up @@ -180,6 +184,10 @@ func (c *Client) UpdateScalyr(i *UpdateScalyrInput) (*Scalyr, error) {
return nil, ErrMissingName
}

if i.Token != nil && *i.Token == "" {
return nil, ErrTokenEmpty
}

path := fmt.Sprintf("/service/%s/version/%d/logging/scalyr/%s", i.ServiceID, i.ServiceVersion, url.PathEscape(i.Name))
resp, err := c.PutForm(path, i, nil)
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions fastly/splunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ func (c *Client) CreateSplunk(i *CreateSplunkInput) (*Splunk, error) {
return nil, ErrMissingServiceVersion
}

if i.Token == "" {
return nil, ErrMissingToken
}

path := fmt.Sprintf("/service/%s/version/%d/logging/splunk", i.ServiceID, i.ServiceVersion)
resp, err := c.PostForm(path, i, nil)
if err != nil {
Expand Down Expand Up @@ -201,6 +205,10 @@ func (c *Client) UpdateSplunk(i *UpdateSplunkInput) (*Splunk, error) {
return nil, ErrMissingName
}

if i.Token != nil && *i.Token == "" {
return nil, ErrTokenEmpty
}

path := fmt.Sprintf("/service/%s/version/%d/logging/splunk/%s", i.ServiceID, i.ServiceVersion, url.PathEscape(i.Name))
resp, err := c.PutForm(path, i, nil)
if err != nil {
Expand Down