Skip to content

Commit

Permalink
Address FIXME notes (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
Integralist authored Nov 2, 2022
1 parent 54608c1 commit e8e32c0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 28 deletions.
6 changes: 3 additions & 3 deletions fastly/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ var ErrMissingServiceAuthorizationsUser = NewFieldError("User").Message("SAUser
// requires a "UserID" key, but one was not set
var ErrMissingUserID = NewFieldError("UserID")

// ErrMissingPermissions is an error that is returned when an input struct
// requires a "Permissions" key, but one was not set
var ErrMissingPermissions = NewFieldError("Permissions")
// ErrMissingPermission is an error that is returned when an input struct
// requires a "Permission" key, but one was not set
var ErrMissingPermission = NewFieldError("Permission")

// ErrMissingServiceVersion is an error that is returned when an input struct
// requires a "ServiceVersion" key, but one was not set.
Expand Down
21 changes: 9 additions & 12 deletions fastly/service_authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,18 @@ type SAService struct {
}

// ServiceAuthorization is the API response model.
// FIXME: Typo (DeltedAt -> DeletedAt).
type ServiceAuthorization struct {
CreatedAt *time.Time `jsonapi:"attr,created_at,iso8601"`
DeltedAt *time.Time `jsonapi:"attr,deleted_at,iso8601"`
DeletedAt *time.Time `jsonapi:"attr,deleted_at,iso8601"`
ID string `jsonapi:"primary,service_authorization"`
Permission string `jsonapi:"attr,permission,omitempty"`
Service *SAService `jsonapi:"relation,service,omitempty"`
UpdatedAt *time.Time `jsonapi:"attr,updated_at,iso8601"`
User *SAUser `jsonapi:"relation,user,omitempty"`
}

// SAResponse is an object containing the list of ServiceAuthorization results.
// FIXME: Ambiguous name (SAResponse -> ServiceAuthorizations)
type SAResponse struct {
// ServiceAuthorizations is an object containing the list of ServiceAuthorization results.
type ServiceAuthorizations struct {
Info infoResponse
Items []*ServiceAuthorization
}
Expand Down Expand Up @@ -69,8 +67,8 @@ func (i *ListServiceAuthorizationsInput) formatFilters() map[string]string {
return result
}

// ListServiceAuthorizations returns the list of wafs for the configuration version.
func (c *Client) ListServiceAuthorizations(i *ListServiceAuthorizationsInput) (*SAResponse, error) {
// ListServiceAuthorizations retrieves all resources.
func (c *Client) ListServiceAuthorizations(i *ListServiceAuthorizationsInput) (*ServiceAuthorizations, error) {
resp, err := c.Get("/service-authorizations", &RequestOptions{
Params: i.formatFilters(),
})
Expand Down Expand Up @@ -100,7 +98,7 @@ func (c *Client) ListServiceAuthorizations(i *ListServiceAuthorizationsInput) (*
sas[i] = typed
}

return &SAResponse{
return &ServiceAuthorizations{
Items: sas,
Info: info,
}, nil
Expand Down Expand Up @@ -177,8 +175,7 @@ type UpdateServiceAuthorizationInput struct {
ID string `jsonapi:"primary,service_authorization"`

// The permission to grant the user to the service referenced by this service authorization.
// FIXME: Should be singular (Permissions -> Permission).
Permissions string `jsonapi:"attr,permission,omitempty"`
Permission string `jsonapi:"attr,permission,omitempty"`
}

// UpdateServiceAuthorization updates an exisitng service authorization. The ID must be known.
Expand All @@ -187,8 +184,8 @@ func (c *Client) UpdateServiceAuthorization(i *UpdateServiceAuthorizationInput)
return nil, ErrMissingID
}

if i.Permissions == "" {
return nil, ErrMissingPermissions
if i.Permission == "" {
return nil, ErrMissingPermission
}

path := fmt.Sprintf("/service-authorizations/%s", i.ID)
Expand Down
16 changes: 8 additions & 8 deletions fastly/service_authorization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestClient_ServiceAuthorizations(t *testing.T) {
}

// List
var sasResp *SAResponse
var sasResp *ServiceAuthorizations
record(t, fixtureBase+"/list", func(c *Client) {
sasResp, err = c.ListServiceAuthorizations(&ListServiceAuthorizationsInput{
PageSize: 10,
Expand Down Expand Up @@ -78,8 +78,8 @@ func TestClient_ServiceAuthorizations(t *testing.T) {
var usa *ServiceAuthorization
record(t, fixtureBase+"update", func(c *Client) {
usa, err = c.UpdateServiceAuthorization(&UpdateServiceAuthorizationInput{
ID: sa.ID,
Permissions: "purge_select",
ID: sa.ID,
Permission: "purge_select",
})
})
if err != nil {
Expand Down Expand Up @@ -136,18 +136,18 @@ func TestClient_CreateServiceAuthorization_validation(t *testing.T) {
func TestClient_UpdateServiceAuthorization_validation(t *testing.T) {
var err error
_, err = testClient.UpdateServiceAuthorization(&UpdateServiceAuthorizationInput{
ID: "",
Permissions: "",
ID: "",
Permission: "",
})
if err != ErrMissingID {
t.Errorf("bad error: %s", err)
}

_, err = testClient.UpdateServiceAuthorization(&UpdateServiceAuthorizationInput{
ID: "my-service-authorization-id",
Permissions: "",
ID: "my-service-authorization-id",
Permission: "",
})
if err != ErrMissingPermissions {
if err != ErrMissingPermission {
t.Errorf("bad error: %s", err)
}
}
Expand Down
7 changes: 3 additions & 4 deletions fastly/waf_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ type WAFRuleResponse struct {
// ListWAFRulesInput used as input for listing WAF rules.
type ListWAFRulesInput struct {
// Excludes individual rules by modsecurity rule IDs.
// FIXME: Should be d not c (ExcludeMocSecIDs -> ExcludeModSecIDs)
ExcludeMocSecIDs []int
ExcludeModSecIDs []int
// Limit the returned rules to a set by modsecurity rule IDs.
FilterModSecIDs []int
// Limit the returned rules to a set by publishers.
Expand All @@ -68,7 +67,7 @@ func (i *ListWAFRulesInput) formatFilters() map[string]string {
"filter[waf_tags][name][in]": i.FilterTagNames,
"filter[publisher][in]": i.FilterPublishers,
"filter[modsec_rule_id][in]": i.FilterModSecIDs,
"filter[modsec_rule_id][not]": i.ExcludeMocSecIDs,
"filter[modsec_rule_id][not]": i.ExcludeModSecIDs,
"page[size]": i.PageSize,
"page[number]": i.PageNumber,
"include": i.Include,
Expand Down Expand Up @@ -163,7 +162,7 @@ func (c *Client) ListAllWAFRules(i *ListAllWAFRulesInput) (*WAFRuleResponse, err
FilterTagNames: i.FilterTagNames,
FilterPublishers: i.FilterPublishers,
FilterModSecIDs: i.FilterModSecIDs,
ExcludeMocSecIDs: i.ExcludeMocSecIDs,
ExcludeModSecIDs: i.ExcludeMocSecIDs,
Include: i.Include,
PageNumber: currentPage,
PageSize: WAFPaginationPageSize,
Expand Down
2 changes: 1 addition & 1 deletion fastly/waf_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestClient_listWAFRules_formatFilters(t *testing.T) {
FilterTagNames: []string{"tag1", "tag2"},
FilterPublishers: []string{"owasp", "trustwave"},
FilterModSecIDs: []int{1010060, 1010070},
ExcludeMocSecIDs: []int{123456, 1234567},
ExcludeModSecIDs: []int{123456, 1234567},
PageSize: 2,
PageNumber: 2,
Include: "included",
Expand Down

0 comments on commit e8e32c0

Please sign in to comment.