diff --git a/fastly/acl.go b/fastly/acl.go index 5179c5870..3b09627da 100644 --- a/fastly/acl.go +++ b/fastly/acl.go @@ -7,6 +7,7 @@ import ( "time" ) +// ACL represents a server response from the Fastly API. type ACL struct { CreatedAt *time.Time `mapstructure:"created_at"` DeletedAt *time.Time `mapstructure:"deleted_at"` @@ -20,9 +21,17 @@ type ACL struct { // ACLsByName is a sortable list of ACLs. type ACLsByName []*ACL -// Len, Swap, and Less implement the sortable interface. -func (s ACLsByName) Len() int { return len(s) } -func (s ACLsByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implements the sortable interface. +func (s ACLsByName) Len() int { + return len(s) +} + +// Swap implements the sortable interface. +func (s ACLsByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implements the sortable interface. func (s ACLsByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -35,7 +44,7 @@ type ListACLsInput struct { ServiceVersion int } -// ListACLs returns the list of ACLs for the configuration version. +// ListACLs retrieves all resources. func (c *Client) ListACLs(i *ListACLsInput) ([]*ACL, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -70,6 +79,7 @@ type CreateACLInput struct { ServiceVersion int } +// CreateACL creates a new resource. func (c *Client) CreateACL(i *CreateACLInput) (*ACL, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -103,7 +113,7 @@ type DeleteACLInput struct { ServiceVersion int } -// DeleteACL deletes the given ACL version. +// DeleteACL deletes the specified resource. func (c *Client) DeleteACL(i *DeleteACLInput) error { if i.ServiceID == "" { return ErrMissingServiceID @@ -144,7 +154,7 @@ type GetACLInput struct { ServiceVersion int } -// GetACL gets the ACL configuration with the given parameters. +// GetACL retrieves the specified resource. func (c *Client) GetACL(i *GetACLInput) (*ACL, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -184,7 +194,7 @@ type UpdateACLInput struct { ServiceVersion int } -// UpdateACL updates the name of the ACL with the given parameters. +// UpdateACL updates the specified resource. func (c *Client) UpdateACL(i *UpdateACLInput) (*ACL, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID diff --git a/fastly/acl_entries_batch_test.go b/fastly/acl_entries_batch_test.go index 36c77b60a..2e5080cd7 100644 --- a/fastly/acl_entries_batch_test.go +++ b/fastly/acl_entries_batch_test.go @@ -6,7 +6,6 @@ import ( ) func TestClient_BatchModifyAclEntries_Create(t *testing.T) { - fixtureBase := "acl_entries_batch/create/" nameSuffix := "BatchModifyAclEntries_Create" @@ -72,12 +71,11 @@ func TestClient_BatchModifyAclEntries_Create(t *testing.T) { } for i, entry := range actualACLEntries { + actualIP := entry.IP + expectedIP := batchCreateOperations.Entries[i].IP - actualIp := entry.IP - expectedIp := batchCreateOperations.Entries[i].IP - - if actualIp != *expectedIp { - t.Errorf("IP did not match, expected %v, got %v", expectedIp, actualIp) + if actualIP != *expectedIP { + t.Errorf("IP did not match, expected %v, got %v", expectedIP, actualIP) } actualSubnet := entry.Subnet @@ -101,11 +99,9 @@ func TestClient_BatchModifyAclEntries_Create(t *testing.T) { t.Errorf("Comment did not match, expected %v, got %v", expectedComment, actualComment) } } - } func TestClient_BatchModifyAclEntries_Delete(t *testing.T) { - fixtureBase := "acl_entries_batch/delete/" nameSuffix := "BatchModifyAclEntries_Delete" @@ -141,7 +137,6 @@ func TestClient_BatchModifyAclEntries_Delete(t *testing.T) { var err error record(t, fixtureBase+"create_acl_entries", func(c *Client) { - err = c.BatchModifyACLEntries(batchCreateOperations) }) if err != nil { @@ -176,7 +171,6 @@ func TestClient_BatchModifyAclEntries_Delete(t *testing.T) { } record(t, fixtureBase+"delete_acl_entries", func(c *Client) { - err = c.BatchModifyACLEntries(batchDeleteOperations) }) if err != nil { @@ -207,7 +201,6 @@ func TestClient_BatchModifyAclEntries_Delete(t *testing.T) { } func TestClient_BatchModifyAclEntries_Update(t *testing.T) { - fixtureBase := "acl_entries_batch/update/" nameSuffix := "BatchModifyAclEntries_Update" @@ -243,7 +236,6 @@ func TestClient_BatchModifyAclEntries_Update(t *testing.T) { var err error record(t, fixtureBase+"create_acl_entries", func(c *Client) { - err = c.BatchModifyACLEntries(batchCreateOperations) }) if err != nil { @@ -282,7 +274,6 @@ func TestClient_BatchModifyAclEntries_Update(t *testing.T) { } record(t, fixtureBase+"update_acl_entries", func(c *Client) { - err = c.BatchModifyACLEntries(batchUpdateOperations) }) if err != nil { @@ -305,10 +296,10 @@ func TestClient_BatchModifyAclEntries_Update(t *testing.T) { return actualACLEntries[i].IP < actualACLEntries[j].IP }) - actualNumberOfAclEntries := len(actualACLEntries) - expectedNumberOfAclEntries := len(batchCreateOperations.Entries) - if actualNumberOfAclEntries != expectedNumberOfAclEntries { - t.Errorf("Incorrect number of ACL entries returned, expected: %d, got %d", expectedNumberOfAclEntries, actualNumberOfAclEntries) + actualNumberOfACLEntries := len(actualACLEntries) + expectedNumberOfACLEntries := len(batchCreateOperations.Entries) + if actualNumberOfACLEntries != expectedNumberOfACLEntries { + t.Errorf("Incorrect number of ACL entries returned, expected: %d, got %d", expectedNumberOfACLEntries, actualNumberOfACLEntries) } actualID := actualACLEntries[0].ID @@ -345,5 +336,4 @@ func TestClient_BatchModifyAclEntries_Update(t *testing.T) { if actualComment != *expectedComment { t.Errorf("First Comment did not match, expected %v, got %v", expectedComment, actualComment) } - } diff --git a/fastly/acl_entry.go b/fastly/acl_entry.go index a203dfc65..113d19467 100644 --- a/fastly/acl_entry.go +++ b/fastly/acl_entry.go @@ -10,6 +10,7 @@ import ( "github.com/peterhellberg/link" ) +// ACLEntry represents a server response from the Fastly API. type ACLEntry struct { ACLID string `mapstructure:"acl_id"` Comment string `mapstructure:"comment"` @@ -23,27 +24,42 @@ type ACLEntry struct { UpdatedAt *time.Time `mapstructure:"updated_at"` } -// entriesById is a sortable list of ACL entries. -type entriesById []*ACLEntry +// entriesByID is a sortable list of ACL entries. +type entriesByID []*ACLEntry -// Len, Swap, and Less implements the sortable interface. -func (s entriesById) Len() int { return len(s) } -func (s entriesById) Swap(i, j int) { s[i], s[j] = s[j], s[i] } -func (s entriesById) Less(i, j int) bool { +// Len implements the sortable interface. +func (s entriesByID) Len() int { + return len(s) +} + +// Swap implements the sortable interface. +func (s entriesByID) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implements the sortable interface. +func (s entriesByID) Less(i, j int) bool { return s[i].ID < s[j].ID } // ListACLEntriesInput is the input parameter to ListACLEntries function. type ListACLEntriesInput struct { - ACLID string + // ACLID is an alphanumeric string identifying a ACL. + ACLID string + // Direction is the direction in which to sort results. Direction string - Page int - PerPage int + // Page is the current page. + Page int + // PerPage is the number of records per page. + PerPage int + // ServiceID is an alphanumeric string identifying the service. ServiceID string - Sort string + // Sort is the field on which to sort. + Sort string } -// ListACLEntries return a list of entries for an ACL +// ListACLEntries retrieves all resources. +// FIXME: The query parameters aren't being processed (e.g. Params: i.formatFilters()). func (c *Client) ListACLEntries(i *ListACLEntriesInput) ([]*ACLEntry, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -66,12 +82,13 @@ func (c *Client) ListACLEntries(i *ListACLEntriesInput) ([]*ACLEntry, error) { return nil, err } - sort.Stable(entriesById(es)) + sort.Stable(entriesByID(es)) return es, nil } -type ListAclEntriesPaginator struct { +// ListACLEntriesPaginator implements the PaginatorACLEntries interface. +type ListACLEntriesPaginator struct { CurrentPage int LastPage int NextPage int @@ -83,12 +100,12 @@ type ListAclEntriesPaginator struct { } // HasNext returns a boolean indicating whether more pages are available -func (p *ListAclEntriesPaginator) HasNext() bool { +func (p *ListACLEntriesPaginator) HasNext() bool { return !p.consumed || p.Remaining() != 0 } // Remaining returns the remaining page count -func (p *ListAclEntriesPaginator) Remaining() int { +func (p *ListACLEntriesPaginator) Remaining() int { if p.LastPage == 0 { return 0 } @@ -96,20 +113,20 @@ func (p *ListAclEntriesPaginator) Remaining() int { } // GetNext retrieves data in the next page -func (p *ListAclEntriesPaginator) GetNext() ([]*ACLEntry, error) { +func (p *ListACLEntriesPaginator) GetNext() ([]*ACLEntry, error) { return p.client.listACLEntriesWithPage(p.options, p) } // NewListACLEntriesPaginator returns a new paginator func (c *Client) NewListACLEntriesPaginator(i *ListACLEntriesInput) PaginatorACLEntries { - return &ListAclEntriesPaginator{ + return &ListACLEntriesPaginator{ client: c, options: i, } } // listACLEntriesWithPage return a list of entries for an ACL of a given page -func (c *Client) listACLEntriesWithPage(i *ListACLEntriesInput, p *ListAclEntriesPaginator) ([]*ACLEntry, error) { +func (c *Client) listACLEntriesWithPage(i *ListACLEntriesInput, p *ListACLEntriesPaginator) ([]*ACLEntry, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID } @@ -181,19 +198,22 @@ func (c *Client) listACLEntriesWithPage(i *ListACLEntriesInput, p *ListAclEntrie return nil, err } - sort.Stable(entriesById(es)) + sort.Stable(entriesByID(es)) return es, nil } // GetACLEntryInput is the input parameter to GetACLEntry function. type GetACLEntryInput struct { - ACLID string - ID string + // ACLID is an alphanumeric string identifying an ACL Entry. + ACLID string + // ID is an alphanumeric string identifying an ACL Entry. + ID string + // ServiceID is an alphanumeric string identifying the service. ServiceID string } -// GetACLEntry returns a single ACL entry based on its ID. +// GetACLEntry retrieves the specified resource. func (c *Client) GetACLEntry(i *GetACLEntryInput) (*ACLEntry, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -223,17 +243,23 @@ func (c *Client) GetACLEntry(i *GetACLEntryInput) (*ACLEntry, error) { return e, nil } -// CreateACLEntryInput the input parameter to CreateACLEntry function. +// CreateACLEntryInput is the input parameter to the CreateACLEntry function. type CreateACLEntryInput struct { - ACLID string - IP string `url:"ip"` + // ACLID is an alphanumeric string identifying a ACL. + ACLID string + // Comment is a freeform descriptive note. + Comment string `url:"comment,omitempty"` + // IP is an IP address. + IP string `url:"ip"` + // Negated is whether to negate the match. Useful primarily when creating individual exceptions to larger subnets. + Negated Compatibool `url:"negated,omitempty"` + // ServiceID is an alphanumeric string identifying the service. ServiceID string - Comment string `url:"comment,omitempty"` - Negated Compatibool `url:"negated,omitempty"` - Subnet int `url:"subnet,omitempty"` + // Subnet is a number of bits for the subnet mask applied to the IP address. + Subnet int `url:"subnet,omitempty"` } -// CreateACLEntry creates and returns a new ACL entry. +// CreateACLEntry creates a new resource. func (c *Client) CreateACLEntry(i *CreateACLEntryInput) (*ACLEntry, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -265,12 +291,15 @@ func (c *Client) CreateACLEntry(i *CreateACLEntryInput) (*ACLEntry, error) { // DeleteACLEntryInput the input parameter to DeleteACLEntry function. type DeleteACLEntryInput struct { - ACLID string - ID string + // ACLID is an alphanumeric string identifying a ACL. + ACLID string + // ID is an alphanumeric string identifying an ACL Entry. + ID string + // ServiceID is an alphanumeric string identifying the service. ServiceID string } -// DeleteACLEntry deletes an entry from an ACL based on its ID +// DeleteACLEntry deletes the specified resource. func (c *Client) DeleteACLEntry(i *DeleteACLEntryInput) error { if i.ServiceID == "" { return ErrMissingServiceID @@ -306,16 +335,23 @@ func (c *Client) DeleteACLEntry(i *DeleteACLEntryInput) error { // UpdateACLEntryInput is the input parameter to UpdateACLEntry function. type UpdateACLEntryInput struct { - ACLID string - Comment *string `url:"comment,omitempty"` - ID string - IP *string `url:"ip,omitempty"` - Negated *Compatibool `url:"negated,omitempty"` + // ACLID is an alphanumeric string identifying a ACL. + ACLID string + // Comment is a freeform descriptive note. + Comment *string `url:"comment,omitempty"` + // ID is an alphanumeric string identifying an ACL Entry. + ID string + // IP is an IP address. + IP *string `url:"ip,omitempty"` + // Negated is whether to negate the match. Useful primarily when creating individual exceptions to larger subnets. + Negated *Compatibool `url:"negated,omitempty"` + // ServiceID is an alphanumeric string identifying the service. ServiceID string - Subnet *int `url:"subnet,omitempty"` + // Subnet is a number of bits for the subnet mask applied to the IP address. + Subnet *int `url:"subnet,omitempty"` } -// UpdateACLEntry updates an ACL entry +// UpdateACLEntry updates the specified resource. func (c *Client) UpdateACLEntry(i *UpdateACLEntryInput) (*ACLEntry, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -345,21 +381,34 @@ func (c *Client) UpdateACLEntry(i *UpdateACLEntryInput) (*ACLEntry, error) { return e, nil } +// BatchModifyACLEntriesInput is the input parameter to the +// BatchModifyACLEntries function. type BatchModifyACLEntriesInput struct { - ACLID string `json:"-"` - Entries []*BatchACLEntry `json:"entries"` - ServiceID string `json:"-"` + // ACLID is an alphanumeric string identifying a ACL. + ACLID string `json:"-"` + // Entries is a list of ACL entries. + Entries []*BatchACLEntry `json:"entries"` + // ServiceID is an alphanumeric string identifying the service. + ServiceID string `json:"-"` } +// BatchACLEntry represents a single ACL entry. type BatchACLEntry struct { - Comment *string `json:"comment,omitempty"` - ID *string `json:"id,omitempty"` - IP *string `json:"ip,omitempty"` - Negated *Compatibool `json:"negated,omitempty"` + // Comment is a freeform descriptive note. + Comment *string `json:"comment,omitempty"` + // ID is an alphanumeric string identifying an ACL Entry. + ID *string `json:"id,omitempty"` + // IP is an IP address. + IP *string `json:"ip,omitempty"` + // Negated is whether to negate the match. Useful primarily when creating individual exceptions to larger subnets. + Negated *Compatibool `json:"negated,omitempty"` + // Operation is a batching operation variant. Operation BatchOperation `json:"op"` - Subnet *int `json:"subnet,omitempty"` + // Subnet is the number of bits for the subnet mask applied to the IP address. + Subnet *int `json:"subnet,omitempty"` } +// BatchModifyACLEntries updates the specified resources. func (c *Client) BatchModifyACLEntries(i *BatchModifyACLEntriesInput) error { if i.ServiceID == "" { return ErrMissingServiceID @@ -381,9 +430,6 @@ func (c *Client) BatchModifyACLEntries(i *BatchModifyACLEntriesInput) error { defer resp.Body.Close() var batchModifyResult map[string]string - if err := decodeBodyMap(resp.Body, &batchModifyResult); err != nil { - return err - } - return nil + return decodeBodyMap(resp.Body, &batchModifyResult) } diff --git a/fastly/acl_entry_test.go b/fastly/acl_entry_test.go index 963891b16..f74b5b68b 100644 --- a/fastly/acl_entry_test.go +++ b/fastly/acl_entry_test.go @@ -5,7 +5,6 @@ import ( ) func TestClient_ACLEntries(t *testing.T) { - fixtureBase := "acl_entries/" nameSuffix := "ACLEntries" @@ -42,7 +41,7 @@ func TestClient_ACLEntries(t *testing.T) { t.Errorf("Bad subnet: %v", e.Subnet) } - if e.Negated != false { + if e.Negated { t.Errorf("Bad negated flag: %t", e.Negated) } @@ -136,7 +135,7 @@ func TestClient_ACLEntries(t *testing.T) { t.Errorf("bad subnet: %v", ne.Subnet) } - if ue.Negated != true { + if !ue.Negated { t.Errorf("bad Negated flag: %v", ne.Negated) } @@ -155,7 +154,6 @@ func TestClient_ACLEntries(t *testing.T) { if err != nil { t.Fatal(err) } - } func TestClient_ListACLEntries_validation(t *testing.T) { @@ -300,5 +298,4 @@ func TestClient_BatchModifyACLEntries_validation(t *testing.T) { if err != ErrMaxExceededEntries { t.Errorf("bad error: %s", err) } - } diff --git a/fastly/acl_test.go b/fastly/acl_test.go index b35375d0a..d013b3937 100644 --- a/fastly/acl_test.go +++ b/fastly/acl_test.go @@ -28,13 +28,13 @@ func TestClient_ACLs(t *testing.T) { // Ensure deleted defer func() { record(t, fixtureBase+"cleanup", func(c *Client) { - c.DeleteACL(&DeleteACLInput{ + _ = c.DeleteACL(&DeleteACLInput{ ServiceID: testServiceID, ServiceVersion: testVersion.Number, Name: "test_acl", }) - c.DeleteACL(&DeleteACLInput{ + _ = c.DeleteACL(&DeleteACLInput{ ServiceID: testServiceID, ServiceVersion: testVersion.Number, Name: "new_test_acl", @@ -109,7 +109,6 @@ func TestClient_ACLs(t *testing.T) { if err != nil { t.Fatal(err) } - } func TestClient_ListACLs_validation(t *testing.T) { diff --git a/fastly/backend.go b/fastly/backend.go index 1d99aac31..345038ecd 100644 --- a/fastly/backend.go +++ b/fastly/backend.go @@ -47,8 +47,14 @@ type Backend struct { type backendsByName []*Backend // Len, Swap, and Less implement the sortable interface. -func (s backendsByName) Len() int { return len(s) } -func (s backendsByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +func (s backendsByName) Len() int { + return len(s) +} + +func (s backendsByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + func (s backendsByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -61,7 +67,7 @@ type ListBackendsInput struct { ServiceVersion int } -// ListBackends returns the list of backends for the configuration version. +// ListBackends retrieves all resources. func (c *Client) ListBackends(i *ListBackendsInput) ([]*Backend, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -88,39 +94,66 @@ func (c *Client) ListBackends(i *ListBackendsInput) ([]*Backend, error) { // CreateBackendInput is used as input to the CreateBackend function. type CreateBackendInput struct { - Address string `url:"address,omitempty"` - AutoLoadbalance Compatibool `url:"auto_loadbalance,omitempty"` - BetweenBytesTimeout *uint `url:"between_bytes_timeout,omitempty"` - Comment string `url:"comment,omitempty"` - ConnectTimeout *uint `url:"connect_timeout,omitempty"` - ErrorThreshold *uint `url:"error_threshold,omitempty"` - FirstByteTimeout *uint `url:"first_byte_timeout,omitempty"` - HealthCheck string `url:"healthcheck,omitempty"` - MaxConn *uint `url:"max_conn,omitempty"` - MaxTLSVersion string `url:"max_tls_version,omitempty"` - MinTLSVersion string `url:"min_tls_version,omitempty"` - Name string `url:"name,omitempty"` - OverrideHost string `url:"override_host,omitempty"` - Port uint `url:"port,omitempty"` - RequestCondition string `url:"request_condition,omitempty"` - SSLCACert string `url:"ssl_ca_cert,omitempty"` - SSLCertHostname string `url:"ssl_cert_hostname,omitempty"` - SSLCheckCert *Compatibool `url:"ssl_check_cert,omitempty"` - SSLCiphers string `url:"ssl_ciphers,omitempty"` - SSLClientCert string `url:"ssl_client_cert,omitempty"` - SSLClientKey string `url:"ssl_client_key,omitempty"` - SSLHostname string `url:"ssl_hostname,omitempty"` - SSLSNIHostname string `url:"ssl_sni_hostname,omitempty"` + // Address is a hostname, IPv4, or IPv6 address for the backend. + Address string `url:"address,omitempty"` + // AutoLoadbalance is whether or not this backend should be automatically load balanced. + AutoLoadbalance Compatibool `url:"auto_loadbalance,omitempty"` + // BetweenBytesTimeout is the maximum duration in milliseconds that Fastly will wait while receiving no data on a download from a backend. + BetweenBytesTimeout *uint `url:"between_bytes_timeout,omitempty"` + // Comment is a freeform descriptive note. + Comment string `url:"comment,omitempty"` + // ConnectTimeout is the maximum duration in milliseconds to wait for a connection to this backend to be established. + ConnectTimeout *uint `url:"connect_timeout,omitempty"` + // ErrorThreshold is the number of errors to allow before the Backend is marked as down. + ErrorThreshold *uint `url:"error_threshold,omitempty"` + // FirstByteTimeout is how long to wait for the first bytes in milliseconds. + FirstByteTimeout *uint `url:"first_byte_timeout,omitempty"` + // HealthCheck is the name of the healthcheck to use with this backend. + HealthCheck string `url:"healthcheck,omitempty"` + // MaxConn is the maximum number of concurrent connections this backend will accept. + MaxConn *uint `url:"max_conn,omitempty"` + // MaxTLSVersion is the maximum allowed TLS version on SSL connections to this backend. + MaxTLSVersion string `url:"max_tls_version,omitempty"` + // MinTLSVersion is the minimum allowed TLS version on SSL connections to this backend. + MinTLSVersion string `url:"min_tls_version,omitempty"` + // Name is the name of the backend. + Name string `url:"name,omitempty"` + // OverrideHost is, if set, will replace the client-supplied HTTP Host header on connections to this backend. + OverrideHost string `url:"override_host,omitempty"` + // Port is the port on which the backend server is listening for connections from Fastly. + Port uint `url:"port,omitempty"` + // RequestCondition is the name of a Condition, which if satisfied, will select this backend during a request. + RequestCondition string `url:"request_condition,omitempty"` + // SSLCACert is a CA certificate attached to origin. + SSLCACert string `url:"ssl_ca_cert,omitempty"` + // SSLCertHostname is an overrides ssl_hostname, but only for cert verification. + SSLCertHostname string `url:"ssl_cert_hostname,omitempty"` + // SSLCheckCert forces being strict on checking SSL certs. + SSLCheckCert *Compatibool `url:"ssl_check_cert,omitempty"` + // SSLCiphers is a list of OpenSSL ciphers to support for connections to this origin. + SSLCiphers string `url:"ssl_ciphers,omitempty"` + // SSLClientCert is a client certificate attached to origin. + SSLClientCert string `url:"ssl_client_cert,omitempty"` + // SSLClientKey is a client key attached to origin. + SSLClientKey string `url:"ssl_client_key,omitempty"` + // SSLHostname is used for both SNI during the TLS handshake and to validate the cert. + // Deprecated: Use ssl_cert_hostname and ssl_sni_hostname to configure certificate validation. + SSLHostname string `url:"ssl_hostname,omitempty"` + // SSLSNIHostname overrides ssl_hostname, but only for SNI in the handshake. Does not affect cert validation at all. + SSLSNIHostname string `url:"ssl_sni_hostname,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - Shield string `url:"shield,omitempty"` - UseSSL Compatibool `url:"use_ssl,omitempty"` - Weight *uint `url:"weight,omitempty"` + // Shield is an identifier of the POP to use as a shield. + Shield string `url:"shield,omitempty"` + // UseSSL indicates whether or not to require TLS for connections to this backend. + UseSSL Compatibool `url:"use_ssl,omitempty"` + // Weight is the weight used to load balance this backend against others. + Weight *uint `url:"weight,omitempty"` } -// CreateBackend creates a new Fastly backend. +// CreateBackend creates a new resource. func (c *Client) CreateBackend(i *CreateBackendInput) (*Backend, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -154,7 +187,7 @@ type GetBackendInput struct { ServiceVersion int } -// GetBackend gets the backend configuration with the given parameters. +// GetBackend retrieves the specified resource. func (c *Client) GetBackend(i *GetBackendInput) (*Backend, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -184,40 +217,64 @@ func (c *Client) GetBackend(i *GetBackendInput) (*Backend, error) { // UpdateBackendInput is used as input to the UpdateBackend function. type UpdateBackendInput struct { - Address *string `url:"address,omitempty"` - AutoLoadbalance *Compatibool `url:"auto_loadbalance,omitempty"` - BetweenBytesTimeout *uint `url:"between_bytes_timeout,omitempty"` - Comment *string `url:"comment,omitempty"` - ConnectTimeout *uint `url:"connect_timeout,omitempty"` - ErrorThreshold *uint `url:"error_threshold,omitempty"` - FirstByteTimeout *uint `url:"first_byte_timeout,omitempty"` - HealthCheck *string `url:"healthcheck,omitempty"` - MaxConn *uint `url:"max_conn,omitempty"` - MaxTLSVersion *string `url:"max_tls_version,omitempty"` - MinTLSVersion *string `url:"min_tls_version,omitempty"` + // Address is a hostname, IPv4, or IPv6 address for the backend. + Address *string `url:"address,omitempty"` + // AutoLoadbalance is whether or not this backend should be automatically load balanced. + AutoLoadbalance *Compatibool `url:"auto_loadbalance,omitempty"` + // BetweenBytesTimeout is the maximum duration in milliseconds that Fastly will wait while receiving no data on a download from a backend. + BetweenBytesTimeout *uint `url:"between_bytes_timeout,omitempty"` + // Comment is a freeform descriptive note. + Comment *string `url:"comment,omitempty"` + // ConnectTimeout is the maximum duration in milliseconds to wait for a connection to this backend to be established. + ConnectTimeout *uint `url:"connect_timeout,omitempty"` + // ErrorThreshold is the number of errors to allow before the Backend is marked as down. + ErrorThreshold *uint `url:"error_threshold,omitempty"` + // FirstByteTimeout is how long to wait for the first bytes in milliseconds. + FirstByteTimeout *uint `url:"first_byte_timeout,omitempty"` + // HealthCheck is the name of the healthcheck to use with this backend. + HealthCheck *string `url:"healthcheck,omitempty"` + // MaxConn is the maximum number of concurrent connections this backend will accept. + MaxConn *uint `url:"max_conn,omitempty"` + // MaxTLSVersion is the maximum allowed TLS version on SSL connections to this backend. + MaxTLSVersion *string `url:"max_tls_version,omitempty"` + // MinTLSVersion is the minimum allowed TLS version on SSL connections to this backend. + MinTLSVersion *string `url:"min_tls_version,omitempty"` // Name is the name of the backend to update. - Name string - NewName *string `url:"name,omitempty"` - OverrideHost *string `url:"override_host,omitempty"` - Port *uint `url:"port,omitempty"` - RequestCondition *string `url:"request_condition,omitempty"` - SSLCACert *string `url:"ssl_ca_cert,omitempty"` - SSLCertHostname *string `url:"ssl_cert_hostname,omitempty"` - SSLCheckCert *Compatibool `url:"ssl_check_cert,omitempty"` - SSLCiphers *string `url:"ssl_ciphers,omitempty"` - SSLClientCert *string `url:"ssl_client_cert,omitempty"` - SSLClientKey *string `url:"ssl_client_key,omitempty"` - SSLSNIHostname *string `url:"ssl_sni_hostname,omitempty"` + Name string + NewName *string `url:"name,omitempty"` + // OverrideHost is, if set, will replace the client-supplied HTTP Host header on connections to this backend. + OverrideHost *string `url:"override_host,omitempty"` + // Port is the port on which the backend server is listening for connections from Fastly. + Port *uint `url:"port,omitempty"` + // RequestCondition is the name of a Condition, which if satisfied, will select this backend during a request. + RequestCondition *string `url:"request_condition,omitempty"` + // SSLCACert is a CA certificate attached to origin. + SSLCACert *string `url:"ssl_ca_cert,omitempty"` + // SSLCertHostname is an overrides ssl_hostname, but only for cert verification. + SSLCertHostname *string `url:"ssl_cert_hostname,omitempty"` + // SSLCheckCert forces being strict on checking SSL certs. + SSLCheckCert *Compatibool `url:"ssl_check_cert,omitempty"` + // SSLCiphers is a list of OpenSSL ciphers to support for connections to this origin. + SSLCiphers *string `url:"ssl_ciphers,omitempty"` + // SSLClientCert is a client certificate attached to origin. + SSLClientCert *string `url:"ssl_client_cert,omitempty"` + // SSLClientKey is a client key attached to origin. + SSLClientKey *string `url:"ssl_client_key,omitempty"` + // SSLSNIHostname overrides ssl_hostname, but only for SNI in the handshake. Does not affect cert validation at all. + SSLSNIHostname *string `url:"ssl_sni_hostname,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - Shield *string `url:"shield,omitempty"` - UseSSL *Compatibool `url:"use_ssl,omitempty"` - Weight *uint `url:"weight,omitempty"` + // Shield is an identifier of the POP to use as a shield. + Shield *string `url:"shield,omitempty"` + // UseSSL indicates whether or not to require TLS for connections to this backend. + UseSSL *Compatibool `url:"use_ssl,omitempty"` + // Weight is the weight used to load balance this backend against others. + Weight *uint `url:"weight,omitempty"` } -// UpdateBackend updates a specific backend. +// UpdateBackend updates the specified resource. func (c *Client) UpdateBackend(i *UpdateBackendInput) (*Backend, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -255,7 +312,7 @@ type DeleteBackendInput struct { ServiceVersion int } -// DeleteBackend deletes the given backend version. +// DeleteBackend deletes the specified resource. func (c *Client) DeleteBackend(i *DeleteBackendInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/backend_test.go b/fastly/backend_test.go index a4bdb6ec5..474e2a7dd 100644 --- a/fastly/backend_test.go +++ b/fastly/backend_test.go @@ -35,13 +35,13 @@ func TestClient_Backends(t *testing.T) { // Ensure deleted defer func() { record(t, "backends/cleanup", func(c *Client) { - c.DeleteBackend(&DeleteBackendInput{ + _ = c.DeleteBackend(&DeleteBackendInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-backend", }) - c.DeleteBackend(&DeleteBackendInput{ + _ = c.DeleteBackend(&DeleteBackendInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "new-test-backend", @@ -64,7 +64,7 @@ func TestClient_Backends(t *testing.T) { if b.OverrideHost != "origin.example.com" { t.Errorf("bad override_host: %q", b.OverrideHost) } - if b.SSLCheckCert != false { + if b.SSLCheckCert { t.Errorf("bad ssl_check_cert: %t", b.SSLCheckCert) // API defaults to true and we want to allow setting false } if b.SSLSNIHostname != "ssl-hostname.com" { @@ -141,7 +141,7 @@ func TestClient_Backends(t *testing.T) { if ub.Port != 1234 { t.Errorf("bad port: %d", ub.Port) } - if ub.SSLCheckCert != false { + if ub.SSLCheckCert { t.Errorf("bad ssl_check_cert: %t", ub.SSLCheckCert) } if ub.SSLSNIHostname != "ssl-hostname-updated.com" { diff --git a/fastly/bigquery.go b/fastly/bigquery.go index 80dc6af50..f390a0e33 100644 --- a/fastly/bigquery.go +++ b/fastly/bigquery.go @@ -31,9 +31,17 @@ type BigQuery struct { // bigQueriesByName is a sortable list of BigQueries. type bigQueriesByName []*BigQuery -// Len, Swap, and Less implement the sortable interface. -func (s bigQueriesByName) Len() int { return len(s) } -func (s bigQueriesByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implements the sortable interface. +func (s bigQueriesByName) Len() int { + return len(s) +} + +// Swap implements the sortable interface. +func (s bigQueriesByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implements the sortable interface. func (s bigQueriesByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -46,7 +54,7 @@ type ListBigQueriesInput struct { ServiceVersion int } -// ListBigQueries returns the list of BigQueries for the configuration version. +// ListBigQueries retrieves all resources. func (c *Client) ListBigQueries(i *ListBigQueriesInput) ([]*BigQuery, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -73,25 +81,37 @@ func (c *Client) ListBigQueries(i *ListBigQueriesInput) ([]*BigQuery, error) { // CreateBigQueryInput is used as input to the CreateBigQuery function. type CreateBigQueryInput struct { - AccountName string `url:"account_name,omitempty"` - Dataset string `url:"dataset,omitempty"` - Format string `url:"format,omitempty"` - FormatVersion uint `url:"format_version,omitempty"` - Name string `url:"name,omitempty"` - Placement string `url:"placement,omitempty"` - ProjectID string `url:"project_id,omitempty"` + // AccountName is the name of the Google Cloud Platform service account associated with the target log collection service. + AccountName string `url:"account_name,omitempty"` + // Dataset is your BigQuery dataset. + Dataset string `url:"dataset,omitempty"` + // Format is a Fastly log format string. Must produce JSON that matches the schema of your BigQuery table. + Format string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion uint `url:"format_version,omitempty"` + // Name is the name of the BigQuery logging object. Used as a primary key for API access. + Name string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement string `url:"placement,omitempty"` + // ProjectID is your Google Cloud Platform project ID. + ProjectID string `url:"project_id,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition string `url:"response_condition,omitempty"` - SecretKey string `url:"secret_key,omitempty"` + // SecretKey is your Google Cloud Platform account secret key. The private_key field in your service account authentication JSON. Not required if account_name is specified. + SecretKey string `url:"secret_key,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - Table string `url:"table,omitempty"` - Template string `url:"template_suffix,omitempty"` - User string `url:"user,omitempty"` + // Table is your BigQuery table. + Table string `url:"table,omitempty"` + // Template is a BigQuery table name suffix template. + Template string `url:"template_suffix,omitempty"` + // User is your Google Cloud Platform service account email address. The client_email field in your service account authentication JSON. Not required if account_name is specified. + User string `url:"user,omitempty"` } -// CreateBigQuery creates a new Fastly BigQuery. +// CreateBigQuery creates a new resource. func (c *Client) CreateBigQuery(i *CreateBigQueryInput) (*BigQuery, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -125,7 +145,7 @@ type GetBigQueryInput struct { ServiceVersion int } -// GetBigQuery gets the BigQuery configuration with the given parameters. +// GetBigQuery retrieves the specified resource. func (c *Client) GetBigQuery(i *GetBigQueryInput) (*BigQuery, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -155,27 +175,39 @@ func (c *Client) GetBigQuery(i *GetBigQueryInput) (*BigQuery, error) { // UpdateBigQueryInput is used as input to the UpdateBigQuery function. type UpdateBigQueryInput struct { - AccountName *string `url:"account_name,omitempty"` - Dataset *string `url:"dataset,omitempty"` - Format *string `url:"format,omitempty"` - FormatVersion *uint `url:"format_version,omitempty"` + // AccountName is the name of the Google Cloud Platform service account associated with the target log collection service. + AccountName *string `url:"account_name,omitempty"` + // Dataset is your BigQuery dataset. + Dataset *string `url:"dataset,omitempty"` + // Format is a Fastly log format string. Must produce JSON that matches the schema of your BigQuery table. + Format *string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion *uint `url:"format_version,omitempty"` // Name is the name of the BigQuery to update. - Name string - NewName *string `url:"name,omitempty"` - Placement *string `url:"placement,omitempty"` - ProjectID *string `url:"project_id,omitempty"` + Name string + // NewName is the new name for the resource. + NewName *string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement *string `url:"placement,omitempty"` + // ProjectID is your Google Cloud Platform project ID. + ProjectID *string `url:"project_id,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition *string `url:"response_condition,omitempty"` - SecretKey *string `url:"secret_key,omitempty"` + // SecretKey is your Google Cloud Platform account secret key. The private_key field in your service account authentication JSON. Not required if account_name is specified. + SecretKey *string `url:"secret_key,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - Table *string `url:"table,omitempty"` - Template *string `url:"template_suffix,omitempty"` - User *string `url:"user,omitempty"` + // Table is your BigQuery table. + Table *string `url:"table,omitempty"` + // Template is a BigQuery table name suffix template. + Template *string `url:"template_suffix,omitempty"` + // User is your Google Cloud Platform service account email address. The client_email field in your service account authentication JSON. Not required if account_name is specified. + User *string `url:"user,omitempty"` } -// UpdateBigQuery updates a specific BigQuery. +// UpdateBigQuery updates the specified resource. func (c *Client) UpdateBigQuery(i *UpdateBigQueryInput) (*BigQuery, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -213,7 +245,7 @@ type DeleteBigQueryInput struct { ServiceVersion int } -// DeleteBigQuery deletes the given BigQuery version. +// DeleteBigQuery deletes the specified resource. func (c *Client) DeleteBigQuery(i *DeleteBigQueryInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/bigquery_test.go b/fastly/bigquery_test.go index da472a18c..36aec445e 100644 --- a/fastly/bigquery_test.go +++ b/fastly/bigquery_test.go @@ -42,13 +42,13 @@ func TestClient_Bigqueries(t *testing.T) { // Ensure deleted defer func() { record(t, "bigqueries/cleanup", func(c *Client) { - c.DeleteBigQuery(&DeleteBigQueryInput{ + _ = c.DeleteBigQuery(&DeleteBigQueryInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-bigquery", }) - c.DeleteBigQuery(&DeleteBigQueryInput{ + _ = c.DeleteBigQuery(&DeleteBigQueryInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "new-test-bigquery", diff --git a/fastly/billing.go b/fastly/billing.go index af12ce653..934cfe969 100644 --- a/fastly/billing.go +++ b/fastly/billing.go @@ -53,8 +53,10 @@ type BillingExtra struct { // GetBillingInput is used as input to the GetBilling function. type GetBillingInput struct { + // Month is a 2-digit month. Month uint8 - Year uint16 + // Year is a 4-digit year. + Year uint16 } // GetBilling returns the billing information for the current account. diff --git a/fastly/blobstorage.go b/fastly/blobstorage.go index f1c28f226..5e3eadaa6 100644 --- a/fastly/blobstorage.go +++ b/fastly/blobstorage.go @@ -35,9 +35,17 @@ type BlobStorage struct { // blobStorageByName is a sortable list of blob storages. type blobStorageByName []*BlobStorage -// Len, Swap, and Less implement the sortable interface. -func (s blobStorageByName) Len() int { return len(s) } -func (s blobStorageByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s blobStorageByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s blobStorageByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s blobStorageByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -50,7 +58,7 @@ type ListBlobStoragesInput struct { ServiceVersion int } -// ListBlobStorages returns the list of blob storages for the configuration version. +// ListBlobStorages retrieves all resources. func (c *Client) ListBlobStorages(i *ListBlobStoragesInput) ([]*BlobStorage, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -77,29 +85,45 @@ func (c *Client) ListBlobStorages(i *ListBlobStoragesInput) ([]*BlobStorage, err // CreateBlobStorageInput is used as input to the CreateBlobStorage function. type CreateBlobStorageInput struct { - AccountName string `url:"account_name,omitempty"` - CompressionCodec string `url:"compression_codec,omitempty"` - Container string `url:"container,omitempty"` - FileMaxBytes uint `url:"file_max_bytes,omitempty"` - Format string `url:"format,omitempty"` - FormatVersion uint `url:"format_version,omitempty"` - GzipLevel uint8 `url:"gzip_level,omitempty"` - MessageType string `url:"message_type,omitempty"` - Name string `url:"name,omitempty"` - Path string `url:"path,omitempty"` - Period uint `url:"period,omitempty"` - Placement string `url:"placement,omitempty"` - PublicKey string `url:"public_key,omitempty"` + // AccountName is the unique Azure Blob Storage namespace in which your data objects are stored. + AccountName string `url:"account_name,omitempty"` + // CompressionCodec is the codec used for compressing your logs (valid values are zstd, snappy, and gzip). + CompressionCodec string `url:"compression_codec,omitempty"` + // Container is the name of the Azure Blob Storage container in which to store logs. + Container string `url:"container,omitempty"` + // FileMaxBytes is the maximum number of bytes for each uploaded file. A value of 0 can be used to indicate there is no limit on the size of uploaded files, otherwise the minimum value is 1048576 bytes (1 MiB.). + FileMaxBytes uint `url:"file_max_bytes,omitempty"` + // Format is a Fastly log format string. + Format string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion uint `url:"format_version,omitempty"` + // GzipLevel is the level of gzip encoding when sending logs (default 0, no compression). + GzipLevel uint8 `url:"gzip_level,omitempty"` + // MessageType is how the message should be formatted. + MessageType string `url:"message_type,omitempty"` + // Name is the name for the real-time logging configuration. + Name string `url:"name,omitempty"` + // Path is the path to upload logs to. + Path string `url:"path,omitempty"` + // Period is how frequently log files are finalized so they can be available for reading (in seconds). + Period uint `url:"period,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement string `url:"placement,omitempty"` + // PublicKey is a PGP public key that Fastly will use to encrypt your log files before writing them to disk. + PublicKey string `url:"public_key,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition string `url:"response_condition,omitempty"` - SASToken string `url:"sas_token,omitempty"` + // SASToken is the Azure shared access signature providing write access to the blob service objects. + SASToken string `url:"sas_token,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). - ServiceVersion int + ServiceVersion int + // TimestampFormat is a timestamp format. TimestampFormat string `url:"timestamp_format,omitempty"` } -// CreateBlobStorage creates a new Fastly blob storage. +// CreateBlobStorage creates a new resource. func (c *Client) CreateBlobStorage(i *CreateBlobStorageInput) (*BlobStorage, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -133,7 +157,7 @@ type GetBlobStorageInput struct { ServiceVersion int } -// GetBlobStorage gets the blob storage configuration with the given parameters. +// GetBlobStorage retrieves the specified resource. func (c *Client) GetBlobStorage(i *GetBlobStorageInput) (*BlobStorage, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -163,31 +187,47 @@ func (c *Client) GetBlobStorage(i *GetBlobStorageInput) (*BlobStorage, error) { // UpdateBlobStorageInput is used as input to the UpdateBlobStorage function. type UpdateBlobStorageInput struct { - AccountName *string `url:"account_name,omitempty"` + // AccountName is the unique Azure Blob Storage namespace in which your data objects are stored. + AccountName *string `url:"account_name,omitempty"` + // CompressionCodec is the codec used for compressing your logs (valid values are zstd, snappy, and gzip). CompressionCodec *string `url:"compression_codec,omitempty"` - Container *string `url:"container,omitempty"` - FileMaxBytes *uint `url:"file_max_bytes,omitempty"` - Format *string `url:"format,omitempty"` - FormatVersion *uint `url:"format_version,omitempty"` - GzipLevel *uint8 `url:"gzip_level,omitempty"` - MessageType *string `url:"message_type,omitempty"` + // Container is the name of the Azure Blob Storage container in which to store logs. + Container *string `url:"container,omitempty"` + // FileMaxBytes is the maximum number of bytes for each uploaded file. A value of 0 can be used to indicate there is no limit on the size of uploaded files, otherwise the minimum value is 1048576 bytes (1 MiB.). + FileMaxBytes *uint `url:"file_max_bytes,omitempty"` + // Format is a Fastly log format string. + Format *string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion *uint `url:"format_version,omitempty"` + // GzipLevel is the level of gzip encoding when sending logs (default 0, no compression). + GzipLevel *uint8 `url:"gzip_level,omitempty"` + // MessageType is how the message should be formatted. + MessageType *string `url:"message_type,omitempty"` // Name is the name of the blob storage to update. - Name string - NewName *string `url:"name,omitempty"` - Path *string `url:"path,omitempty"` - Period *uint `url:"period,omitempty"` - Placement *string `url:"placement,omitempty"` - PublicKey *string `url:"public_key,omitempty"` + Name string + // NewName is the new name for the resource. + NewName *string `url:"name,omitempty"` + // Path is the path to upload logs to. + Path *string `url:"path,omitempty"` + // Period is how frequently log files are finalized so they can be available for reading (in seconds). + Period *uint `url:"period,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement *string `url:"placement,omitempty"` + // PublicKey is a PGP public key that Fastly will use to encrypt your log files before writing them to disk. + PublicKey *string `url:"public_key,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition *string `url:"response_condition,omitempty"` - SASToken *string `url:"sas_token,omitempty"` + // SASToken is the Azure shared access signature providing write access to the blob service objects. + SASToken *string `url:"sas_token,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). - ServiceVersion int + ServiceVersion int + // TimestampFormat is a timestamp format. TimestampFormat *string `url:"timestamp_format,omitempty"` } -// UpdateBlobStorage updates a specific blob storage. +// UpdateBlobStorage updates the specified resource. func (c *Client) UpdateBlobStorage(i *UpdateBlobStorageInput) (*BlobStorage, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -225,7 +265,7 @@ type DeleteBlobStorageInput struct { ServiceVersion int } -// DeleteBlobStorage deletes the given blob storage version. +// DeleteBlobStorage deletes the specified resource. func (c *Client) DeleteBlobStorage(i *DeleteBlobStorageInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/blobstorage_test.go b/fastly/blobstorage_test.go index 868ec8c21..c1f9ceada 100644 --- a/fastly/blobstorage_test.go +++ b/fastly/blobstorage_test.go @@ -120,25 +120,25 @@ func TestClient_BlobStorages(t *testing.T) { // Ensure deleted defer func() { record(t, "blobstorages/cleanup", func(c *Client) { - c.DeleteBlobStorage(&DeleteBlobStorageInput{ + _ = c.DeleteBlobStorage(&DeleteBlobStorageInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-blobstorage", }) - c.DeleteBlobStorage(&DeleteBlobStorageInput{ + _ = c.DeleteBlobStorage(&DeleteBlobStorageInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-blobstorage-2", }) - c.DeleteBlobStorage(&DeleteBlobStorageInput{ + _ = c.DeleteBlobStorage(&DeleteBlobStorageInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-blobstorage-3", }) - c.DeleteBlobStorage(&DeleteBlobStorageInput{ + _ = c.DeleteBlobStorage(&DeleteBlobStorageInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "new-test-blobstorage", diff --git a/fastly/cache_setting.go b/fastly/cache_setting.go index 565ad74a0..464cd63fb 100644 --- a/fastly/cache_setting.go +++ b/fastly/cache_setting.go @@ -38,9 +38,17 @@ type CacheSetting struct { // cacheSettingsByName is a sortable list of cache settings. type cacheSettingsByName []*CacheSetting -// Len, Swap, and Less implement the sortable interface. -func (s cacheSettingsByName) Len() int { return len(s) } -func (s cacheSettingsByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s cacheSettingsByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s cacheSettingsByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s cacheSettingsByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -53,8 +61,7 @@ type ListCacheSettingsInput struct { ServiceVersion int } -// ListCacheSettings returns the list of cache settings for the configuration -// version. +// ListCacheSettings retrieves all resources. func (c *Client) ListCacheSettings(i *ListCacheSettingsInput) ([]*CacheSetting, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -81,18 +88,23 @@ func (c *Client) ListCacheSettings(i *ListCacheSettingsInput) ([]*CacheSetting, // CreateCacheSettingInput is used as input to the CreateCacheSetting function. type CreateCacheSettingInput struct { - Action CacheSettingAction `url:"action,omitempty"` - CacheCondition string `url:"cache_condition,omitempty"` - Name string `url:"name,omitempty"` + // Action determines vcl_fetch behaviour (pass, cache, restart). + Action CacheSettingAction `url:"action,omitempty"` + // CacheCondition is name of the cache condition controlling when this configuration applies. + CacheCondition string `url:"cache_condition,omitempty"` + // Name is the name for the cache settings object. + Name string `url:"name,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - StaleTTL uint `url:"stale_ttl,omitempty"` - TTL uint `url:"ttl,omitempty"` + // StaleTTL is the maximum time in seconds to continue to use a stale version of the object if future requests to your backend server fail (also known as 'stale if error'). + StaleTTL uint `url:"stale_ttl,omitempty"` + // TTL is the maximum time to consider the object fresh in the cache (the cache 'time to live'). + TTL uint `url:"ttl,omitempty"` } -// CreateCacheSetting creates a new Fastly cache setting. +// CreateCacheSetting creates a new resource. func (c *Client) CreateCacheSetting(i *CreateCacheSettingInput) (*CacheSetting, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -126,8 +138,7 @@ type GetCacheSettingInput struct { ServiceVersion int } -// GetCacheSetting gets the cache setting configuration with the given -// parameters. +// GetCacheSetting retrieves the specified resource. func (c *Client) GetCacheSetting(i *GetCacheSettingInput) (*CacheSetting, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -157,20 +168,25 @@ func (c *Client) GetCacheSetting(i *GetCacheSettingInput) (*CacheSetting, error) // UpdateCacheSettingInput is used as input to the UpdateCacheSetting function. type UpdateCacheSettingInput struct { - Action CacheSettingAction `url:"action,omitempty"` - CacheCondition *string `url:"cache_condition,omitempty"` + // Action determines vcl_fetch behaviour (pass, cache, restart). + Action CacheSettingAction `url:"action,omitempty"` + // CacheCondition is name of the cache condition controlling when this configuration applies. + CacheCondition *string `url:"cache_condition,omitempty"` // Name is the name of the cache setting to update. - Name string + Name string + // NewName is the new name for the resource. NewName *string `url:"name,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - StaleTTL *uint `url:"stale_ttl,omitempty"` - TTL *uint `url:"ttl,omitempty"` + // StaleTTL is the maximum time in seconds to continue to use a stale version of the object if future requests to your backend server fail (also known as 'stale if error'). + StaleTTL *uint `url:"stale_ttl,omitempty"` + // TTL is the maximum time to consider the object fresh in the cache (the cache 'time to live'). + TTL *uint `url:"ttl,omitempty"` } -// UpdateCacheSetting updates a specific cache setting. +// UpdateCacheSetting updates the specified resource. func (c *Client) UpdateCacheSetting(i *UpdateCacheSettingInput) (*CacheSetting, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -208,7 +224,7 @@ type DeleteCacheSettingInput struct { ServiceVersion int } -// DeleteCacheSetting deletes the given cache setting version. +// DeleteCacheSetting deletes the specified resource. func (c *Client) DeleteCacheSetting(i *DeleteCacheSettingInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/cache_setting_test.go b/fastly/cache_setting_test.go index 7cf558f87..9f3080fcc 100644 --- a/fastly/cache_setting_test.go +++ b/fastly/cache_setting_test.go @@ -32,13 +32,13 @@ func TestClient_CacheSettings(t *testing.T) { // Ensure deleted defer func() { record(t, "cache_settings/cleanup", func(c *Client) { - c.DeleteCacheSetting(&DeleteCacheSettingInput{ + _ = c.DeleteCacheSetting(&DeleteCacheSettingInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-cache-setting", }) - c.DeleteCacheSetting(&DeleteCacheSettingInput{ + _ = c.DeleteCacheSetting(&DeleteCacheSettingInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "new-test-cache-setting", diff --git a/fastly/client.go b/fastly/client.go index ebd218124..3b1499dd6 100644 --- a/fastly/client.go +++ b/fastly/client.go @@ -287,7 +287,6 @@ func (c *Client) Request(verb, p string, ro *RequestOptions) (*http.Response, er if ro == nil || !ro.Parallel { c.updateLock.Lock() defer c.updateLock.Unlock() - } resp, err := checkResp(c.HTTPClient.Do(req)) if err != nil { @@ -405,6 +404,7 @@ func (c *Client) RequestFormFile(verb, urlPath string, filePath string, fieldNam return c.Request(verb, urlPath, ro) } +// RequestJSON constructs JSON HTTP request. func (c *Client) RequestJSON(verb, p string, i interface{}, ro *RequestOptions) (*http.Response, error) { if ro == nil { ro = new(RequestOptions) @@ -427,6 +427,7 @@ func (c *Client) RequestJSON(verb, p string, i interface{}, ro *RequestOptions) return c.Request(verb, p, ro) } +// RequestJSONAPI constructs JSON API HTTP request. func (c *Client) RequestJSONAPI(verb, p string, i interface{}, ro *RequestOptions) (*http.Response, error) { if ro == nil { ro = new(RequestOptions) @@ -450,6 +451,7 @@ func (c *Client) RequestJSONAPI(verb, p string, i interface{}, ro *RequestOption return c.Request(verb, p, ro) } +// RequestJSONAPIBulk constructs bulk JSON API HTTP request. func (c *Client) RequestJSONAPIBulk(verb, p string, i interface{}, ro *RequestOptions) (*http.Response, error) { if ro == nil { ro = new(RequestOptions) diff --git a/fastly/cloudfiles.go b/fastly/cloudfiles.go index e9b3b1280..8d30942ce 100644 --- a/fastly/cloudfiles.go +++ b/fastly/cloudfiles.go @@ -35,9 +35,17 @@ type Cloudfiles struct { // cloudfilesByName is a sortable list of Cloudfiles. type cloudfilesByName []*Cloudfiles -// Len, Swap, and Less implement the sortable interface. -func (c cloudfilesByName) Len() int { return len(c) } -func (c cloudfilesByName) Swap(i, j int) { c[i], c[j] = c[j], c[i] } +// Len implement the sortable interface. +func (c cloudfilesByName) Len() int { + return len(c) +} + +// Swap implement the sortable interface. +func (c cloudfilesByName) Swap(i, j int) { + c[i], c[j] = c[j], c[i] +} + +// Less implement the sortable interface. func (c cloudfilesByName) Less(i, j int) bool { return c[i].Name < c[j].Name } @@ -50,7 +58,7 @@ type ListCloudfilesInput struct { ServiceVersion int } -// ListCloudfiles returns the list of Cloudfiles for the configuration version. +// ListCloudfiles retrieves all resources. func (c *Client) ListCloudfiles(i *ListCloudfilesInput) ([]*Cloudfiles, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -77,29 +85,45 @@ func (c *Client) ListCloudfiles(i *ListCloudfilesInput) ([]*Cloudfiles, error) { // CreateCloudfilesInput is used as input to the CreateCloudfiles function. type CreateCloudfilesInput struct { - AccessKey string `url:"access_key,omitempty"` - BucketName string `url:"bucket_name,omitempty"` - CompressionCodec string `url:"compression_codec,omitempty"` - Format string `url:"format,omitempty"` - FormatVersion uint `url:"format_version,omitempty"` - GzipLevel uint8 `url:"gzip_level,omitempty"` - MessageType string `url:"message_type,omitempty"` - Name string `url:"name,omitempty"` - Path string `url:"path,omitempty"` - Period uint `url:"period,omitempty"` - Placement string `url:"placement,omitempty"` - PublicKey string `url:"public_key,omitempty"` - Region string `url:"region,omitempty"` + // AccessKey is your Cloud Files account access key. + AccessKey string `url:"access_key,omitempty"` + // BucketName is the name of your Cloud Files container. + BucketName string `url:"bucket_name,omitempty"` + // CompressionCodec is the codec used for compressing your logs (zstd, snappy, gzip). + CompressionCodec string `url:"compression_codec,omitempty"` + // Format is a Fastly log format string. + Format string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion uint `url:"format_version,omitempty"` + // GzipLevel is the level of gzip encoding when sending logs (default 0, no compression). + GzipLevel uint8 `url:"gzip_level,omitempty"` + // MessageType is how the message should be formatted (classic, loggly, logplex, blank). + MessageType string `url:"message_type,omitempty"` + // Name is the name for the real-time logging configuration. + Name string `url:"name,omitempty"` + // Path is the path to upload logs to. + Path string `url:"path,omitempty"` + // Period is how frequently log files are finalized so they can be available for reading (in seconds). + Period uint `url:"period,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement string `url:"placement,omitempty"` + // PublicKey is a PGP public key that Fastly will use to encrypt your log files before writing them to disk. + PublicKey string `url:"public_key,omitempty"` + // Region is the region to stream logs to. + Region string `url:"region,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). - ServiceVersion int + ServiceVersion int + // TimestampFormat is a timestamp format. TimestampFormat string `url:"timestamp_format,omitempty"` - User string `url:"user,omitempty"` + // User is the username for your Cloud Files account. + User string `url:"user,omitempty"` } -// CreateCloudfiles creates a new Fastly Cloudfiles. +// CreateCloudfiles creates a new resource. func (c *Client) CreateCloudfiles(i *CreateCloudfilesInput) (*Cloudfiles, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -133,7 +157,7 @@ type GetCloudfilesInput struct { ServiceVersion int } -// GetCloudfiles gets the Cloudfiles configuration with the given parameters. +// GetCloudfiles retrieves the specified resource. func (c *Client) GetCloudfiles(i *GetCloudfilesInput) (*Cloudfiles, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -163,31 +187,47 @@ func (c *Client) GetCloudfiles(i *GetCloudfilesInput) (*Cloudfiles, error) { // UpdateCloudfilesInput is used as input to the UpdateCloudfiles function. type UpdateCloudfilesInput struct { - AccessKey *string `url:"access_key,omitempty"` - BucketName *string `url:"bucket_name,omitempty"` + // AccessKey is your Cloud Files account access key. + AccessKey *string `url:"access_key,omitempty"` + // BucketName is the name of your Cloud Files container. + BucketName *string `url:"bucket_name,omitempty"` + // CompressionCodec is the codec used for compressing your logs (zstd, snappy, gzip). CompressionCodec *string `url:"compression_codec,omitempty"` - Format *string `url:"format,omitempty"` - FormatVersion *uint `url:"format_version,omitempty"` - GzipLevel *uint8 `url:"gzip_level,omitempty"` - MessageType *string `url:"message_type,omitempty"` + // Format is a Fastly log format string. + Format *string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion *uint `url:"format_version,omitempty"` + // GzipLevel is the level of gzip encoding when sending logs (default 0, no compression). + GzipLevel *uint8 `url:"gzip_level,omitempty"` + // MessageType is how the message should be formatted (classic, loggly, logplex, blank). + MessageType *string `url:"message_type,omitempty"` // Name is the name of the Cloudfiles to update. - Name string - NewName *string `url:"name,omitempty"` - Path *string `url:"path,omitempty"` - Period *uint `url:"period,omitempty"` - Placement *string `url:"placement,omitempty"` - PublicKey *string `url:"public_key,omitempty"` - Region *string `url:"region,omitempty"` + Name string + // NewName is the new name for the resource. + NewName *string `url:"name,omitempty"` + // Path is the path to upload logs to. + Path *string `url:"path,omitempty"` + // Period is how frequently log files are finalized so they can be available for reading (in seconds). + Period *uint `url:"period,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement *string `url:"placement,omitempty"` + // PublicKey is a PGP public key that Fastly will use to encrypt your log files before writing them to disk. + PublicKey *string `url:"public_key,omitempty"` + // Region is the region to stream logs to. + Region *string `url:"region,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition *string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). - ServiceVersion int + ServiceVersion int + // TimestampFormat is a timestamp format. TimestampFormat *string `url:"timestamp_format,omitempty"` - User *string `url:"user,omitempty"` + // User is the username for your Cloud Files account. + User *string `url:"user,omitempty"` } -// UpdateCloudfiles updates a specific Cloudfiles. +// UpdateCloudfiles updates the specified resource. func (c *Client) UpdateCloudfiles(i *UpdateCloudfilesInput) (*Cloudfiles, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -225,7 +265,7 @@ type DeleteCloudfilesInput struct { ServiceVersion int } -// DeleteCloudfiles deletes the given Cloudfiles version. +// DeleteCloudfiles deletes the specified resource. func (c *Client) DeleteCloudfiles(i *DeleteCloudfilesInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/cloudfiles_test.go b/fastly/cloudfiles_test.go index aaa233882..d5af4f3c1 100644 --- a/fastly/cloudfiles_test.go +++ b/fastly/cloudfiles_test.go @@ -117,25 +117,25 @@ func TestClient_Cloudfiles(t *testing.T) { // Ensure deleted defer func() { record(t, "cloudfiles/cleanup", func(c *Client) { - c.DeleteCloudfiles(&DeleteCloudfilesInput{ + _ = c.DeleteCloudfiles(&DeleteCloudfilesInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-cloudfiles", }) - c.DeleteCloudfiles(&DeleteCloudfilesInput{ + _ = c.DeleteCloudfiles(&DeleteCloudfilesInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-cloudfiles-2", }) - c.DeleteCloudfiles(&DeleteCloudfilesInput{ + _ = c.DeleteCloudfiles(&DeleteCloudfilesInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-cloudfiles-3", }) - c.DeleteCloudfiles(&DeleteCloudfilesInput{ + _ = c.DeleteCloudfiles(&DeleteCloudfilesInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "new-test-cloudfiles", diff --git a/fastly/condition.go b/fastly/condition.go index e6e7479ec..452198f5b 100644 --- a/fastly/condition.go +++ b/fastly/condition.go @@ -24,9 +24,17 @@ type Condition struct { // conditionsByName is a sortable list of conditions. type conditionsByName []*Condition -// Len, Swap, and Less implement the sortable interface. -func (s conditionsByName) Len() int { return len(s) } -func (s conditionsByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s conditionsByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s conditionsByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s conditionsByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -39,7 +47,7 @@ type ListConditionsInput struct { ServiceVersion int } -// ListConditions returns the list of conditions for the configuration version. +// ListConditions retrieves all resources. func (c *Client) ListConditions(i *ListConditionsInput) ([]*Condition, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -66,17 +74,21 @@ func (c *Client) ListConditions(i *ListConditionsInput) ([]*Condition, error) { // CreateConditionInput is used as input to the CreateCondition function. type CreateConditionInput struct { - Name string `url:"name,omitempty"` - Priority *int `url:"priority,omitempty"` + // Name is the name of the condition. + 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 // ServiceVersion is the specific configuration version (required). ServiceVersion int - Statement string `url:"statement,omitempty"` - Type string `url:"type,omitempty"` + // 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). + Type string `url:"type,omitempty"` } -// CreateCondition creates a new Fastly condition. +// CreateCondition creates a new resource. func (c *Client) CreateCondition(i *CreateConditionInput) (*Condition, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -110,7 +122,7 @@ type GetConditionInput struct { ServiceVersion int } -// GetCondition gets the condition configuration with the given parameters. +// GetCondition retrieves the specified resource. func (c *Client) GetCondition(i *GetConditionInput) (*Condition, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -140,19 +152,23 @@ func (c *Client) GetCondition(i *GetConditionInput) (*Condition, error) { // UpdateConditionInput is used as input to the UpdateCondition function. 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 string + // 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 // ServiceVersion is the specific configuration version (required). ServiceVersion int - Statement *string `url:"statement,omitempty"` - Type *string `url:"type,omitempty"` + // 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). + Type *string `url:"type,omitempty"` } -// UpdateCondition updates a specific condition. +// UpdateCondition updates the specified resource. func (c *Client) UpdateCondition(i *UpdateConditionInput) (*Condition, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -190,7 +206,7 @@ type DeleteConditionInput struct { ServiceVersion int } -// DeleteCondition deletes the given condition version. +// DeleteCondition deletes the specified resource. func (c *Client) DeleteCondition(i *DeleteConditionInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/condition_test.go b/fastly/condition_test.go index 4d41be9cb..2726b727c 100644 --- a/fastly/condition_test.go +++ b/fastly/condition_test.go @@ -32,7 +32,7 @@ func TestClient_Conditions(t *testing.T) { // // Ensure deleted defer func() { record(t, "conditions/cleanup", func(c *Client) { - c.DeleteCondition(&DeleteConditionInput{ + _ = c.DeleteCondition(&DeleteConditionInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test/condition", diff --git a/fastly/content.go b/fastly/content.go index 7731836c3..abf007e8b 100644 --- a/fastly/content.go +++ b/fastly/content.go @@ -26,6 +26,7 @@ type EdgeCheckResponse struct { // EdgeCheckInput is used as input to the EdgeCheck function. type EdgeCheckInput struct { + // URL is the full URL (host and path) to check on all nodes. if protocol is omitted, http will be assumed. URL string `url:"url,omitempty"` } diff --git a/fastly/custom_tls_activation.go b/fastly/custom_tls_activation.go index f4b9a947b..29da0955c 100644 --- a/fastly/custom_tls_activation.go +++ b/fastly/custom_tls_activation.go @@ -20,12 +20,18 @@ type TLSActivation struct { // ListTLSActivationsInput is used as input to the ListTLSActivations function. type ListTLSActivationsInput struct { - FilterTLSCertificateID string // Limit the returned activations to a specific certificate. - FilterTLSConfigurationID string // Limit the returned activations to a specific TLS configuration. - FilterTLSDomainID string // Limit the returned rules to a specific domain name. - Include string // Include related objects. Optional, comma-separated values. Permitted values: tls_certificate, tls_configuration, and tls_domain. - PageNumber int // The page index for pagination. - PageSize int // The number of activations per page. + // FilterTLSCertificateID limits the returned activations to a specific certificate. + FilterTLSCertificateID string + // FilterTLSConfigurationID limits the returned activations to a specific TLS configuration. + FilterTLSConfigurationID string + // FilterTLSDomainID limits the returned rules to a specific domain name. + FilterTLSDomainID string + // Include captures related objects. Optional, comma-separated values. Permitted values: tls_certificate, tls_configuration, and tls_domain. + Include string + // PageNumber is the page index for pagination. + PageNumber int + // PageSize is the number of activations per page. + PageSize int } // formatFilters converts user input into query parameters for filtering. @@ -56,7 +62,7 @@ func (i *ListTLSActivationsInput) formatFilters() map[string]string { return result } -// ListTLSActivations list all activations. +// ListTLSActivations retrieves all resources. func (c *Client) ListTLSActivations(i *ListTLSActivationsInput) ([]*TLSActivation, error) { p := "/tls/activations" filters := &RequestOptions{ @@ -90,11 +96,13 @@ func (c *Client) ListTLSActivations(i *ListTLSActivationsInput) ([]*TLSActivatio // GetTLSActivationInput is used as input to the GetTLSActivation function. type GetTLSActivationInput struct { - ID string - Include *string // Include related objects. Optional, comma-separated values. Permitted values: tls_certificate, tls_configuration, and tls_domain. + // ID is an alphanumeric string identifying a TLS activation. + ID string + // Include related objects. Optional, comma-separated values. Permitted values: tls_certificate, tls_configuration, and tls_domain. + Include *string } -// GetTLSActivation retrieve a single activation. +// GetTLSActivation retrieves the specified resource. func (c *Client) GetTLSActivation(i *GetTLSActivationInput) (*TLSActivation, error) { if i.ID == "" { return nil, ErrMissingID @@ -127,13 +135,17 @@ func (c *Client) GetTLSActivation(i *GetTLSActivationInput) (*TLSActivation, err // CreateTLSActivationInput is used as input to the CreateTLSActivation function. type CreateTLSActivationInput struct { - Certificate *CustomTLSCertificate `jsonapi:"relation,tls_certificate"` // Only ID of CustomTLSCertificate needs to be set. - Configuration *TLSConfiguration `jsonapi:"relation,tls_configuration,omitempty"` - Domain *TLSDomain `jsonapi:"relation,tls_domain"` - ID string `jsonapi:"primary,tls_activation"` // ID value does not need to be set. + // Certificate is an alphanumeric string identifying a TLS certificate. + Certificate *CustomTLSCertificate `jsonapi:"relation,tls_certificate"` // Only ID of CustomTLSCertificate needs to be set. + // Configuration is an alphanumeric string identifying a TLS configuration. + Configuration *TLSConfiguration `jsonapi:"relation,tls_configuration,omitempty"` + // Domain is the domain name. + Domain *TLSDomain `jsonapi:"relation,tls_domain"` + // ID is an aphanumeric string identifying a TLS activation. + ID string `jsonapi:"primary,tls_activation"` // ID value does not need to be set. } -// CreateTLSActivation enable TLS for a domain using a custom certificate. +// CreateTLSActivation creates a new resource. func (c *Client) CreateTLSActivation(i *CreateTLSActivationInput) (*TLSActivation, error) { if i.Certificate == nil { return nil, ErrMissingTLSCertificate @@ -159,11 +171,13 @@ func (c *Client) CreateTLSActivation(i *CreateTLSActivationInput) (*TLSActivatio // UpdateTLSActivationInput is used as input to the UpdateTLSActivation function. type UpdateTLSActivationInput struct { + // Certificate is an alphanumeric string identifying a TLS certificate. Certificate *CustomTLSCertificate `jsonapi:"relation,tls_certificate"` // Only ID of CustomTLSCertificate needs to be set. - ID string `jsonapi:"primary,tls_activation"` + // ID is an aphanumeric string identifying a TLS activation. + ID string `jsonapi:"primary,tls_activation"` } -// UpdateTLSActivation updates the certificate used to terminate TLS traffic for the domain associated with this TLS activation. +// UpdateTLSActivation updates the specified resource. func (c *Client) UpdateTLSActivation(i *UpdateTLSActivationInput) (*TLSActivation, error) { if i.ID == "" { return nil, ErrMissingID @@ -188,10 +202,11 @@ func (c *Client) UpdateTLSActivation(i *UpdateTLSActivationInput) (*TLSActivatio // DeleteTLSActivationInput used for deleting a certificate. type DeleteTLSActivationInput struct { + // ID is an alphanumeric string identifying a TLS activation. ID string } -// DeleteTLSActivation destroy a certificate. +// DeleteTLSActivation deletes the specified resource. func (c *Client) DeleteTLSActivation(i *DeleteTLSActivationInput) error { if i.ID == "" { return ErrMissingID diff --git a/fastly/custom_tls_activation_test.go b/fastly/custom_tls_activation_test.go index f714ed4c6..51a27b914 100644 --- a/fastly/custom_tls_activation_test.go +++ b/fastly/custom_tls_activation_test.go @@ -26,7 +26,7 @@ func TestClient_TLSActivation(t *testing.T) { // Ensure deleted defer func() { record(t, fixtureBase+"cleanup", func(c *Client) { - c.DeleteTLSActivation(&DeleteTLSActivationInput{ + _ = c.DeleteTLSActivation(&DeleteTLSActivationInput{ ID: ta.ID, }) }) diff --git a/fastly/custom_tls_certificate.go b/fastly/custom_tls_certificate.go index e1c02edaa..0a74b9af1 100644 --- a/fastly/custom_tls_certificate.go +++ b/fastly/custom_tls_certificate.go @@ -27,12 +27,18 @@ type CustomTLSCertificate struct { // ListCustomTLSCertificatesInput is used as input to the Client.ListCustomTLSCertificates function. type ListCustomTLSCertificatesInput struct { - FilterNotAfter string // Limit the returned certificates to those that expire prior to the specified date in UTC. Accepts parameters: lte (e.g., filter[not_after][lte]=2020-05-05). - FilterTLSDomainsID string // Limit the returned certificates to those that include the specific domain. - Include string // Include related objects. Optional, comma-separated values. Permitted values: tls_activations. - PageNumber int // The page index for pagination. - PageSize int // The number of keys per page. - Sort string // The order in which to list certificates. Valid values are created_at, not_before, not_after. May precede any value with a - for descending. + // FilterNotAfter limits the returned certificates to those that expire prior to the specified date in UTC. Accepts parameters: lte (e.g., filter[not_after][lte]=2020-05-05). + FilterNotAfter string + // FilterTLSDomainsID limits the returned certificates to those that include the specific domain. + FilterTLSDomainsID string + // Include captures related objects. Optional, comma-separated values. Permitted values: tls_activations. + Include string + // PageNumber is the page index for pagination. + PageNumber int + // PageSize is the number of keys per page. + PageSize int + // Sort is the order in which to list certificates. Valid values are created_at, not_before, not_after. May precede any value with a - for descending. + Sort string } // formatFilters converts user input into query parameters for filtering. @@ -63,7 +69,7 @@ func (i *ListCustomTLSCertificatesInput) formatFilters() map[string]string { return result } -// ListCustomTLSCertificates list all certificates. +// ListCustomTLSCertificates retrieves all resources. func (c *Client) ListCustomTLSCertificates(i *ListCustomTLSCertificatesInput) ([]*CustomTLSCertificate, error) { p := "/tls/certificates" filters := &RequestOptions{ @@ -97,9 +103,11 @@ func (c *Client) ListCustomTLSCertificates(i *ListCustomTLSCertificatesInput) ([ // GetCustomTLSCertificateInput is used as input to the GetCustomTLSCertificate function. type GetCustomTLSCertificateInput struct { + // ID is an alphanumeric string identifying a TLS certificate. ID string } +// GetCustomTLSCertificate retrieves the specified resource. func (c *Client) GetCustomTLSCertificate(i *GetCustomTLSCertificateInput) (*CustomTLSCertificate, error) { if i.ID == "" { return nil, ErrMissingID @@ -122,12 +130,15 @@ func (c *Client) GetCustomTLSCertificate(i *GetCustomTLSCertificateInput) (*Cust // CreateCustomTLSCertificateInput is used as input to the CreateCustomTLSCertificate function. type CreateCustomTLSCertificateInput struct { + // CertBlob is the PEM-formatted certificate blob. CertBlob string `jsonapi:"attr,cert_blob"` - ID string `jsonapi:"primary,tls_certificate"` // ID value does not need to be set. - Name string `jsonapi:"attr,name,omitempty"` + // ID is an alphanumeric string identifying a TLS certificate. + ID string `jsonapi:"primary,tls_certificate"` // ID value does not need to be set. + // Name is a customizable name for your certificate. + Name string `jsonapi:"attr,name,omitempty"` } -// CreateCustomTLSCertificate creates a custom TLS certificate. +// CreateCustomTLSCertificate creates a new resource. func (c *Client) CreateCustomTLSCertificate(i *CreateCustomTLSCertificateInput) (*CustomTLSCertificate, error) { if i.CertBlob == "" { return nil, ErrMissingCertBlob @@ -150,12 +161,16 @@ func (c *Client) CreateCustomTLSCertificate(i *CreateCustomTLSCertificateInput) // UpdateCustomTLSCertificateInput is used as input to the UpdateCustomTLSCertificate function. type UpdateCustomTLSCertificateInput struct { - ID string `jsonapi:"primary,tls_certificate"` + // CertBlob is the PEM-formatted certificate blob. CertBlob string `jsonapi:"attr,cert_blob"` - Name string `jsonapi:"attr,name,omitempty"` + // ID is an alphanumeric string identifying a TLS certificate. + ID string `jsonapi:"primary,tls_certificate"` + // Name is a customizable name for your certificate. + Name string `jsonapi:"attr,name,omitempty"` } -// UpdateCustomTLSCertificate replace a certificate with a newly reissued certificate. +// UpdateCustomTLSCertificate updates the specified resource. +// // By using this endpoint, the original certificate will cease to be used for future TLS handshakes. // Thus, only SAN entries that appear in the replacement certificate will become TLS enabled. // Any SAN entries that are missing in the replacement certificate will become disabled. @@ -184,10 +199,11 @@ func (c *Client) UpdateCustomTLSCertificate(i *UpdateCustomTLSCertificateInput) // DeleteCustomTLSCertificateInput used for deleting a certificate. type DeleteCustomTLSCertificateInput struct { + // ID is an alphanumeric string identifying a TLS certificate. ID string } -// DeleteCustomTLSCertificate destroy a certificate. This disables TLS for all domains listed as SAN entries. +// DeleteCustomTLSCertificate deletes the specified resource. func (c *Client) DeleteCustomTLSCertificate(i *DeleteCustomTLSCertificateInput) error { if i.ID == "" { return ErrMissingID diff --git a/fastly/custom_tls_certificate_test.go b/fastly/custom_tls_certificate_test.go index 305981483..94b4b43e2 100644 --- a/fastly/custom_tls_certificate_test.go +++ b/fastly/custom_tls_certificate_test.go @@ -46,10 +46,10 @@ func TestClient_CustomTLSCertificate(t *testing.T) { // Ensure deleted defer func() { - testClient.DeleteCustomTLSCertificate(&DeleteCustomTLSCertificateInput{ + _ = testClient.DeleteCustomTLSCertificate(&DeleteCustomTLSCertificateInput{ ID: cc.ID, }) - testClient.DeletePrivateKey(&DeletePrivateKeyInput{ + _ = testClient.DeletePrivateKey(&DeletePrivateKeyInput{ ID: pk.ID, }) }() diff --git a/fastly/custom_tls_configuration.go b/fastly/custom_tls_configuration.go index 170691b55..60cb4ff9b 100644 --- a/fastly/custom_tls_configuration.go +++ b/fastly/custom_tls_configuration.go @@ -31,10 +31,14 @@ type DNSRecord struct { // ListCustomTLSConfigurationsInput is used as input to the ListCustomTLSConfigurationsInput function. type ListCustomTLSConfigurationsInput struct { - FilterBulk bool // Whether or not to only include bulk=true configurations - Include string // Include related objects. Optional, comma-separated values. Permitted values: dns_records. - PageNumber int // The page index for pagination. - PageSize int // The number of keys per page. + // FilterBulk is whether or not to only include bulk=true configurations + FilterBulk bool + // Include captures related objects. Optional, comma-separated values. Permitted values: dns_records. + Include string + // PageNumber is the page index for pagination. + PageNumber int + // PageSize is the number of keys per page. + PageSize int } // formatFilters converts user input into query parameters for filtering. @@ -63,7 +67,7 @@ func (i *ListCustomTLSConfigurationsInput) formatFilters() map[string]string { return result } -// ListCustomTLSConfigurations list all TLS configurations. +// ListCustomTLSConfigurations retrieves all resources. func (c *Client) ListCustomTLSConfigurations(i *ListCustomTLSConfigurationsInput) ([]*CustomTLSConfiguration, error) { p := "/tls/configurations" ro := &RequestOptions{ @@ -97,11 +101,13 @@ func (c *Client) ListCustomTLSConfigurations(i *ListCustomTLSConfigurationsInput // GetCustomTLSConfigurationInput is used as input to the GetCustomTLSConfiguration function. type GetCustomTLSConfigurationInput struct { - ID string - Include string // Include related objects. Optional, comma-separated values. Permitted values: dns_records. + // ID is an alphanumeric string identifying a TLS configuration. + ID string + // Include captures related objects. Optional, comma-separated values. Permitted values: dns_records. + Include string } -// GetCustomTLSConfiguration returns a single TLS configuration. +// GetCustomTLSConfiguration retrieves the specified resource. func (c *Client) GetCustomTLSConfiguration(i *GetCustomTLSConfigurationInput) (*CustomTLSConfiguration, error) { if i.ID == "" { return nil, ErrMissingID @@ -134,11 +140,13 @@ func (c *Client) GetCustomTLSConfiguration(i *GetCustomTLSConfigurationInput) (* // UpdateCustomTLSConfigurationInput is used as input to the UpdateCustomTLSConfiguration function. type UpdateCustomTLSConfigurationInput struct { - ID string + // ID is an alphanumeric string identifying a TLS configuration. + ID string + // Name is a custom name for your TLS configuration. Name string `jsonapi:"attr,name"` } -// UpdateCustomTLSConfiguration can only be used to change the name of the configuration +// UpdateCustomTLSConfiguration updates the specified resource. func (c *Client) UpdateCustomTLSConfiguration(i *UpdateCustomTLSConfigurationInput) (*CustomTLSConfiguration, error) { if i.ID == "" { return nil, ErrMissingID diff --git a/fastly/custom_tls_configuration_test.go b/fastly/custom_tls_configuration_test.go index a307fe922..024c7b317 100644 --- a/fastly/custom_tls_configuration_test.go +++ b/fastly/custom_tls_configuration_test.go @@ -56,7 +56,6 @@ func TestClient_CustomTLSConfiguration(t *testing.T) { if ucon.Name != newName { t.Errorf("bad Name: %q (%q)", newName, ucon.Name) } - } func TestClient_ListCustomTLSConfigurations_validation(t *testing.T) { diff --git a/fastly/custom_tls_domain.go b/fastly/custom_tls_domain.go index 2efc05149..bdaa52a47 100644 --- a/fastly/custom_tls_domain.go +++ b/fastly/custom_tls_domain.go @@ -10,19 +10,19 @@ import ( // ListTLSDomainsInput is used as input to Client.ListTLSDomains. type ListTLSDomainsInput struct { - // Limit the returned domains to those currently using Fastly to terminate TLS with SNI (that is, domains considered "in use") + // FilterInUse limits the returned domains to those currently using Fastly to terminate TLS with SNI (that is, domains considered "in use") FilterInUse *bool - // Limit the returned domains to those listed in the given TLS certificate's SAN list + // FilterTLSCertificateID Limits the returned domains to those listed in the given TLS certificate's SAN list FilterTLSCertificateID string - // Limit the returned domains to those for a given TLS subscription + // FilterTLSSubscriptionID limits the returned domains to those for a given TLS subscription FilterTLSSubscriptionID string - // Include related objects + // Include captures related objects Include string - // Current page + // PageNumber is the current page. PageNumber int - // Number of records per page + // PageSize is the number of records per page PageSize int - // The order in which to list the results by creation date + // Sort is the order in which to list the results by creation date Sort string } @@ -59,7 +59,7 @@ func (l *ListTLSDomainsInput) formatFilters() map[string]string { return result } -// ListTLSDomains retrieves a page of TLS domains. +// ListTLSDomains retrieves all resources. func (c *Client) ListTLSDomains(i *ListTLSDomainsInput) ([]*TLSDomain, error) { p := "/tls/domains" filters := &RequestOptions{ diff --git a/fastly/custom_tls_domain_test.go b/fastly/custom_tls_domain_test.go index 280e1bd79..e2e7e1b8c 100644 --- a/fastly/custom_tls_domain_test.go +++ b/fastly/custom_tls_domain_test.go @@ -24,7 +24,6 @@ func TestClient_ListTLSDomains(t *testing.T) { if len(ldom) < 1 { t.Errorf("bad tls domains: %v", ldom) } - } func TestClient_ListTLSDomainsFilterCertificates(t *testing.T) { @@ -47,5 +46,4 @@ func TestClient_ListTLSDomainsFilterCertificates(t *testing.T) { if len(ldom) != 1 { t.Errorf("bad tls domains: %v", ldom) } - } diff --git a/fastly/datadog.go b/fastly/datadog.go index d87b90e00..e5c85ec7c 100644 --- a/fastly/datadog.go +++ b/fastly/datadog.go @@ -26,9 +26,17 @@ type Datadog struct { // datadogByName is a sortable list of Datadog. type datadogByName []*Datadog -// Len, Swap, and Less implement the sortable interface. -func (s datadogByName) Len() int { return len(s) } -func (s datadogByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s datadogByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s datadogByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s datadogByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -42,7 +50,7 @@ type ListDatadogInput struct { ServiceVersion int } -// ListDatadog returns the list of Datadog for the configuration version. +// ListDatadog retrieves all resources. func (c *Client) ListDatadog(i *ListDatadogInput) ([]*Datadog, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -69,20 +77,27 @@ func (c *Client) ListDatadog(i *ListDatadogInput) ([]*Datadog, error) { // CreateDatadogInput is used as input to the CreateDatadog function. type CreateDatadogInput struct { - Format string `url:"format,omitempty"` - FormatVersion uint `url:"format_version,omitempty"` - Name string `url:"name,omitempty"` - Placement string `url:"placement,omitempty"` - Region string `url:"region,omitempty"` + // Format is a Fastly log format string. Must produce valid JSON that Datadog can ingest. + Format string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion uint `url:"format_version,omitempty"` + // Name is the name for the real-time logging configuration. + Name string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement string `url:"placement,omitempty"` + // Region is the region that log data will be sent to. + Region string `url:"region,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - Token string `url:"token,omitempty"` + // Token is the API key from your Datadog account. + Token string `url:"token,omitempty"` } -// CreateDatadog creates a new Datadog logging endpoint on a Fastly service version. +// CreateDatadog creates a new resource. func (c *Client) CreateDatadog(i *CreateDatadogInput) (*Datadog, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -120,7 +135,7 @@ type GetDatadogInput struct { ServiceVersion int } -// GetDatadog gets the Datadog configuration with the given parameters. +// GetDatadog retrieves the specified resource. func (c *Client) GetDatadog(i *GetDatadogInput) (*Datadog, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -150,22 +165,29 @@ func (c *Client) GetDatadog(i *GetDatadogInput) (*Datadog, error) { // UpdateDatadogInput is used as input to the UpdateDatadog function. type UpdateDatadogInput struct { - Format *string `url:"format,omitempty"` - FormatVersion *uint `url:"format_version,omitempty"` + // Format is a Fastly log format string. Must produce valid JSON that Datadog can ingest. + Format *string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion *uint `url:"format_version,omitempty"` // Name is the name of the Datadog to update. - Name string - NewName *string `url:"name,omitempty"` - Placement *string `url:"placement,omitempty"` - Region *string `url:"region,omitempty"` + Name string + // NewName is the new name for the resource. + NewName *string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement *string `url:"placement,omitempty"` + // Region is the region that log data will be sent to. + Region *string `url:"region,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition *string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - Token *string `url:"token,omitempty"` + // Token is the API key from your Datadog account. + Token *string `url:"token,omitempty"` } -// UpdateDatadog updates a Datadog logging endpoint on a Fastly service version. +// UpdateDatadog updates the specified resource. func (c *Client) UpdateDatadog(i *UpdateDatadogInput) (*Datadog, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -207,7 +229,7 @@ type DeleteDatadogInput struct { ServiceVersion int } -// DeleteDatadog deletes a Datadog logging endpoint on a Fastly service version. +// DeleteDatadog deletes the specified resource. func (c *Client) DeleteDatadog(i *DeleteDatadogInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/dictionary.go b/fastly/dictionary.go index 0fea50268..bc5bc9685 100644 --- a/fastly/dictionary.go +++ b/fastly/dictionary.go @@ -22,9 +22,17 @@ type Dictionary struct { // dictionariesByName is a sortable list of dictionaries. type dictionariesByName []*Dictionary -// Len, Swap, and Less implement the sortable interface. -func (s dictionariesByName) Len() int { return len(s) } -func (s dictionariesByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s dictionariesByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s dictionariesByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s dictionariesByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -37,7 +45,7 @@ type ListDictionariesInput struct { ServiceVersion int } -// ListDictionaries returns the list of dictionaries for the configuration version. +// ListDictionaries retrieves all resources. func (c *Client) ListDictionaries(i *ListDictionariesInput) ([]*Dictionary, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -64,15 +72,17 @@ func (c *Client) ListDictionaries(i *ListDictionariesInput) ([]*Dictionary, erro // CreateDictionaryInput is used as input to the CreateDictionary function. type CreateDictionaryInput struct { + // Name is the name of the dictionary to create. Name string `url:"name,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - WriteOnly Compatibool `url:"write_only,omitempty"` + // WriteOnly determines if items in the dictionary are readable or not. + WriteOnly Compatibool `url:"write_only,omitempty"` } -// CreateDictionary creates a new Fastly dictionary. +// CreateDictionary creates a new resource. func (c *Client) CreateDictionary(i *CreateDictionaryInput) (*Dictionary, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -106,7 +116,7 @@ type GetDictionaryInput struct { ServiceVersion int } -// GetDictionary gets the dictionary configuration with the given parameters. +// GetDictionary retrieves the specified resource. func (c *Client) GetDictionary(i *GetDictionaryInput) (*Dictionary, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -137,16 +147,18 @@ func (c *Client) GetDictionary(i *GetDictionaryInput) (*Dictionary, error) { // UpdateDictionaryInput is used as input to the UpdateDictionary function. type UpdateDictionaryInput struct { // Name is the name of the dictionary to update. - Name string + Name string + // NewName is the new name for the resource. NewName *string `url:"name,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - WriteOnly *Compatibool `url:"write_only,omitempty"` + // WriteOnly determines if items in the dictionary are readable or not. + WriteOnly *Compatibool `url:"write_only,omitempty"` } -// UpdateDictionary updates a specific dictionary. +// UpdateDictionary updates the specified resource. func (c *Client) UpdateDictionary(i *UpdateDictionaryInput) (*Dictionary, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -184,7 +196,7 @@ type DeleteDictionaryInput struct { ServiceVersion int } -// DeleteDictionary deletes the given dictionary version. +// DeleteDictionary deletes the specified resource. func (c *Client) DeleteDictionary(i *DeleteDictionaryInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/dictionary_info.go b/fastly/dictionary_info.go index e05265525..3fbcaa6b7 100644 --- a/fastly/dictionary_info.go +++ b/fastly/dictionary_info.go @@ -25,7 +25,7 @@ type GetDictionaryInfoInput struct { ServiceVersion int } -// GetDictionaryInfo gets the dictionary metadata with the given parameters. +// GetDictionaryInfo retrieves the specified resource. func (c *Client) GetDictionaryInfo(i *GetDictionaryInfoInput) (*DictionaryInfo, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID diff --git a/fastly/dictionary_info_test.go b/fastly/dictionary_info_test.go index 77b54539a..149155714 100644 --- a/fastly/dictionary_info_test.go +++ b/fastly/dictionary_info_test.go @@ -5,7 +5,6 @@ import ( ) func TestClient_GetDictionaryInfo(t *testing.T) { - fixtureBase := "dictionary_info/" nameSuffix := "DictionaryInfo" diff --git a/fastly/dictionary_item.go b/fastly/dictionary_item.go index 24c54e62a..b4f737f35 100644 --- a/fastly/dictionary_item.go +++ b/fastly/dictionary_item.go @@ -24,9 +24,17 @@ type DictionaryItem struct { // dictionaryItemsByKey is a sortable list of dictionary items. type dictionaryItemsByKey []*DictionaryItem -// Len, Swap, and Less implement the sortable interface. -func (s dictionaryItemsByKey) Len() int { return len(s) } -func (s dictionaryItemsByKey) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s dictionaryItemsByKey) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s dictionaryItemsByKey) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s dictionaryItemsByKey) Less(i, j int) bool { return s[i].ItemKey < s[j].ItemKey } @@ -35,15 +43,19 @@ func (s dictionaryItemsByKey) Less(i, j int) bool { type ListDictionaryItemsInput struct { // DictionaryID is the ID of the dictionary to retrieve items for (required). DictionaryID string - Direction string - Page int - PerPage int + // Direction is the direction in which to sort results. + Direction string + // Page is the current page. + Page int + // PerPage is the number of records per page. + PerPage int // ServiceID is the ID of the service (required). ServiceID string - Sort string + // Sort is the field on which to sort. + Sort string } -// ListDictionaryItems returns a list of items for a dictionary +// ListDictionaryItems retrieves all resources. func (c *Client) ListDictionaryItems(i *ListDictionaryItemsInput) ([]*DictionaryItem, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -68,6 +80,7 @@ func (c *Client) ListDictionaryItems(i *ListDictionaryItemsInput) ([]*Dictionary return bs, nil } +// ListDictionaryItemsPaginator implements the PaginatorDictionaryItems interface. type ListDictionaryItemsPaginator struct { CurrentPage int LastPage int @@ -184,7 +197,9 @@ func (c *Client) listDictionaryItemsWithPage(i *ListDictionaryItemsInput, p *Lis // CreateDictionaryItemInput is used as input to the CreateDictionaryItem function. type CreateDictionaryItemInput struct { - ItemKey string `url:"item_key,omitempty"` + // ItemKey is the dictionary item key, maximum 256 characters. + ItemKey string `url:"item_key,omitempty"` + // ItemValue is the dictionary item value, maximum 8000 characters. ItemValue string `url:"item_value,omitempty"` // ServiceID is the ID of the service (required). ServiceID string @@ -192,7 +207,7 @@ type CreateDictionaryItemInput struct { DictionaryID string } -// CreateDictionaryItem creates a new Fastly dictionary item. +// CreateDictionaryItem creates a new resource. func (c *Client) CreateDictionaryItem(i *CreateDictionaryItemInput) (*DictionaryItem, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -216,7 +231,7 @@ func (c *Client) CreateDictionaryItem(i *CreateDictionaryItemInput) (*Dictionary return b, nil } -// CreateDictionaryItems creates new Fastly dictionary items from a slice. +// CreateDictionaryItems creates a new resource. func (c *Client) CreateDictionaryItems(i []CreateDictionaryItemInput) ([]DictionaryItem, error) { var b []DictionaryItem for _, cdii := range i { @@ -239,7 +254,7 @@ type GetDictionaryItemInput struct { ServiceID string } -// GetDictionaryItem gets the dictionary item with the given parameters. +// GetDictionaryItem retrieves the specified resource. func (c *Client) GetDictionaryItem(i *GetDictionaryItemInput) (*DictionaryItem, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -279,7 +294,7 @@ type UpdateDictionaryItemInput struct { ServiceID string } -// UpdateDictionaryItem updates a specific dictionary item. +// UpdateDictionaryItem updates the specified resource. func (c *Client) UpdateDictionaryItem(i *UpdateDictionaryItemInput) (*DictionaryItem, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -307,20 +322,28 @@ func (c *Client) UpdateDictionaryItem(i *UpdateDictionaryItemInput) (*Dictionary return b, nil } +// BatchModifyDictionaryItemsInput is the input parameter to the +// BatchModifyDictionaryItems function. type BatchModifyDictionaryItemsInput struct { // DictionaryID is the ID of the dictionary to modify items for (required). - DictionaryID string `json:"-"` - Items []*BatchDictionaryItem `json:"items"` + DictionaryID string `json:"-"` + // Items is a list of dictionary items. + Items []*BatchDictionaryItem `json:"items"` // ServiceID is the ID of the service (required). ServiceID string `json:"-"` } +// BatchDictionaryItem represents a dictionary item. type BatchDictionaryItem struct { - ItemKey string `json:"item_key"` - ItemValue string `json:"item_value"` + // ItemKey is an item key (maximum 256 characters). + ItemKey string `json:"item_key"` + // ItemValue is an item value (maximum 8000 characters). + ItemValue string `json:"item_value"` + // Operation is a batching operation variant. Operation BatchOperation `json:"op"` } +// BatchModifyDictionaryItems bulk updates dictionary items. func (c *Client) BatchModifyDictionaryItems(i *BatchModifyDictionaryItemsInput) error { if i.ServiceID == "" { return ErrMissingServiceID @@ -342,11 +365,7 @@ func (c *Client) BatchModifyDictionaryItems(i *BatchModifyDictionaryItemsInput) defer resp.Body.Close() var batchModifyResult map[string]string - if err := decodeBodyMap(resp.Body, &batchModifyResult); err != nil { - return err - } - - return nil + return decodeBodyMap(resp.Body, &batchModifyResult) } // DeleteDictionaryItemInput is the input parameter to DeleteDictionaryItem. @@ -359,7 +378,7 @@ type DeleteDictionaryItemInput struct { ServiceID string } -// DeleteDictionaryItem deletes the given dictionary item. +// DeleteDictionaryItem deletes the specified resource. func (c *Client) DeleteDictionaryItem(i *DeleteDictionaryItemInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/dictionary_item_batch_test.go b/fastly/dictionary_item_batch_test.go index 2b01990f8..751d17c6d 100644 --- a/fastly/dictionary_item_batch_test.go +++ b/fastly/dictionary_item_batch_test.go @@ -5,7 +5,6 @@ import ( ) func TestClient_BatchModifyDictionaryItems_Create(t *testing.T) { - fixtureBase := "dictionary_items_batch/create/" nameSuffix := "BatchModifyDictionaryItems_Create" @@ -38,7 +37,6 @@ func TestClient_BatchModifyDictionaryItems_Create(t *testing.T) { // When: I execute the batch create operations against the Fastly API, var err error record(t, fixtureBase+"create_dictionary_items", func(c *Client) { - err = c.BatchModifyDictionaryItems(batchCreateOperations) }) if err != nil { @@ -64,7 +62,6 @@ func TestClient_BatchModifyDictionaryItems_Create(t *testing.T) { } for i, item := range actualDictionaryItems { - actualItemKey := item.ItemKey expectedItemKey := batchCreateOperations.Items[i].ItemKey if actualItemKey != expectedItemKey { @@ -76,13 +73,10 @@ func TestClient_BatchModifyDictionaryItems_Create(t *testing.T) { if actualItemValue != expectedItemValue { t.Errorf("First ItemValue did not match, expected %s, got %s", expectedItemValue, actualItemValue) } - } - } func TestClient_BatchModifyDictionaryItems_Delete(t *testing.T) { - fixtureBase := "dictionary_items_batch/delete/" nameSuffix := "BatchModifyDictionaryItems_Delete" @@ -114,7 +108,6 @@ func TestClient_BatchModifyDictionaryItems_Delete(t *testing.T) { var err error record(t, fixtureBase+"create_dictionary_items", func(c *Client) { - err = c.BatchModifyDictionaryItems(batchCreateOperations) }) if err != nil { @@ -135,7 +128,6 @@ func TestClient_BatchModifyDictionaryItems_Delete(t *testing.T) { } record(t, fixtureBase+"delete_dictionary_items", func(c *Client) { - err = c.BatchModifyDictionaryItems(batchDeleteOperations) }) if err != nil { @@ -162,7 +154,6 @@ func TestClient_BatchModifyDictionaryItems_Delete(t *testing.T) { } func TestClient_BatchModifyDictionaryItems_Update(t *testing.T) { - fixtureBase := "dictionary_items_batch/update/" nameSuffix := "BatchModifyDictionaryItems_Update" @@ -194,7 +185,6 @@ func TestClient_BatchModifyDictionaryItems_Update(t *testing.T) { var err error record(t, fixtureBase+"create_dictionary_items", func(c *Client) { - err = c.BatchModifyDictionaryItems(batchCreateOperations) }) if err != nil { @@ -215,7 +205,6 @@ func TestClient_BatchModifyDictionaryItems_Update(t *testing.T) { } record(t, fixtureBase+"update_dictionary_items", func(c *Client) { - err = c.BatchModifyDictionaryItems(batchUpdateOperations) }) if err != nil { @@ -268,11 +257,9 @@ func TestClient_BatchModifyDictionaryItems_Update(t *testing.T) { if actualItemValue != expectedItemValue { t.Errorf("Second ItemValue did not match, expected %s, got %s", expectedItemValue, actualItemValue) } - } func TestClient_BatchModifyDictionaryItems_Upsert(t *testing.T) { - fixtureBase := "dictionary_items_batch/upsert/" nameSuffix := "BatchModifyDictionaryItems_Upsert" @@ -299,7 +286,6 @@ func TestClient_BatchModifyDictionaryItems_Upsert(t *testing.T) { var err error record(t, fixtureBase+"create_dictionary_items", func(c *Client) { - err = c.BatchModifyDictionaryItems(batchCreateOperations) }) if err != nil { @@ -325,7 +311,6 @@ func TestClient_BatchModifyDictionaryItems_Upsert(t *testing.T) { } record(t, fixtureBase+"upsert_dictionary_items", func(c *Client) { - err = c.BatchModifyDictionaryItems(batchUpsertOperations) }) if err != nil { @@ -351,7 +336,6 @@ func TestClient_BatchModifyDictionaryItems_Upsert(t *testing.T) { } for i, item := range actualDictionaryItems { - actualItemKey := item.ItemKey expectedItemKey := batchUpsertOperations.Items[i].ItemKey if actualItemKey != expectedItemKey { @@ -363,7 +347,5 @@ func TestClient_BatchModifyDictionaryItems_Upsert(t *testing.T) { if actualItemValue != expectedItemValue { t.Errorf("First ItemValue did not match, expected %s, got %s", expectedItemValue, actualItemValue) } - } - } diff --git a/fastly/dictionary_item_test.go b/fastly/dictionary_item_test.go index 6e39516c9..26b4ff8c8 100644 --- a/fastly/dictionary_item_test.go +++ b/fastly/dictionary_item_test.go @@ -5,7 +5,6 @@ import ( ) func TestClient_DictionaryItems(t *testing.T) { - fixtureBase := "dictionary_items/" nameSuffix := "DictionaryItems" @@ -35,7 +34,7 @@ func TestClient_DictionaryItems(t *testing.T) { // Ensure deleted defer func() { record(t, fixtureBase+"cleanup", func(c *Client) { - c.DeleteDictionaryItem(&DeleteDictionaryItemInput{ + _ = c.DeleteDictionaryItem(&DeleteDictionaryItemInput{ ServiceID: testService.ID, DictionaryID: testDictionary.ID, ItemKey: "test-dictionary-item", diff --git a/fastly/dictionary_test.go b/fastly/dictionary_test.go index f4d7edf8e..cd2d3dd00 100644 --- a/fastly/dictionary_test.go +++ b/fastly/dictionary_test.go @@ -28,13 +28,13 @@ func TestClient_Dictionaries(t *testing.T) { // Ensure deleted defer func() { record(t, fixtureBase+"cleanup", func(c *Client) { - c.DeleteDictionary(&DeleteDictionaryInput{ + _ = c.DeleteDictionary(&DeleteDictionaryInput{ ServiceID: testServiceID, ServiceVersion: testVersion.Number, Name: "test_dictionary", }) - c.DeleteDictionary(&DeleteDictionaryInput{ + _ = c.DeleteDictionary(&DeleteDictionaryInput{ ServiceID: testServiceID, ServiceVersion: testVersion.Number, Name: "new_test_dictionary", diff --git a/fastly/diff.go b/fastly/diff.go index f36c745b1..c9df4aca8 100644 --- a/fastly/diff.go +++ b/fastly/diff.go @@ -26,7 +26,7 @@ type GetDiffInput struct { To int } -// GetDiff returns the diff of the given versions. +// GetDiff retrieves the specified resource. func (c *Client) GetDiff(i *GetDiffInput) (*Diff, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID diff --git a/fastly/diff_test.go b/fastly/diff_test.go index a2efcf97b..d4f482243 100644 --- a/fastly/diff_test.go +++ b/fastly/diff_test.go @@ -47,7 +47,7 @@ func TestClient_Diff(t *testing.T) { // Ensure we delete the backend we just created defer func() { record(t, "diff/cleanup", func(c *Client) { - c.DeleteBackend(&DeleteBackendInput{ + _ = c.DeleteBackend(&DeleteBackendInput{ ServiceID: testServiceID, ServiceVersion: tv2.Number, Name: "test-backend", diff --git a/fastly/digitalocean.go b/fastly/digitalocean.go index f538ded11..ad0e32dd2 100644 --- a/fastly/digitalocean.go +++ b/fastly/digitalocean.go @@ -35,9 +35,17 @@ type DigitalOcean struct { // digitaloceansByName is a sortable list of DigitalOceans. type digitaloceansByName []*DigitalOcean -// Len, Swap, and Less implement the sortable interface. -func (d digitaloceansByName) Len() int { return len(d) } -func (d digitaloceansByName) Swap(i, j int) { d[i], d[j] = d[j], d[i] } +// Len implement the sortable interface. +func (d digitaloceansByName) Len() int { + return len(d) +} + +// Swap implement the sortable interface. +func (d digitaloceansByName) Swap(i, j int) { + d[i], d[j] = d[j], d[i] +} + +// Less implement the sortable interface. func (d digitaloceansByName) Less(i, j int) bool { return d[i].Name < d[j].Name } @@ -50,7 +58,7 @@ type ListDigitalOceansInput struct { ServiceVersion int } -// ListDigitalOceans returns the list of DigitalOceans for the configuration version. +// ListDigitalOceans retrieves all resources. func (c *Client) ListDigitalOceans(i *ListDigitalOceansInput) ([]*DigitalOcean, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -77,29 +85,45 @@ func (c *Client) ListDigitalOceans(i *ListDigitalOceansInput) ([]*DigitalOcean, // CreateDigitalOceanInput is used as input to the CreateDigitalOcean function. type CreateDigitalOceanInput struct { - AccessKey string `url:"access_key,omitempty"` - BucketName string `url:"bucket_name,omitempty"` - CompressionCodec string `url:"compression_codec,omitempty"` - Domain string `url:"domain,omitempty"` - Format string `url:"format,omitempty"` - FormatVersion uint `url:"format_version,omitempty"` - GzipLevel uint8 `url:"gzip_level,omitempty"` - MessageType string `url:"message_type,omitempty"` - Name string `url:"name,omitempty"` - Path string `url:"path,omitempty"` - Period uint `url:"period,omitempty"` - Placement string `url:"placement,omitempty"` - PublicKey string `url:"public_key,omitempty"` + // AccessKey is your DigitalOcean Spaces account access key. + AccessKey string `url:"access_key,omitempty"` + // BucketName is the name of the DigitalOcean Space. + BucketName string `url:"bucket_name,omitempty"` + // CompressionCodec is the codec used for compressing your logs (zstd, snappy, gzip). + CompressionCodec string `url:"compression_codec,omitempty"` + // Domain is the domain of the DigitalOcean Spaces endpoint. + Domain string `url:"domain,omitempty"` + // Format is aFastly log format string. + Format string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion uint `url:"format_version,omitempty"` + // GzipLevel is the level of gzip encoding when sending logs (default 0, no compression). + GzipLevel uint8 `url:"gzip_level,omitempty"` + // MessageType is how the message should be formatted (classic, loggly, logplex, blank). + MessageType string `url:"message_type,omitempty"` + // Name is the name for the real-time logging configuration. + Name string `url:"name,omitempty"` + // Path is the path to upload logs to. + Path string `url:"path,omitempty"` + // Period is how frequently log files are finalized so they can be available for reading (in seconds). + Period uint `url:"period,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement string `url:"placement,omitempty"` + // PublicKey is a PGP public key that Fastly will use to encrypt your log files before writing them to disk. + PublicKey string `url:"public_key,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition string `url:"response_condition,omitempty"` - SecretKey string `url:"secret_key,omitempty"` + // SecretKey is your DigitalOcean Spaces account secret key. + SecretKey string `url:"secret_key,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). - ServiceVersion int + ServiceVersion int + // TimestampFormat is a timestamp format. TimestampFormat string `url:"timestamp_format,omitempty"` } -// CreateDigitalOcean creates a new Fastly DigitalOcean. +// CreateDigitalOcean creates a new resource. func (c *Client) CreateDigitalOcean(i *CreateDigitalOceanInput) (*DigitalOcean, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -133,7 +157,7 @@ type GetDigitalOceanInput struct { ServiceVersion int } -// GetDigitalOcean gets the DigitalOcean configuration with the given parameters. +// GetDigitalOcean retrieves the specified resource. func (c *Client) GetDigitalOcean(i *GetDigitalOceanInput) (*DigitalOcean, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -163,31 +187,47 @@ func (c *Client) GetDigitalOcean(i *GetDigitalOceanInput) (*DigitalOcean, error) // UpdateDigitalOceanInput is used as input to the UpdateDigitalOcean function. type UpdateDigitalOceanInput struct { - AccessKey *string `url:"access_key,omitempty"` - BucketName *string `url:"bucket_name,omitempty"` + // AccessKey is your DigitalOcean Spaces account access key. + AccessKey *string `url:"access_key,omitempty"` + // BucketName is the name of the DigitalOcean Space. + BucketName *string `url:"bucket_name,omitempty"` + // CompressionCodec is the codec used for compressing your logs (zstd, snappy, gzip). CompressionCodec *string `url:"compression_codec,omitempty"` - Domain *string `url:"domain,omitempty"` - Format *string `url:"format,omitempty"` - FormatVersion *uint `url:"format_version,omitempty"` - GzipLevel *uint8 `url:"gzip_level,omitempty"` - MessageType *string `url:"message_type,omitempty"` + // Domain is the domain of the DigitalOcean Spaces endpoint. + Domain *string `url:"domain,omitempty"` + // Format is aFastly log format string. + Format *string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion *uint `url:"format_version,omitempty"` + // GzipLevel is the level of gzip encoding when sending logs (default 0, no compression). + GzipLevel *uint8 `url:"gzip_level,omitempty"` + // MessageType is how the message should be formatted (classic, loggly, logplex, blank). + MessageType *string `url:"message_type,omitempty"` // Name is the name of the DigitalOcean to update. - Name string - NewName *string `url:"name,omitempty"` - Path *string `url:"path,omitempty"` - Period *uint `url:"period,omitempty"` - Placement *string `url:"placement,omitempty"` - PublicKey *string `url:"public_key,omitempty"` + Name string + // NewName is the new name for the resource. + NewName *string `url:"name,omitempty"` + // Path is the path to upload logs to. + Path *string `url:"path,omitempty"` + // Period is how frequently log files are finalized so they can be available for reading (in seconds). + Period *uint `url:"period,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement *string `url:"placement,omitempty"` + // PublicKey is a PGP public key that Fastly will use to encrypt your log files before writing them to disk. + PublicKey *string `url:"public_key,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition *string `url:"response_condition,omitempty"` - SecretKey *string `url:"secret_key,omitempty"` + // SecretKey is your DigitalOcean Spaces account secret key. + SecretKey *string `url:"secret_key,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). - ServiceVersion int + ServiceVersion int + // TimestampFormat is a timestamp format. TimestampFormat *string `url:"timestamp_format,omitempty"` } -// UpdateDigitalOcean updates a specific DigitalOcean. +// UpdateDigitalOcean updates the specified resource. func (c *Client) UpdateDigitalOcean(i *UpdateDigitalOceanInput) (*DigitalOcean, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -225,7 +265,7 @@ type DeleteDigitalOceanInput struct { ServiceVersion int } -// DeleteDigitalOcean deletes the given DigitalOcean version. +// DeleteDigitalOcean deletes the specified resource. func (c *Client) DeleteDigitalOcean(i *DeleteDigitalOceanInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/digitalocean_test.go b/fastly/digitalocean_test.go index bc7fc981b..2ad68b859 100644 --- a/fastly/digitalocean_test.go +++ b/fastly/digitalocean_test.go @@ -117,25 +117,25 @@ func TestClient_DigitalOceans(t *testing.T) { // Ensure deleted defer func() { record(t, "digitaloceans/cleanup", func(c *Client) { - c.DeleteDigitalOcean(&DeleteDigitalOceanInput{ + _ = c.DeleteDigitalOcean(&DeleteDigitalOceanInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-digitalocean", }) - c.DeleteDigitalOcean(&DeleteDigitalOceanInput{ + _ = c.DeleteDigitalOcean(&DeleteDigitalOceanInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-digitalocean-2", }) - c.DeleteDigitalOcean(&DeleteDigitalOceanInput{ + _ = c.DeleteDigitalOcean(&DeleteDigitalOceanInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-digitalocean-3", }) - c.DeleteDigitalOcean(&DeleteDigitalOceanInput{ + _ = c.DeleteDigitalOcean(&DeleteDigitalOceanInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "new-test-digitalocean", diff --git a/fastly/director.go b/fastly/director.go index 6eebc4af6..d3d159227 100644 --- a/fastly/director.go +++ b/fastly/director.go @@ -44,9 +44,17 @@ type Director struct { // directorsByName is a sortable list of directors. type directorsByName []*Director -// Len, Swap, and Less implement the sortable interface. -func (s directorsByName) Len() int { return len(s) } -func (s directorsByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s directorsByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s directorsByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s directorsByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -59,7 +67,7 @@ type ListDirectorsInput struct { ServiceVersion int } -// ListDirectors returns the list of directors for the configuration version. +// ListDirectors retrieves all resources. func (c *Client) ListDirectors(i *ListDirectorsInput) ([]*Director, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -86,20 +94,25 @@ func (c *Client) ListDirectors(i *ListDirectorsInput) ([]*Director, error) { // CreateDirectorInput is used as input to the CreateDirector function. type CreateDirectorInput struct { - Capacity *uint `url:"capacity,omitempty"` - Comment string `url:"comment,omitempty"` - Name string `url:"name,omitempty"` - Quorum *uint `url:"quorum,omitempty"` - Retries *uint `url:"retries,omitempty"` + // Comment is a freeform descriptive note. + Comment string `url:"comment,omitempty"` + // Name is the name for the Director. + Name string `url:"name,omitempty"` + // Quorum is the percentage of capacity that needs to be up for a director to be considered up. 0 to 100. + Quorum *uint `url:"quorum,omitempty"` + // Retries is how many backends to search if it fails. + Retries *uint `url:"retries,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - Shield string `url:"shield,omitempty"` - Type DirectorType `url:"type,omitempty"` + // Shield is selected POP to serve as a shield for the backends. + Shield string `url:"shield,omitempty"` + // Type is what type of load balance group to use (random, hash, client). + Type DirectorType `url:"type,omitempty"` } -// CreateDirector creates a new Fastly director. +// CreateDirector creates a new resource. func (c *Client) CreateDirector(i *CreateDirectorInput) (*Director, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -133,7 +146,7 @@ type GetDirectorInput struct { ServiceVersion int } -// GetDirector gets the director configuration with the given parameters. +// GetDirector retrieves the specified resource. func (c *Client) GetDirector(i *GetDirectorInput) (*Director, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -163,22 +176,27 @@ func (c *Client) GetDirector(i *GetDirectorInput) (*Director, error) { // UpdateDirectorInput is used as input to the UpdateDirector function. type UpdateDirectorInput struct { - Capacity *uint `url:"capacity,omitempty"` - Comment *string `url:"comment,omitempty"` + // Comment is a freeform descriptive note. + Comment *string `url:"comment,omitempty"` // Name is the name of the director to update. - Name string + Name string + // NewName is the new name for the resource. NewName *string `url:"name,omitempty"` - Quorum *uint `url:"quorum,omitempty"` - Retries *uint `url:"retries,omitempty"` + // Quorum is the percentage of capacity that needs to be up for a director to be considered up. 0 to 100. + Quorum *uint `url:"quorum,omitempty"` + // Retries is how many backends to search if it fails. + Retries *uint `url:"retries,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - Shield *string `url:"shield,omitempty"` - Type DirectorType `url:"type,omitempty"` + // Shield is selected POP to serve as a shield for the backends. + Shield *string `url:"shield,omitempty"` + // Type is what type of load balance group to use (random, hash, client). + Type DirectorType `url:"type,omitempty"` } -// UpdateDirector updates a specific director. +// UpdateDirector updates the specified resource. func (c *Client) UpdateDirector(i *UpdateDirectorInput) (*Director, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -216,7 +234,7 @@ type DeleteDirectorInput struct { ServiceVersion int } -// DeleteDirector deletes the given director version. +// DeleteDirector deletes the specified resource. func (c *Client) DeleteDirector(i *DeleteDirectorInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/director_backend.go b/fastly/director_backend.go index 013e2480a..13dec5b13 100644 --- a/fastly/director_backend.go +++ b/fastly/director_backend.go @@ -31,7 +31,7 @@ type CreateDirectorBackendInput struct { ServiceVersion int } -// CreateDirectorBackend creates a new Fastly backend. +// CreateDirectorBackend creates a new resource. func (c *Client) CreateDirectorBackend(i *CreateDirectorBackendInput) (*DirectorBackend, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -77,7 +77,7 @@ type GetDirectorBackendInput struct { ServiceVersion int } -// GetDirectorBackend gets the backend configuration with the given parameters. +// GetDirectorBackend retrieves the specified resource. func (c *Client) GetDirectorBackend(i *GetDirectorBackendInput) (*DirectorBackend, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -123,7 +123,7 @@ type DeleteDirectorBackendInput struct { ServiceVersion int } -// DeleteDirectorBackend deletes the given backend version. +// DeleteDirectorBackend deletes the specified resource. func (c *Client) DeleteDirectorBackend(i *DeleteDirectorBackendInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/director_backend_test.go b/fastly/director_backend_test.go index 4afef56f3..38e006669 100644 --- a/fastly/director_backend_test.go +++ b/fastly/director_backend_test.go @@ -30,7 +30,7 @@ func TestClient_DirectorBackends(t *testing.T) { // Ensure deleted defer func() { record(t, "director_backends/cleanup", func(c *Client) { - c.DeleteDirectorBackend(&DeleteDirectorBackendInput{ + _ = c.DeleteDirectorBackend(&DeleteDirectorBackendInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Director: "director", diff --git a/fastly/director_test.go b/fastly/director_test.go index b638be613..50d0dcd73 100644 --- a/fastly/director_test.go +++ b/fastly/director_test.go @@ -59,26 +59,26 @@ func TestClient_Directors(t *testing.T) { // Ensure deleted defer func() { record(t, "directors/cleanup", func(c *Client) { - c.DeleteDirectorBackend(&DeleteDirectorBackendInput{ + _ = c.DeleteDirectorBackend(&DeleteDirectorBackendInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Director: d.Name, Backend: b.Name, }) - c.DeleteBackend(&DeleteBackendInput{ + _ = c.DeleteBackend(&DeleteBackendInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: b.Name, }) - c.DeleteDirector(&DeleteDirectorInput{ + _ = c.DeleteDirector(&DeleteDirectorInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-director", }) - c.DeleteDirector(&DeleteDirectorInput{ + _ = c.DeleteDirector(&DeleteDirectorInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "new-test-director", diff --git a/fastly/domain.go b/fastly/domain.go index 6b8afe544..ca0609519 100644 --- a/fastly/domain.go +++ b/fastly/domain.go @@ -23,9 +23,17 @@ type Domain struct { // domainsByName is a sortable list of backends. type domainsByName []*Domain -// Len, Swap, and Less implement the sortable interface. -func (s domainsByName) Len() int { return len(s) } -func (s domainsByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s domainsByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s domainsByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s domainsByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -38,7 +46,7 @@ type ListDomainsInput struct { ServiceVersion int } -// ListDomains returns the list of domains for this Service. +// ListDomains retrieves all resources. func (c *Client) ListDomains(i *ListDomainsInput) ([]*Domain, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -75,7 +83,7 @@ type CreateDomainInput struct { ServiceVersion int } -// CreateDomain creates a new domain with the given information. +// CreateDomain creates a new resource. func (c *Client) CreateDomain(i *CreateDomainInput) (*Domain, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -109,7 +117,7 @@ type GetDomainInput struct { ServiceVersion int } -// GetDomain retrieves information about the given domain name. +// GetDomain retrieves the specified resource. func (c *Client) GetDomain(i *GetDomainInput) (*Domain, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -151,8 +159,7 @@ type UpdateDomainInput struct { ServiceVersion int } -// UpdateDomain updates a single domain for the current service. The only allowed -// parameters are `Name` and `Comment`. +// UpdateDomain updates the specified resource. func (c *Client) UpdateDomain(i *UpdateDomainInput) (*Domain, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -194,7 +201,7 @@ type DeleteDomainInput struct { ServiceVersion int } -// DeleteDomain removes a single domain by the given name. +// DeleteDomain deletes the specified resource. func (c *Client) DeleteDomain(i *DeleteDomainInput) error { if i.ServiceID == "" { return ErrMissingServiceID @@ -226,7 +233,7 @@ type ValidateDomainInput struct { ServiceVersion int } -// ValidateDomain validates the given domain. +// ValidateDomain validates the specified resource. func (c *Client) ValidateDomain(i *ValidateDomainInput) (*DomainValidationResult, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -315,7 +322,7 @@ type ValidateAllDomainsInput struct { ServiceVersion int } -// ValidateAllDomains validates the given domain. +// ValidateAllDomains validates the specified resource. func (c *Client) ValidateAllDomains(i *ValidateAllDomainsInput) (results []*DomainValidationResult, err error) { if i.ServiceID == "" { return nil, ErrMissingServiceID diff --git a/fastly/domain_test.go b/fastly/domain_test.go index 1bf1a05d3..8995645d7 100644 --- a/fastly/domain_test.go +++ b/fastly/domain_test.go @@ -50,13 +50,13 @@ func TestClient_Domains(t *testing.T) { // Ensure deleted defer func() { record(t, "domains/cleanup", func(c *Client) { - c.DeleteDomain(&DeleteDomainInput{ + _ = c.DeleteDomain(&DeleteDomainInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: domain1, }) - c.DeleteDomain(&DeleteDomainInput{ + _ = c.DeleteDomain(&DeleteDomainInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: domain3, @@ -137,7 +137,7 @@ func TestClient_Domains(t *testing.T) { if err != nil { t.Fatal(err) } - if vd.Valid != false { + if vd.Valid { t.Errorf("valid domain unexpected: %q", vd.Metadata.Name) } @@ -155,7 +155,7 @@ func TestClient_Domains(t *testing.T) { t.Errorf("invalid domains: %v", vds) } for _, d := range vds { - if d.Valid != false { + if d.Valid { t.Errorf("valid domain unexpected: %q", d.Metadata.Name) } } diff --git a/fastly/elasticsearch.go b/fastly/elasticsearch.go index b9eab0646..0d9c0541b 100644 --- a/fastly/elasticsearch.go +++ b/fastly/elasticsearch.go @@ -35,9 +35,17 @@ type Elasticsearch struct { // elasticsearchByName is a sortable list of Elasticsearch logs. type elasticsearchByName []*Elasticsearch -// Len, Swap, and Less implement the sortable interface. -func (s elasticsearchByName) Len() int { return len(s) } -func (s elasticsearchByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s elasticsearchByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s elasticsearchByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s elasticsearchByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -50,7 +58,7 @@ type ListElasticsearchInput struct { ServiceVersion int } -// ListElasticsearch returns the list of Elasticsearch logs for the configuration version. +// ListElasticsearch retrieves all resources. func (c *Client) ListElasticsearch(i *ListElasticsearchInput) ([]*Elasticsearch, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -77,29 +85,45 @@ func (c *Client) ListElasticsearch(i *ListElasticsearchInput) ([]*Elasticsearch, // CreateElasticsearchInput is used as input to the CreateElasticsearch function. type CreateElasticsearchInput struct { - Format string `url:"format,omitempty"` - FormatVersion uint `url:"format_version,omitempty"` - Index string `url:"index,omitempty"` - Name string `url:"name,omitempty"` - Password string `url:"password,omitempty"` - Pipeline string `url:"pipeline,omitempty"` - Placement string `url:"placement,omitempty"` - RequestMaxBytes uint `url:"request_max_bytes,omitempty"` - RequestMaxEntries uint `url:"request_max_entries,omitempty"` + // Format is a Fastly log format string. Must produce valid JSON that Elasticsearch can ingest. + Format string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion uint `url:"format_version,omitempty"` + // Index is the name of the Elasticsearch index to send documents (logs) to. + Index string `url:"index,omitempty"` + // Name is the name for the real-time logging configuration. + Name string `url:"name,omitempty"` + // Password is basic Auth password. + Password string `url:"password,omitempty"` + // Pipeline is the ID of the Elasticsearch ingest pipeline to apply pre-process transformations to before indexing. + Pipeline string `url:"pipeline,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement string `url:"placement,omitempty"` + // RequestMaxBytes is the maximum number of bytes sent in one request. + RequestMaxBytes uint `url:"request_max_bytes,omitempty"` + // RequestMaxEntries is the maximum number of logs sent in one request. + RequestMaxEntries uint `url:"request_max_entries,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - TLSCACert string `url:"tls_ca_cert,omitempty"` - TLSClientCert string `url:"tls_client_cert,omitempty"` - TLSClientKey string `url:"tls_client_key,omitempty"` - TLSHostname string `url:"tls_hostname,omitempty"` - URL string `url:"url,omitempty"` - User string `url:"user,omitempty"` + // TLSCACert is a secure certificate to authenticate a server with. Must be in PEM format. + TLSCACert string `url:"tls_ca_cert,omitempty"` + // TLSClientCert is the client certificate used to make authenticated requests. Must be in PEM format. + TLSClientCert string `url:"tls_client_cert,omitempty"` + // TLSClientKey is the client private key used to make authenticated requests. Must be in PEM format. + TLSClientKey string `url:"tls_client_key,omitempty"` + // TLSHostname is the hostname to verify the server's certificate. This should be one of the Subject Alternative Name (SAN) fields for the certificate. Common Names (CN) are not supported. + TLSHostname string `url:"tls_hostname,omitempty"` + // URL is the URL to stream logs to. Must use HTTPS. + URL string `url:"url,omitempty"` + // User is basic Auth username. + User string `url:"user,omitempty"` } -// CreateElasticsearch creates a new Fastly Elasticsearch logging endpoint. +// CreateElasticsearch creates a new resource. func (c *Client) CreateElasticsearch(i *CreateElasticsearchInput) (*Elasticsearch, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -133,6 +157,7 @@ type GetElasticsearchInput struct { ServiceVersion int } +// GetElasticsearch retrieves the specified resource. func (c *Client) GetElasticsearch(i *GetElasticsearchInput) (*Elasticsearch, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -161,31 +186,50 @@ func (c *Client) GetElasticsearch(i *GetElasticsearchInput) (*Elasticsearch, err return es, nil } +// UpdateElasticsearchInput is the input parameter to the UpdateElasticsearch +// function. type UpdateElasticsearchInput struct { - Format *string `url:"format,omitempty"` - FormatVersion *uint `url:"format_version,omitempty"` - Index *string `url:"index,omitempty"` + // Format is a Fastly log format string. Must produce valid JSON that Elasticsearch can ingest. + Format *string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion *uint `url:"format_version,omitempty"` + // Index is the name of the Elasticsearch index to send documents (logs) to. + Index *string `url:"index,omitempty"` // Name is the name of the Elasticsearch endpoint to fetch. - Name string - NewName *string `url:"name,omitempty"` - Password *string `url:"password,omitempty"` - Pipeline *string `url:"pipeline,omitempty"` - Placement *string `url:"placement,omitempty"` - RequestMaxBytes *uint `url:"request_max_bytes,omitempty"` - RequestMaxEntries *uint `url:"request_max_entries,omitempty"` + Name string + // NewName is the new name for the resource. + NewName *string `url:"name,omitempty"` + // Password is basic Auth password. + Password *string `url:"password,omitempty"` + // Pipeline is the ID of the Elasticsearch ingest pipeline to apply pre-process transformations to before indexing. + Pipeline *string `url:"pipeline,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement *string `url:"placement,omitempty"` + // RequestMaxBytes is the maximum number of bytes sent in one request. + RequestMaxBytes *uint `url:"request_max_bytes,omitempty"` + // RequestMaxEntries is the maximum number of logs sent in one request. + RequestMaxEntries *uint `url:"request_max_entries,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition *string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - TLSCACert *string `url:"tls_ca_cert,omitempty"` - TLSClientCert *string `url:"tls_client_cert,omitempty"` - TLSClientKey *string `url:"tls_client_key,omitempty"` - TLSHostname *string `url:"tls_hostname,omitempty"` - URL *string `url:"url,omitempty"` - User *string `url:"user,omitempty"` + // TLSCACert is a secure certificate to authenticate a server with. Must be in PEM format. + TLSCACert *string `url:"tls_ca_cert,omitempty"` + // TLSClientCert is the client certificate used to make authenticated requests. Must be in PEM format. + TLSClientCert *string `url:"tls_client_cert,omitempty"` + // TLSClientKey is the client private key used to make authenticated requests. Must be in PEM format. + TLSClientKey *string `url:"tls_client_key,omitempty"` + // TLSHostname is the hostname to verify the server's certificate. This should be one of the Subject Alternative Name (SAN) fields for the certificate. Common Names (CN) are not supported. + TLSHostname *string `url:"tls_hostname,omitempty"` + // URL is the URL to stream logs to. Must use HTTPS. + URL *string `url:"url,omitempty"` + // User is basic Auth username. + User *string `url:"user,omitempty"` } +// UpdateElasticsearch updates the specified resource. func (c *Client) UpdateElasticsearch(i *UpdateElasticsearchInput) (*Elasticsearch, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -213,6 +257,8 @@ func (c *Client) UpdateElasticsearch(i *UpdateElasticsearchInput) (*Elasticsearc return es, nil } +// DeleteElasticsearchInput is the input parameter to the DeleteElasticsearch +// function. type DeleteElasticsearchInput struct { // Name is the name of the Elasticsearch endpoint to fetch. Name string @@ -222,6 +268,7 @@ type DeleteElasticsearchInput struct { ServiceVersion int } +// DeleteElasticsearch deletes the specified resource. func (c *Client) DeleteElasticsearch(i *DeleteElasticsearchInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/elasticsearch_test.go b/fastly/elasticsearch_test.go index 2abd81985..2bf5e1268 100644 --- a/fastly/elasticsearch_test.go +++ b/fastly/elasticsearch_test.go @@ -64,14 +64,14 @@ Wm7DCfrPNGVwFWUQOmsPue9rZBgO // ensure deleted defer func() { record(t, "elasticsearch/cleanup", func(c *Client) { - c.DeleteElasticsearch(&DeleteElasticsearchInput{ + _ = c.DeleteElasticsearch(&DeleteElasticsearchInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-elasticsearch", }) // ensure that renamed endpoint created in Update test is deleted - c.DeleteElasticsearch(&DeleteElasticsearchInput{ + _ = c.DeleteElasticsearch(&DeleteElasticsearchInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "new-test-elasticsearch", diff --git a/fastly/erl.go b/fastly/erl.go index 312669466..f5f037071 100644 --- a/fastly/erl.go +++ b/fastly/erl.go @@ -17,7 +17,7 @@ type ERL struct { CreatedAt *time.Time `mapstructure:"created_at"` DeletedAt *time.Time `mapstructure:"deleted_at"` FeatureRevision int `mapstructure:"feature_revision"` // 1.. - HttpMethods []string `mapstructure:"http_methods"` + HTTPMethods []string `mapstructure:"http_methods"` ID string `mapstructure:"id"` LoggerType ERLLogger `mapstructure:"logger_type"` Name string `mapstructure:"name"` @@ -25,9 +25,9 @@ type ERL struct { Response *ERLResponseType `mapstructure:"response"` // required if Action != Log ResponseObjectName string `mapstructure:"response_object_name"` RpsLimit int `mapstructure:"rps_limit"` // 10..10000 - ServiceId string `mapstructure:"service_id"` + ServiceID string `mapstructure:"service_id"` UpdatedAt *time.Time `mapstructure:"updated_at"` - UriDictionaryName string `mapstructure:"uri_dictionary_name"` + URIDictionaryName string `mapstructure:"uri_dictionary_name"` Version int `mapstructure:"version"` // 1.. WindowSize ERLWindowSize `mapstructure:"window_size"` } @@ -44,8 +44,11 @@ type ERLResponseType struct { type ERLAction string const ( - ERLActionLogOnly ERLAction = "log_only" - ERLActionResponse ERLAction = "response" + // ERLActionLogOnly represents an action variant. + ERLActionLogOnly ERLAction = "log_only" + // ERLActionResponse represents an action variant. + ERLActionResponse ERLAction = "response" + // ERLActionResponseObject represents an action variant. ERLActionResponseObject ERLAction = "response_object" ) @@ -53,35 +56,64 @@ const ( type ERLLogger string const ( - ERLLogAzureBlob ERLLogger = "azureblob" - ERLLogBigQuery ERLLogger = "bigquery" - ERLLogCloudFiles ERLLogger = "cloudfiles" - ERLLogDataDog ERLLogger = "datadog" - ERLLogDigitalOcean ERLLogger = "digitalocean" - ERLLogElasticSearch ERLLogger = "elasticsearch" - ERLLogFtp ERLLogger = "ftp" - ERLLogGcs ERLLogger = "gcs" + // ERLLogAzureBlob represents a log provider variant. + ERLLogAzureBlob ERLLogger = "azureblob" + // ERLLogBigQuery represents a log provider variant. + ERLLogBigQuery ERLLogger = "bigquery" + // ERLLogCloudFiles represents a log provider variant. + ERLLogCloudFiles ERLLogger = "cloudfiles" + // ERLLogDataDog represents a log provider variant. + ERLLogDataDog ERLLogger = "datadog" + // ERLLogDigitalOcean represents a log provider variant. + ERLLogDigitalOcean ERLLogger = "digitalocean" + // ERLLogElasticSearch represents a log provider variant. + ERLLogElasticSearch ERLLogger = "elasticsearch" + // ERLLogFtp represents a log provider variant. + ERLLogFtp ERLLogger = "ftp" + // ERLLogGcs represents a log provider variant. + ERLLogGcs ERLLogger = "gcs" + // ERLLogGoogleAnalytics represents a log provider variant. ERLLogGoogleAnalytics ERLLogger = "googleanalytics" - ERLLogHeroku ERLLogger = "heroku" - ERLLogHoneycomb ERLLogger = "honeycomb" - ERLLogHttp ERLLogger = "http" - ERLLogHttps ERLLogger = "https" - ERLLogKafta ERLLogger = "kafka" - ERLLogKinesis ERLLogger = "kinesis" - ERLLogLogEntries ERLLogger = "logentries" - ERLLogLoggly ERLLogger = "loggly" - ERLLogLogShuttle ERLLogger = "logshuttle" - ERLLogNewRelic ERLLogger = "newrelic" - ERLLogOpenStack ERLLogger = "openstack" - ERLLogPaperTrail ERLLogger = "papertrail" - ERLLogPubSub ERLLogger = "pubsub" - ERLLogS3 ERLLogger = "s3" - ERLLogScalyr ERLLogger = "scalyr" - ERLLogSftp ERLLogger = "sftp" - ERLLogSplunk ERLLogger = "splunk" - ERLLogStackDriver ERLLogger = "stackdriver" - ERLLogSumoLogiuc ERLLogger = "sumologic" - ERLLogSysLog ERLLogger = "syslog" + // ERLLogHeroku represents a log provider variant. + ERLLogHeroku ERLLogger = "heroku" + // ERLLogHoneycomb represents a log provider variant. + ERLLogHoneycomb ERLLogger = "honeycomb" + // ERLLogHTTP represents a log provider variant. + ERLLogHTTP ERLLogger = "http" + // ERLLogHTTPS represents a log provider variant. + ERLLogHTTPS ERLLogger = "https" + // ERLLogKafta represents a log provider variant. + ERLLogKafta ERLLogger = "kafka" + // ERLLogKinesis represents a log provider variant. + ERLLogKinesis ERLLogger = "kinesis" + // ERLLogLogEntries represents a log provider variant. + ERLLogLogEntries ERLLogger = "logentries" + // ERLLogLoggly represents a log provider variant. + ERLLogLoggly ERLLogger = "loggly" + // ERLLogLogShuttle represents a log provider variant. + ERLLogLogShuttle ERLLogger = "logshuttle" + // ERLLogNewRelic represents a log provider variant. + ERLLogNewRelic ERLLogger = "newrelic" + // ERLLogOpenStack represents a log provider variant. + ERLLogOpenStack ERLLogger = "openstack" + // ERLLogPaperTrail represents a log provider variant. + ERLLogPaperTrail ERLLogger = "papertrail" + // ERLLogPubSub represents a log provider variant. + ERLLogPubSub ERLLogger = "pubsub" + // ERLLogS3 represents a log provider variant. + ERLLogS3 ERLLogger = "s3" + // ERLLogScalyr represents a log provider variant. + ERLLogScalyr ERLLogger = "scalyr" + // ERLLogSftp represents a log provider variant. + ERLLogSftp ERLLogger = "sftp" + // ERLLogSplunk represents a log provider variant. + ERLLogSplunk ERLLogger = "splunk" + // ERLLogStackDriver represents a log provider variant. + ERLLogStackDriver ERLLogger = "stackdriver" + // ERLLogSumoLogic represents a log provider variant. + ERLLogSumoLogic ERLLogger = "sumologic" + // ERLLogSysLog represents a log provider variant. + ERLLogSysLog ERLLogger = "syslog" ) // ERLWindowSize represents the duration variants for when the RPS limit is @@ -89,28 +121,41 @@ const ( type ERLWindowSize int const ( - ERLSize1 ERLWindowSize = 1 + // ERLSize1 represents a duration variant. + ERLSize1 ERLWindowSize = 1 + // ERLSize10 represents a duration variant. ERLSize10 ERLWindowSize = 10 + // ERLSize60 represents a duration variant. ERLSize60 ERLWindowSize = 60 ) // ERLsByName is a sortable list of ERLs type ERLsByName []*ERL -// Len, Swap, and Less implement the sortable interface -func (s ERLsByName) Len() int { return len(s) } -func (s ERLsByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s ERLsByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s ERLsByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s ERLsByName) Less(i, j int) bool { return s[i].Name < s[j].Name } // ListERLsInput is used as input to the ListERLs function. type ListERLsInput struct { - ServiceID string // required - ServiceVersion int // required + // ServiceID is the ID of the service (required). + ServiceID string + // ServiceVersion is the version number to fetch (required). + ServiceVersion int } -// ListERLs returns the list of ERLs for the specified service version. +// ListERLs retrieves all resources. func (c *Client) ListERLs(i *ListERLsInput) ([]*ERL, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -137,19 +182,29 @@ func (c *Client) ListERLs(i *ListERLsInput) ([]*ERL, error) { // CreateERLInput is used as input to the CreateERL function. type CreateERLInput struct { - Action ERLAction `url:"action"` - ClientKey []string `url:"client_key,brackets"` - HttpMethods []string `url:"http_methods,brackets"` - Name string `url:"name"` - PenaltyBoxDuration int `url:"penalty_box_duration"` - Response *ERLResponseType `url:"response,omitempty"` - RpsLimit int `url:"rps_limit"` - ServiceID string `url:"-"` - ServiceVersion int `url:"-"` - WindowSize ERLWindowSize `url:"window_size"` + // Action is the action to take when a rate limiter violation is detected (response, response_object, log_only). + Action ERLAction `url:"action"` + // ClientKey is an array of VCL variables used to generate a counter key to identify a client. + ClientKey []string `url:"client_key,brackets"` + // HTTPMethods is an array of HTTP methods to apply rate limiting to. + HTTPMethods []string `url:"http_methods,brackets"` + // Name is a human readable name for the rate limiting rule. + Name string `url:"name"` + // PenaltyBoxDuration is a length of time in minutes that the rate limiter is in effect after the initial violation is detected. + PenaltyBoxDuration int `url:"penalty_box_duration"` + // Response is a custom response to be sent when the rate limit is exceeded. Required if action is response. + Response *ERLResponseType `url:"response,omitempty"` + // RpsLimit is an upper limit of requests per second allowed by the rate limiter. + RpsLimit int `url:"rps_limit"` + // ServiceID is an alphanumeric string identifying the service (required). + ServiceID string `url:"-"` + // ServiceVersion is the specific configuration version (required). + ServiceVersion int `url:"-"` + // WindowSize is the number of seconds during which the RPS limit must be exceeded in order to trigger a violation (1, 10, 60). + WindowSize ERLWindowSize `url:"window_size"` } -// CreateERL returns a new ERL. +// CreateERL creates a new resource. func (c *Client) CreateERL(i *CreateERLInput) (*ERL, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -175,12 +230,15 @@ func (c *Client) CreateERL(i *CreateERLInput) (*ERL, error) { // DeleteERLInput is used as input to the DeleteERL function. type DeleteERLInput struct { - ERLID string `form:"id"` - ServiceID string `form:"service_id"` - ServiceVersion int `form:"version"` + // ERLID is an alphanumeric string identifying the rate limiter (required). + ERLID string `form:"id"` + // ServiceID is an alphanumeric string identifying the service (required). + ServiceID string `form:"service_id"` + // ServiceVersion is the specific configuration version (required). + ServiceVersion int `form:"version"` } -// DeleteERL deletes the specified ERL. +// DeleteERL deletes the specified resource. func (c *Client) DeleteERL(i *DeleteERLInput) error { if i.ServiceID == "" { return ErrMissingServiceID @@ -212,12 +270,15 @@ func (c *Client) DeleteERL(i *DeleteERLInput) error { // GetERLInput is used as input to the GetERL function. type GetERLInput struct { - ERLID string `form:"id"` - ServiceID string `form:"service_id"` - ServiceVersion int `form:"version"` + // ERLID is an alphanumeric string identifying the rate limiter (required). + ERLID string `form:"id"` + // ServiceID is an alphanumeric string identifying the service (required). + ServiceID string `form:"service_id"` + // ServiceVersion is the specific configuration version (required). + ServiceVersion int `form:"version"` } -// GetERL returns the specified ERL. +// GetERL retrieves the specified resource. func (c *Client) GetERL(i *GetERLInput) (*ERL, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -246,20 +307,31 @@ func (c *Client) GetERL(i *GetERLInput) (*ERL, error) { // UpdateERLInput is used as input to the UpdateERL function. type UpdateERLInput struct { - Action ERLAction `url:"action,omitempty"` - ClientKey []string `url:"client_key,omitempty,brackets"` - HttpMethods []string `url:"http_methods,omitempty,brackets"` - ID string `url:"id"` - Name string `url:"name,omitempty"` - PenaltyBoxDuration int `url:"penalty_box_duration,omitempty"` - Response *ERLResponseType `url:"response,omitempty"` - RpsLimit int `url:"rps_limit,omitempty"` - ServiceID string `url:"-"` - ServiceVersion int `url:"-"` - WindowSize ERLWindowSize `url:"window_size,omitempty"` + // Action is the action to take when a rate limiter violation is detected (response, response_object, log_only). + Action ERLAction `url:"action,omitempty"` + // ClientKey is an array of VCL variables used to generate a counter key to identify a client. + ClientKey []string `url:"client_key,omitempty,brackets"` + // HTTPMethods is an array of HTTP methods to apply rate limiting to. + HTTPMethods []string `url:"http_methods,omitempty,brackets"` + // ID is an alphanumeric string identifying the rate limiter (required). + ID string `url:"id"` + // Name is a human readable name for the rate limiting rule. + Name string `url:"name,omitempty"` + // PenaltyBoxDuration is a length of time in minutes that the rate limiter is in effect after the initial violation is detected. + PenaltyBoxDuration int `url:"penalty_box_duration,omitempty"` + // Response is a custom response to be sent when the rate limit is exceeded. Required if action is response. + Response *ERLResponseType `url:"response,omitempty"` + // RpsLimit is an upper limit of requests per second allowed by the rate limiter. + RpsLimit int `url:"rps_limit,omitempty"` + // ServiceID is an alphanumeric string identifying the service (required). + ServiceID string `url:"-"` + // ServiceVersion is the specific configuration version (required). + ServiceVersion int `url:"-"` + // WindowSize is the number of seconds during which the RPS limit must be exceeded in order to trigger a violation (1, 10, 60). + WindowSize ERLWindowSize `url:"window_size,omitempty"` } -// UpdateERLInput updates the specified ERL. +// UpdateERL updates the specified resource. func (c *Client) UpdateERL(i *UpdateERLInput) (*ERL, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID diff --git a/fastly/erl_test.go b/fastly/erl_test.go index c6dbf97c6..2be51606a 100644 --- a/fastly/erl_test.go +++ b/fastly/erl_test.go @@ -23,12 +23,13 @@ func TestClient_ERL(t *testing.T) { Name: "test_erl", Action: ERLActionResponse, ClientKey: []string{"req.http.Fastly-Client-IP"}, - HttpMethods: []string{http.MethodGet, http.MethodPost}, + HTTPMethods: []string{http.MethodGet, http.MethodPost}, PenaltyBoxDuration: 30, Response: &ERLResponseType{ ERLStatus: 429, ERLContentType: "application/json", - ERLContent: "Too many requests"}, + ERLContent: "Too many requests", + }, RpsLimit: 20, WindowSize: 10, }) @@ -40,7 +41,7 @@ func TestClient_ERL(t *testing.T) { // Ensure deleted defer func() { record(t, fixtureBase+"cleanup", func(c *Client) { - c.DeleteERL(&DeleteERLInput{ + _ = c.DeleteERL(&DeleteERLInput{ ServiceID: testServiceID, ServiceVersion: testVersion.Number, ERLID: e.ID, @@ -67,7 +68,7 @@ func TestClient_ERL(t *testing.T) { if err != nil { t.Fatal(err) } - var want, got = 1, len(es) + want, got := 1, len(es) if got < want { t.Errorf("want %d, got %d", want, got) } diff --git a/fastly/errors.go b/fastly/errors.go index 0dbf8ed21..7991b522e 100644 --- a/fastly/errors.go +++ b/fastly/errors.go @@ -35,6 +35,7 @@ func (e *FieldError) Error() string { return fmt.Sprintf("missing required field '%s'", e.kind) } +// Message prints the error message. func (e *FieldError) Message(msg string) *FieldError { e.message = msg return e @@ -348,7 +349,7 @@ func NewHTTPError(resp *http.Response) *HTTPError { default: var lerr *legacyError - decodeBodyMap(resp.Body, &lerr) + _ = decodeBodyMap(resp.Body, &lerr) if lerr != nil { e.Errors = append(e.Errors, &ErrorObject{ Title: lerr.Message, diff --git a/fastly/event_logs.go b/fastly/event_logs.go index db1a3fb5a..fb4b927fc 100644 --- a/fastly/event_logs.go +++ b/fastly/event_logs.go @@ -13,7 +13,7 @@ import ( "github.com/google/jsonapi" ) -// Events represents an event_logs item response from the Fastly API. +// Event represents an event_logs item response from the Fastly API. type Event struct { Admin bool `jsonapi:"attr,admin"` CreatedAt *time.Time `jsonapi:"attr,created_at,iso8601"` @@ -27,7 +27,7 @@ type Event struct { UserID string `jsonapi:"attr,user_id"` } -// GetAPIEventsFilter is used as input to the GetAPIEvents function. +// GetAPIEventsFilterInput is used as input to the GetAPIEvents function. type GetAPIEventsFilterInput struct { // CustomerID to Limit the returned events to a specific customer. CustomerID string @@ -88,7 +88,7 @@ type GetAPIEventInput struct { EventID string } -// GetAPIEvent gets a specific event +// GetAPIEvent retrieves the specified resource. func (c *Client) GetAPIEvent(i *GetAPIEventInput) (*Event, error) { if i.EventID == "" { return nil, ErrMissingEventID @@ -132,6 +132,7 @@ func (c *Client) interpretAPIEventsPage(answer *GetAPIEventsResponse, pageNum in } answer.Events = append(answer.Events, typed) } + if pageNum == 0 { if pages.Next != "" { // NOTE: pages.Next URL includes filters already @@ -140,9 +141,8 @@ func (c *Client) interpretAPIEventsPage(answer *GetAPIEventsResponse, pageNum in return err } defer resp.Body.Close() - c.interpretAPIEventsPage(answer, pageNum, resp) + return c.interpretAPIEventsPage(answer, pageNum, resp) } - return nil } return nil } @@ -160,7 +160,10 @@ func getEventsPages(body io.Reader) (EventsPaginationInfo, io.Reader, error) { } var pages *GetAPIEventsResponse - json.Unmarshal(bodyBytes, &pages) + err = json.Unmarshal(bodyBytes, &pages) + if err != nil { + return pages.Links, nil, err + } return pages.Links, bytes.NewReader(buf.Bytes()), nil } diff --git a/fastly/event_logs_test.go b/fastly/event_logs_test.go index fc6121226..a2c2e211b 100644 --- a/fastly/event_logs_test.go +++ b/fastly/event_logs_test.go @@ -36,7 +36,6 @@ func TestClient_APIEvents(t *testing.T) { if len(event.ID) < 1 { t.Errorf("bad event: %v", event) } - } func TestClient_GetAPIEvent_validation(t *testing.T) { @@ -47,7 +46,6 @@ func TestClient_GetAPIEvent_validation(t *testing.T) { if err != ErrMissingEventID { t.Errorf("bad error: %s", err) } - } func TestGetAPIEventsFilterInput_formatFilters(t *testing.T) { diff --git a/fastly/fastly.go b/fastly/fastly.go index c9bf5dba2..0c6113db5 100644 --- a/fastly/fastly.go +++ b/fastly/fastly.go @@ -6,22 +6,30 @@ import ( "net/url" ) +// BatchOperation represents batching variants. type BatchOperation string const ( + // CreateBatchOperation represents a batching variant. CreateBatchOperation BatchOperation = "create" + // UpdateBatchOperation represents a batching variant. UpdateBatchOperation BatchOperation = "update" + // UpsertBatchOperation represents a batching variant. UpsertBatchOperation BatchOperation = "upsert" + // DeleteBatchOperation represents a batching variant. DeleteBatchOperation BatchOperation = "delete" - // Represents the maximum number of operations that can be sent within a single batch request. - // This is currently not documented in the API. + // BatchModifyMaximumOperations represents the maximum number of operations + // that can be sent within a single batch request. This is currently not + // documented in the API. BatchModifyMaximumOperations = 1000 - // Represents the maximum number of items that can be placed within an Edge Dictionary. + // MaximumDictionarySize represents the maximum number of items that can be + // placed within an Edge Dictionary. MaximumDictionarySize = 10000 - // Represents the maximum number of entries that can be placed within an ACL. + // MaximumACLSize represents the maximum number of entries that can be placed + // within an ACL. MaximumACLSize = 10000 ) @@ -40,7 +48,7 @@ var ( _ encoding.TextUnmarshaler = new(Compatibool) ) -// Helper function to get a pointer to bool +// CBool is a helper function to get a pointer to a bool. func CBool(b bool) *Compatibool { c := Compatibool(b) return &c diff --git a/fastly/fastly_test.go b/fastly/fastly_test.go index 9634922a0..060b12528 100644 --- a/fastly/fastly_test.go +++ b/fastly/fastly_test.go @@ -120,7 +120,6 @@ func recordRealtimeStats(t *testing.T, fixture string, f func(*RTSClient)) { } func createTestService(t *testing.T, serviceFixture string, serviceNameSuffix string) *Service { - var err error var service *Service @@ -139,7 +138,6 @@ func createTestService(t *testing.T, serviceFixture string, serviceNameSuffix st } func createTestServiceWasm(t *testing.T, serviceFixture string, serviceNameSuffix string) *Service { - var err error var service *Service @@ -171,8 +169,7 @@ func testVersion(t *testing.T, c *Client) *Version { return v } -func createTestVersion(t *testing.T, versionFixture string, serviceId string) *Version { - +func createTestVersion(t *testing.T, versionFixture string, serviceID string) *Version { var err error var version *Version @@ -181,7 +178,7 @@ func createTestVersion(t *testing.T, versionFixture string, serviceId string) *V defer testVersionLock.Unlock() version, err = client.CreateVersion(&CreateVersionInput{ - ServiceID: serviceId, + ServiceID: serviceID, }) if err != nil { t.Fatal(err) @@ -191,14 +188,13 @@ func createTestVersion(t *testing.T, versionFixture string, serviceId string) *V return version } -func createTestDictionary(t *testing.T, dictionaryFixture string, serviceId string, version int, dictionaryNameSuffix string) *Dictionary { - +func createTestDictionary(t *testing.T, dictionaryFixture string, serviceID string, version int, dictionaryNameSuffix string) *Dictionary { var err error var dictionary *Dictionary record(t, dictionaryFixture, func(client *Client) { dictionary, err = client.CreateDictionary(&CreateDictionaryInput{ - ServiceID: serviceId, + ServiceID: serviceID, ServiceVersion: version, Name: fmt.Sprintf("test_dictionary_%s", dictionaryNameSuffix), }) @@ -210,7 +206,6 @@ func createTestDictionary(t *testing.T, dictionaryFixture string, serviceId stri } func deleteTestDictionary(t *testing.T, dictionary *Dictionary, deleteFixture string) { - var err error record(t, deleteFixture, func(client *Client) { @@ -225,14 +220,13 @@ func deleteTestDictionary(t *testing.T, dictionary *Dictionary, deleteFixture st } } -func createTestACL(t *testing.T, createFixture string, serviceId string, version int, aclNameSuffix string) *ACL { - +func createTestACL(t *testing.T, createFixture string, serviceID string, version int, aclNameSuffix string) *ACL { var err error var acl *ACL record(t, createFixture, func(client *Client) { acl, err = client.CreateACL(&CreateACLInput{ - ServiceID: serviceId, + ServiceID: serviceID, ServiceVersion: version, Name: fmt.Sprintf("test_acl_%s", aclNameSuffix), }) @@ -244,7 +238,6 @@ func createTestACL(t *testing.T, createFixture string, serviceId string, version } func deleteTestACL(t *testing.T, acl *ACL, deleteFixture string) { - var err error record(t, deleteFixture, func(client *Client) { @@ -259,14 +252,13 @@ func deleteTestACL(t *testing.T, acl *ACL, deleteFixture string) { } } -func createTestPool(t *testing.T, createFixture string, serviceId string, version int, poolNameSuffix string) *Pool { - +func createTestPool(t *testing.T, createFixture string, serviceID string, version int, poolNameSuffix string) *Pool { var err error var pool *Pool record(t, createFixture, func(client *Client) { pool, err = client.CreatePool(&CreatePoolInput{ - ServiceID: serviceId, + ServiceID: serviceID, ServiceVersion: version, Name: fmt.Sprintf("test_pool_%s", poolNameSuffix), }) @@ -278,7 +270,6 @@ func createTestPool(t *testing.T, createFixture string, serviceId string, versio } func createTestLogging(t *testing.T, fixture, serviceID string, serviceNumber int) *Syslog { - var err error var log *Syslog @@ -304,7 +295,6 @@ func createTestLogging(t *testing.T, fixture, serviceID string, serviceNumber in } func deleteTestPool(t *testing.T, pool *Pool, deleteFixture string) { - var err error record(t, deleteFixture, func(client *Client) { @@ -320,7 +310,6 @@ func deleteTestPool(t *testing.T, pool *Pool, deleteFixture string) { } func deleteTestLogging(t *testing.T, fixture, serviceID string, serviceNumber int) { - var err error record(t, fixture, func(c *Client) { @@ -336,7 +325,6 @@ func deleteTestLogging(t *testing.T, fixture, serviceID string, serviceNumber in } func createTestWAFCondition(t *testing.T, fixture, serviceID, name string, serviceNumber int) *Condition { - var err error var condition *Condition @@ -357,7 +345,6 @@ func createTestWAFCondition(t *testing.T, fixture, serviceID, name string, servi } func deleteTestCondition(t *testing.T, fixture, serviceID, name string, serviceNumber int) { - var err error record(t, fixture, func(c *Client) { @@ -373,7 +360,6 @@ func deleteTestCondition(t *testing.T, fixture, serviceID, name string, serviceN } func createTestWAFResponseObject(t *testing.T, fixture, serviceID, name string, serviceNumber int) *ResponseObject { - var err error var ro *ResponseObject @@ -392,7 +378,6 @@ func createTestWAFResponseObject(t *testing.T, fixture, serviceID, name string, } func deleteTestResponseObject(t *testing.T, fixture, serviceID, name string, serviceNumber int) { - var err error record(t, fixture, func(c *Client) { @@ -408,7 +393,6 @@ func deleteTestResponseObject(t *testing.T, fixture, serviceID, name string, ser } func createWAF(t *testing.T, fixture, serviceID, condition, response string, serviceNumber int) *WAF { - var err error var waf *WAF @@ -426,14 +410,13 @@ func createWAF(t *testing.T, fixture, serviceID, condition, response string, ser return waf } -func deleteWAF(t *testing.T, fixture, WAFID string, WAFVersion int) { - +func deleteWAF(t *testing.T, fixture, wafID string, wafVersion int) { var err error record(t, fixture, func(c *Client) { err = c.DeleteWAF(&DeleteWAFInput{ - ID: WAFID, - ServiceVersion: WAFVersion, + ID: wafID, + ServiceVersion: wafVersion, }) }) if err != nil { @@ -442,7 +425,6 @@ func deleteWAF(t *testing.T, fixture, WAFID string, WAFVersion int) { } func deleteTestService(t *testing.T, cleanupFixture, serviceID string) { - var err error record(t, cleanupFixture, func(client *Client) { diff --git a/fastly/ftp.go b/fastly/ftp.go index 4486c6c6a..963e1e2f5 100644 --- a/fastly/ftp.go +++ b/fastly/ftp.go @@ -35,9 +35,17 @@ type FTP struct { // ftpsByName is a sortable list of ftps. type ftpsByName []*FTP -// Len, Swap, and Less implement the sortable interface. -func (s ftpsByName) Len() int { return len(s) } -func (s ftpsByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s ftpsByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s ftpsByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s ftpsByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -50,7 +58,7 @@ type ListFTPsInput struct { ServiceVersion int } -// ListFTPs returns the list of ftps for the configuration version. +// ListFTPs retrieves all resources. func (c *Client) ListFTPs(i *ListFTPsInput) ([]*FTP, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -77,29 +85,45 @@ func (c *Client) ListFTPs(i *ListFTPsInput) ([]*FTP, error) { // CreateFTPInput is used as input to the CreateFTP function. type CreateFTPInput struct { - Address string `url:"address,omitempty"` - CompressionCodec string `url:"compression_codec,omitempty"` - Format string `url:"format,omitempty"` - FormatVersion uint `url:"format_version,omitempty"` - GzipLevel uint8 `url:"gzip_level,omitempty"` - MessageType string `url:"message_type,omitempty"` - Name string `url:"name,omitempty"` - Password string `url:"password,omitempty"` - Path string `url:"path,omitempty"` - Period uint `url:"period,omitempty"` - Placement string `url:"placement,omitempty"` - Port uint `url:"port,omitempty"` - PublicKey string `url:"public_key,omitempty"` + // Address is an hostname or IPv4 address. + Address string `url:"address,omitempty"` + // CompressionCodec is the codec used for compressing your logs (zstd, snappy, gzip). + CompressionCodec string `url:"compression_codec,omitempty"` + // Format is a Fastly log format string. + Format string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion uint `url:"format_version,omitempty"` + // GzipLevel is the level of gzip encoding when sending logs (default 0, no compression). + GzipLevel uint8 `url:"gzip_level,omitempty"` + // MessageType is how the message should be formatted (classic, loggly, logplex, blank). + MessageType string `url:"message_type,omitempty"` + // Name is the name for the real-time logging configuration. + Name string `url:"name,omitempty"` + // Password is the password for the server. For anonymous use an email address. + Password string `url:"password,omitempty"` + // Path is the path to upload log files to. If the path ends in / then it is treated as a directory. + Path string `url:"path,omitempty"` + // Period is how frequently log files are finalized so they can be available for reading (in seconds). + Period uint `url:"period,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement string `url:"placement,omitempty"` + // Port is the port number. + Port uint `url:"port,omitempty"` + // PublicKey is a PGP public key that Fastly will use to encrypt your log files before writing them to disk. + PublicKey string `url:"public_key,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). - ServiceVersion int + ServiceVersion int + // TimestampFormat is a timestamp format. TimestampFormat string `url:"timestamp_format,omitempty"` - Username string `url:"user,omitempty"` + // Username is the username for the server. Can be anonymous. + Username string `url:"user,omitempty"` } -// CreateFTP creates a new Fastly FTP. +// CreateFTP creates a new resource. func (c *Client) CreateFTP(i *CreateFTPInput) (*FTP, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -133,7 +157,7 @@ type GetFTPInput struct { ServiceVersion int } -// GetFTP gets the FTP configuration with the given parameters. +// GetFTP retrieves the specified resource. func (c *Client) GetFTP(i *GetFTPInput) (*FTP, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -163,31 +187,47 @@ func (c *Client) GetFTP(i *GetFTPInput) (*FTP, error) { // UpdateFTPInput is used as input to the UpdateFTP function. type UpdateFTPInput struct { - Address *string `url:"address,omitempty"` + // Address is an hostname or IPv4 address. + Address *string `url:"address,omitempty"` + // CompressionCodec is the codec used for compressing your logs (zstd, snappy, gzip). CompressionCodec *string `url:"compression_codec,omitempty"` - Format *string `url:"format,omitempty"` - FormatVersion *uint `url:"format_version,omitempty"` - GzipLevel *uint8 `url:"gzip_level,omitempty"` - MessageType *string `url:"message_type,omitempty"` + // Format is a Fastly log format string. + Format *string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion *uint `url:"format_version,omitempty"` + // GzipLevel is the level of gzip encoding when sending logs (default 0, no compression). + GzipLevel *uint8 `url:"gzip_level,omitempty"` + // MessageType is how the message should be formatted (classic, loggly, logplex, blank). + MessageType *string `url:"message_type,omitempty"` // Name is the name of the FTP to update. - Name string - NewName *string `url:"name,omitempty"` - Password *string `url:"password,omitempty"` - Path *string `url:"path,omitempty"` - Period *uint `url:"period,omitempty"` - Placement *string `url:"placement,omitempty"` - Port *uint `url:"port,omitempty"` - PublicKey *string `url:"public_key,omitempty"` + Name string + // NewName is the new name for the resource. + NewName *string `url:"name,omitempty"` + // Password is the password for the server. For anonymous use an email address. + Password *string `url:"password,omitempty"` + // Path is the path to upload log files to. If the path ends in / then it is treated as a directory. + Path *string `url:"path,omitempty"` + // Period is how frequently log files are finalized so they can be available for reading (in seconds). + Period *uint `url:"period,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement *string `url:"placement,omitempty"` + // Port is the port number. + Port *uint `url:"port,omitempty"` + // PublicKey is a PGP public key that Fastly will use to encrypt your log files before writing them to disk. + PublicKey *string `url:"public_key,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition *string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). - ServiceVersion int + ServiceVersion int + // TimestampFormat is a timestamp format. TimestampFormat *string `url:"timestamp_format,omitempty"` - Username *string `url:"user,omitempty"` + // Username is the username for the server. Can be anonymous. + Username *string `url:"user,omitempty"` } -// UpdateFTP updates a specific FTP. +// UpdateFTP updates the specified resource. func (c *Client) UpdateFTP(i *UpdateFTPInput) (*FTP, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -225,7 +265,7 @@ type DeleteFTPInput struct { ServiceVersion int } -// DeleteFTP deletes the given FTP version. +// DeleteFTP deletes the specified resource. func (c *Client) DeleteFTP(i *DeleteFTPInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/ftp_test.go b/fastly/ftp_test.go index 70b26d980..53ad7e694 100644 --- a/fastly/ftp_test.go +++ b/fastly/ftp_test.go @@ -116,25 +116,25 @@ func TestClient_FTPs(t *testing.T) { // Ensure deleted defer func() { record(t, "ftps/cleanup", func(c *Client) { - c.DeleteFTP(&DeleteFTPInput{ + _ = c.DeleteFTP(&DeleteFTPInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-ftp", }) - c.DeleteFTP(&DeleteFTPInput{ + _ = c.DeleteFTP(&DeleteFTPInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-ftp-2", }) - c.DeleteFTP(&DeleteFTPInput{ + _ = c.DeleteFTP(&DeleteFTPInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-ftp-3", }) - c.DeleteFTP(&DeleteFTPInput{ + _ = c.DeleteFTP(&DeleteFTPInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "new-test-ftp", diff --git a/fastly/gcs.go b/fastly/gcs.go index 522267b18..a2a9b471d 100644 --- a/fastly/gcs.go +++ b/fastly/gcs.go @@ -34,9 +34,17 @@ type GCS struct { // gcsesByName is a sortable list of gcses. type gcsesByName []*GCS -// Len, Swap, and Less implement the sortable interface. -func (s gcsesByName) Len() int { return len(s) } -func (s gcsesByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s gcsesByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s gcsesByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s gcsesByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -49,7 +57,7 @@ type ListGCSsInput struct { ServiceVersion int } -// ListGCSs returns the list of gcses for the configuration version. +// ListGCSs retrieves all resources. func (c *Client) ListGCSs(i *ListGCSsInput) ([]*GCS, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -75,28 +83,43 @@ func (c *Client) ListGCSs(i *ListGCSsInput) ([]*GCS, error) { // CreateGCSInput is used as input to the CreateGCS function. type CreateGCSInput struct { - AccountName string `url:"account_name,omitempty"` - Bucket string `url:"bucket_name,omitempty"` - CompressionCodec string `url:"compression_codec,omitempty"` - Format string `url:"format,omitempty"` - FormatVersion uint `url:"format_version,omitempty"` - GzipLevel uint8 `url:"gzip_level,omitempty"` - MessageType string `url:"message_type,omitempty"` - Name string `url:"name,omitempty"` - Path string `url:"path,omitempty"` - Period uint `url:"period,omitempty"` - Placement string `url:"placement,omitempty"` + // AccountName is the name of the Google Cloud Platform service account associated with the target log collection service. Not required if user and secret_key are provided. + AccountName string `url:"account_name,omitempty"` + // Bucket is the name of the GCS bucket. + Bucket string `url:"bucket_name,omitempty"` + // CompressionCodec is he codec used for compressing your logs (zstd, snappy, gzip). + CompressionCodec string `url:"compression_codec,omitempty"` + // Format is a Fastly log format string. + Format string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion uint `url:"format_version,omitempty"` + // GzipLevel is the level of gzip encoding when sending logs (default 0, no compression). + GzipLevel uint8 `url:"gzip_level,omitempty"` + // MessageType is how the message should be formatted (classic, loggly, logplex, blank). + MessageType string `url:"message_type,omitempty"` + // Name is the name for the real-time logging configuration. + Name string `url:"name,omitempty"` + // Path is the path to upload logs to. + Path string `url:"path,omitempty"` + // Period is how frequently log files are finalized so they can be available for reading (in seconds). + Period uint `url:"period,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement string `url:"placement,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition string `url:"response_condition,omitempty"` - SecretKey string `url:"secret_key,omitempty"` + // SecretKey is your Google Cloud Platform account secret key. The private_key field in your service account authentication JSON. Not required if account_name is specified. + SecretKey string `url:"secret_key,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). - ServiceVersion int + ServiceVersion int + // TimestampFormat is a timestamp format. TimestampFormat string `url:"timestamp_format,omitempty"` - User string `url:"user,omitempty"` + // User is your Google Cloud Platform service account email address. The client_email field in your service account authentication JSON. Not required if account_name is specified. + User string `url:"user,omitempty"` } -// CreateGCS creates a new Fastly GCS. +// CreateGCS creates a new resource. func (c *Client) CreateGCS(i *CreateGCSInput) (*GCS, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -130,7 +153,7 @@ type GetGCSInput struct { ServiceVersion int } -// GetGCS gets the GCS configuration with the given parameters. +// GetGCS retrieves the specified resource. func (c *Client) GetGCS(i *GetGCSInput) (*GCS, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -160,30 +183,45 @@ func (c *Client) GetGCS(i *GetGCSInput) (*GCS, error) { // UpdateGCSInput is used as input to the UpdateGCS function. type UpdateGCSInput struct { - AccountName *string `url:"account_name,omitempty"` - Bucket *string `url:"bucket_name,omitempty"` + // AccountName is the name of the Google Cloud Platform service account associated with the target log collection service. Not required if user and secret_key are provided. + AccountName *string `url:"account_name,omitempty"` + // Bucket is the name of the GCS bucket. + Bucket *string `url:"bucket_name,omitempty"` + // CompressionCodec is he codec used for compressing your logs (zstd, snappy, gzip). CompressionCodec *string `url:"compression_codec,omitempty"` - Format *string `url:"format,omitempty"` - FormatVersion *uint `url:"format_version,omitempty"` - GzipLevel *uint8 `url:"gzip_level,omitempty"` - MessageType *string `url:"message_type,omitempty"` + // Format is a Fastly log format string. + Format *string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion *uint `url:"format_version,omitempty"` + // GzipLevel is the level of gzip encoding when sending logs (default 0, no compression). + GzipLevel *uint8 `url:"gzip_level,omitempty"` + // MessageType is how the message should be formatted (classic, loggly, logplex, blank). + MessageType *string `url:"message_type,omitempty"` // Name is the name of the GCS to update. - Name string - NewName *string `url:"name,omitempty"` - Path *string `url:"path,omitempty"` - Period *uint `url:"period,omitempty"` - Placement *string `url:"placement,omitempty"` + Name string + // NewName is the new name for the resource. + NewName *string `url:"name,omitempty"` + // Path is the path to upload logs to. + Path *string `url:"path,omitempty"` + // Period is how frequently log files are finalized so they can be available for reading (in seconds). + Period *uint `url:"period,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement *string `url:"placement,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition *string `url:"response_condition,omitempty"` - SecretKey *string `url:"secret_key,omitempty"` + // SecretKey is your Google Cloud Platform account secret key. The private_key field in your service account authentication JSON. Not required if account_name is specified. + SecretKey *string `url:"secret_key,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). - ServiceVersion int + ServiceVersion int + // TimestampFormat is a timestamp format. TimestampFormat *string `url:"timestamp_format,omitempty"` - User *string `url:"user,omitempty"` + // User is your Google Cloud Platform service account email address. The client_email field in your service account authentication JSON. Not required if account_name is specified. + User *string `url:"user,omitempty"` } -// UpdateGCS updates a specific GCS. +// UpdateGCS updates the specified resource. func (c *Client) UpdateGCS(i *UpdateGCSInput) (*GCS, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -221,7 +259,7 @@ type DeleteGCSInput struct { ServiceVersion int } -// DeleteGCS deletes the given GCS version. +// DeleteGCS deletes the specified resource. func (c *Client) DeleteGCS(i *DeleteGCSInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/gcs_test.go b/fastly/gcs_test.go index ae5b436ff..19a0aa6b9 100644 --- a/fastly/gcs_test.go +++ b/fastly/gcs_test.go @@ -110,25 +110,25 @@ func TestClient_GCSs(t *testing.T) { // Ensure deleted defer func() { record(t, "gcses/cleanup", func(c *Client) { - c.DeleteGCS(&DeleteGCSInput{ + _ = c.DeleteGCS(&DeleteGCSInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-gcs", }) - c.DeleteGCS(&DeleteGCSInput{ + _ = c.DeleteGCS(&DeleteGCSInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-gcs-2", }) - c.DeleteGCS(&DeleteGCSInput{ + _ = c.DeleteGCS(&DeleteGCSInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-gcs-3", }) - c.DeleteGCS(&DeleteGCSInput{ + _ = c.DeleteGCS(&DeleteGCSInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "new-test-gcs", diff --git a/fastly/gzip.go b/fastly/gzip.go index 24382e9fb..a0daf08a1 100644 --- a/fastly/gzip.go +++ b/fastly/gzip.go @@ -23,9 +23,17 @@ type Gzip struct { // gzipsByName is a sortable list of gzips. type gzipsByName []*Gzip -// Len, Swap, and Less implement the sortable interface. -func (s gzipsByName) Len() int { return len(s) } -func (s gzipsByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s gzipsByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s gzipsByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s gzipsByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -38,7 +46,7 @@ type ListGzipsInput struct { ServiceVersion int } -// ListGzips returns the list of gzips for the configuration version. +// ListGzips retrieves all resources. func (c *Client) ListGzips(i *ListGzipsInput) ([]*Gzip, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -65,17 +73,21 @@ func (c *Client) ListGzips(i *ListGzipsInput) ([]*Gzip, error) { // CreateGzipInput is used as input to the CreateGzip function. type CreateGzipInput struct { + // CacheCondition is the name of the cache condition controlling when this configuration applies. CacheCondition string `url:"cache_condition,omitempty"` - ContentTypes string `url:"content_types,omitempty"` - Extensions string `url:"extensions,omitempty"` - Name string `url:"name,omitempty"` + // ContentTypes is a space-separated list of content types to compress. + ContentTypes string `url:"content_types,omitempty"` + // Extensions is a space-separated list of file extensions to compress. + Extensions string `url:"extensions,omitempty"` + // Name is the name of the gzip configuration. + Name string `url:"name,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int } -// CreateGzip creates a new Fastly Gzip. +// CreateGzip creates a new resource. func (c *Client) CreateGzip(i *CreateGzipInput) (*Gzip, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -109,7 +121,7 @@ type GetGzipInput struct { ServiceVersion int } -// GetGzip gets the Gzip configuration with the given parameters. +// GetGzip retrieves the specified resource. func (c *Client) GetGzip(i *GetGzipInput) (*Gzip, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -139,11 +151,15 @@ func (c *Client) GetGzip(i *GetGzipInput) (*Gzip, error) { // UpdateGzipInput is used as input to the UpdateGzip function. type UpdateGzipInput struct { + // CacheCondition is the name of the cache condition controlling when this configuration applies. CacheCondition *string `url:"cache_condition,omitempty"` - ContentTypes *string `url:"content_types,omitempty"` - Extensions *string `url:"extensions,omitempty"` + // ContentTypes is a space-separated list of content types to compress. + ContentTypes *string `url:"content_types,omitempty"` + // Extensions is a space-separated list of file extensions to compress. + Extensions *string `url:"extensions,omitempty"` // Name is the name of the Gzip to update. - Name string + Name string + // NewName is the new name for the resource. NewName *string `url:"name,omitempty"` // ServiceID is the ID of the service (required). ServiceID string @@ -151,7 +167,7 @@ type UpdateGzipInput struct { ServiceVersion int } -// UpdateGzip updates a specific Gzip. +// UpdateGzip updates the specified resource. func (c *Client) UpdateGzip(i *UpdateGzipInput) (*Gzip, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -189,7 +205,7 @@ type DeleteGzipInput struct { ServiceVersion int } -// DeleteGzip deletes the given Gzip version. +// DeleteGzip deletes the specified resource. func (c *Client) DeleteGzip(i *DeleteGzipInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/gzip_test.go b/fastly/gzip_test.go index 7297a9a94..d89918dd0 100644 --- a/fastly/gzip_test.go +++ b/fastly/gzip_test.go @@ -51,19 +51,19 @@ func TestClient_Gzips(t *testing.T) { // Ensure deleted defer func() { record(t, "gzips/cleanup", func(c *Client) { - c.DeleteGzip(&DeleteGzipInput{ + _ = c.DeleteGzip(&DeleteGzipInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-gzip", }) - c.DeleteGzip(&DeleteGzipInput{ + _ = c.DeleteGzip(&DeleteGzipInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-gzip-omit", }) - c.DeleteGzip(&DeleteGzipInput{ + _ = c.DeleteGzip(&DeleteGzipInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "new-test-gzip", diff --git a/fastly/header.go b/fastly/header.go index 9ed01693a..94568dba7 100644 --- a/fastly/header.go +++ b/fastly/header.go @@ -86,9 +86,17 @@ type Header struct { // headersByName is a sortable list of headers. type headersByName []*Header -// Len, Swap, and Less implement the sortable interface. -func (s headersByName) Len() int { return len(s) } -func (s headersByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s headersByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s headersByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s headersByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -101,7 +109,7 @@ type ListHeadersInput struct { ServiceVersion int } -// ListHeaders returns the list of headers for the configuration version. +// ListHeaders retrieves all resources. func (c *Client) ListHeaders(i *ListHeadersInput) ([]*Header, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -127,30 +135,41 @@ func (c *Client) ListHeaders(i *ListHeadersInput) ([]*Header, error) { // CreateHeaderInput is used as input to the CreateHeader function. type CreateHeaderInput struct { - Action HeaderAction `url:"action,omitempty"` - CacheCondition string `url:"cache_condition,omitempty"` - Destination string `url:"dst,omitempty"` - IgnoreIfSet Compatibool `url:"ignore_if_set,omitempty"` - Name string `url:"name,omitempty"` - Priority *uint `url:"priority,omitempty"` - Regex string `url:"regex,omitempty"` - RequestCondition string `url:"request_condition,omitempty"` - ResponseCondition string `url:"response_condition,omitempty"` + // Action accepts a string value (set, append, delete, regex, regex_repeat). + Action HeaderAction `url:"action,omitempty"` + // CacheCondition is the name of the cache condition controlling when this configuration applies. + CacheCondition string `url:"cache_condition,omitempty"` + // Destination is the header to set. + Destination string `url:"dst,omitempty"` + // IgnoreIfSet prevents adding the header if it is added already. Only applies to 'set' action. + IgnoreIfSet Compatibool `url:"ignore_if_set,omitempty"` + // Name is a handle to refer to this Header object. + Name string `url:"name,omitempty"` + // Priority determines execution order. Lower numbers execute first. + Priority *uint `url:"priority,omitempty"` + // Regex is the regular expression to use. Only applies to regex and regex_repeat actions. + Regex string `url:"regex,omitempty"` + // RequestCondition is the condition which, if met, will select this configuration during a request. + RequestCondition string `url:"request_condition,omitempty"` + // ResponseCondition is an optional name of a response condition to apply. + ResponseCondition string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - Source string `url:"src,omitempty"` - Substitution string `url:"substitution,omitempty"` - Type HeaderType `url:"type,omitempty"` + // Source is a variable to be used as a source for the header content. Does not apply to delete action. + Source string `url:"src,omitempty"` + // Substitution is a value to substitute in place of regular expression. Only applies to regex and regex_repeat actions. + Substitution string `url:"substitution,omitempty"` + // Type is a type of header (request, cache, response). + Type HeaderType `url:"type,omitempty"` } -// CreateHeader creates a new Fastly header. +// CreateHeader creates a new resource. func (c *Client) CreateHeader(i *CreateHeaderInput) (*Header, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID } - if i.ServiceVersion == 0 { return nil, ErrMissingServiceVersion } @@ -179,16 +198,14 @@ type GetHeaderInput struct { ServiceVersion int } -// GetHeader gets the header configuration with the given parameters. +// GetHeader retrieves the specified resource. func (c *Client) GetHeader(i *GetHeaderInput) (*Header, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID } - if i.ServiceVersion == 0 { return nil, ErrMissingServiceVersion } - if i.Name == "" { return nil, ErrMissingName } @@ -209,36 +226,46 @@ func (c *Client) GetHeader(i *GetHeaderInput) (*Header, error) { // UpdateHeaderInput is used as input to the UpdateHeader function. type UpdateHeaderInput struct { - Action *HeaderAction `url:"action,omitempty"` - CacheCondition *string `url:"cache_condition,omitempty"` - Destination *string `url:"dst,omitempty"` - IgnoreIfSet *Compatibool `url:"ignore_if_set,omitempty"` + // Action accepts a string value (set, append, delete, regex, regex_repeat). + Action *HeaderAction `url:"action,omitempty"` + // CacheCondition is the name of the cache condition controlling when this configuration applies. + CacheCondition *string `url:"cache_condition,omitempty"` + // Destination is the header to set. + Destination *string `url:"dst,omitempty"` + // IgnoreIfSet prevents adding the header if it is added already. Only applies to 'set' action. + IgnoreIfSet *Compatibool `url:"ignore_if_set,omitempty"` // Name is the name of the header to update. - Name string - NewName *string `url:"name,omitempty"` - Priority *uint `url:"priority,omitempty"` - Regex *string `url:"regex,omitempty"` - RequestCondition *string `url:"request_condition,omitempty"` + Name string + // NewName is the new name for the resource. + NewName *string `url:"name,omitempty"` + // Priority determines execution order. Lower numbers execute first. + Priority *uint `url:"priority,omitempty"` + // Regex is the regular expression to use. Only applies to regex and regex_repeat actions. + Regex *string `url:"regex,omitempty"` + // RequestCondition is the condition which, if met, will select this configuration during a request. + RequestCondition *string `url:"request_condition,omitempty"` + // ResponseCondition is an optional name of a response condition to apply. ResponseCondition *string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - Source *string `url:"src,omitempty"` - Substitution *string `url:"substitution,omitempty"` - Type *HeaderType `url:"type,omitempty"` + // Source is a variable to be used as a source for the header content. Does not apply to delete action. + Source *string `url:"src,omitempty"` + // Substitution is a value to substitute in place of regular expression. Only applies to regex and regex_repeat actions. + Substitution *string `url:"substitution,omitempty"` + // Type is a type of header (request, cache, response). + Type *HeaderType `url:"type,omitempty"` } -// UpdateHeader updates a specific header. +// UpdateHeader updates the specified resource. func (c *Client) UpdateHeader(i *UpdateHeaderInput) (*Header, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID } - if i.ServiceVersion == 0 { return nil, ErrMissingServiceVersion } - if i.Name == "" { return nil, ErrMissingName } @@ -267,16 +294,14 @@ type DeleteHeaderInput struct { ServiceVersion int } -// DeleteHeader deletes the given header version. +// DeleteHeader deletes the specified resource. func (c *Client) DeleteHeader(i *DeleteHeaderInput) error { if i.ServiceID == "" { return ErrMissingServiceID } - if i.ServiceVersion == 0 { return ErrMissingServiceVersion } - if i.Name == "" { return ErrMissingName } diff --git a/fastly/header_test.go b/fastly/header_test.go index d8400058b..4248351c1 100644 --- a/fastly/header_test.go +++ b/fastly/header_test.go @@ -37,13 +37,13 @@ func TestClient_Headers(t *testing.T) { // Ensure deleted defer func() { record(t, "headers/cleanup", func(c *Client) { - c.DeleteHeader(&DeleteHeaderInput{ + _ = c.DeleteHeader(&DeleteHeaderInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-header", }) - c.DeleteHeader(&DeleteHeaderInput{ + _ = c.DeleteHeader(&DeleteHeaderInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "new-test-header", @@ -57,7 +57,7 @@ func TestClient_Headers(t *testing.T) { if h.Action != HeaderActionSet { t.Errorf("bad header_action_set: %q", h.Action) } - if h.IgnoreIfSet != false { + if h.IgnoreIfSet { t.Errorf("bad ignore_if_set: %t", h.IgnoreIfSet) } if h.Type != HeaderTypeRequest { diff --git a/fastly/health_check.go b/fastly/health_check.go index f2c6a2d0c..02ef9a117 100644 --- a/fastly/health_check.go +++ b/fastly/health_check.go @@ -32,9 +32,17 @@ type HealthCheck struct { // healthChecksByName is a sortable list of health checks. type healthChecksByName []*HealthCheck -// Len, Swap, and Less implement the sortable interface. -func (s healthChecksByName) Len() int { return len(s) } -func (s healthChecksByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s healthChecksByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s healthChecksByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s healthChecksByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -47,8 +55,7 @@ type ListHealthChecksInput struct { ServiceVersion int } -// ListHealthChecks returns the list of health checks for the configuration -// version. +// ListHealthChecks retrieves all resources. func (c *Client) ListHealthChecks(i *ListHealthChecksInput) ([]*HealthCheck, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -74,31 +81,43 @@ func (c *Client) ListHealthChecks(i *ListHealthChecksInput) ([]*HealthCheck, err // CreateHealthCheckInput is used as input to the CreateHealthCheck function. type CreateHealthCheckInput struct { - CheckInterval *uint `url:"check_interval,omitempty"` - Comment string `url:"comment,omitempty"` - ExpectedResponse *uint `url:"expected_response,omitempty"` - HTTPVersion string `url:"http_version,omitempty"` - Headers []string `url:"headers,omitempty"` - Host string `url:"host,omitempty"` - Initial *uint `url:"initial,omitempty"` - Method string `url:"method,omitempty"` - Name string `url:"name,omitempty"` - Path string `url:"path,omitempty"` + // CheckInterval is how often to run the health check in milliseconds. + CheckInterval *uint `url:"check_interval,omitempty"` + // Comment is a freeform descriptive note. + Comment string `url:"comment,omitempty"` + // ExpectedResponse is the status code expected from the host. + ExpectedResponse *uint `url:"expected_response,omitempty"` + // HTTPVersion is whether to use version 1.0 or 1.1 HTTP. + HTTPVersion string `url:"http_version,omitempty"` + // Headers is an array of custom headers that will be added to the health check probes. + Headers []string `url:"headers,omitempty"` + // Host is which host to check. + Host string `url:"host,omitempty"` + // Initial is when loading a config, the initial number of probes to be seen as OK. + Initial *uint `url:"initial,omitempty"` + // Method is which HTTP method to use. + Method string `url:"method,omitempty"` + // Name is the name of the health check. + Name string `url:"name,omitempty"` + // Path is the path to check. + Path string `url:"path,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - Threshold *uint `url:"threshold,omitempty"` - Timeout *uint `url:"timeout,omitempty"` - Window *uint `url:"window,omitempty"` + // Threshold is how many health checks must succeed to be considered healthy. + Threshold *uint `url:"threshold,omitempty"` + // Timeout is timeout in milliseconds. + Timeout *uint `url:"timeout,omitempty"` + // Window is the number of most recent health check queries to keep for this health check. + Window *uint `url:"window,omitempty"` } -// CreateHealthCheck creates a new Fastly health check. +// CreateHealthCheck creates a new resource. func (c *Client) CreateHealthCheck(i *CreateHealthCheckInput) (*HealthCheck, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID } - if i.ServiceVersion == 0 { return nil, ErrMissingServiceVersion } @@ -130,16 +149,14 @@ type GetHealthCheckInput struct { ServiceVersion int } -// GetHealthCheck gets the health check configuration with the given parameters. +// GetHealthCheck retrieves the specified resource. func (c *Client) GetHealthCheck(i *GetHealthCheckInput) (*HealthCheck, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID } - if i.ServiceVersion == 0 { return nil, ErrMissingServiceVersion } - if i.Name == "" { return nil, ErrMissingName } @@ -160,37 +177,48 @@ func (c *Client) GetHealthCheck(i *GetHealthCheckInput) (*HealthCheck, error) { // UpdateHealthCheckInput is used as input to the UpdateHealthCheck function. type UpdateHealthCheckInput struct { - CheckInterval *uint `url:"check_interval,omitempty"` - Comment *string `url:"comment,omitempty"` - ExpectedResponse *uint `url:"expected_response,omitempty"` - HTTPVersion *string `url:"http_version,omitempty"` - Headers *[]string `url:"headers,omitempty"` - Host *string `url:"host,omitempty"` - Initial *uint `url:"initial,omitempty"` - Method *string `url:"method,omitempty"` + // CheckInterval is how often to run the health check in milliseconds. + CheckInterval *uint `url:"check_interval,omitempty"` + // Comment is a freeform descriptive note. + Comment *string `url:"comment,omitempty"` + // ExpectedResponse is the status code expected from the host. + ExpectedResponse *uint `url:"expected_response,omitempty"` + // HTTPVersion is whether to use version 1.0 or 1.1 HTTP. + HTTPVersion *string `url:"http_version,omitempty"` + // Headers is an array of custom headers that will be added to the health check probes. + Headers *[]string `url:"headers,omitempty"` + // Host is which host to check. + Host *string `url:"host,omitempty"` + // Initial is when loading a config, the initial number of probes to be seen as OK. + Initial *uint `url:"initial,omitempty"` + // Method is which HTTP method to use. + Method *string `url:"method,omitempty"` // Name is the name of the health check to update. - Name string + Name string + // NewName is the new name for the resource. NewName *string `url:"name,omitempty"` - Path *string `url:"path,omitempty"` + // Path is the path to check. + Path *string `url:"path,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - Threshold *uint `url:"threshold,omitempty"` - Timeout *uint `url:"timeout,omitempty"` - Window *uint `url:"window,omitempty"` + // Threshold is how many health checks must succeed to be considered healthy. + Threshold *uint `url:"threshold,omitempty"` + // Timeout is timeout in milliseconds. + Timeout *uint `url:"timeout,omitempty"` + // Window is the number of most recent health check queries to keep for this health check. + Window *uint `url:"window,omitempty"` } -// UpdateHealthCheck updates a specific health check. +// UpdateHealthCheck updates the specified resource. func (c *Client) UpdateHealthCheck(i *UpdateHealthCheckInput) (*HealthCheck, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID } - if i.ServiceVersion == 0 { return nil, ErrMissingServiceVersion } - if i.Name == "" { return nil, ErrMissingName } @@ -222,7 +250,7 @@ type DeleteHealthCheckInput struct { ServiceVersion int } -// DeleteHealthCheck deletes the given health check. +// DeleteHealthCheck deletes the specified resource. func (c *Client) DeleteHealthCheck(i *DeleteHealthCheckInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/health_check_test.go b/fastly/health_check_test.go index a7b410c12..063e65f45 100644 --- a/fastly/health_check_test.go +++ b/fastly/health_check_test.go @@ -43,13 +43,13 @@ func TestClient_HealthChecks(t *testing.T) { // Ensure deleted defer func() { record(t, "health_checks/cleanup", func(c *Client) { - c.DeleteHealthCheck(&DeleteHealthCheckInput{ + _ = c.DeleteHealthCheck(&DeleteHealthCheckInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-healthcheck", }) - c.DeleteHealthCheck(&DeleteHealthCheckInput{ + _ = c.DeleteHealthCheck(&DeleteHealthCheckInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "new-test-healthcheck", diff --git a/fastly/heroku.go b/fastly/heroku.go index 32ee2573a..9750683ae 100644 --- a/fastly/heroku.go +++ b/fastly/heroku.go @@ -26,9 +26,17 @@ type Heroku struct { // herokusByName is a sortable list of herokus. type herokusByName []*Heroku -// Len, Swap, and Less implement the sortable interface. -func (h herokusByName) Len() int { return len(h) } -func (h herokusByName) Swap(i, j int) { h[i], h[j] = h[j], h[i] } +// Len implement the sortable interface. +func (h herokusByName) Len() int { + return len(h) +} + +// Swap implement the sortable interface. +func (h herokusByName) Swap(i, j int) { + h[i], h[j] = h[j], h[i] +} + +// Less implement the sortable interface. func (h herokusByName) Less(i, j int) bool { return h[i].Name < h[j].Name } @@ -41,7 +49,7 @@ type ListHerokusInput struct { ServiceVersion int } -// ListHerokus returns the list of herokus for the configuration version. +// ListHerokus retrieves all resources. func (c *Client) ListHerokus(i *ListHerokusInput) ([]*Heroku, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -67,25 +75,31 @@ func (c *Client) ListHerokus(i *ListHerokusInput) ([]*Heroku, error) { // CreateHerokuInput is used as input to the CreateHeroku function. type CreateHerokuInput struct { - Format string `url:"format,omitempty"` - FormatVersion uint `url:"format_version,omitempty"` - Name string `url:"name,omitempty"` - Placement string `url:"placement,omitempty"` + // Format is a fastly log format string. + Format string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion uint `url:"format_version,omitempty"` + // Name is the name for the real-time logging configuration. + Name string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement string `url:"placement,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - Token string `url:"token,omitempty"` - URL string `url:"url,omitempty"` + // Token is the token to use for authentication. + Token string `url:"token,omitempty"` + // URL is the URL to stream logs to. + URL string `url:"url,omitempty"` } -// CreateHeroku creates a new Fastly heroku. +// CreateHeroku creates a new resource. func (c *Client) CreateHeroku(i *CreateHerokuInput) (*Heroku, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID } - if i.ServiceVersion == 0 { return nil, ErrMissingServiceVersion } @@ -114,16 +128,14 @@ type GetHerokuInput struct { ServiceVersion int } -// GetHeroku gets the heroku configuration with the given parameters. +// GetHeroku retrieves the specified resource. func (c *Client) GetHeroku(i *GetHerokuInput) (*Heroku, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID } - if i.ServiceVersion == 0 { return nil, ErrMissingServiceVersion } - if i.Name == "" { return nil, ErrMissingName } @@ -144,31 +156,36 @@ func (c *Client) GetHeroku(i *GetHerokuInput) (*Heroku, error) { // UpdateHerokuInput is used as input to the UpdateHeroku function. type UpdateHerokuInput struct { - Format *string `url:"format,omitempty"` - FormatVersion *uint `url:"format_version,omitempty"` + // Format is a fastly log format string. + Format *string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion *uint `url:"format_version,omitempty"` // Name is the name of the heroku to update. - Name string - NewName *string `url:"name,omitempty"` - Placement *string `url:"placement,omitempty"` + Name string + // NewName is the new name for the resource. + NewName *string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement *string `url:"placement,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition *string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - Token *string `url:"token,omitempty"` - URL *string `url:"url,omitempty"` + // Token is the token to use for authentication. + Token *string `url:"token,omitempty"` + // URL is the URL to stream logs to. + URL *string `url:"url,omitempty"` } -// UpdateHeroku updates a specific heroku. +// UpdateHeroku updates the specified resource. func (c *Client) UpdateHeroku(i *UpdateHerokuInput) (*Heroku, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID } - if i.ServiceVersion == 0 { return nil, ErrMissingServiceVersion } - if i.Name == "" { return nil, ErrMissingName } @@ -197,16 +214,14 @@ type DeleteHerokuInput struct { ServiceVersion int } -// DeleteHeroku deletes the given heroku version. +// DeleteHeroku deletes the specified resource. func (c *Client) DeleteHeroku(i *DeleteHerokuInput) error { if i.ServiceID == "" { return ErrMissingServiceID } - if i.ServiceVersion == 0 { return ErrMissingServiceVersion } - if i.Name == "" { return ErrMissingName } diff --git a/fastly/heroku_test.go b/fastly/heroku_test.go index 7085e4a03..f13a53188 100644 --- a/fastly/heroku_test.go +++ b/fastly/heroku_test.go @@ -34,13 +34,13 @@ func TestClient_Herokus(t *testing.T) { // Ensure deleted defer func() { record(t, "herokus/cleanup", func(c *Client) { - c.DeleteHeroku(&DeleteHerokuInput{ + _ = c.DeleteHeroku(&DeleteHerokuInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-heroku", }) - c.DeleteHeroku(&DeleteHerokuInput{ + _ = c.DeleteHeroku(&DeleteHerokuInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "new-test-heroku", diff --git a/fastly/honeycomb.go b/fastly/honeycomb.go index cdccdf38e..b5fd5ea30 100644 --- a/fastly/honeycomb.go +++ b/fastly/honeycomb.go @@ -26,9 +26,17 @@ type Honeycomb struct { // honeycombsByName is a sortable list of honeycombs. type honeycombsByName []*Honeycomb -// Len, Swap, and Less implement the sortable interface. -func (h honeycombsByName) Len() int { return len(h) } -func (h honeycombsByName) Swap(i, j int) { h[i], h[j] = h[j], h[i] } +// Len implement the sortable interface. +func (h honeycombsByName) Len() int { + return len(h) +} + +// Swap implement the sortable interface. +func (h honeycombsByName) Swap(i, j int) { + h[i], h[j] = h[j], h[i] +} + +// Less implement the sortable interface. func (h honeycombsByName) Less(i, j int) bool { return h[i].Name < h[j].Name } @@ -41,7 +49,7 @@ type ListHoneycombsInput struct { ServiceVersion int } -// ListHoneycombs returns the list of honeycombs for the configuration version. +// ListHoneycombs retrieves all resources. func (c *Client) ListHoneycombs(i *ListHoneycombsInput) ([]*Honeycomb, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -68,29 +76,34 @@ func (c *Client) ListHoneycombs(i *ListHoneycombsInput) ([]*Honeycomb, error) { // CreateHoneycombInput is used as input to the CreateHoneycomb function. type CreateHoneycombInput struct { - Dataset string `url:"dataset,omitempty"` - Format string `url:"format,omitempty"` - FormatVersion uint `url:"format_version,omitempty"` - Name string `url:"name,omitempty"` - Placement string `url:"placement,omitempty"` + // Dataset is the Honeycomb Dataset you want to log to. + Dataset string `url:"dataset,omitempty"` + // Format is a Fastly log format string. Must produce valid JSON that Honeycomb can ingest. + Format string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion uint `url:"format_version,omitempty"` + // Name is the name for the real-time logging configuration. + Name string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement string `url:"placement,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - Token string `url:"token,omitempty"` + // Token is the Write Key from the Account page of your Honeycomb account. + Token string `url:"token,omitempty"` } -// CreateHoneycomb creates a new Fastly honeycomb. +// CreateHoneycomb creates a new resource. func (c *Client) CreateHoneycomb(i *CreateHoneycombInput) (*Honeycomb, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID } - if i.ServiceVersion == 0 { return nil, ErrMissingServiceVersion } - if i.Token == "" { return nil, ErrMissingToken } @@ -111,7 +124,7 @@ func (c *Client) CreateHoneycomb(i *CreateHoneycombInput) (*Honeycomb, error) { // GetHoneycombInput is used as input to the GetHoneycomb function. type GetHoneycombInput struct { - // Name is the name of the honeycomb to fetch. + // Name is the name for the real-time logging configuration. Name string // ServiceID is the ID of the service (required). ServiceID string @@ -119,16 +132,14 @@ type GetHoneycombInput struct { ServiceVersion int } -// GetHoneycomb gets the honeycomb configuration with the given parameters. +// GetHoneycomb retrieves the specified resource. func (c *Client) GetHoneycomb(i *GetHoneycombInput) (*Honeycomb, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID } - if i.ServiceVersion == 0 { return nil, ErrMissingServiceVersion } - if i.Name == "" { return nil, ErrMissingName } @@ -149,35 +160,39 @@ func (c *Client) GetHoneycomb(i *GetHoneycombInput) (*Honeycomb, error) { // UpdateHoneycombInput is used as input to the UpdateHoneycomb function. type UpdateHoneycombInput struct { - Dataset *string `url:"dataset,omitempty"` - Format *string `url:"format,omitempty"` - FormatVersion *uint `url:"format_version,omitempty"` + // Dataset is the Honeycomb Dataset you want to log to. + Dataset *string `url:"dataset,omitempty"` + // Format is a Fastly log format string. Must produce valid JSON that Honeycomb can ingest. + Format *string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion *uint `url:"format_version,omitempty"` // Name is the name of the honeycomb to update. - Name string - NewName *string `url:"name,omitempty"` - Placement *string `url:"placement,omitempty"` + Name string + // NewName is the new name for the resource. + NewName *string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement *string `url:"placement,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition *string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - Token *string `url:"token,omitempty"` + // Token is the Write Key from the Account page of your Honeycomb account. + Token *string `url:"token,omitempty"` } -// UpdateHoneycomb updates a specific honeycomb. +// UpdateHoneycomb updates the specified resource. func (c *Client) UpdateHoneycomb(i *UpdateHoneycombInput) (*Honeycomb, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID } - if i.ServiceVersion == 0 { return nil, ErrMissingServiceVersion } - if i.Name == "" { return nil, ErrMissingName } - if i.Token != nil && *i.Token == "" { return nil, ErrTokenEmpty } @@ -206,16 +221,14 @@ type DeleteHoneycombInput struct { ServiceVersion int } -// DeleteHoneycomb deletes the given honeycomb version. +// DeleteHoneycomb deletes the specified resource. func (c *Client) DeleteHoneycomb(i *DeleteHoneycombInput) error { if i.ServiceID == "" { return ErrMissingServiceID } - if i.ServiceVersion == 0 { return ErrMissingServiceVersion } - if i.Name == "" { return ErrMissingName } diff --git a/fastly/honeycomb_test.go b/fastly/honeycomb_test.go index eb123e3bd..a31c2110f 100644 --- a/fastly/honeycomb_test.go +++ b/fastly/honeycomb_test.go @@ -34,13 +34,13 @@ func TestClient_Honeycombs(t *testing.T) { // Ensure deleted defer func() { record(t, "honeycombs/cleanup", func(c *Client) { - c.DeleteHoneycomb(&DeleteHoneycombInput{ + _ = c.DeleteHoneycomb(&DeleteHoneycombInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-honeycomb", }) - c.DeleteHoneycomb(&DeleteHoneycombInput{ + _ = c.DeleteHoneycomb(&DeleteHoneycombInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "new-test-honeycomb", diff --git a/fastly/https.go b/fastly/https.go index 6284ea0ba..d2be0b5b5 100644 --- a/fastly/https.go +++ b/fastly/https.go @@ -37,9 +37,17 @@ type HTTPS struct { // httpsByName is a sortable list of HTTPS logs. type httpsByName []*HTTPS -// Len, Swap, and Less implement the sortable interface. -func (s httpsByName) Len() int { return len(s) } -func (s httpsByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s httpsByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s httpsByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s httpsByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -52,12 +60,11 @@ type ListHTTPSInput struct { ServiceVersion int } -// ListHTTPS returns the list of HTTPS logs for the configuration version. +// ListHTTPS retrieves all resources. func (c *Client) ListHTTPS(i *ListHTTPSInput) ([]*HTTPS, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID } - if i.ServiceVersion == 0 { return nil, ErrMissingServiceVersion } @@ -79,36 +86,53 @@ func (c *Client) ListHTTPS(i *ListHTTPSInput) ([]*HTTPS, error) { // CreateHTTPSInput is used as input to the CreateHTTPS function. type CreateHTTPSInput struct { - ContentType string `url:"content_type,omitempty"` - Format string `url:"format,omitempty"` - FormatVersion uint `url:"format_version,omitempty"` - HeaderName string `url:"header_name,omitempty"` - HeaderValue string `url:"header_value,omitempty"` - JSONFormat string `url:"json_format,omitempty"` - MessageType string `url:"message_type,omitempty"` - Method string `url:"method,omitempty"` - Name string `url:"name,omitempty"` - Placement string `url:"placement,omitempty"` - RequestMaxBytes uint `url:"request_max_bytes,omitempty"` - RequestMaxEntries uint `url:"request_max_entries,omitempty"` + // ContentType is the content type of the header sent with the request. + ContentType string `url:"content_type,omitempty"` + // Format is a Fastly log format string. + Format string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion uint `url:"format_version,omitempty"` + // HeaderName is the name of the custom header sent with the request. + HeaderName string `url:"header_name,omitempty"` + // HeaderValue is the value of the custom header sent with the request. + HeaderValue string `url:"header_value,omitempty"` + // JSONFormat enforces valid JSON formatting for log entries (0: disabled, 1: array of JSON, 2: newline delimited JSON). + JSONFormat string `url:"json_format,omitempty"` + // MessageType is how the message should be formatted (classic, loggly, logplex, blank). + MessageType string `url:"message_type,omitempty"` + // Method is the HTTP method used for request (POST, PUT). + Method string `url:"method,omitempty"` + // Name is the name for the real-time logging configuration. + Name string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement string `url:"placement,omitempty"` + // RequestMaxBytes is the maximum number of bytes sent in one request. Defaults 0 (100MB). + RequestMaxBytes uint `url:"request_max_bytes,omitempty"` + // RequestMaxEntries is the maximum number of logs sent in one request. Defaults 0 (10k). + RequestMaxEntries uint `url:"request_max_entries,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - TLSCACert string `url:"tls_ca_cert,omitempty"` - TLSClientCert string `url:"tls_client_cert,omitempty"` - TLSClientKey string `url:"tls_client_key,omitempty"` - TLSHostname string `url:"tls_hostname,omitempty"` - URL string `url:"url,omitempty"` + // TLSCACert is a secure certificate to authenticate a server with. Must be in PEM format. + TLSCACert string `url:"tls_ca_cert,omitempty"` + // TLSClientCert is the client certificate used to make authenticated requests. Must be in PEM format. + TLSClientCert string `url:"tls_client_cert,omitempty"` + // TLSClientKey is the client private key used to make authenticated requests. Must be in PEM format. + TLSClientKey string `url:"tls_client_key,omitempty"` + // TLSHostname is the hostname to verify the server's certificate. This should be one of the Subject Alternative Name (SAN) fields for the certificate. Common Names (CN) are not supported. + TLSHostname string `url:"tls_hostname,omitempty"` + // URL is the URL to send logs to. Must use HTTPS + URL string `url:"url,omitempty"` } -// CreateHTTPS creates a new Fastly HTTPS logging endpoint. +// CreateHTTPS creates a new resource. func (c *Client) CreateHTTPS(i *CreateHTTPSInput) (*HTTPS, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID } - if i.ServiceVersion == 0 { return nil, ErrMissingServiceVersion } @@ -137,15 +161,14 @@ type GetHTTPSInput struct { ServiceVersion int } +// GetHTTPS retrieves the specified resource. func (c *Client) GetHTTPS(i *GetHTTPSInput) (*HTTPS, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID } - if i.ServiceVersion == 0 { return nil, ErrMissingServiceVersion } - if i.Name == "" { return nil, ErrMissingName } @@ -165,42 +188,60 @@ func (c *Client) GetHTTPS(i *GetHTTPSInput) (*HTTPS, error) { return h, nil } +// UpdateHTTPSInput is the input parameter to the UpdateHTTPS function. type UpdateHTTPSInput struct { - ContentType *string `url:"content_type,omitempty"` - Format *string `url:"format,omitempty"` - FormatVersion *uint `url:"format_version,omitempty"` - HeaderName *string `url:"header_name,omitempty"` - HeaderValue *string `url:"header_value,omitempty"` - JSONFormat *string `url:"json_format,omitempty"` - MessageType *string `url:"message_type,omitempty"` - Method *string `url:"method,omitempty"` + // ContentType is the content type of the header sent with the request. + ContentType *string `url:"content_type,omitempty"` + // Format is a Fastly log format string. + Format *string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion *uint `url:"format_version,omitempty"` + // HeaderName is the name of the custom header sent with the request. + HeaderName *string `url:"header_name,omitempty"` + // HeaderValue is the value of the custom header sent with the request. + HeaderValue *string `url:"header_value,omitempty"` + // JSONFormat enforces valid JSON formatting for log entries (0: disabled, 1: array of JSON, 2: newline delimited JSON). + JSONFormat *string `url:"json_format,omitempty"` + // MessageType is how the message should be formatted (classic, loggly, logplex, blank). + MessageType *string `url:"message_type,omitempty"` + // Method is the HTTP method used for request (POST, PUT). + Method *string `url:"method,omitempty"` // Name is the name of the HTTPS endpoint to fetch. - Name string - NewName *string `url:"name,omitempty"` - Placement *string `url:"placement,omitempty"` - RequestMaxBytes *uint `url:"request_max_bytes,omitempty"` - RequestMaxEntries *uint `url:"request_max_entries,omitempty"` + Name string + // NewName is the new name for the resource. + NewName *string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement *string `url:"placement,omitempty"` + // RequestMaxBytes is the maximum number of bytes sent in one request. Defaults 0 (100MB). + RequestMaxBytes *uint `url:"request_max_bytes,omitempty"` + // RequestMaxEntries is the maximum number of logs sent in one request. Defaults 0 (10k). + RequestMaxEntries *uint `url:"request_max_entries,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition *string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - TLSCACert *string `url:"tls_ca_cert,omitempty"` - TLSClientCert *string `url:"tls_client_cert,omitempty"` - TLSClientKey *string `url:"tls_client_key,omitempty"` - TLSHostname *string `url:"tls_hostname,omitempty"` - URL *string `url:"url,omitempty"` + // TLSCACert is a secure certificate to authenticate a server with. Must be in PEM format. + TLSCACert *string `url:"tls_ca_cert,omitempty"` + // TLSClientCert is the client certificate used to make authenticated requests. Must be in PEM format. + TLSClientCert *string `url:"tls_client_cert,omitempty"` + // TLSClientKey is the client private key used to make authenticated requests. Must be in PEM format. + TLSClientKey *string `url:"tls_client_key,omitempty"` + // TLSHostname is the hostname to verify the server's certificate. This should be one of the Subject Alternative Name (SAN) fields for the certificate. Common Names (CN) are not supported. + TLSHostname *string `url:"tls_hostname,omitempty"` + // URL is the URL to send logs to. Must use HTTPS + URL *string `url:"url,omitempty"` } +// UpdateHTTPS updates the specified resource. func (c *Client) UpdateHTTPS(i *UpdateHTTPSInput) (*HTTPS, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID } - if i.ServiceVersion == 0 { return nil, ErrMissingServiceVersion } - if i.Name == "" { return nil, ErrMissingName } @@ -219,6 +260,7 @@ func (c *Client) UpdateHTTPS(i *UpdateHTTPSInput) (*HTTPS, error) { return h, nil } +// DeleteHTTPSInput is the input parameter to the DeleteHTTPS function. type DeleteHTTPSInput struct { // Name is the name of the HTTPS endpoint to fetch. Name string @@ -228,15 +270,14 @@ type DeleteHTTPSInput struct { ServiceVersion int } +// DeleteHTTPS deletes the specified resource. func (c *Client) DeleteHTTPS(i *DeleteHTTPSInput) error { if i.ServiceID == "" { return ErrMissingServiceID } - if i.ServiceVersion == 0 { return ErrMissingServiceVersion } - if i.Name == "" { return ErrMissingName } diff --git a/fastly/https_test.go b/fastly/https_test.go index b742377af..9fc13e7f5 100644 --- a/fastly/https_test.go +++ b/fastly/https_test.go @@ -66,14 +66,14 @@ Wm7DCfrPNGVwFWUQOmsPue9rZBgO // ensure deleted defer func() { record(t, "https/cleanup", func(c *Client) { - c.DeleteHTTPS(&DeleteHTTPSInput{ + _ = c.DeleteHTTPS(&DeleteHTTPSInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-https", }) // ensure that renamed endpoint created in Update test is deleted - c.DeleteHTTPS(&DeleteHTTPSInput{ + _ = c.DeleteHTTPS(&DeleteHTTPSInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "new-test-https", diff --git a/fastly/kafka.go b/fastly/kafka.go index d682dd894..ea1f73a04 100644 --- a/fastly/kafka.go +++ b/fastly/kafka.go @@ -38,9 +38,17 @@ type Kafka struct { // kafkaByName is a sortable list of kafkas. type kafkasByName []*Kafka -// Len, Swap, and Less implement the sortable interface. -func (s kafkasByName) Len() int { return len(s) } -func (s kafkasByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implements the sortable interface. +func (s kafkasByName) Len() int { + return len(s) +} + +// Swap implements the sortable interface. +func (s kafkasByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implements the sortable interface. func (s kafkasByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -53,7 +61,7 @@ type ListKafkasInput struct { ServiceVersion int } -// ListKafkas returns the list of kafkas for the configuration version. +// ListKafkas retrieves all resources. func (c *Client) ListKafkas(i *ListKafkasInput) ([]*Kafka, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -80,32 +88,51 @@ func (c *Client) ListKafkas(i *ListKafkasInput) ([]*Kafka, error) { // CreateKafkaInput is used as input to the CreateKafka function. type CreateKafkaInput struct { - AuthMethod string `url:"auth_method,omitempty"` - Brokers string `url:"brokers,omitempty"` - CompressionCodec string `url:"compression_codec,omitempty"` - Format string `url:"format,omitempty"` - FormatVersion uint `url:"format_version,omitempty"` - Name string `url:"name,omitempty"` - ParseLogKeyvals Compatibool `url:"parse_log_keyvals,omitempty"` - Password string `url:"password,omitempty"` - Placement string `url:"placement,omitempty"` - RequestMaxBytes uint `url:"request_max_bytes,omitempty"` - RequiredACKs string `url:"required_acks,omitempty"` - ResponseCondition string `url:"response_condition,omitempty"` + // AuthMethod is the SASL authentication method (plain, scram-sha-256, scram-sha-512). + AuthMethod string `url:"auth_method,omitempty"` + // Brokers is a comma-separated list of IP addresses or hostnames of Kafka brokers. + Brokers string `url:"brokers,omitempty"` + // CompressionCodec is the codec used for compression of your logs (gzip, snappy, lz4, null). + CompressionCodec string `url:"compression_codec,omitempty"` + // Format is a Fastly log format string. + Format string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion uint `url:"format_version,omitempty"` + // Name is the name for the real-time logging configuration. + Name string `url:"name,omitempty"` + // ParseLogKeyvals enables parsing of key=value tuples from the beginning of a logline, turning them into record headers. + ParseLogKeyvals Compatibool `url:"parse_log_keyvals,omitempty"` + // Password is the SASL password. + Password string `url:"password,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement string `url:"placement,omitempty"` + // RequestMaxBytes is the maximum number of bytes sent in one request. Defaults 0 (no limit). + RequestMaxBytes uint `url:"request_max_bytes,omitempty"` + // RequiredACKs is the number of acknowledgements a leader must receive before a write is considered successful. + RequiredACKs string `url:"required_acks,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. + ResponseCondition string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - TLSCACert string `url:"tls_ca_cert,omitempty"` - TLSClientCert string `url:"tls_client_cert,omitempty"` - TLSClientKey string `url:"tls_client_key,omitempty"` - TLSHostname string `url:"tls_hostname,omitempty"` - Topic string `url:"topic,omitempty"` - UseTLS Compatibool `url:"use_tls,omitempty"` - User string `url:"user,omitempty"` + // TLSCACert is a secure certificate to authenticate a server with. Must be in PEM format. + TLSCACert string `url:"tls_ca_cert,omitempty"` + // TLSClientCert is the client certificate used to make authenticated requests. Must be in PEM format. + TLSClientCert string `url:"tls_client_cert,omitempty"` + // TLSClientKey is the client private key used to make authenticated requests. Must be in PEM format. + TLSClientKey string `url:"tls_client_key,omitempty"` + // TLSHostname is the hostname to verify the server's certificate. This should be one of the Subject Alternative Name (SAN) fields for the certificate. Common Names (CN) are not supported. + TLSHostname string `url:"tls_hostname,omitempty"` + // Topic is the Kafka topic to send logs to. + Topic string `url:"topic,omitempty"` + // UseTLS is whether to use TLS (0: do not use, 1: use). + UseTLS Compatibool `url:"use_tls,omitempty"` + // User is the SASL user. + User string `url:"user,omitempty"` } -// CreateKafka creates a new Fastly kafka. +// CreateKafka creates a new resource. func (c *Client) CreateKafka(i *CreateKafkaInput) (*Kafka, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -139,7 +166,7 @@ type GetKafkaInput struct { ServiceVersion int } -// GetKafka gets the kafka configuration with the given parameters. +// GetKafka retrieves the specified resource. func (c *Client) GetKafka(i *GetKafkaInput) (*Kafka, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -169,34 +196,53 @@ func (c *Client) GetKafka(i *GetKafkaInput) (*Kafka, error) { // UpdateKafkaInput is used as input to the UpdateKafka function. type UpdateKafkaInput struct { - AuthMethod *string `url:"auth_method,omitempty"` - Brokers *string `url:"brokers,omitempty"` + // AuthMethod is the SASL authentication method (plain, scram-sha-256, scram-sha-512). + AuthMethod *string `url:"auth_method,omitempty"` + // Brokers is a comma-separated list of IP addresses or hostnames of Kafka brokers. + Brokers *string `url:"brokers,omitempty"` + // CompressionCodec is the codec used for compression of your logs (gzip, snappy, lz4, null). CompressionCodec *string `url:"compression_codec,omitempty"` - Format *string `url:"format,omitempty"` - FormatVersion *uint `url:"format_version,omitempty"` + // Format is a Fastly log format string. + Format *string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion *uint `url:"format_version,omitempty"` // Name is the name of the kafka to update. - Name string - NewName *string `url:"name,omitempty"` - ParseLogKeyvals *Compatibool `url:"parse_log_keyvals,omitempty"` - Password *string `url:"password,omitempty"` - Placement *string `url:"placement,omitempty"` - RequestMaxBytes *uint `url:"request_max_bytes,omitempty"` - RequiredACKs *string `url:"required_acks,omitempty"` - ResponseCondition *string `url:"response_condition,omitempty"` + Name string + // NewName is the new name for the resource. + NewName *string `url:"name,omitempty"` + // ParseLogKeyvals enables parsing of key=value tuples from the beginning of a logline, turning them into record headers. + ParseLogKeyvals *Compatibool `url:"parse_log_keyvals,omitempty"` + // Password is the SASL password. + Password *string `url:"password,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement *string `url:"placement,omitempty"` + // RequestMaxBytes is the maximum number of bytes sent in one request. Defaults 0 (no limit). + RequestMaxBytes *uint `url:"request_max_bytes,omitempty"` + // RequiredACKs is the number of acknowledgements a leader must receive before a write is considered successful. + RequiredACKs *string `url:"required_acks,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. + ResponseCondition *string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - TLSCACert *string `url:"tls_ca_cert,omitempty"` - TLSClientCert *string `url:"tls_client_cert,omitempty"` - TLSClientKey *string `url:"tls_client_key,omitempty"` - TLSHostname *string `url:"tls_hostname,omitempty"` - Topic *string `url:"topic,omitempty"` - UseTLS *Compatibool `url:"use_tls,omitempty"` - User *string `url:"user,omitempty"` + // TLSCACert is a secure certificate to authenticate a server with. Must be in PEM format. + TLSCACert *string `url:"tls_ca_cert,omitempty"` + // TLSClientCert is the client certificate used to make authenticated requests. Must be in PEM format. + TLSClientCert *string `url:"tls_client_cert,omitempty"` + // TLSClientKey is the client private key used to make authenticated requests. Must be in PEM format. + TLSClientKey *string `url:"tls_client_key,omitempty"` + // TLSHostname is the hostname to verify the server's certificate. This should be one of the Subject Alternative Name (SAN) fields for the certificate. Common Names (CN) are not supported. + TLSHostname *string `url:"tls_hostname,omitempty"` + // Topic is the Kafka topic to send logs to. + Topic *string `url:"topic,omitempty"` + // UseTLS is whether to use TLS (0: do not use, 1: use). + UseTLS *Compatibool `url:"use_tls,omitempty"` + // User is the SASL user. + User *string `url:"user,omitempty"` } -// UpdateKafka updates a specific kafka. +// UpdateKafka updates the specified resource. func (c *Client) UpdateKafka(i *UpdateKafkaInput) (*Kafka, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -234,7 +280,7 @@ type DeleteKafkaInput struct { ServiceVersion int } -// DeleteKafka deletes the given kafka version. +// DeleteKafka deletes the specified resource. func (c *Client) DeleteKafka(i *DeleteKafkaInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/kafka_test.go b/fastly/kafka_test.go index 28e5592f1..be9c5378a 100644 --- a/fastly/kafka_test.go +++ b/fastly/kafka_test.go @@ -53,13 +53,13 @@ func TestClient_Kafkas(t *testing.T) { // Ensure deleted defer func() { record(t, "kafkas/cleanup", func(c *Client) { - c.DeleteKafka(&DeleteKafkaInput{ + _ = c.DeleteKafka(&DeleteKafkaInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-kafka", }) - c.DeleteKafka(&DeleteKafkaInput{ + _ = c.DeleteKafka(&DeleteKafkaInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "new-test-kafka", @@ -79,7 +79,7 @@ func TestClient_Kafkas(t *testing.T) { if k.RequiredACKs != "-1" { t.Errorf("bad required_acks: %q", k.RequiredACKs) } - if k.UseTLS != true { + if !k.UseTLS { t.Errorf("bad use_tls: %t", k.UseTLS) } if k.CompressionCodec != "lz4" { @@ -106,7 +106,7 @@ func TestClient_Kafkas(t *testing.T) { if k.TLSClientKey != clientKey { t.Errorf("bad tls_client_key: %q", k.TLSClientKey) } - if k.ParseLogKeyvals != true { + if !k.ParseLogKeyvals { t.Errorf("bad parse_log_keyvals: %t", k.ParseLogKeyvals) } if k.RequestMaxBytes != requestMaxBytes { @@ -188,7 +188,7 @@ func TestClient_Kafkas(t *testing.T) { if k.TLSClientKey != nk.TLSClientKey { t.Errorf("bad tls_client_key: %q", k.TLSClientKey) } - if k.ParseLogKeyvals != true { + if !k.ParseLogKeyvals { t.Errorf("bad parse_log_keyvals: %t", k.ParseLogKeyvals) } if k.RequestMaxBytes != requestMaxBytes { diff --git a/fastly/kinesis.go b/fastly/kinesis.go index dc6b021e1..53942e642 100644 --- a/fastly/kinesis.go +++ b/fastly/kinesis.go @@ -29,9 +29,17 @@ type Kinesis struct { // kinesisByName is a sortable list of Kinesis. type kinesisByName []*Kinesis -// Len, Swap, and Less implement the sortable interface. -func (s kinesisByName) Len() int { return len(s) } -func (s kinesisByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s kinesisByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s kinesisByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s kinesisByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -44,7 +52,7 @@ type ListKinesisInput struct { ServiceVersion int } -// ListKinesis returns the list of Kinesis for the configuration version. +// ListKinesis retrieves all resources. func (c *Client) ListKinesis(i *ListKinesisInput) ([]*Kinesis, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -71,23 +79,33 @@ func (c *Client) ListKinesis(i *ListKinesisInput) ([]*Kinesis, error) { // CreateKinesisInput is used as input to the CreateKinesis function. type CreateKinesisInput struct { - AccessKey string `url:"access_key,omitempty"` - Format string `url:"format,omitempty"` - FormatVersion uint `url:"format_version,omitempty"` - IAMRole string `url:"iam_role,omitempty"` - Name string `url:"name,omitempty"` - Placement string `url:"placement,omitempty"` - Region string `url:"region,omitempty"` + // AccessKey is the access key associated with the target Amazon Kinesis stream. Not required if iam_role is specified. + AccessKey string `url:"access_key,omitempty"` + // Format is a Fastly log format string. Must produce valid JSON that Kinesis can ingest. + Format string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion uint `url:"format_version,omitempty"` + // IAMRole is the ARN for an IAM role granting Fastly access to the target Amazon Kinesis stream. + IAMRole string `url:"iam_role,omitempty"` + // Name is the name for the real-time logging configuration. + Name string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement string `url:"placement,omitempty"` + // Region is a named set of AWS resources that's in the same geographical area. + Region string `url:"region,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition string `url:"response_condition,omitempty"` - SecretKey string `url:"secret_key,omitempty"` + // SecretKey is the secret key associated with the target Amazon Kinesis stream. Not required if iam_role is specified. + SecretKey string `url:"secret_key,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - StreamName string `url:"topic,omitempty"` + // StreamName is the Amazon Kinesis stream to send logs to. + StreamName string `url:"topic,omitempty"` } -// CreateKinesis creates a new Fastly Kinesis. +// CreateKinesis creates a new resource. func (c *Client) CreateKinesis(i *CreateKinesisInput) (*Kinesis, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -121,7 +139,7 @@ type GetKinesisInput struct { ServiceVersion int } -// GetKinesis gets the Kinesis configuration with the given parameters. +// GetKinesis retrieves the specified resource. func (c *Client) GetKinesis(i *GetKinesisInput) (*Kinesis, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -151,25 +169,35 @@ func (c *Client) GetKinesis(i *GetKinesisInput) (*Kinesis, error) { // UpdateKinesisInput is used as input to the UpdateKinesis function. type UpdateKinesisInput struct { - AccessKey *string `url:"access_key,omitempty"` - Format *string `url:"format,omitempty"` - FormatVersion *uint `url:"format_version,omitempty"` - IAMRole *string `url:"iam_role,omitempty"` + // AccessKey is the access key associated with the target Amazon Kinesis stream. Not required if iam_role is specified. + AccessKey *string `url:"access_key,omitempty"` + // Format is a Fastly log format string. Must produce valid JSON that Kinesis can ingest. + Format *string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion *uint `url:"format_version,omitempty"` + // IAMRole is the ARN for an IAM role granting Fastly access to the target Amazon Kinesis stream. + IAMRole *string `url:"iam_role,omitempty"` // Name is the name of the Kinesis logging object to update (required). - Name string - NewName *string `url:"name,omitempty"` - Placement *string `url:"placement,omitempty"` - Region *string `url:"region,omitempty"` + Name string + // NewName is the new name for the resource. + NewName *string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement *string `url:"placement,omitempty"` + // Region is a named set of AWS resources that's in the same geographical area. + Region *string `url:"region,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition *string `url:"response_condition,omitempty"` - SecretKey *string `url:"secret_key,omitempty"` + // SecretKey is the secret key associated with the target Amazon Kinesis stream. Not required if iam_role is specified. + SecretKey *string `url:"secret_key,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - StreamName *string `url:"topic,omitempty"` + // StreamName is the Amazon Kinesis stream to send logs to. + StreamName *string `url:"topic,omitempty"` } -// UpdateKinesis updates a specific Kinesis. +// UpdateKinesis updates the specified resource. func (c *Client) UpdateKinesis(i *UpdateKinesisInput) (*Kinesis, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -207,7 +235,7 @@ type DeleteKinesisInput struct { ServiceVersion int } -// DeleteKinesis deletes the given Kinesis version. +// DeleteKinesis deletes the specified resource. func (c *Client) DeleteKinesis(i *DeleteKinesisInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/logentries.go b/fastly/logentries.go index 8bb2a7b3a..c1c2cf406 100644 --- a/fastly/logentries.go +++ b/fastly/logentries.go @@ -28,9 +28,17 @@ type Logentries struct { // logentriesByName is a sortable list of logentries. type logentriesByName []*Logentries -// Len, Swap, and Less implement the sortable interface. -func (s logentriesByName) Len() int { return len(s) } -func (s logentriesByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implements the sortable interface. +func (s logentriesByName) Len() int { + return len(s) +} + +// Swap implements the sortable interface. +func (s logentriesByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implements the sortable interface. func (s logentriesByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -43,7 +51,7 @@ type ListLogentriesInput struct { ServiceVersion int } -// ListLogentries returns the list of logentries for the configuration version. +// ListLogentries retrieves all resources. func (c *Client) ListLogentries(i *ListLogentriesInput) ([]*Logentries, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -70,22 +78,31 @@ func (c *Client) ListLogentries(i *ListLogentriesInput) ([]*Logentries, error) { // CreateLogentriesInput is used as input to the CreateLogentries function. type CreateLogentriesInput struct { - Format string `url:"format,omitempty"` - FormatVersion uint `url:"format_version,omitempty"` - Name string `url:"name,omitempty"` - Placement string `url:"placement,omitempty"` - Port uint `url:"port,omitempty"` - Region string `url:"region,omitempty"` + // Format is a Fastly log format string. + Format string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion uint `url:"format_version,omitempty"` + // Name is the name for the real-time logging configuration. + Name string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement string `url:"placement,omitempty"` + // Port is the port number. + Port uint `url:"port,omitempty"` + // Region is the region to which to stream logs. + Region string `url:"region,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - Token string `url:"token,omitempty"` - UseTLS Compatibool `url:"use_tls,omitempty"` + // Token is token based authentication + Token string `url:"token,omitempty"` + // UseTLS is whether to use TLS (0: do not use, 1: use). + UseTLS Compatibool `url:"use_tls,omitempty"` } -// CreateLogentries creates a new Fastly logentries. +// CreateLogentries creates a new resource. func (c *Client) CreateLogentries(i *CreateLogentriesInput) (*Logentries, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -119,7 +136,7 @@ type GetLogentriesInput struct { ServiceVersion int } -// GetLogentries gets the logentries configuration with the given parameters. +// GetLogentries retrieves the specified resource. func (c *Client) GetLogentries(i *GetLogentriesInput) (*Logentries, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -149,24 +166,33 @@ func (c *Client) GetLogentries(i *GetLogentriesInput) (*Logentries, error) { // UpdateLogentriesInput is used as input to the UpdateLogentries function. type UpdateLogentriesInput struct { - Format *string `url:"format,omitempty"` - FormatVersion *uint `url:"format_version,omitempty"` + // Format is a Fastly log format string. + Format *string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion *uint `url:"format_version,omitempty"` // Name is the name of the logentries to update. - Name string - NewName *string `url:"name,omitempty"` - Placement *string `url:"placement,omitempty"` - Port *uint `url:"port,omitempty"` - Region *string `url:"region,omitempty"` + Name string + // NewName is the new name for the resource. + NewName *string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement *string `url:"placement,omitempty"` + // Port is the port number. + Port *uint `url:"port,omitempty"` + // Region is the region to which to stream logs. + Region *string `url:"region,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition *string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - Token *string `url:"token,omitempty"` - UseTLS *Compatibool `url:"use_tls,omitempty"` + // Token is token based authentication + Token *string `url:"token,omitempty"` + // UseTLS is whether to use TLS (0: do not use, 1: use). + UseTLS *Compatibool `url:"use_tls,omitempty"` } -// UpdateLogentries updates a specific logentries. +// UpdateLogentries updates the specified resource. func (c *Client) UpdateLogentries(i *UpdateLogentriesInput) (*Logentries, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -204,7 +230,7 @@ type DeleteLogentriesInput struct { ServiceVersion int } -// DeleteLogentries deletes the given logentries version. +// DeleteLogentries deletes the specified resource. func (c *Client) DeleteLogentries(i *DeleteLogentriesInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/logentries_test.go b/fastly/logentries_test.go index 7c5b4837a..57a78a725 100644 --- a/fastly/logentries_test.go +++ b/fastly/logentries_test.go @@ -35,13 +35,13 @@ func TestClient_Logentries(t *testing.T) { // Ensure deleted defer func() { record(t, "logentries/delete", func(c *Client) { - c.DeleteLogentries(&DeleteLogentriesInput{ + _ = c.DeleteLogentries(&DeleteLogentriesInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-logentries", }) - c.DeleteLogentries(&DeleteLogentriesInput{ + _ = c.DeleteLogentries(&DeleteLogentriesInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "new-test-logentries", @@ -55,7 +55,7 @@ func TestClient_Logentries(t *testing.T) { if le.Port != 0 { t.Errorf("bad port: %q", le.Port) } - if le.UseTLS != true { + if !le.UseTLS { t.Errorf("bad use_tls: %t", le.UseTLS) } if le.Token != "abcd1234" { diff --git a/fastly/loggly.go b/fastly/loggly.go index f597fd372..f4c334342 100644 --- a/fastly/loggly.go +++ b/fastly/loggly.go @@ -25,9 +25,17 @@ type Loggly struct { // logglyByName is a sortable list of loggly. type logglyByName []*Loggly -// Len, Swap, and Less implement the sortable interface. -func (s logglyByName) Len() int { return len(s) } -func (s logglyByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s logglyByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s logglyByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s logglyByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -40,7 +48,7 @@ type ListLogglyInput struct { ServiceVersion int } -// ListLoggly returns the list of loggly for the configuration version. +// ListLoggly retrieves all resources. func (c *Client) ListLoggly(i *ListLogglyInput) ([]*Loggly, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -67,19 +75,25 @@ func (c *Client) ListLoggly(i *ListLogglyInput) ([]*Loggly, error) { // CreateLogglyInput is used as input to the CreateLoggly function. type CreateLogglyInput struct { - Format string `url:"format,omitempty"` - FormatVersion uint `url:"format_version,omitempty"` - Name string `url:"name,omitempty"` - Placement string `url:"placement,omitempty"` + // Format is a Fastly log format string. + Format string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion uint `url:"format_version,omitempty"` + // Name is the name for the real-time logging configuration. + Name string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement string `url:"placement,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - Token string `url:"token,omitempty"` + // Token is the token to use for authentication. + Token string `url:"token,omitempty"` } -// CreateLoggly creates a new Fastly loggly. +// CreateLoggly creates a new resource. func (c *Client) CreateLoggly(i *CreateLogglyInput) (*Loggly, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -113,7 +127,7 @@ type GetLogglyInput struct { ServiceVersion int } -// GetLoggly gets the loggly configuration with the given parameters. +// GetLoggly retrieves the specified resource. func (c *Client) GetLoggly(i *GetLogglyInput) (*Loggly, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -143,21 +157,27 @@ func (c *Client) GetLoggly(i *GetLogglyInput) (*Loggly, error) { // UpdateLogglyInput is used as input to the UpdateLoggly function. type UpdateLogglyInput struct { - Format *string `url:"format,omitempty"` - FormatVersion *uint `url:"format_version,omitempty"` + // Format is a Fastly log format string. + Format *string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion *uint `url:"format_version,omitempty"` // Name is the name of the loggly to update. - Name string - NewName *string `url:"name,omitempty"` - Placement *string `url:"placement,omitempty"` + Name string + // NewName is the new name for the resource. + NewName *string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement *string `url:"placement,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition *string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - Token *string `url:"token,omitempty"` + // Token is the token to use for authentication. + Token *string `url:"token,omitempty"` } -// UpdateLoggly updates a specific loggly. +// UpdateLoggly updates the specified resource. func (c *Client) UpdateLoggly(i *UpdateLogglyInput) (*Loggly, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -195,7 +215,7 @@ type DeleteLogglyInput struct { ServiceVersion int } -// DeleteLoggly deletes the given loggly version. +// DeleteLoggly deletes the specified resource. func (c *Client) DeleteLoggly(i *DeleteLogglyInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/loggly_test.go b/fastly/loggly_test.go index a164a9307..b87660184 100644 --- a/fastly/loggly_test.go +++ b/fastly/loggly_test.go @@ -32,13 +32,13 @@ func TestClient_Loggly(t *testing.T) { // Ensure deleted defer func() { record(t, "loggly/delete", func(c *Client) { - c.DeleteLoggly(&DeleteLogglyInput{ + _ = c.DeleteLoggly(&DeleteLogglyInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-loggly", }) - c.DeleteLoggly(&DeleteLogglyInput{ + _ = c.DeleteLoggly(&DeleteLogglyInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "new-test-loggly", diff --git a/fastly/logshuttle.go b/fastly/logshuttle.go index 1092c60f9..8e67a2d36 100644 --- a/fastly/logshuttle.go +++ b/fastly/logshuttle.go @@ -26,9 +26,17 @@ type Logshuttle struct { // logshuttlesByName is a sortable list of logshuttles. type logshuttlesByName []*Logshuttle -// Len, Swap, and Less implement the sortable interface. -func (l logshuttlesByName) Len() int { return len(l) } -func (l logshuttlesByName) Swap(i, j int) { l[i], l[j] = l[j], l[i] } +// Len implement the sortable interface. +func (l logshuttlesByName) Len() int { + return len(l) +} + +// Swap implement the sortable interface. +func (l logshuttlesByName) Swap(i, j int) { + l[i], l[j] = l[j], l[i] +} + +// Less implement the sortable interface. func (l logshuttlesByName) Less(i, j int) bool { return l[i].Name < l[j].Name } @@ -41,7 +49,7 @@ type ListLogshuttlesInput struct { ServiceVersion int } -// ListLogshuttles returns the list of logshuttles for the configuration version. +// ListLogshuttles retrieves all resources. func (c *Client) ListLogshuttles(i *ListLogshuttlesInput) ([]*Logshuttle, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -68,20 +76,27 @@ func (c *Client) ListLogshuttles(i *ListLogshuttlesInput) ([]*Logshuttle, error) // CreateLogshuttleInput is used as input to the CreateLogshuttle function. type CreateLogshuttleInput struct { - Format string `url:"format,omitempty"` - FormatVersion uint `url:"format_version,omitempty"` - Name string `url:"name,omitempty"` - Placement string `url:"placement,omitempty"` + // Format is a Fastly log format string. + Format string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion uint `url:"format_version,omitempty"` + // Name is the name for the real-time logging configuration. + Name string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement string `url:"placement,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - Token string `url:"token,omitempty"` - URL string `url:"url,omitempty"` + // Token is the data authentication token associated with this endpoint. + Token string `url:"token,omitempty"` + // URL is the URL to stream logs to. + URL string `url:"url,omitempty"` } -// CreateLogshuttle creates a new Fastly logshuttle. +// CreateLogshuttle creates a new resource. func (c *Client) CreateLogshuttle(i *CreateLogshuttleInput) (*Logshuttle, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -115,7 +130,7 @@ type GetLogshuttleInput struct { ServiceVersion int } -// GetLogshuttle gets the logshuttle configuration with the given parameters. +// GetLogshuttle retrieves the specified resource. func (c *Client) GetLogshuttle(i *GetLogshuttleInput) (*Logshuttle, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -145,22 +160,29 @@ func (c *Client) GetLogshuttle(i *GetLogshuttleInput) (*Logshuttle, error) { // UpdateLogshuttleInput is used as input to the UpdateLogshuttle function. type UpdateLogshuttleInput struct { - Format *string `url:"format,omitempty"` - FormatVersion *uint `url:"format_version,omitempty"` + // Format is a Fastly log format string. + Format *string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion *uint `url:"format_version,omitempty"` // Name is the name of the logshuttle to update. - Name string - NewName *string `url:"name,omitempty"` - Placement *string `url:"placement,omitempty"` + Name string + // NewName is the new name for the resource. + NewName *string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement *string `url:"placement,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition *string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - Token *string `url:"token,omitempty"` - URL *string `url:"url,omitempty"` + // Token is the data authentication token associated with this endpoint. + Token *string `url:"token,omitempty"` + // URL is the URL to stream logs to. + URL *string `url:"url,omitempty"` } -// UpdateLogshuttle updates a specific logshuttle. +// UpdateLogshuttle updates the specified resource. func (c *Client) UpdateLogshuttle(i *UpdateLogshuttleInput) (*Logshuttle, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -198,7 +220,7 @@ type DeleteLogshuttleInput struct { ServiceVersion int } -// DeleteLogshuttle deletes the given logshuttle version. +// DeleteLogshuttle deletes the specified resource. func (c *Client) DeleteLogshuttle(i *DeleteLogshuttleInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/logshuttle_test.go b/fastly/logshuttle_test.go index abea34e76..049b32930 100644 --- a/fastly/logshuttle_test.go +++ b/fastly/logshuttle_test.go @@ -34,13 +34,13 @@ func TestClient_Logshuttles(t *testing.T) { // Ensure deleted defer func() { record(t, "logshuttles/cleanup", func(c *Client) { - c.DeleteLogshuttle(&DeleteLogshuttleInput{ + _ = c.DeleteLogshuttle(&DeleteLogshuttleInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-logshuttle", }) - c.DeleteLogshuttle(&DeleteLogshuttleInput{ + _ = c.DeleteLogshuttle(&DeleteLogshuttleInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "new-test-logshuttle", diff --git a/fastly/managed_logging.go b/fastly/managed_logging.go index 9ddc6af60..9ae1edc70 100644 --- a/fastly/managed_logging.go +++ b/fastly/managed_logging.go @@ -25,11 +25,13 @@ type ( ) const ( + // ManagedLoggingUnset is a log stream variant. ManagedLoggingUnset ManagedLoggingKind = iota + // ManagedLoggingInstanceOutput is a log stream variant. ManagedLoggingInstanceOutput ) -// CreateManagedLogging enables managed logging for a service. +// CreateManagedLogging creates a new resource. func (c *Client) CreateManagedLogging(i *CreateManagedLoggingInput) (*ManagedLogging, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -73,7 +75,7 @@ type DeleteManagedLoggingInput struct { ServiceID string } -// DeleteManagedLogging disables managed logging for a service +// DeleteManagedLogging deletes the specified resource. func (c *Client) DeleteManagedLogging(i *DeleteManagedLoggingInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/newrelic.go b/fastly/newrelic.go index fb587e9d5..2f6e82c6a 100644 --- a/fastly/newrelic.go +++ b/fastly/newrelic.go @@ -26,9 +26,17 @@ type NewRelic struct { // newrelicByName is a sortable list of newrelic. type newrelicByName []*NewRelic -// Len, Swap, and Less implement the sortable interface. -func (s newrelicByName) Len() int { return len(s) } -func (s newrelicByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s newrelicByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s newrelicByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s newrelicByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -41,7 +49,7 @@ type ListNewRelicInput struct { ServiceVersion int } -// ListNewRelic returns the list of newrelic for the configuration version. +// ListNewRelic retrieves all resources. func (c *Client) ListNewRelic(i *ListNewRelicInput) ([]*NewRelic, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -68,20 +76,27 @@ func (c *Client) ListNewRelic(i *ListNewRelicInput) ([]*NewRelic, error) { // CreateNewRelicInput is used as input to the CreateNewRelic function. type CreateNewRelicInput struct { - Format string `url:"format,omitempty"` - FormatVersion uint `url:"format_version,omitempty"` - Name string `url:"name,omitempty"` - Placement string `url:"placement,omitempty"` - Region string `url:"region,omitempty"` + // Format is a Fastly log format string. Must produce valid JSON that New Relic Logs can ingest. + Format string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion uint `url:"format_version,omitempty"` + // Name is the name for the real-time logging configuration. + Name string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement string `url:"placement,omitempty"` + // Region is the region to which to stream logs. + Region string `url:"region,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - Token string `url:"token,omitempty"` + // Token is the Insert API key from the Account page of your New Relic account. + Token string `url:"token,omitempty"` } -// CreateNewRelic creates a new Fastly newrelic. +// CreateNewRelic creates a new resource. func (c *Client) CreateNewRelic(i *CreateNewRelicInput) (*NewRelic, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -119,7 +134,7 @@ type GetNewRelicInput struct { ServiceVersion int } -// GetNewRelic gets the newrelic configuration with the given parameters. +// GetNewRelic retrieves the specified resource. func (c *Client) GetNewRelic(i *GetNewRelicInput) (*NewRelic, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -149,22 +164,29 @@ func (c *Client) GetNewRelic(i *GetNewRelicInput) (*NewRelic, error) { // UpdateNewRelicInput is used as input to the UpdateNewRelic function. type UpdateNewRelicInput struct { - Format *string `url:"format,omitempty"` - FormatVersion *uint `url:"format_version,omitempty"` + // Format is a Fastly log format string. Must produce valid JSON that New Relic Logs can ingest. + Format *string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion *uint `url:"format_version,omitempty"` // Name is the name of the newrelic to update. - Name string - NewName *string `url:"name,omitempty"` - Placement *string `url:"placement,omitempty"` - Region *string `url:"region,omitempty"` + Name string + // NewName is the new name for the resource. + NewName *string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement *string `url:"placement,omitempty"` + // Region is the region to which to stream logs. + Region *string `url:"region,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition *string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - Token *string `url:"token,omitempty"` + // Token is the Insert API key from the Account page of your New Relic account. + Token *string `url:"token,omitempty"` } -// UpdateNewRelic updates a specific newrelic. +// UpdateNewRelic updates the specified resource. func (c *Client) UpdateNewRelic(i *UpdateNewRelicInput) (*NewRelic, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -206,7 +228,7 @@ type DeleteNewRelicInput struct { ServiceVersion int } -// DeleteNewRelic deletes the given newrelic version. +// DeleteNewRelic deletes the specified resource. func (c *Client) DeleteNewRelic(i *DeleteNewRelicInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/newrelic_test.go b/fastly/newrelic_test.go index 81fee6b1d..ce6c1e657 100644 --- a/fastly/newrelic_test.go +++ b/fastly/newrelic_test.go @@ -64,19 +64,19 @@ func TestClient_NewRelic(t *testing.T) { // Ensure deleted defer func() { record(t, "newrelic/delete", func(c *Client) { - c.DeleteNewRelic(&DeleteNewRelicInput{ + _ = c.DeleteNewRelic(&DeleteNewRelicInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-newrelic", }) - c.DeleteNewRelic(&DeleteNewRelicInput{ + _ = c.DeleteNewRelic(&DeleteNewRelicInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-newrelic-2", }) - c.DeleteNewRelic(&DeleteNewRelicInput{ + _ = c.DeleteNewRelic(&DeleteNewRelicInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "new-test-newrelic", diff --git a/fastly/object_store.go b/fastly/object_store.go index 184827d00..89eb290e6 100644 --- a/fastly/object_store.go +++ b/fastly/object_store.go @@ -24,7 +24,7 @@ type CreateObjectStoreInput struct { Name string `json:"name"` } -// CreateObjectStore create a new object store. +// CreateObjectStore creates a new resource. func (c *Client) CreateObjectStore(i *CreateObjectStoreInput) (*ObjectStore, error) { if i.Name == "" { return nil, ErrMissingName @@ -43,10 +43,12 @@ func (c *Client) CreateObjectStore(i *CreateObjectStoreInput) (*ObjectStore, err return store, nil } -// ListObjectStoreInput is used as an input to the ListObjectStores function. +// ListObjectStoresInput is used as an input to the ListObjectStores function. type ListObjectStoresInput struct { + // Cursor is used for paginating through results. Cursor string - Limit int + // Limit is the maximum number of items included the response. + Limit int } func (l *ListObjectStoresInput) formatFilters() map[string]string { @@ -71,7 +73,7 @@ func (l *ListObjectStoresInput) formatFilters() map[string]string { return m } -// ListObjectStoresResponse is the return type for the ListObjectStores function. +// ListObjectStoresResponse retrieves all resources. type ListObjectStoresResponse struct { // Data is the list of returned object stores Data []ObjectStore @@ -79,7 +81,7 @@ type ListObjectStoresResponse struct { Meta map[string]string } -// ListObjectStores lists the object stores for the current customer. +// ListObjectStores retrieves all resources. func (c *Client) ListObjectStores(i *ListObjectStoresInput) (*ListObjectStoresResponse, error) { const path = "/resources/stores/object" @@ -98,7 +100,7 @@ func (c *Client) ListObjectStores(i *ListObjectStoresInput) (*ListObjectStoresRe return output, nil } -// ListObjectStoresPagiator is the opaque type for a ListObjectStores call with pagination. +// ListObjectStoresPaginator is the opaque type for a ListObjectStores call with pagination. type ListObjectStoresPaginator struct { client *Client cursor string // == "" if no more pages @@ -156,7 +158,7 @@ type GetObjectStoreInput struct { ID string } -// GetObjectStore fetches information about the given object store. +// GetObjectStore retrieves the specified resource. func (c *Client) GetObjectStore(i *GetObjectStoreInput) (*ObjectStore, error) { if i.ID == "" { return nil, ErrMissingID @@ -181,7 +183,7 @@ type DeleteObjectStoreInput struct { ID string } -// DeleteObjectStore deletes the given object store. +// DeleteObjectStore deletes the specified resource. func (c *Client) DeleteObjectStore(i *DeleteObjectStoreInput) error { if i.ID == "" { return ErrMissingID @@ -202,9 +204,11 @@ func (c *Client) DeleteObjectStore(i *DeleteObjectStoreInput) error { // ListObjectStoreKeysInput is the input to the ListObjectStoreKeys function. type ListObjectStoreKeysInput struct { + // Cursor is used for paginating through results. Cursor string // ID is the ID of the object store to list keys for. - ID string + ID string + // Limit is the maximum number of items included the response. Limit int } @@ -230,7 +234,7 @@ func (l *ListObjectStoreKeysInput) formatFilters() map[string]string { return m } -// ListObjectStoreKeysResponse is the response to the ListObjectStoreKeys function. +// ListObjectStoreKeysResponse retrieves all resources. type ListObjectStoreKeysResponse struct { // Data is the list of keys Data []string @@ -238,7 +242,7 @@ type ListObjectStoreKeysResponse struct { Meta map[string]string } -// ListObjectStoreKeys lists the keys for the given object store. +// ListObjectStoreKeys retrieves all resources. func (c *Client) ListObjectStoreKeys(i *ListObjectStoreKeysInput) (*ListObjectStoreKeysResponse, error) { if i.ID == "" { return nil, ErrMissingID @@ -261,7 +265,7 @@ func (c *Client) ListObjectStoreKeys(i *ListObjectStoreKeysInput) (*ListObjectSt } // ListObjectStoreKeysPaginator is the opaque type for a ListObjectStoreKeys calls with pagination. -type ListObjectsStoreKeysPaginator struct { +type ListObjectStoreKeysPaginator struct { client *Client cursor string // == "" if no more pages err error @@ -271,15 +275,15 @@ type ListObjectsStoreKeysPaginator struct { } // NewListObjectStoreKeysPaginator returns a new paginator for the provided LitObjectStoreKeysInput. -func (c *Client) NewListObjectStoreKeysPaginator(i *ListObjectStoreKeysInput) *ListObjectsStoreKeysPaginator { - return &ListObjectsStoreKeysPaginator{ +func (c *Client) NewListObjectStoreKeysPaginator(i *ListObjectStoreKeysInput) *ListObjectStoreKeysPaginator { + return &ListObjectStoreKeysPaginator{ client: c, input: i, } } // Next advanced the paginator. -func (l *ListObjectsStoreKeysPaginator) Next() bool { +func (l *ListObjectStoreKeysPaginator) Next() bool { if l.finished { l.keys = nil return false @@ -303,12 +307,12 @@ func (l *ListObjectsStoreKeysPaginator) Next() bool { } // Err returns any error from the paginator. -func (l *ListObjectsStoreKeysPaginator) Err() error { +func (l *ListObjectStoreKeysPaginator) Err() error { return l.err } // Keys returns the current set of keys retrieved by the paginator. -func (l *ListObjectsStoreKeysPaginator) Keys() []string { +func (l *ListObjectStoreKeysPaginator) Keys() []string { return l.keys } @@ -320,7 +324,7 @@ type GetObjectStoreKeyInput struct { Key string } -// GetObjectStoreKey returns the value associated with a key in an object store. +// GetObjectStoreKey retrieves the specified resource. func (c *Client) GetObjectStoreKey(i *GetObjectStoreKeyInput) (string, error) { if i.ID == "" { return "", ErrMissingID @@ -382,7 +386,7 @@ type DeleteObjectStoreKeyInput struct { Key string } -// DeleteObjectStoreKey deletes a key from an object store. +// DeleteObjectStoreKey deletes the specified resource. func (c *Client) DeleteObjectStoreKey(i *DeleteObjectStoreKeyInput) error { if i.ID == "" { return ErrMissingID diff --git a/fastly/object_store_test.go b/fastly/object_store_test.go index cdb82ec5a..548e10451 100644 --- a/fastly/object_store_test.go +++ b/fastly/object_store_test.go @@ -82,7 +82,6 @@ func TestClient_ObjectStore(t *testing.T) { if getObjectStoreResponse.Name != objectStore.Name || getObjectStoreResponse.ID != objectStore.ID { t.Errorf("error fetching info for store %q: got %q, want %q", createStoreName, getObjectStoreResponse, objectStore) - } // create a bunch of keys in our object store diff --git a/fastly/openstack.go b/fastly/openstack.go index cb2bf394f..a3fdd4b78 100644 --- a/fastly/openstack.go +++ b/fastly/openstack.go @@ -35,9 +35,17 @@ type Openstack struct { // openstacksByName is a sortable list of Openstack. type openstacksByName []*Openstack -// Len, Swap, and Less implement the sortable interface. -func (o openstacksByName) Len() int { return len(o) } -func (o openstacksByName) Swap(i, j int) { o[i], o[j] = o[j], o[i] } +// Len implement the sortable interface. +func (o openstacksByName) Len() int { + return len(o) +} + +// Swap implement the sortable interface. +func (o openstacksByName) Swap(i, j int) { + o[i], o[j] = o[j], o[i] +} + +// Less implement the sortable interface. func (o openstacksByName) Less(i, j int) bool { return o[i].Name < o[j].Name } @@ -50,7 +58,7 @@ type ListOpenstackInput struct { ServiceVersion int } -// ListOpenstack returns the list of Openstack for the configuration version. +// ListOpenstack retrieves all resources. func (c *Client) ListOpenstack(i *ListOpenstackInput) ([]*Openstack, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -77,29 +85,45 @@ func (c *Client) ListOpenstack(i *ListOpenstackInput) ([]*Openstack, error) { // CreateOpenstackInput is used as input to the CreateOpenstack function. type CreateOpenstackInput struct { - AccessKey string `url:"access_key,omitempty"` - BucketName string `url:"bucket_name,omitempty"` - CompressionCodec string `url:"compression_codec,omitempty"` - Format string `url:"format,omitempty"` - FormatVersion uint `url:"format_version,omitempty"` - GzipLevel uint8 `url:"gzip_level,omitempty"` - MessageType string `url:"message_type,omitempty"` - Name string `url:"name,omitempty"` - Path string `url:"path,omitempty"` - Period uint `url:"period,omitempty"` - Placement string `url:"placement,omitempty"` - PublicKey string `url:"public_key,omitempty"` + // AccessKey is your OpenStack account access key. + AccessKey string `url:"access_key,omitempty"` + // BucketName is the name of your OpenStack container. + BucketName string `url:"bucket_name,omitempty"` + // CompressionCodec is he codec used for compressing your logs (zstd, snappy, gzip). + CompressionCodec string `url:"compression_codec,omitempty"` + // Format is a Fastly log format string. + Format string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion uint `url:"format_version,omitempty"` + // GzipLevel is the level of gzip encoding when sending logs (default 0, no compression). + GzipLevel uint8 `url:"gzip_level,omitempty"` + // MessageType is how the message should be formatted (classic, loggly, logplex, blank). + MessageType string `url:"message_type,omitempty"` + // Name is the name for the real-time logging configuration. + Name string `url:"name,omitempty"` + // Path is the path to upload logs to. + Path string `url:"path,omitempty"` + // Period is how frequently log files are finalized so they can be available for reading (in seconds). + Period uint `url:"period,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement string `url:"placement,omitempty"` + // PublicKey is a PGP public key that Fastly will use to encrypt your log files before writing them to disk. + PublicKey string `url:"public_key,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). - ServiceVersion int + ServiceVersion int + // TimestampFormat is a timestamp format. TimestampFormat string `url:"timestamp_format,omitempty"` - URL string `url:"url,omitempty"` - User string `url:"user,omitempty"` + // URL is your OpenStack auth url. + URL string `url:"url,omitempty"` + // User is the username for your OpenStack account. + User string `url:"user,omitempty"` } -// CreateOpenstack creates a new Fastly Openstack. +// CreateOpenstack creates a new resource. func (c *Client) CreateOpenstack(i *CreateOpenstackInput) (*Openstack, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -133,7 +157,7 @@ type GetOpenstackInput struct { ServiceVersion int } -// GetOpenstack gets the Openstack configuration with the given parameters. +// GetOpenstack retrieves the specified resource. func (c *Client) GetOpenstack(i *GetOpenstackInput) (*Openstack, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -163,31 +187,47 @@ func (c *Client) GetOpenstack(i *GetOpenstackInput) (*Openstack, error) { // UpdateOpenstackInput is used as input to the UpdateOpenstack function. type UpdateOpenstackInput struct { - AccessKey *string `url:"access_key,omitempty"` - BucketName *string `url:"bucket_name,omitempty"` + // AccessKey is your OpenStack account access key. + AccessKey *string `url:"access_key,omitempty"` + // BucketName is the name of your OpenStack container. + BucketName *string `url:"bucket_name,omitempty"` + // CompressionCodec is he codec used for compressing your logs (zstd, snappy, gzip). CompressionCodec *string `url:"compression_codec,omitempty"` - Format *string `url:"format,omitempty"` - FormatVersion *uint `url:"format_version,omitempty"` - GzipLevel *uint8 `url:"gzip_level,omitempty"` - MessageType *string `url:"message_type,omitempty"` + // Format is a Fastly log format string. + Format *string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion *uint `url:"format_version,omitempty"` + // GzipLevel is the level of gzip encoding when sending logs (default 0, no compression). + GzipLevel *uint8 `url:"gzip_level,omitempty"` + // MessageType is how the message should be formatted (classic, loggly, logplex, blank). + MessageType *string `url:"message_type,omitempty"` // Name is the name of the Openstack to update. - Name string - NewName *string `url:"name,omitempty"` - Path *string `url:"path,omitempty"` - Period *uint `url:"period,omitempty"` - Placement *string `url:"placement,omitempty"` - PublicKey *string `url:"public_key,omitempty"` + Name string + // NewName is the new name for the resource. + NewName *string `url:"name,omitempty"` + // Path is the path to upload logs to. + Path *string `url:"path,omitempty"` + // Period is how frequently log files are finalized so they can be available for reading (in seconds). + Period *uint `url:"period,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement *string `url:"placement,omitempty"` + // PublicKey is a PGP public key that Fastly will use to encrypt your log files before writing them to disk. + PublicKey *string `url:"public_key,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition *string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). - ServiceVersion int + ServiceVersion int + // TimestampFormat is a timestamp format. TimestampFormat *string `url:"timestamp_format,omitempty"` - URL *string `url:"url,omitempty"` - User *string `url:"user,omitempty"` + // URL is your OpenStack auth url. + URL *string `url:"url,omitempty"` + // User is the username for your OpenStack account. + User *string `url:"user,omitempty"` } -// UpdateOpenstack updates a specific Openstack. +// UpdateOpenstack updates the specified resource. func (c *Client) UpdateOpenstack(i *UpdateOpenstackInput) (*Openstack, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -225,7 +265,7 @@ type DeleteOpenstackInput struct { ServiceVersion int } -// DeleteOpenstack deletes the given Openstack version. +// DeleteOpenstack deletes the specified resource. func (c *Client) DeleteOpenstack(i *DeleteOpenstackInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/openstack_test.go b/fastly/openstack_test.go index 84f9b77d5..b1516491f 100644 --- a/fastly/openstack_test.go +++ b/fastly/openstack_test.go @@ -117,25 +117,25 @@ func TestClient_Openstack(t *testing.T) { // Ensure deleted defer func() { record(t, "openstack/cleanup", func(c *Client) { - c.DeleteOpenstack(&DeleteOpenstackInput{ + _ = c.DeleteOpenstack(&DeleteOpenstackInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-openstack", }) - c.DeleteOpenstack(&DeleteOpenstackInput{ + _ = c.DeleteOpenstack(&DeleteOpenstackInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-openstack-2", }) - c.DeleteOpenstack(&DeleteOpenstackInput{ + _ = c.DeleteOpenstack(&DeleteOpenstackInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-openstack-3", }) - c.DeleteOpenstack(&DeleteOpenstackInput{ + _ = c.DeleteOpenstack(&DeleteOpenstackInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "new-test-openstack", diff --git a/fastly/origin_inspector.go b/fastly/origin_inspector.go index 0c6e601a1..93966d219 100644 --- a/fastly/origin_inspector.go +++ b/fastly/origin_inspector.go @@ -81,19 +81,29 @@ type OriginMeta struct { // GetOriginMetricsInput is the input to an OriginMetrics request. type GetOriginMetricsInput struct { - Cursor string + // Cursor is the value from a previous response to retrieve the next page. To request the first page, this should be empty. + Cursor string + // Datacenters limits query to one or more specific POPs. Datacenters []string - Downsample string - End time.Time - GroupBy []string - Hosts []string - Metrics []string - Regions []string - ServiceID string - Start time.Time + // Downsample is the duration of sample windows. + Downsample string + // End is a valid ISO-8601-formatted date and time, or UNIX timestamp, indicating the exclusive end of the query time range. If not provided, a default is chosen based on the provided downsample value. + End time.Time + // GroupBy is the dimensions to return in the query. + GroupBy []string + // Hosts limits query to one or more specific origin hosts. + Hosts []string + // Metrics is the metric to retrieve. Up to ten metrics are accepted. + Metrics []string + // Regions limits query to one or more specific geographic regions. + Regions []string + // ServiceID is an alphanumeric string identifying the service. + ServiceID string + // Start is a valid ISO-8601-formatted date and time, or UNIX timestamp, indicating the inclusive start of the query time range. If not provided, a default is chosen based on the provided downsample value. + Start time.Time } -// GetOriginMetricsForService returns stats data based on GetOriginMetricsInput +// GetOriginMetricsForService retrieves the specified resource. func (c *Client) GetOriginMetricsForService(i *GetOriginMetricsInput) (*OriginInspector, error) { var resp interface{} if err := c.GetOriginMetricsForServiceJSON(i, &resp); err != nil { @@ -107,8 +117,7 @@ func (c *Client) GetOriginMetricsForService(i *GetOriginMetricsInput) (*OriginIn return or, nil } -// GetOriginMetricsForServiceJSON fetches Origin Inspector metrics for a single service and decodes the response -// directly to the JSON struct dst. +// GetOriginMetricsForServiceJSON retrieves the specified resource. func (c *Client) GetOriginMetricsForServiceJSON(i *GetOriginMetricsInput, dst interface{}) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/package.go b/fastly/package.go index f3f7b8b02..b2320c17b 100644 --- a/fastly/package.go +++ b/fastly/package.go @@ -17,7 +17,7 @@ type Package struct { UpdatedAt *time.Time `mapstructure:"updated_at"` } -// Package is a container for metadata returned about a package. +// PackageMetadata is a container for metadata returned about a package. // It is a separate struct to allow correct serialisation by mapstructure - // the raw data is returned as a json sub-block. type PackageMetadata struct { @@ -37,7 +37,7 @@ type GetPackageInput struct { ServiceVersion int `mapstructure:"version"` } -// GetPackage retrieves package information for the given service and version. +// GetPackage retrieves the specified resource. func (c *Client) GetPackage(i *GetPackageInput) (*Package, error) { path, err := MakePackagePath(i.ServiceID, i.ServiceVersion) if err != nil { @@ -63,7 +63,7 @@ type UpdatePackageInput struct { ServiceVersion int `mapstructure:"version"` } -// UpdatePackage updates a package for a specific version. +// UpdatePackage updates the specified resource. func (c *Client) UpdatePackage(i *UpdatePackageInput) (*Package, error) { urlPath, err := MakePackagePath(i.ServiceID, i.ServiceVersion) if err != nil { @@ -80,14 +80,14 @@ func (c *Client) UpdatePackage(i *UpdatePackageInput) (*Package, error) { } // MakePackagePath ensures we create the correct REST path for referencing packages in the API. -func MakePackagePath(ServiceID string, ServiceVersion int) (string, error) { - if ServiceID == "" { +func MakePackagePath(serviceID string, serviceVersion int) (string, error) { + if serviceID == "" { return "", ErrMissingServiceID } - if ServiceVersion == 0 { + if serviceVersion == 0 { return "", ErrMissingServiceVersion } - return fmt.Sprintf("/service/%s/version/%d/package", ServiceID, ServiceVersion), nil + return fmt.Sprintf("/service/%s/version/%d/package", serviceID, serviceVersion), nil } // PopulatePackage encapsulates the decoding of returned package data. diff --git a/fastly/package_test.go b/fastly/package_test.go index 5aee8015e..d1890af64 100644 --- a/fastly/package_test.go +++ b/fastly/package_test.go @@ -5,7 +5,6 @@ import ( ) func TestClient_Package(t *testing.T) { - fixtureBase := "package/" nameSuffix := "package" @@ -13,7 +12,7 @@ func TestClient_Package(t *testing.T) { testVersion := createTestVersion(t, fixtureBase+"service_version", testService.ID) defer deleteTestService(t, fixtureBase+"service_delete", testService.ID) - var testData = Package{ + testData := Package{ Metadata: PackageMetadata{ Name: "wasm-test", Description: "Default package template used by the Fastly CLI for Rust-based Compute@Edge projects.", @@ -95,7 +94,6 @@ func TestClient_Package(t *testing.T) { wp.Metadata.Name != "" { t.Fatal("Invalid package upload completed rather than failed.") } - } func TestClient_GetPackage_validation(t *testing.T) { diff --git a/fastly/papertrail.go b/fastly/papertrail.go index d33d8b779..59eb0f039 100644 --- a/fastly/papertrail.go +++ b/fastly/papertrail.go @@ -26,9 +26,17 @@ type Papertrail struct { // papertrailsByName is a sortable list of papertrails. type papertrailsByName []*Papertrail -// Len, Swap, and Less implement the sortable interface. -func (s papertrailsByName) Len() int { return len(s) } -func (s papertrailsByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s papertrailsByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s papertrailsByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s papertrailsByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -41,7 +49,7 @@ type ListPapertrailsInput struct { ServiceVersion int } -// ListPapertrails returns the list of papertrails for the configuration version. +// ListPapertrails retrieves all resources. func (c *Client) ListPapertrails(i *ListPapertrailsInput) ([]*Papertrail, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -68,23 +76,27 @@ func (c *Client) ListPapertrails(i *ListPapertrailsInput) ([]*Papertrail, error) // CreatePapertrailInput is used as input to the CreatePapertrail function. type CreatePapertrailInput struct { - Address string `url:"address,omitempty"` - CreatedAt *time.Time `url:"created_at,omitempty"` - DeletedAt *time.Time `url:"deleted_at,omitempty"` - Format string `url:"format,omitempty"` - FormatVersion uint `url:"format_version,omitempty"` - Name string `url:"name,omitempty"` - Placement string `url:"placement,omitempty"` - Port uint `url:"port,omitempty"` - ResponseCondition string `url:"response_condition,omitempty"` + // Address is a hostname or IPv4 address. + Address string `url:"address,omitempty"` + // Format is a Fastly log format string. + Format string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion uint `url:"format_version,omitempty"` + // Name is the name for the real-time logging configuration. + Name string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement string `url:"placement,omitempty"` + // Port is the port number. + Port uint `url:"port,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. + ResponseCondition string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - UpdatedAt *time.Time `url:"updated_at,omitempty"` } -// CreatePapertrail creates a new Fastly papertrail. +// CreatePapertrail creates a new resource. func (c *Client) CreatePapertrail(i *CreatePapertrailInput) (*Papertrail, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -118,7 +130,7 @@ type GetPapertrailInput struct { ServiceVersion int } -// GetPapertrail gets the papertrail configuration with the given parameters. +// GetPapertrail retrieves the specified resource. func (c *Client) GetPapertrail(i *GetPapertrailInput) (*Papertrail, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -148,25 +160,29 @@ func (c *Client) GetPapertrail(i *GetPapertrailInput) (*Papertrail, error) { // UpdatePapertrailInput is used as input to the UpdatePapertrail function. type UpdatePapertrailInput struct { - Address *string `url:"address,omitempty"` - CreatedAt *time.Time `url:"created_at,omitempty"` - DeletedAt *time.Time `url:"deleted_at,omitempty"` - Format *string `url:"format,omitempty"` - FormatVersion *uint `url:"format_version,omitempty"` + // Address is a hostname or IPv4 address. + Address *string `url:"address,omitempty"` + // Format is a Fastly log format string. + Format *string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion *uint `url:"format_version,omitempty"` // Name is the name of the papertrail to update. - Name string - NewName *string `url:"name,omitempty"` - Placement *string `url:"placement,omitempty"` - Port *uint `url:"port,omitempty"` + Name string + // NewName is the new name for the resource. + NewName *string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement *string `url:"placement,omitempty"` + // Port is the port number. + Port *uint `url:"port,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition *string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - UpdatedAt *time.Time `url:"updated_at,omitempty"` } -// UpdatePapertrail updates a specific papertrail. +// UpdatePapertrail updates the specified resource. func (c *Client) UpdatePapertrail(i *UpdatePapertrailInput) (*Papertrail, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -204,7 +220,7 @@ type DeletePapertrailInput struct { ServiceVersion int } -// DeletePapertrail deletes the given papertrail version. +// DeletePapertrail deletes the specified resource. func (c *Client) DeletePapertrail(i *DeletePapertrailInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/papertrail_test.go b/fastly/papertrail_test.go index 12de8c245..1bbe445bd 100644 --- a/fastly/papertrail_test.go +++ b/fastly/papertrail_test.go @@ -34,13 +34,13 @@ func TestClient_Papertrails(t *testing.T) { // Ensure deleted defer func() { record(t, "papertrails/cleanup", func(c *Client) { - c.DeletePapertrail(&DeletePapertrailInput{ + _ = c.DeletePapertrail(&DeletePapertrailInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-papertrail", }) - c.DeletePapertrail(&DeletePapertrailInput{ + _ = c.DeletePapertrail(&DeletePapertrailInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "new-test-papertrail", diff --git a/fastly/platform_tls.go b/fastly/platform_tls.go index d188a0058..dc89e37c0 100644 --- a/fastly/platform_tls.go +++ b/fastly/platform_tls.go @@ -23,25 +23,36 @@ type BulkCertificate struct { // TLSConfiguration represents the dedicated IP address pool that will be used to route traffic from the TLSDomain. type TLSConfiguration struct { - ID string `jsonapi:"primary,tls_configuration"` + // ID is an alphanumeric string identifying a TLS configuration. + ID string `jsonapi:"primary,tls_configuration"` + // Type is a resource type (default: tls_configuration). Type string `jsonapi:"attr,type"` } // TLSDomain represents a domain (including wildcard domains) that is listed on a certificate's Subject Alternative Names (SAN) list. type TLSDomain struct { - Activations []*TLSActivation `jsonapi:"relation,tls_activations,omitempty"` - Certificates []*CustomTLSCertificate `jsonapi:"relation,tls_certificates,omitempty"` - ID string `jsonapi:"primary,tls_domain"` - Subscriptions []*TLSSubscription `jsonapi:"relation,tls_subscriptions,omitempty"` - Type string `jsonapi:"attr,type"` + // Activations is a list of TLS Activations. + Activations []*TLSActivation `jsonapi:"relation,tls_activations,omitempty"` + // Certificates is a list of Custom TLS Certificates. + Certificates []*CustomTLSCertificate `jsonapi:"relation,tls_certificates,omitempty"` + // ID is the domain name. + ID string `jsonapi:"primary,tls_domain"` + // Subscriptions is a list of TLS Subscriptions. + Subscriptions []*TLSSubscription `jsonapi:"relation,tls_subscriptions,omitempty"` + // Type is the resource type (default: tls_domain). + Type string `jsonapi:"attr,type"` } // ListBulkCertificatesInput is used as input to the ListBulkCertificates function. type ListBulkCertificatesInput struct { - FilterTLSDomainsIDMatch string // Filter certificates by their matching, fully-qualified domain name. Returns all partial matches. Must provide a value longer than 3 characters. - PageNumber int // The page index for pagination. - PageSize int // The number of keys per page. - Sort string // The order in which to list certificates. Valid values are created_at, not_before, not_after. May precede any value with a - for descending. + // FilterTLSDomainsIDMatch filters certificates by their matching, fully-qualified domain name. Returns all partial matches. Must provide a value longer than 3 characters. + FilterTLSDomainsIDMatch string + // PageNumber is the page index for pagination. + PageNumber int + // PageSize is the number of keys per page. + PageSize int + // Sort is the order in which to list certificates. Valid values are created_at, not_before, not_after. May precede any value with a - for descending. + Sort string } // formatFilters converts user input into query parameters for filtering. @@ -68,7 +79,7 @@ func (i *ListBulkCertificatesInput) formatFilters() map[string]string { return result } -// ListBulkCertificates list all certificates. +// ListBulkCertificates retrieves all resources. func (c *Client) ListBulkCertificates(i *ListBulkCertificatesInput) ([]*BulkCertificate, error) { p := "/tls/bulk/certificates" filters := &RequestOptions{ @@ -103,10 +114,11 @@ func (c *Client) ListBulkCertificates(i *ListBulkCertificatesInput) ([]*BulkCert // GetBulkCertificateInput is used as input to the GetBulkCertificate function. type GetBulkCertificateInput struct { + // ID is an alphanumeric string identifying a TLS bulk certificate. ID string } -// GetBulkCertificate retrieve a single certificate. +// GetBulkCertificate retrieves the specified resource. func (c *Client) GetBulkCertificate(i *GetBulkCertificateInput) (*BulkCertificate, error) { if i.ID == "" { return nil, ErrMissingID @@ -130,13 +142,17 @@ func (c *Client) GetBulkCertificate(i *GetBulkCertificateInput) (*BulkCertificat // CreateBulkCertificateInput is used as input to the CreateBulkCertificate function. type CreateBulkCertificateInput struct { - AllowUntrusted bool `jsonapi:"attr,allow_untrusted_root,omitempty"` - CertBlob string `jsonapi:"attr,cert_blob"` - Configurations []*TLSConfiguration `jsonapi:"relation,tls_configurations,tls_configuration"` - IntermediatesBlob string `jsonapi:"attr,intermediates_blob"` + // AllowUntrusted enables certificates that chain to untrusted roots. + AllowUntrusted bool `jsonapi:"attr,allow_untrusted_root,omitempty"` + // CertBlob is the PEM-formatted certificate blob. + CertBlob string `jsonapi:"attr,cert_blob"` + // Configurations is a list of TLS configurations. + Configurations []*TLSConfiguration `jsonapi:"relation,tls_configurations,tls_configuration"` + // IntermediatesBlob is the PEM-formatted chain of intermediate blobs. + IntermediatesBlob string `jsonapi:"attr,intermediates_blob"` } -// CreateBulkCertificate create a TLS private key. +// CreateBulkCertificate creates a new resource. func (c *Client) CreateBulkCertificate(i *CreateBulkCertificateInput) (*BulkCertificate, error) { if i.CertBlob == "" { return nil, ErrMissingCertBlob @@ -163,13 +179,18 @@ func (c *Client) CreateBulkCertificate(i *CreateBulkCertificateInput) (*BulkCert // UpdateBulkCertificateInput is used as input to the UpdateBulkCertificate function. type UpdateBulkCertificateInput struct { - AllowUntrusted bool `jsonapi:"attr,allow_untrusted_root"` - CertBlob string `jsonapi:"attr,cert_blob"` - ID string `jsonapi:"attr,id"` + // AllowUntrusted enables certificates that chain to untrusted roots. + AllowUntrusted bool `jsonapi:"attr,allow_untrusted_root"` + // CertBlob is the PEM-formatted certificate blob. + CertBlob string `jsonapi:"attr,cert_blob"` + // ID is an alphanumeric string identifying a TLS bulk certificate. + ID string `jsonapi:"attr,id"` + // IntermediatesBlob is the PEM-formatted chain of intermediate blobs. IntermediatesBlob string `jsonapi:"attr,intermediates_blob,omitempty"` } -// UpdateBulkCertificate replace a certificate with a newly reissued certificate. +// UpdateBulkCertificate updates the specified resource. +// // By using this endpoint, the original certificate will cease to be used for future TLS handshakes. // Thus, only SAN entries that appear in the replacement certificate will become TLS enabled. // Any SAN entries that are missing in the replacement certificate will become disabled. @@ -202,10 +223,11 @@ func (c *Client) UpdateBulkCertificate(i *UpdateBulkCertificateInput) (*BulkCert // DeleteBulkCertificateInput used for deleting a certificate. type DeleteBulkCertificateInput struct { + // ID is an alphanumeric string identifying a TLS bulk certificate. ID string } -// DeleteBulkCertificate destroy a certificate. This disables TLS for all domains listed as SAN entries. +// DeleteBulkCertificate deletes the specified resource. func (c *Client) DeleteBulkCertificate(i *DeleteBulkCertificateInput) error { if i.ID == "" { return ErrMissingID diff --git a/fastly/pool.go b/fastly/pool.go index 53ef53291..6c2a59f23 100644 --- a/fastly/pool.go +++ b/fastly/pool.go @@ -61,9 +61,17 @@ type Pool struct { // poolsByName is a sortable list of pools. type poolsByName []*Pool -// Len, Swap, and Less implement the sortable interface. -func (s poolsByName) Len() int { return len(s) } -func (s poolsByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s poolsByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s poolsByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s poolsByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -76,7 +84,7 @@ type ListPoolsInput struct { ServiceVersion int } -// ListPools lists all pools for a particular service and version. +// ListPools retrieves all resources. func (c *Client) ListPools(i *ListPoolsInput) ([]*Pool, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -103,35 +111,55 @@ func (c *Client) ListPools(i *ListPoolsInput) ([]*Pool, error) { // CreatePoolInput is used as input to the CreatePool function. type CreatePoolInput struct { - Comment string `url:"comment,omitempty"` - ConnectTimeout uint `url:"connect_timeout,omitempty"` - FirstByteTimeout uint `url:"first_byte_timeout,omitempty"` - Healthcheck string `url:"healthcheck,omitempty"` - MaxConnDefault uint `url:"max_conn_default,omitempty"` - MaxTLSVersion string `url:"max_tls_version,omitempty"` - MinTLSVersion string `url:"min_tls_version,omitempty"` + // Comment is a freeform descriptive note. + Comment string `url:"comment,omitempty"` + // ConnectTimeout is how long to wait for a timeout in milliseconds. + ConnectTimeout uint `url:"connect_timeout,omitempty"` + // FirstByteTimeout is how long to wait for the first byte in milliseconds. + FirstByteTimeout uint `url:"first_byte_timeout,omitempty"` + // Healthcheck is the name of the healthcheck to use with this pool. + Healthcheck string `url:"healthcheck,omitempty"` + // MaxConnDefault is the maximum number of connections. + MaxConnDefault uint `url:"max_conn_default,omitempty"` + // MaxTLSVersion is the maximum allowed TLS version on connections to this server. + MaxTLSVersion string `url:"max_tls_version,omitempty"` + // MinTLSVersion is the minimum allowed TLS version on connections to this server. + MinTLSVersion string `url:"min_tls_version,omitempty"` // Name is the name of the pool to create (required). - Name string `url:"name"` - OverrideHost string `url:"override_host,omitempty"` - Quorum uint `url:"quorum,omitempty"` + Name string `url:"name"` + // OverrideHost is the hostname to override the Host header. + OverrideHost string `url:"override_host,omitempty"` + // Quorum is the percentage of capacity (0-100) that needs to be operationally available for a pool to be considered up. + Quorum uint `url:"quorum,omitempty"` + // RequestCondition is the condition which, if met, will select this configuration during a request. RequestCondition string `url:"request_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). - ServiceVersion int - Shield string `url:"shield,omitempty"` - TLSCACert string `url:"tls_ca_cert,omitempty"` - TLSCertHostname string `url:"tls_cert_hostname,omitempty"` - TLSCheckCert Compatibool `url:"tls_check_cert,omitempty"` - TLSCiphers string `url:"tls_ciphers,omitempty"` - TLSClientCert string `url:"tls_client_cert,omitempty"` - TLSClientKey string `url:"tls_client_key,omitempty"` - TLSSNIHostname string `url:"tls_sni_hostname,omitempty"` - Type PoolType `url:"type,omitempty"` - UseTLS Compatibool `url:"use_tls,omitempty"` + ServiceVersion int + // Shield is the selected POP to serve as a shield for the servers. + Shield string `url:"shield,omitempty"` + // TLSCACert is a secure certificate to authenticate a server with. Must be in PEM format. + TLSCACert string `url:"tls_ca_cert,omitempty"` + // TLSCertHostname is the hostname used to verify a server's certificate. + TLSCertHostname string `url:"tls_cert_hostname,omitempty"` + // TLSCheckCert forces strict checking of TLS certs. + TLSCheckCert Compatibool `url:"tls_check_cert,omitempty"` + // TLSCiphers is a list of OpenSSL ciphers (see the openssl.org manpages for details). + TLSCiphers string `url:"tls_ciphers,omitempty"` + // TLSClientCert is the client certificate used to make authenticated requests. Must be in PEM format. + TLSClientCert string `url:"tls_client_cert,omitempty"` + // TLSClientKey is the client private key used to make authenticated requests. Must be in PEM format. + TLSClientKey string `url:"tls_client_key,omitempty"` + // TLSSNIHostname is the SNI hostname. + TLSSNIHostname string `url:"tls_sni_hostname,omitempty"` + // Type is what type of load balance group to use (random, hash, client). + Type PoolType `url:"type,omitempty"` + // UseTLS indicates whether to use TLS. + UseTLS Compatibool `url:"use_tls,omitempty"` } -// CreatePool creates a pool for a particular service and version. +// CreatePool creates a new resource. func (c *Client) CreatePool(i *CreatePoolInput) (*Pool, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -169,7 +197,7 @@ type GetPoolInput struct { ServiceVersion int } -// GetPool gets a single pool for a particular service and version. +// GetPool retrieves the specified resource. func (c *Client) GetPool(i *GetPoolInput) (*Pool, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -199,36 +227,57 @@ func (c *Client) GetPool(i *GetPoolInput) (*Pool, error) { // UpdatePoolInput is used as input to the UpdatePool function. type UpdatePoolInput struct { - Comment *string `url:"comment,omitempty"` - ConnectTimeout *uint `url:"connect_timeout,omitempty"` - FirstByteTimeout *uint `url:"first_byte_timeout,omitempty"` - Healthcheck *string `url:"healthcheck,omitempty"` - MaxConnDefault *uint `url:"max_conn_default,omitempty"` - MaxTLSVersion *string `url:"max_tls_version,omitempty"` - MinTLSVersion *string `url:"min_tls_version,omitempty"` + // Comment is a freeform descriptive note. + Comment *string `url:"comment,omitempty"` + // ConnectTimeout is how long to wait for a timeout in milliseconds. + ConnectTimeout *uint `url:"connect_timeout,omitempty"` + // FirstByteTimeout is how long to wait for the first byte in milliseconds. + FirstByteTimeout *uint `url:"first_byte_timeout,omitempty"` + // Healthcheck is the name of the healthcheck to use with this pool. + Healthcheck *string `url:"healthcheck,omitempty"` + // MaxConnDefault is the maximum number of connections. + MaxConnDefault *uint `url:"max_conn_default,omitempty"` + // MaxTLSVersion is the maximum allowed TLS version on connections to this server. + MaxTLSVersion *string `url:"max_tls_version,omitempty"` + // MinTLSVersion is the minimum allowed TLS version on connections to this server. + MinTLSVersion *string `url:"min_tls_version,omitempty"` // Name is the name of the pool to update (required). - Name string - NewName *string `url:"name,omitempty"` - OverrideHost *string `url:"override_host,omitempty"` - Quorum *uint `url:"quorum,omitempty"` + Name string + // NewName is the new name for the resource. + NewName *string `url:"name,omitempty"` + // OverrideHost is the hostname to override the Host header. + OverrideHost *string `url:"override_host,omitempty"` + // Quorum is the percentage of capacity (0-100) that needs to be operationally available for a pool to be considered up. + Quorum *uint `url:"quorum,omitempty"` + // RequestCondition is the condition which, if met, will select this configuration during a request. RequestCondition *string `url:"request_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). - ServiceVersion int - Shield *string `url:"shield,omitempty"` - TLSCACert *string `url:"tls_ca_cert,omitempty"` - TLSCertHostname *string `url:"tls_cert_hostname,omitempty"` - TLSCheckCert *Compatibool `url:"tls_check_cert,omitempty"` - TLSCiphers *string `url:"tls_ciphers,omitempty"` - TLSClientCert *string `url:"tls_client_cert,omitempty"` - TLSClientKey *string `url:"tls_client_key,omitempty"` - TLSSNIHostname *string `url:"tls_sni_hostname,omitempty"` - Type *PoolType `url:"type,omitempty"` - UseTLS *Compatibool `url:"use_tls,omitempty"` + ServiceVersion int + // Shield is the selected POP to serve as a shield for the servers. + Shield *string `url:"shield,omitempty"` + // TLSCACert is a secure certificate to authenticate a server with. Must be in PEM format. + TLSCACert *string `url:"tls_ca_cert,omitempty"` + // TLSCertHostname is the hostname used to verify a server's certificate. + TLSCertHostname *string `url:"tls_cert_hostname,omitempty"` + // TLSCheckCert forces strict checking of TLS certs. + TLSCheckCert *Compatibool `url:"tls_check_cert,omitempty"` + // TLSCiphers is a list of OpenSSL ciphers (see the openssl.org manpages for details). + TLSCiphers *string `url:"tls_ciphers,omitempty"` + // TLSClientCert is the client certificate used to make authenticated requests. Must be in PEM format. + TLSClientCert *string `url:"tls_client_cert,omitempty"` + // TLSClientKey is the client private key used to make authenticated requests. Must be in PEM format. + TLSClientKey *string `url:"tls_client_key,omitempty"` + // TLSSNIHostname is the SNI hostname. + TLSSNIHostname *string `url:"tls_sni_hostname,omitempty"` + // Type is what type of load balance group to use (random, hash, client). + Type *PoolType `url:"type,omitempty"` + // UseTLS indicates whether to use TLS. + UseTLS *Compatibool `url:"use_tls,omitempty"` } -// UpdatePool updates a specufic pool for a particular service and version. +// UpdatePool updates the specified resource. func (c *Client) UpdatePool(i *UpdatePoolInput) (*Pool, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -266,7 +315,7 @@ type DeletePoolInput struct { ServiceVersion int } -// DeletePool deletes a specific pool for a particular service and version. +// DeletePool deletes the specified resource. func (c *Client) DeletePool(i *DeletePoolInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/pool_test.go b/fastly/pool_test.go index 4e2101877..52f1243ab 100644 --- a/fastly/pool_test.go +++ b/fastly/pool_test.go @@ -34,13 +34,13 @@ func TestClient_Pools(t *testing.T) { // Ensure deleted defer func() { record(t, "pools/cleanup", func(c *Client) { - c.DeletePool(&DeletePoolInput{ + _ = c.DeletePool(&DeletePoolInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test_pool", }) - c.DeletePool(&DeletePoolInput{ + _ = c.DeletePool(&DeletePoolInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "new_test_pool", @@ -56,7 +56,7 @@ func TestClient_Pools(t *testing.T) { t.Errorf("bad quorum: %q", p.Quorum) } - if p.UseTLS != true { + if !p.UseTLS { t.Errorf("bad use_tls: %t", p.UseTLS) } diff --git a/fastly/pubsub.go b/fastly/pubsub.go index 2a38c15b5..fbeb9e484 100644 --- a/fastly/pubsub.go +++ b/fastly/pubsub.go @@ -29,9 +29,17 @@ type Pubsub struct { // pubsubsByName is a sortable list of pubsubs. type pubsubsByName []*Pubsub -// Len, Swap, and Less implement the sortable interface. -func (s pubsubsByName) Len() int { return len(s) } -func (s pubsubsByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s pubsubsByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s pubsubsByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s pubsubsByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -44,7 +52,7 @@ type ListPubsubsInput struct { ServiceVersion int } -// ListPubsubs returns the list of pubsubs for the configuration version. +// ListPubsubs retrieves all resources. func (c *Client) ListPubsubs(i *ListPubsubsInput) ([]*Pubsub, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -71,23 +79,33 @@ func (c *Client) ListPubsubs(i *ListPubsubsInput) ([]*Pubsub, error) { // CreatePubsubInput is used as input to the CreatePubsub function. type CreatePubsubInput struct { - AccountName string `url:"account_name,omitempty"` - Format string `url:"format,omitempty"` - FormatVersion uint `url:"format_version,omitempty"` - Name string `url:"name,omitempty"` - Placement string `url:"placement,omitempty"` - ProjectID string `url:"project_id,omitempty"` + // AccountName is the name of the Google Cloud Platform service account associated with the target log collection service. Not required if user and secret_key are provided. + AccountName string `url:"account_name,omitempty"` + // Format is a Fastly log format string. + Format string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion uint `url:"format_version,omitempty"` + // Name is the name for the real-time logging configuration. + Name string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement string `url:"placement,omitempty"` + // ProjectID is your Google Cloud Platform project ID. Required. + ProjectID string `url:"project_id,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition string `url:"response_condition,omitempty"` - SecretKey string `url:"secret_key,omitempty"` + // SecretKey is your Google Cloud Platform account secret key. The private_key field in your service account authentication JSON. Not required if account_name is specified. + SecretKey string `url:"secret_key,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - Topic string `url:"topic,omitempty"` - User string `url:"user,omitempty"` + // Topic is the Google Cloud Pub/Sub topic to which logs will be published. + Topic string `url:"topic,omitempty"` + // User is your Google Cloud Platform service account email address. The client_email field in your service account authentication JSON. Not required if account_name is specified. + User string `url:"user,omitempty"` } -// CreatePubsub creates a new Fastly Pubsub. +// CreatePubsub creates a new resource. func (c *Client) CreatePubsub(i *CreatePubsubInput) (*Pubsub, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -121,7 +139,7 @@ type GetPubsubInput struct { ServiceVersion int } -// GetPubsub gets the Pubsub configuration with the given parameters. +// GetPubsub retrieves the specified resource. func (c *Client) GetPubsub(i *GetPubsubInput) (*Pubsub, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -151,25 +169,35 @@ func (c *Client) GetPubsub(i *GetPubsubInput) (*Pubsub, error) { // UpdatePubsubInput is used as input to the UpdatePubsub function. type UpdatePubsubInput struct { - AccountName *string `url:"account_name,omitempty"` - Format *string `url:"format,omitempty"` - FormatVersion *uint `url:"format_version,omitempty"` + // AccountName is the name of the Google Cloud Platform service account associated with the target log collection service. Not required if user and secret_key are provided. + AccountName *string `url:"account_name,omitempty"` + // Format is a Fastly log format string. + Format *string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion *uint `url:"format_version,omitempty"` // Name is the name of the Pubsub to update. - Name string - NewName *string `url:"name,omitempty"` - Placement *string `url:"placement,omitempty"` - ProjectID *string `url:"project_id,omitempty"` + Name string + // NewName is the new name for the resource. + NewName *string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement *string `url:"placement,omitempty"` + // ProjectID is your Google Cloud Platform project ID. Required. + ProjectID *string `url:"project_id,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition *string `url:"response_condition,omitempty"` - SecretKey *string `url:"secret_key,omitempty"` + // SecretKey is your Google Cloud Platform account secret key. The private_key field in your service account authentication JSON. Not required if account_name is specified. + SecretKey *string `url:"secret_key,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - Topic *string `url:"topic,omitempty"` - User *string `url:"user,omitempty"` + // Topic is the Google Cloud Pub/Sub topic to which logs will be published. + Topic *string `url:"topic,omitempty"` + // User is your Google Cloud Platform service account email address. The client_email field in your service account authentication JSON. Not required if account_name is specified. + User *string `url:"user,omitempty"` } -// UpdatePubsub updates a specific Pubsub. +// UpdatePubsub updates the specified resource. func (c *Client) UpdatePubsub(i *UpdatePubsubInput) (*Pubsub, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -207,7 +235,7 @@ type DeletePubsubInput struct { ServiceVersion int } -// DeletePubsub deletes the given Pubsub version. +// DeletePubsub deletes the specified resource. func (c *Client) DeletePubsub(i *DeletePubsubInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/pubsub_test.go b/fastly/pubsub_test.go index a299801e2..fa7c6a6dd 100644 --- a/fastly/pubsub_test.go +++ b/fastly/pubsub_test.go @@ -38,13 +38,13 @@ func TestClient_Pubsubs(t *testing.T) { // Ensure deleted defer func() { record(t, "pubsubs/cleanup", func(c *Client) { - c.DeletePubsub(&DeletePubsubInput{ + _ = c.DeletePubsub(&DeletePubsubInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-pubsub", }) - c.DeletePubsub(&DeletePubsubInput{ + _ = c.DeletePubsub(&DeletePubsubInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "new-test-pubsub", diff --git a/fastly/realtime_stats.go b/fastly/realtime_stats.go index f8ade9a9b..6a9497db3 100644 --- a/fastly/realtime_stats.go +++ b/fastly/realtime_stats.go @@ -7,24 +7,32 @@ import ( // RealtimeStatsResponse is a response from Fastly's real-time analytics endpoint type RealtimeStatsResponse struct { - AggregateDelay uint32 `mapstructure:"AggregateDelay"` - Data []*RealtimeData `mapstructure:"Data"` - Error string `mapstructure:"Error"` - Timestamp uint64 `mapstructure:"Timestamp"` + // AggregateDelay is how long the system will wait before aggregating messages for each second. + AggregateDelay uint32 `mapstructure:"AggregateDelay"` + // Data is a list of records, each representing one second of time. + Data []*RealtimeData `mapstructure:"Data"` + Error string `mapstructure:"Error"` + // Timestamp is a value to use for subsequent requests. + Timestamp uint64 `mapstructure:"Timestamp"` } // RealtimeData represents combined stats for all Fastly's POPs and aggregate of them. // It also includes a timestamp of when the stats were recorded type RealtimeData struct { - Aggregated *Stats `mapstructure:"aggregated"` + // Aggregated aggregates measurements across all Fastly POPs. + Aggregated *Stats `mapstructure:"aggregated"` + // Datacenter groups measurements by POP. Datacenter map[string]*Stats `mapstructure:"datacenter"` - Recorded uint64 `mapstructure:"recorded"` + // Recorded is the Unix timestamp at which this record's data was generated. + Recorded uint64 `mapstructure:"recorded"` } // GetRealtimeStatsInput is an input parameter to GetRealtimeStats function type GetRealtimeStatsInput struct { - Limit uint32 + Limit uint32 + // ServiceID is the ID of the service. ServiceID string + // Timestamp is a value to use for subsequent requests. Timestamp uint64 } diff --git a/fastly/request.go b/fastly/request.go index 67e2cf183..3185c249f 100644 --- a/fastly/request.go +++ b/fastly/request.go @@ -79,12 +79,12 @@ func (c *Client) SimpleGet(target string) (*http.Response, error) { // We parse the URL and then convert it right back to a string // later; this just acts as a check that Fastly isn't sending // us nonsense. - url, err := url.Parse(target) + u, err := url.Parse(target) if err != nil { return nil, err } - request, err := http.NewRequest("GET", url.String(), nil) + request, err := http.NewRequest("GET", u.String(), nil) if err != nil { return nil, err } diff --git a/fastly/request_setting.go b/fastly/request_setting.go index f519db160..14af290f4 100644 --- a/fastly/request_setting.go +++ b/fastly/request_setting.go @@ -63,9 +63,17 @@ type RequestSetting struct { // requestSettingsByName is a sortable list of request settings. type requestSettingsByName []*RequestSetting -// Len, Swap, and Less implement the sortable interface. -func (s requestSettingsByName) Len() int { return len(s) } -func (s requestSettingsByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s requestSettingsByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s requestSettingsByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s requestSettingsByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -79,8 +87,7 @@ type ListRequestSettingsInput struct { ServiceVersion int } -// ListRequestSettings returns the list of request settings for the -// configuration version. +// ListRequestSettings retrieves all resources. func (c *Client) ListRequestSettings(i *ListRequestSettingsInput) ([]*RequestSetting, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -108,25 +115,37 @@ func (c *Client) ListRequestSettings(i *ListRequestSettingsInput) ([]*RequestSet // CreateRequestSettingInput is used as input to the CreateRequestSetting // function. type CreateRequestSettingInput struct { - Action RequestSettingAction `url:"action,omitempty"` - BypassBusyWait Compatibool `url:"bypass_busy_wait,omitempty"` - DefaultHost string `url:"default_host,omitempty"` - ForceMiss Compatibool `url:"force_miss,omitempty"` - ForceSSL Compatibool `url:"force_ssl,omitempty"` - GeoHeaders Compatibool `url:"geo_headers,omitempty"` - HashKeys string `url:"hash_keys,omitempty"` - MaxStaleAge *uint `url:"max_stale_age,omitempty"` - Name string `url:"name,omitempty"` - RequestCondition string `url:"request_condition,omitempty"` + // Action allows you to terminate request handling and immediately perform an action. + Action RequestSettingAction `url:"action,omitempty"` + // BypassBusyWait disables collapsed forwarding, so you don't wait for other objects to origin. + BypassBusyWait Compatibool `url:"bypass_busy_wait,omitempty"` + // DefaultHost sets the host header. + DefaultHost string `url:"default_host,omitempty"` + // ForceMiss allows you to force a cache miss for the request. Replaces the item in the cache if the content is cacheable. + ForceMiss Compatibool `url:"force_miss,omitempty"` + // ForceSSL forces the request use SSL (redirects a non-SSL to SSL). + ForceSSL Compatibool `url:"force_ssl,omitempty"` + // GeoHeaders injects Fastly-Geo-Country, Fastly-Geo-City, and Fastly-Geo-Region into the request headers. + GeoHeaders Compatibool `url:"geo_headers,omitempty"` + // HashKeys is a comma separated list of varnish request object fields that should be in the hash key. + HashKeys string `url:"hash_keys,omitempty"` + // MaxStaleAge is how old an object is allowed to be to serve stale-if-error or stale-while-revalidate. + MaxStaleAge *uint `url:"max_stale_age,omitempty"` + // Name is the name for the request settings. + Name string `url:"name,omitempty"` + // RequestCondition is the condition which, if met, will select this configuration during a request. + RequestCondition string `url:"request_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - TimerSupport Compatibool `url:"timer_support,omitempty"` - XForwardedFor RequestSettingXFF `url:"xff,omitempty"` + // TimerSupport injects the X-Timer info into the request for viewing origin fetch durations. + TimerSupport Compatibool `url:"timer_support,omitempty"` + // XForwardedFor determines header value (clear, leave, append, append_all, overwrite) + XForwardedFor RequestSettingXFF `url:"xff,omitempty"` } -// CreateRequestSetting creates a new Fastly request settings. +// CreateRequestSetting creates a new resource. func (c *Client) CreateRequestSetting(i *CreateRequestSettingInput) (*RequestSetting, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -160,8 +179,7 @@ type GetRequestSettingInput struct { ServiceVersion int } -// GetRequestSetting gets the request settings configuration with the given -// parameters. +// GetRequestSetting retrieves the specified resource. func (c *Client) GetRequestSetting(i *GetRequestSettingInput) (*RequestSetting, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -192,27 +210,39 @@ func (c *Client) GetRequestSetting(i *GetRequestSettingInput) (*RequestSetting, // UpdateRequestSettingInput is used as input to the UpdateRequestSetting // function. type UpdateRequestSettingInput struct { - Action RequestSettingAction `url:"action,omitempty"` - BypassBusyWait *Compatibool `url:"bypass_busy_wait,omitempty"` - DefaultHost *string `url:"default_host,omitempty"` - ForceMiss *Compatibool `url:"force_miss,omitempty"` - ForceSSL *Compatibool `url:"force_ssl,omitempty"` - GeoHeaders *Compatibool `url:"geo_headers,omitempty"` - HashKeys *string `url:"hash_keys,omitempty"` - MaxStaleAge *uint `url:"max_stale_age,omitempty"` + // Action allows you to terminate request handling and immediately perform an action. + Action RequestSettingAction `url:"action,omitempty"` + // BypassBusyWait disables collapsed forwarding, so you don't wait for other objects to origin. + BypassBusyWait *Compatibool `url:"bypass_busy_wait,omitempty"` + // DefaultHost sets the host header. + DefaultHost *string `url:"default_host,omitempty"` + // ForceMiss allows you to force a cache miss for the request. Replaces the item in the cache if the content is cacheable. + ForceMiss *Compatibool `url:"force_miss,omitempty"` + // ForceSSL forces the request use SSL (redirects a non-SSL to SSL). + ForceSSL *Compatibool `url:"force_ssl,omitempty"` + // GeoHeaders injects Fastly-Geo-Country, Fastly-Geo-City, and Fastly-Geo-Region into the request headers. + GeoHeaders *Compatibool `url:"geo_headers,omitempty"` + // HashKeys is a comma separated list of varnish request object fields that should be in the hash key. + HashKeys *string `url:"hash_keys,omitempty"` + // MaxStaleAge is how old an object is allowed to be to serve stale-if-error or stale-while-revalidate. + MaxStaleAge *uint `url:"max_stale_age,omitempty"` // Name is the name of the request settings to update. - Name string - NewName *string `url:"name,omitempty"` + Name string + // NewName is the new name for the resource. + NewName *string `url:"name,omitempty"` + // RequestCondition is the condition which, if met, will select this configuration during a request. RequestCondition *string `url:"request_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - TimerSupport *Compatibool `url:"timer_support,omitempty"` - XForwardedFor RequestSettingXFF `url:"xff,omitempty"` + // TimerSupport injects the X-Timer info into the request for viewing origin fetch durations. + TimerSupport *Compatibool `url:"timer_support,omitempty"` + // XForwardedFor determines header value (clear, leave, append, append_all, overwrite) + XForwardedFor RequestSettingXFF `url:"xff,omitempty"` } -// UpdateRequestSetting updates a specific request settings. +// UpdateRequestSetting updates the specified resource. func (c *Client) UpdateRequestSetting(i *UpdateRequestSettingInput) (*RequestSetting, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -250,7 +280,7 @@ type DeleteRequestSettingInput struct { ServiceVersion int } -// DeleteRequestSetting deletes the given request settings version. +// DeleteRequestSetting deletes the specified resource. func (c *Client) DeleteRequestSetting(i *DeleteRequestSettingInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/request_setting_test.go b/fastly/request_setting_test.go index 2b6fb0fa9..a130a370a 100644 --- a/fastly/request_setting_test.go +++ b/fastly/request_setting_test.go @@ -39,13 +39,13 @@ func TestClient_RequestSettings(t *testing.T) { // Ensure deleted defer func() { record(t, "request_settings/cleanup", func(c *Client) { - c.DeleteRequestSetting(&DeleteRequestSettingInput{ + _ = c.DeleteRequestSetting(&DeleteRequestSettingInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-request-setting", }) - c.DeleteRequestSetting(&DeleteRequestSettingInput{ + _ = c.DeleteRequestSetting(&DeleteRequestSettingInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "new-test-request-setting", @@ -56,16 +56,16 @@ func TestClient_RequestSettings(t *testing.T) { if rs.Name != "test-request-setting" { t.Errorf("bad name: %q", rs.Name) } - if rs.ForceMiss != true { + if !rs.ForceMiss { t.Errorf("bad force_miss: %t", rs.ForceMiss) } - if rs.ForceSSL != true { + if !rs.ForceSSL { t.Errorf("bad force_ssl: %t", rs.ForceSSL) } if rs.Action != RequestSettingActionLookup { t.Errorf("bad action: %q", rs.Action) } - if rs.BypassBusyWait != true { + if !rs.BypassBusyWait { t.Errorf("bad bypass_busy_wait: %t", rs.BypassBusyWait) } if rs.MaxStaleAge != 30 { @@ -77,10 +77,10 @@ func TestClient_RequestSettings(t *testing.T) { if rs.XForwardedFor != RequestSettingXFFLeave { t.Errorf("bad xff: %q", rs.XForwardedFor) } - if rs.TimerSupport != true { + if !rs.TimerSupport { t.Errorf("bad timer_support: %t", rs.TimerSupport) } - if rs.GeoHeaders != true { + if !rs.GeoHeaders { t.Errorf("bad geo_headers: %t", rs.GeoHeaders) } if rs.DefaultHost != "example.com" { diff --git a/fastly/response_object.go b/fastly/response_object.go index df7f57937..10e709a9d 100644 --- a/fastly/response_object.go +++ b/fastly/response_object.go @@ -26,9 +26,17 @@ type ResponseObject struct { // responseObjectsByName is a sortable list of response objects. type responseObjectsByName []*ResponseObject -// Len, Swap, and Less implement the sortable interface. -func (s responseObjectsByName) Len() int { return len(s) } -func (s responseObjectsByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s responseObjectsByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s responseObjectsByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s responseObjectsByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -42,8 +50,7 @@ type ListResponseObjectsInput struct { ServiceVersion int } -// ListResponseObjects returns the list of response objects for the -// configuration version. +// ListResponseObjects retrieves all resources. func (c *Client) ListResponseObjects(i *ListResponseObjectsInput) ([]*ResponseObject, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -71,20 +78,27 @@ func (c *Client) ListResponseObjects(i *ListResponseObjectsInput) ([]*ResponseOb // CreateResponseObjectInput is used as input to the CreateResponseObject // function. type CreateResponseObjectInput struct { - CacheCondition string `url:"cache_condition,omitempty"` - Content string `url:"content,omitempty"` - ContentType string `url:"content_type,omitempty"` - Name string `url:"name,omitempty"` + // CacheCondition is the name of the cache condition controlling when this configuration applies. + CacheCondition string `url:"cache_condition,omitempty"` + // Content is the content to deliver for the response object, can be empty. + Content string `url:"content,omitempty"` + // ContentType is the MIME type of the content, can be empty. + ContentType string `url:"content_type,omitempty"` + // Name is the name for the request settings. + Name string `url:"name,omitempty"` + // RequestCondition is the condition which, if met, will select this configuration during a request. RequestCondition string `url:"request_condition,omitempty"` - Response string `url:"response,omitempty"` + // Response is the HTTP response. + Response string `url:"response,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - Status *uint `url:"status,omitempty"` + // Status is the HTTP status code. + Status *uint `url:"status,omitempty"` } -// CreateResponseObject creates a new Fastly response object. +// CreateResponseObject creates a new resource. func (c *Client) CreateResponseObject(i *CreateResponseObjectInput) (*ResponseObject, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -118,8 +132,7 @@ type GetResponseObjectInput struct { ServiceVersion int } -// GetResponseObject gets the response object configuration with the given -// parameters. +// GetResponseObject retrieves the specified resource. func (c *Client) GetResponseObject(i *GetResponseObjectInput) (*ResponseObject, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -150,22 +163,29 @@ func (c *Client) GetResponseObject(i *GetResponseObjectInput) (*ResponseObject, // UpdateResponseObjectInput is used as input to the UpdateResponseObject // function. type UpdateResponseObjectInput struct { + // CacheCondition is the name of the cache condition controlling when this configuration applies. CacheCondition *string `url:"cache_condition,omitempty"` - Content *string `url:"content,omitempty"` - ContentType *string `url:"content_type,omitempty"` + // Content is the content to deliver for the response object, can be empty. + Content *string `url:"content,omitempty"` + // ContentType is the MIME type of the content, can be empty. + ContentType *string `url:"content_type,omitempty"` // Name is the name of the response object to update. - Name string - NewName *string `url:"name,omitempty"` + Name string + // NewName is the new name for the resource. + NewName *string `url:"name,omitempty"` + // RequestCondition is the condition which, if met, will select this configuration during a request. RequestCondition *string `url:"request_condition,omitempty"` - Response *string `url:"response,omitempty"` + // Response is the HTTP response. + Response *string `url:"response,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - Status *uint `url:"status,omitempty"` + // Status is the HTTP status code. + Status *uint `url:"status,omitempty"` } -// UpdateResponseObject updates a specific response object. +// UpdateResponseObject updates the specified resource. func (c *Client) UpdateResponseObject(i *UpdateResponseObjectInput) (*ResponseObject, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -203,7 +223,7 @@ type DeleteResponseObjectInput struct { ServiceVersion int } -// DeleteResponseObject deletes the given response object version. +// DeleteResponseObject deletes the specified resource. func (c *Client) DeleteResponseObject(i *DeleteResponseObjectInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/response_object_test.go b/fastly/response_object_test.go index f95fb16af..10bb204b2 100644 --- a/fastly/response_object_test.go +++ b/fastly/response_object_test.go @@ -33,13 +33,13 @@ func TestClient_ResponseObjects(t *testing.T) { // Ensure deleted defer func() { record(t, "response_objects/cleanup", func(c *Client) { - c.DeleteResponseObject(&DeleteResponseObjectInput{ + _ = c.DeleteResponseObject(&DeleteResponseObjectInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-response-object", }) - c.DeleteResponseObject(&DeleteResponseObjectInput{ + _ = c.DeleteResponseObject(&DeleteResponseObjectInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "new-test-response-object", diff --git a/fastly/s3.go b/fastly/s3.go index 3193bddae..9b8b63c38 100644 --- a/fastly/s3.go +++ b/fastly/s3.go @@ -7,37 +7,66 @@ import ( "time" ) +// S3Redundancy represents the redundancy variants for S3. type S3Redundancy string -func S3RedundancyPtr(v S3Redundancy) *S3Redundancy { return &v } +// S3RedundancyPtr returns a pointer to a S3Redundancy. +func S3RedundancyPtr(v S3Redundancy) *S3Redundancy { + return &v +} +// S3ServerSideEncryption represents the encryption variants for S3. type S3ServerSideEncryption string -func S3ServerSideEncryptionPtr(v S3ServerSideEncryption) *S3ServerSideEncryption { return &v } +// S3ServerSideEncryptionPtr returns a pointer to a S3ServerSideEncryption. +func S3ServerSideEncryptionPtr(v S3ServerSideEncryption) *S3ServerSideEncryption { + return &v +} +// S3AccessControlList represents the control list variants for S3. type S3AccessControlList string -func S3AccessControlListPtr(v S3AccessControlList) *S3AccessControlList { return &v } +// S3AccessControlListPtr returns a pointer to a S3AccessControlList. +func S3AccessControlListPtr(v S3AccessControlList) *S3AccessControlList { + return &v +} const ( - S3RedundancyStandard S3Redundancy = "standard" - S3RedundancyIntelligentTiering S3Redundancy = "intelligent_tiering" - S3RedundancyStandardIA S3Redundancy = "standard_ia" - S3RedundancyOneZoneIA S3Redundancy = "onezone_ia" - S3RedundancyGlacierInstantRetrieval S3Redundancy = "glacier_ir" + // S3RedundancyStandard represents a redundancy variant. + S3RedundancyStandard S3Redundancy = "standard" + // S3RedundancyIntelligentTiering represents a redundancy variant. + S3RedundancyIntelligentTiering S3Redundancy = "intelligent_tiering" + // S3RedundancyStandardIA represents a redundancy variant. + S3RedundancyStandardIA S3Redundancy = "standard_ia" + // S3RedundancyOneZoneIA represents a redundancy variant. + S3RedundancyOneZoneIA S3Redundancy = "onezone_ia" + // S3RedundancyGlacierInstantRetrieval represents a redundancy variant. + S3RedundancyGlacierInstantRetrieval S3Redundancy = "glacier_ir" + // S3RedundancyGlacierFlexibleRetrieval represents a redundancy variant. S3RedundancyGlacierFlexibleRetrieval S3Redundancy = "glacier" - S3RedundancyGlacierDeepArchive S3Redundancy = "deep_archive" - S3RedundancyReduced S3Redundancy = "reduced_redundancy" + // S3RedundancyGlacierDeepArchive represents a redundancy variant. + S3RedundancyGlacierDeepArchive S3Redundancy = "deep_archive" + // S3RedundancyReduced represents a redundancy variant. + S3RedundancyReduced S3Redundancy = "reduced_redundancy" + // S3ServerSideEncryptionAES represents an encryption variant. S3ServerSideEncryptionAES S3ServerSideEncryption = "AES256" + // S3ServerSideEncryptionKMS represents an encryption variant. S3ServerSideEncryptionKMS S3ServerSideEncryption = "aws:kms" - S3AccessControlListPrivate S3AccessControlList = "private" - S3AccessControlListPublicRead S3AccessControlList = "public-read" - S3AccessControlListPublicReadWrite S3AccessControlList = "public-read-write" - S3AccessControlListAWSExecRead S3AccessControlList = "aws-exec-read" - S3AccessControlListAuthenticatedRead S3AccessControlList = "authenticated-read" - S3AccessControlListBucketOwnerRead S3AccessControlList = "bucket-owner-read" + // S3AccessControlListPrivate represents a control list variant. + S3AccessControlListPrivate S3AccessControlList = "private" + // S3AccessControlListPublicRead represents a control list variant. + S3AccessControlListPublicRead S3AccessControlList = "public-read" + // S3AccessControlListPublicReadWrite represents a control list variant. + S3AccessControlListPublicReadWrite S3AccessControlList = "public-read-write" + // S3AccessControlListAWSExecRead represents a control list variant. + S3AccessControlListAWSExecRead S3AccessControlList = "aws-exec-read" + // S3AccessControlListAuthenticatedRead represents a control list variant. + S3AccessControlListAuthenticatedRead S3AccessControlList = "authenticated-read" + // S3AccessControlListBucketOwnerRead represents a control list variant. + S3AccessControlListBucketOwnerRead S3AccessControlList = "bucket-owner-read" + // S3AccessControlListBucketOwnerFullControl represents a control list variant. S3AccessControlListBucketOwnerFullControl S3AccessControlList = "bucket-owner-full-control" ) @@ -74,9 +103,17 @@ type S3 struct { // s3sByName is a sortable list of S3s. type s3sByName []*S3 -// Len, Swap, and Less implement the sortable interface. -func (s s3sByName) Len() int { return len(s) } -func (s s3sByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s s3sByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s s3sByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s s3sByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -89,7 +126,7 @@ type ListS3sInput struct { ServiceVersion int } -// ListS3s returns the list of S3s for the configuration version. +// ListS3s retrieves all resources. func (c *Client) ListS3s(i *ListS3sInput) ([]*S3, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -116,34 +153,55 @@ func (c *Client) ListS3s(i *ListS3sInput) ([]*S3, error) { // CreateS3Input is used as input to the CreateS3 function. type CreateS3Input struct { - ACL S3AccessControlList `url:"acl,omitempty"` - AccessKey string `url:"access_key,omitempty"` - BucketName string `url:"bucket_name,omitempty"` - CompressionCodec string `url:"compression_codec,omitempty"` - Domain string `url:"domain,omitempty"` - Format string `url:"format,omitempty"` - FormatVersion uint `url:"format_version,omitempty"` - GzipLevel uint8 `url:"gzip_level,omitempty"` - IAMRole string `url:"iam_role,omitempty"` - MessageType string `url:"message_type,omitempty"` - Name string `url:"name,omitempty"` - Path string `url:"path,omitempty"` - Period uint `url:"period,omitempty"` - Placement string `url:"placement,omitempty"` - PublicKey string `url:"public_key,omitempty"` - Redundancy S3Redundancy `url:"redundancy,omitempty"` - ResponseCondition string `url:"response_condition,omitempty"` - SecretKey string `url:"secret_key,omitempty"` - ServerSideEncryption S3ServerSideEncryption `url:"server_side_encryption,omitempty"` - ServerSideEncryptionKMSKeyID string `url:"server_side_encryption_kms_key_id,omitempty"` + // ACL is the access control list (ACL) specific request header. + ACL S3AccessControlList `url:"acl,omitempty"` + // AccessKey is the access key for your S3 account. Not required if iam_role is provided. + AccessKey string `url:"access_key,omitempty"` + // BucketName is the bucket name for S3 account. + BucketName string `url:"bucket_name,omitempty"` + // CompressionCodec is the codec used for compressing your logs. Valid values are zstd, snappy, and gzip. + CompressionCodec string `url:"compression_codec,omitempty"` + // Domain is the domain of the Amazon S3 endpoint. + Domain string `url:"domain,omitempty"` + // Format is a Fastly log format string. + Format string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion uint `url:"format_version,omitempty"` + // GzipLevel is the level of gzip encoding when sending logs (default 0, no compression). + GzipLevel uint8 `url:"gzip_level,omitempty"` + // IAMRole is the Amazon Resource Name (ARN) for the IAM role granting Fastly access to S3. Not required if access_key and secret_key are provided. + IAMRole string `url:"iam_role,omitempty"` + // MessageType is how the message should be formatted (classic, loggly, logplex, blank). + MessageType string `url:"message_type,omitempty"` + // Name is the name of the SFTP to update (required). + Name string `url:"name,omitempty"` + // Path is the path to upload logs to. + Path string `url:"path,omitempty"` + // Period is how frequently log files are finalized so they can be available for reading (in seconds). + Period uint `url:"period,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement string `url:"placement,omitempty"` + // PublicKey is a PGP public key that Fastly will use to encrypt your log files before writing them to disk. + PublicKey string `url:"public_key,omitempty"` + // Redundancy is the S3 redundancy level. + Redundancy S3Redundancy `url:"redundancy,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. + ResponseCondition string `url:"response_condition,omitempty"` + // SecretKey is the secret key for your S3 account. Not required if iam_role is provided. + SecretKey string `url:"secret_key,omitempty"` + // ServerSideEncryption should be set to AES256 or aws:kms to enable S3 Server Side Encryption. + ServerSideEncryption S3ServerSideEncryption `url:"server_side_encryption,omitempty"` + // ServerSideEncryptionKMSKeyID is an optional server-side KMS Key ID. Must be set if ServerSideEncryption is set to aws:kms or AES256. + ServerSideEncryptionKMSKeyID string `url:"server_side_encryption_kms_key_id,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). - ServiceVersion int + ServiceVersion int + // TimestampFormat is a timestamp format. TimestampFormat string `url:"timestamp_format,omitempty"` } -// CreateS3 creates a new Fastly S3. +// CreateS3 creates a new resource. func (c *Client) CreateS3(i *CreateS3Input) (*S3, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -181,7 +239,7 @@ type GetS3Input struct { ServiceVersion int } -// GetS3 gets the S3 configuration with the given parameters. +// GetS3 retrieves the specified resource. func (c *Client) GetS3(i *GetS3Input) (*S3, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -211,36 +269,57 @@ func (c *Client) GetS3(i *GetS3Input) (*S3, error) { // UpdateS3Input is used as input to the UpdateS3 function. type UpdateS3Input struct { - ACL *S3AccessControlList `url:"acl,omitempty"` - AccessKey *string `url:"access_key,omitempty"` - BucketName *string `url:"bucket_name,omitempty"` - CompressionCodec *string `url:"compression_codec,omitempty"` - Domain *string `url:"domain,omitempty"` - Format *string `url:"format,omitempty"` - FormatVersion *uint `url:"format_version,omitempty"` - GzipLevel *uint8 `url:"gzip_level,omitempty"` - IAMRole *string `url:"iam_role,omitempty"` - MessageType *string `url:"message_type,omitempty"` + // ACL is the access control list (ACL) specific request header. + ACL *S3AccessControlList `url:"acl,omitempty"` + // AccessKey is the access key for your S3 account. Not required if iam_role is provided. + AccessKey *string `url:"access_key,omitempty"` + // BucketName is the bucket name for S3 account. + BucketName *string `url:"bucket_name,omitempty"` + // CompressionCodec is the codec used for compressing your logs. Valid values are zstd, snappy, and gzip. + CompressionCodec *string `url:"compression_codec,omitempty"` + // Domain is the domain of the Amazon S3 endpoint. + Domain *string `url:"domain,omitempty"` + // Format is a Fastly log format string. + Format *string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion *uint `url:"format_version,omitempty"` + // GzipLevel is the level of gzip encoding when sending logs (default 0, no compression). + GzipLevel *uint8 `url:"gzip_level,omitempty"` + // IAMRole is the Amazon Resource Name (ARN) for the IAM role granting Fastly access to S3. Not required if access_key and secret_key are provided. + IAMRole *string `url:"iam_role,omitempty"` + // MessageType is how the message should be formatted (classic, loggly, logplex, blank). + MessageType *string `url:"message_type,omitempty"` // Name is the name of the S3 to update. - Name string - NewName *string `url:"name,omitempty"` - Path *string `url:"path,omitempty"` - Period *uint `url:"period,omitempty"` - Placement *string `url:"placement,omitempty"` - PublicKey *string `url:"public_key,omitempty"` - Redundancy *S3Redundancy `url:"redundancy,omitempty"` - ResponseCondition *string `url:"response_condition,omitempty"` - SecretKey *string `url:"secret_key,omitempty"` - ServerSideEncryption *S3ServerSideEncryption `url:"server_side_encryption,omitempty"` - ServerSideEncryptionKMSKeyID *string `url:"server_side_encryption_kms_key_id,omitempty"` + Name string + // NewName is the new name for the resource. + NewName *string `url:"name,omitempty"` + // Path is the path to upload logs to. + Path *string `url:"path,omitempty"` + // Period is how frequently log files are finalized so they can be available for reading (in seconds). + Period *uint `url:"period,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement *string `url:"placement,omitempty"` + // PublicKey is a PGP public key that Fastly will use to encrypt your log files before writing them to disk. + PublicKey *string `url:"public_key,omitempty"` + // Redundancy is the S3 redundancy level. + Redundancy *S3Redundancy `url:"redundancy,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. + ResponseCondition *string `url:"response_condition,omitempty"` + // SecretKey is the secret key for your S3 account. Not required if iam_role is provided. + SecretKey *string `url:"secret_key,omitempty"` + // ServerSideEncryption should be set to AES256 or aws:kms to enable S3 Server Side Encryption. + ServerSideEncryption *S3ServerSideEncryption `url:"server_side_encryption,omitempty"` + // ServerSideEncryptionKMSKeyID is an optional server-side KMS Key ID. Must be set if ServerSideEncryption is set to aws:kms or AES256. + ServerSideEncryptionKMSKeyID *string `url:"server_side_encryption_kms_key_id,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). - ServiceVersion int + ServiceVersion int + // TimestampFormat is a timestamp format. TimestampFormat *string `url:"timestamp_format,omitempty"` } -// UpdateS3 updates a specific S3. +// UpdateS3 updates the specified resource. func (c *Client) UpdateS3(i *UpdateS3Input) (*S3, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -282,7 +361,7 @@ type DeleteS3Input struct { ServiceVersion int } -// DeleteS3 deletes the given S3 version. +// DeleteS3 deletes the specified resource. func (c *Client) DeleteS3(i *DeleteS3Input) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/scalyr.go b/fastly/scalyr.go index f6faa25e1..8436dcaa6 100644 --- a/fastly/scalyr.go +++ b/fastly/scalyr.go @@ -26,9 +26,17 @@ type Scalyr struct { // scalyrByName is a sortable list of scalyrs. type scalyrsByName []*Scalyr -// Len, Swap, and Less implement the sortable interface. -func (s scalyrsByName) Len() int { return len(s) } -func (s scalyrsByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implements the sortable interface. +func (s scalyrsByName) Len() int { + return len(s) +} + +// Swap implements the sortable interface. +func (s scalyrsByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implements the sortable interface. func (s scalyrsByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -41,7 +49,7 @@ type ListScalyrsInput struct { ServiceVersion int } -// ListScalyrs returns the list of scalyrs for the configuration version. +// ListScalyrs retrieves all resources. func (c *Client) ListScalyrs(i *ListScalyrsInput) ([]*Scalyr, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -68,20 +76,27 @@ func (c *Client) ListScalyrs(i *ListScalyrsInput) ([]*Scalyr, error) { // CreateScalyrInput is used as input to the CreateScalyr function. type CreateScalyrInput struct { - Format string `url:"format,omitempty"` - FormatVersion uint `url:"format_version,omitempty"` - Name string `url:"name,omitempty"` - Placement string `url:"placement,omitempty"` - Region string `url:"region,omitempty"` + // Format is a Fastly log format string. + Format string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion uint `url:"format_version,omitempty"` + // Name is the name for the real-time logging configuration. + Name string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement string `url:"placement,omitempty"` + // Region is the region that log data will be sent to. + Region string `url:"region,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - Token string `url:"token,omitempty"` + // Token is the token to use for authentication + Token string `url:"token,omitempty"` } -// CreateScalyr creates a new Fastly scalyr. +// CreateScalyr creates a new resource. func (c *Client) CreateScalyr(i *CreateScalyrInput) (*Scalyr, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -119,7 +134,7 @@ type GetScalyrInput struct { ServiceVersion int } -// GetScalyr gets the scalyr configuration with the given parameters. +// GetScalyr retrieves the specified resource. func (c *Client) GetScalyr(i *GetScalyrInput) (*Scalyr, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -149,22 +164,29 @@ func (c *Client) GetScalyr(i *GetScalyrInput) (*Scalyr, error) { // UpdateScalyrInput is used as input to the UpdateScalyr function. type UpdateScalyrInput struct { - Format *string `url:"format,omitempty"` - FormatVersion *uint `url:"format_version,omitempty"` + // Format is a Fastly log format string. + Format *string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion *uint `url:"format_version,omitempty"` // Name is the name of the scalyr to update. - Name string - NewName *string `url:"name,omitempty"` - Placement *string `url:"placement,omitempty"` - Region *string `url:"region,omitempty"` + Name string + // NewName is the new name for the resource. + NewName *string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement *string `url:"placement,omitempty"` + // Region is the region that log data will be sent to. + Region *string `url:"region,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition *string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - Token *string `url:"token,omitempty"` + // Token is the token to use for authentication + Token *string `url:"token,omitempty"` } -// UpdateScalyr updates a specific scalyr. +// UpdateScalyr updates the specified resource. func (c *Client) UpdateScalyr(i *UpdateScalyrInput) (*Scalyr, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -206,7 +228,7 @@ type DeleteScalyrInput struct { ServiceVersion int } -// DeleteScalyr deletes the given scalyr version. +// DeleteScalyr deletes the specified resource. func (c *Client) DeleteScalyr(i *DeleteScalyrInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/scalyr_test.go b/fastly/scalyr_test.go index 26ccbec44..eedf144ac 100644 --- a/fastly/scalyr_test.go +++ b/fastly/scalyr_test.go @@ -34,13 +34,13 @@ func TestClient_Scalyrs(t *testing.T) { // Ensure deleted defer func() { record(t, "scalyrs/cleanup", func(c *Client) { - c.DeleteScalyr(&DeleteScalyrInput{ + _ = c.DeleteScalyr(&DeleteScalyrInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-scalyr", }) - c.DeleteScalyr(&DeleteScalyrInput{ + _ = c.DeleteScalyr(&DeleteScalyrInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "new-test-scalyr", diff --git a/fastly/secret_store.go b/fastly/secret_store.go index 25d012bf6..741498a90 100644 --- a/fastly/secret_store.go +++ b/fastly/secret_store.go @@ -30,7 +30,7 @@ type CreateSecretStoreInput struct { Name string } -// CreateSecretStore creates a new Secret Store. +// CreateSecretStore creates a new resource. func (c *Client) CreateSecretStore(i *CreateSecretStoreInput) (*SecretStore, error) { if i.Name == "" { return nil, ErrMissingName @@ -86,7 +86,8 @@ type ListSecretStoresInput struct { Limit int } -// ListSecretStores returns a paginated list of Secret Stores. +// ListSecretStores retrieves all resources. +// // The returned next cursor, if non-blank, can be used as input to a subsequent // request for the next page of results. func (c *Client) ListSecretStores(i *ListSecretStoresInput) (*SecretStores, error) { @@ -127,7 +128,7 @@ type GetSecretStoreInput struct { ID string } -// GetSecretStore gets a single Secret Store. +// GetSecretStore retrieves the specified resource. func (c *Client) GetSecretStore(i *GetSecretStoreInput) (*SecretStore, error) { if i.ID == "" { return nil, ErrMissingID @@ -161,7 +162,7 @@ type DeleteSecretStoreInput struct { ID string } -// DeleteSecretStore deletes the given Secret Store and associated Secrets. +// DeleteSecretStore deletes the specified resource. func (c *Client) DeleteSecretStore(i *DeleteSecretStoreInput) error { if i.ID == "" { return ErrMissingID @@ -201,7 +202,7 @@ type CreateSecretInput struct { Secret []byte } -// CreateSecret creates a new Secret within a Secret Store. +// CreateSecret creates a new resource. func (c *Client) CreateSecret(i *CreateSecretInput) (*Secret, error) { if i.ID == "" { return nil, ErrMissingID @@ -266,7 +267,8 @@ type ListSecretsInput struct { Limit int } -// ListSecrets returns a list of Secrets for the given Secret Store. +// ListSecrets retrieves all resources. +// // The returned next cursor, if non-blank, can be used as input to a subsequent // request for the next page of results. func (c *Client) ListSecrets(i *ListSecretsInput) (*Secrets, error) { @@ -313,7 +315,7 @@ type GetSecretInput struct { Name string } -// GetSecret returns a single Secret from a given Secret Store. +// GetSecret retrieves the specified resource. func (c *Client) GetSecret(i *GetSecretInput) (*Secret, error) { if i.ID == "" { return nil, ErrMissingID @@ -352,7 +354,7 @@ type DeleteSecretInput struct { Name string } -// DeleteSecret deletes the given Secret. +// DeleteSecret deletes the specified resource. func (c *Client) DeleteSecret(i *DeleteSecretInput) error { if i.ID == "" { return ErrMissingID diff --git a/fastly/server.go b/fastly/server.go index 6713f4ec6..3be4e5a24 100644 --- a/fastly/server.go +++ b/fastly/server.go @@ -6,7 +6,7 @@ import ( "time" ) -// ServerType represents a server response from the Fastly API. +// Server represents a server response from the Fastly API. type Server struct { Address string `mapstructure:"address"` Comment string `mapstructure:"comment"` @@ -26,9 +26,17 @@ type Server struct { // serversByAddress is a sortable list of servers. type serversByAddress []*Server -// Len, Swap, and Less implement the sortable interface. -func (s serversByAddress) Len() int { return len(s) } -func (s serversByAddress) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s serversByAddress) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s serversByAddress) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s serversByAddress) Less(i, j int) bool { return s[i].Address < s[j].Address } @@ -41,7 +49,7 @@ type ListServersInput struct { ServiceID string } -// ListServers lists all servers for a particular service and pool. +// ListServers retrieves all resources. func (c *Client) ListServers(i *ListServersInput) ([]*Server, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -69,20 +77,26 @@ func (c *Client) ListServers(i *ListServersInput) ([]*Server, error) { // CreateServerInput is used as input to the CreateServer function. type CreateServerInput struct { // Address is the hostname or IP of the origin server (required). - Address string `url:"address"` - Comment string `url:"comment,omitempty"` - Disabled bool `url:"disabled,omitempty"` - MaxConn uint `url:"max_conn,omitempty"` + Address string `url:"address"` + // Comment is a freeform descriptive note. + Comment string `url:"comment,omitempty"` + // Disabled allows servers to be enabled and disabled in a pool. + Disabled bool `url:"disabled,omitempty"` + // MaxConn is the maximum number of connections. If the value is 0, it inherits the value from pool's max_conn_default. + MaxConn uint `url:"max_conn,omitempty"` + // OverrideHost is the hostname to override the Host header. OverrideHost string `url:"override_host,omitempty"` // PoolID is the ID of the pool (required). PoolID string - Port uint `url:"port,omitempty"` + // Port is the port number. + Port uint `url:"port,omitempty"` // ServiceID is the ID of the service (required). ServiceID string - Weight uint `url:"weight,omitempty"` + // Weight is the weight (1-100) used to load balance this server against others. + Weight uint `url:"weight,omitempty"` } -// CreateServer creates a single server for a particular service and pool. +// CreateServer creates a new resource. // Servers are versionless resources that are associated with a Pool. func (c *Client) CreateServer(i *CreateServerInput) (*Server, error) { if i.ServiceID == "" { @@ -115,12 +129,13 @@ func (c *Client) CreateServer(i *CreateServerInput) (*Server, error) { type GetServerInput struct { // PoolID is the ID of the pool (required). PoolID string + // Server is an alphanumeric string identifying a Server (required). Server string // ServiceID is the ID of the service (required). ServiceID string } -// GetServer gets a single server for a particular service and pool. +// GetServer retrieves the specified resource. func (c *Client) GetServer(i *GetServerInput) (*Server, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -150,21 +165,29 @@ func (c *Client) GetServer(i *GetServerInput) (*Server, error) { // UpdateServerInput is used as input to the UpdateServer function. type UpdateServerInput struct { - Address *string `url:"address,omitempty"` - Comment *string `url:"comment,omitempty"` - Disabled *bool `url:"disabled,omitempty"` - MaxConn *uint `url:"max_conn,omitempty"` + // Address is the hostname or IP of the origin server (required). + Address *string `url:"address,omitempty"` + // Comment is a freeform descriptive note. + Comment *string `url:"comment,omitempty"` + // Disabled allows servers to be enabled and disabled in a pool. + Disabled *bool `url:"disabled,omitempty"` + // MaxConn is the maximum number of connections. If the value is 0, it inherits the value from pool's max_conn_default. + MaxConn *uint `url:"max_conn,omitempty"` + // OverrideHost is the hostname to override the Host header. OverrideHost *string `url:"override_host,omitempty"` // PoolID is the ID of the pool (required). PoolID string - Port *uint `url:"port,omitempty"` + // Port is the port number. + Port *uint `url:"port,omitempty"` + // Server is an alphanumeric string identifying a Server. Server string // ServiceID is the ID of the service (required). ServiceID string - Weight *uint `url:"weight,omitempty"` + // Weight is the weight (1-100) used to load balance this server against others. + Weight *uint `url:"weight,omitempty"` } -// UpdateServer updates a single server for a particular service and pool. +// UpdateServer updates the specified resource. func (c *Client) UpdateServer(i *UpdateServerInput) (*Server, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -196,12 +219,13 @@ func (c *Client) UpdateServer(i *UpdateServerInput) (*Server, error) { type DeleteServerInput struct { // PoolID is the ID of the pool (required). PoolID string + // Server is an alphanumeric string identifying a Server. Server string // ServiceID is the ID of the service (required). ServiceID string } -// DeleteServer deletes a single server for a particular service and pool. +// DeleteServer deletes the specified resource. func (c *Client) DeleteServer(i *DeleteServerInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/server_test.go b/fastly/server_test.go index ff7064571..eb0cf45a3 100644 --- a/fastly/server_test.go +++ b/fastly/server_test.go @@ -44,7 +44,7 @@ func TestClient_Servers(t *testing.T) { record(t, "servers/cleanup", func(c *Client) { // Expected to fail as this was explicitly deleted in the test. - c.DeleteServer(&DeleteServerInput{ + _ = c.DeleteServer(&DeleteServerInput{ ServiceID: testServiceID, PoolID: testPool.ID, Server: altServer.ID, @@ -53,7 +53,7 @@ func TestClient_Servers(t *testing.T) { // Expected to fail as the API forbids deleting the last server in // the pool. The pool is deleted from this version but it still // exists as it may be associated with other versions. - c.DeleteServer(&DeleteServerInput{ + _ = c.DeleteServer(&DeleteServerInput{ ServiceID: testServiceID, PoolID: testPool.ID, Server: server.ID, diff --git a/fastly/service.go b/fastly/service.go index bf5595a23..a776857fc 100644 --- a/fastly/service.go +++ b/fastly/service.go @@ -10,7 +10,7 @@ import ( "github.com/peterhellberg/link" ) -// Service represents a single service for the Fastly account. +// Service represents a server response from the Fastly API. type Service struct { ActiveVersion uint `mapstructure:"version"` Comment string `mapstructure:"comment"` @@ -24,6 +24,7 @@ type Service struct { Versions []*Version `mapstructure:"versions"` } +// ServiceDetail represents a server response from the Fastly API. type ServiceDetail struct { ActiveVersion Version `mapstructure:"active_version"` Comment string `mapstructure:"comment"` @@ -38,6 +39,7 @@ type ServiceDetail struct { Versions []*Version `mapstructure:"versions"` } +// ServiceDomain represents a server response from the Fastly API. type ServiceDomain struct { Comment string `mapstructure:"comment"` CreatedAt *time.Time `mapstructure:"created_at"` @@ -48,27 +50,42 @@ type ServiceDomain struct { ServiceVersion int64 `mapstructure:"version"` UpdatedAt *time.Time `mapstructure:"updated_at"` } + +// ServiceDomainsList represents a list of service domains. type ServiceDomainsList []*ServiceDomain // servicesByName is a sortable list of services. type servicesByName []*Service -// Len, Swap, and Less implement the sortable interface. -func (s servicesByName) Len() int { return len(s) } -func (s servicesByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s servicesByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s servicesByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s servicesByName) Less(i, j int) bool { return s[i].Name < s[j].Name } // ListServicesInput is used as input to the ListServices function. type ListServicesInput struct { + // Direction is the direction in which to sort results. Direction string - Page int - PerPage int - Sort string + // Page is the current page. + Page int + // PerPage is the number of records per page. + PerPage int + // Sort is the field on which to sort. + Sort string } -// ListServices returns the full list of services for the current account. +// ListServices retrieves all resources. +// FIXME: input isn't used at all (e.g. Params: i.formatFilters()). func (c *Client) ListServices(i *ListServicesInput) ([]*Service, error) { resp, err := c.Get("/service", nil) if err != nil { @@ -84,6 +101,7 @@ func (c *Client) ListServices(i *ListServicesInput) ([]*Service, error) { return s, nil } +// ListServicesPaginator implements the PaginatorServices interface. type ListServicesPaginator struct { CurrentPage int LastPage int @@ -192,12 +210,15 @@ func (c *Client) listServicesWithPage(i *ListServicesInput, p *ListServicesPagin // CreateServiceInput is used as input to the CreateService function. type CreateServiceInput struct { + // Comment is a freeform descriptive note. Comment string `url:"comment,omitempty"` - Name string `url:"name,omitempty"` - Type string `url:"type,omitempty"` + // Name is the name of the service. + Name string `url:"name,omitempty"` + // Type is the type of this service (vcl, wasm). + Type string `url:"type,omitempty"` } -// CreateService creates a new service with the given information. +// CreateService creates a new resource. func (c *Client) CreateService(i *CreateServiceInput) (*Service, error) { resp, err := c.PostForm("/service", i, nil) if err != nil { @@ -214,12 +235,13 @@ func (c *Client) CreateService(i *CreateServiceInput) (*Service, error) { // GetServiceInput is used as input to the GetService function. type GetServiceInput struct { + // ID is an alphanumeric string identifying the service. ID string } -// GetService retrieves the service information for the service with the given -// id. If no service exists for the given id, the API returns a 400 response -// (not a 404). +// GetService retrieves the specified resource. +// +// If no service exists for the given id, the API returns a 400 response not 404. func (c *Client) GetService(i *GetServiceInput) (*Service, error) { if i.ID == "" { return nil, ErrMissingID @@ -252,8 +274,9 @@ func (c *Client) GetService(i *GetServiceInput) (*Service, error) { return s, nil } -// GetService retrieves the details for the service with the given id. If no -// service exists for the given id, the API returns a 400 response (not a 404). +// GetServiceDetails retrieves the specified resource. +// +// If no service exists for the given id, the API returns a 400 response not 404. func (c *Client) GetServiceDetails(i *GetServiceInput) (*ServiceDetail, error) { if i.ID == "" { return nil, ErrMissingID @@ -276,12 +299,15 @@ func (c *Client) GetServiceDetails(i *GetServiceInput) (*ServiceDetail, error) { // UpdateServiceInput is used as input to the UpdateService function. type UpdateServiceInput struct { - Comment *string `url:"comment,omitempty"` - Name *string `url:"name,omitempty"` + // Comment is a freeform descriptive note. + Comment *string `url:"comment,omitempty"` + // Name is the name of the service. + Name *string `url:"name,omitempty"` + // ServiceID is the ID of the service (required). ServiceID string } -// UpdateService updates the service with the given input. +// UpdateService updates the specified resource. func (c *Client) UpdateService(i *UpdateServiceInput) (*Service, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -311,10 +337,11 @@ func (c *Client) UpdateService(i *UpdateServiceInput) (*Service, error) { // DeleteServiceInput is used as input to the DeleteService function. type DeleteServiceInput struct { + // ID is an alphanumeric string identifying the service. ID string } -// DeleteService updates the service with the given input. +// DeleteService deletes the specified resource. func (c *Client) DeleteService(i *DeleteServiceInput) error { if i.ID == "" { return ErrMissingID @@ -339,11 +366,13 @@ func (c *Client) DeleteService(i *DeleteServiceInput) error { // SearchServiceInput is used as input to the SearchService function. type SearchServiceInput struct { + // Name is the name of the service. Name string } -// SearchService gets a specific service by name. If no service exists by that -// name, the API returns a 400 response (not a 404). +// SearchService retrieves the specified resource. +// +// If no service exists by that name, the API returns a 400 response not a 404. func (c *Client) SearchService(i *SearchServiceInput) (*Service, error) { if i.Name == "" { return nil, ErrMissingName @@ -367,16 +396,19 @@ func (c *Client) SearchService(i *SearchServiceInput) (*Service, error) { return s, nil } +// ListServiceDomainInput is the input parameter to the ListServiceDomains +// function. type ListServiceDomainInput struct { - ID string + // ServiceID is the ID of the service (required). + ServiceID string } -// ListServiceDomains lists all domains associated with a given service +// ListServiceDomains retrieves all resources. func (c *Client) ListServiceDomains(i *ListServiceDomainInput) (ServiceDomainsList, error) { - if i.ID == "" { - return nil, ErrMissingID + if i.ServiceID == "" { + return nil, ErrMissingServiceID } - path := fmt.Sprintf("/service/%s/domain", i.ID) + path := fmt.Sprintf("/service/%s/domain", i.ServiceID) resp, err := c.Get(path, nil) if err != nil { return nil, err diff --git a/fastly/service_authorization.go b/fastly/service_authorization.go index c4315e6fc..3509ade87 100644 --- a/fastly/service_authorization.go +++ b/fastly/service_authorization.go @@ -110,7 +110,7 @@ type GetServiceAuthorizationInput struct { ID string } -// GetServiceAuthorization retrieves an existing service authorization using its ID. +// GetServiceAuthorization retrieves the specified resource. func (c *Client) GetServiceAuthorization(i *GetServiceAuthorizationInput) (*ServiceAuthorization, error) { if i.ID == "" { return nil, ErrMissingID @@ -146,7 +146,7 @@ type CreateServiceAuthorizationInput struct { User *SAUser `jsonapi:"relation,user,omitempty"` } -// CreateServiceAuthorization creates a new service authorization granting granular service and user permissions. +// CreateServiceAuthorization creates a new resource. func (c *Client) CreateServiceAuthorization(i *CreateServiceAuthorizationInput) (*ServiceAuthorization, error) { if i.Service == nil || i.Service.ID == "" { return nil, ErrMissingServiceAuthorizationsService @@ -178,7 +178,7 @@ type UpdateServiceAuthorizationInput struct { Permission string `jsonapi:"attr,permission,omitempty"` } -// UpdateServiceAuthorization updates an exisitng service authorization. The ID must be known. +// UpdateServiceAuthorization updates the specified resource. func (c *Client) UpdateServiceAuthorization(i *UpdateServiceAuthorizationInput) (*ServiceAuthorization, error) { if i.ID == "" { return nil, ErrMissingID @@ -209,7 +209,7 @@ type DeleteServiceAuthorizationInput struct { ID string } -// DeleteServiceAuthorization deletes an existing service authorization using the ID. +// DeleteServiceAuthorization deletes the specified resource. func (c *Client) DeleteServiceAuthorization(i *DeleteServiceAuthorizationInput) error { if i.ID == "" { return ErrMissingID diff --git a/fastly/service_authorization_test.go b/fastly/service_authorization_test.go index 86ad6f06f..62d4f5516 100644 --- a/fastly/service_authorization_test.go +++ b/fastly/service_authorization_test.go @@ -41,7 +41,7 @@ func TestClient_ServiceAuthorizations(t *testing.T) { // Ensure deleted defer func() { record(t, fixtureBase+"cleanup", func(c *Client) { - c.DeleteServiceAuthorization(&DeleteServiceAuthorizationInput{ + _ = c.DeleteServiceAuthorization(&DeleteServiceAuthorizationInput{ ID: sa.ID, }) }) diff --git a/fastly/service_test.go b/fastly/service_test.go index 57a64b92d..b5dfc0ceb 100644 --- a/fastly/service_test.go +++ b/fastly/service_test.go @@ -24,11 +24,11 @@ func TestClient_Services(t *testing.T) { // Ensure deleted defer func() { record(t, "services/cleanup", func(c *Client) { - c.DeleteService(&DeleteServiceInput{ + _ = c.DeleteService(&DeleteServiceInput{ ID: s.ID, }) - c.DeleteService(&DeleteServiceInput{ + _ = c.DeleteService(&DeleteServiceInput{ ID: s.ID, }) }) @@ -169,7 +169,7 @@ func TestClient_Services(t *testing.T) { var ds ServiceDomainsList record(t, "services/domain", func(c *Client) { ds, err = c.ListServiceDomains(&ListServiceDomainInput{ - ID: s.ID, + ServiceID: s.ID, }) }) if err != nil { diff --git a/fastly/settings.go b/fastly/settings.go index 186a8409d..9069d1ec6 100644 --- a/fastly/settings.go +++ b/fastly/settings.go @@ -20,7 +20,7 @@ type GetSettingsInput struct { ServiceVersion int } -// GetSettings gets the backend configuration with the given parameters. +// GetSettings retrieves the specified resource. func (c *Client) GetSettings(i *GetSettingsInput) (*Settings, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -46,17 +46,21 @@ func (c *Client) GetSettings(i *GetSettingsInput) (*Settings, error) { // UpdateSettingsInput is used as input to the UpdateSettings function. type UpdateSettingsInput struct { + // DefaultHost is the default host name for the version. DefaultHost *string `url:"general.default_host,omitempty"` - DefaultTTL uint `url:"general.default_ttl"` + // DefaultTTL is the default time-to-live (TTL) for the version. + DefaultTTL uint `url:"general.default_ttl"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). - ServiceVersion int - StaleIfError *bool `url:"general.stale_if_error,omitempty"` + ServiceVersion int + // StaleIfError enables serving a stale object if there is an error. + StaleIfError *bool `url:"general.stale_if_error,omitempty"` + // StaleIfErrorTTL is the default time-to-live (TTL) for serving the stale object for the version. StaleIfErrorTTL *uint `url:"general.stale_if_error_ttl,omitempty"` } -// UpdateSettings updates a specific backend. +// UpdateSettings updates the specified resource. func (c *Client) UpdateSettings(i *UpdateSettingsInput) (*Settings, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID diff --git a/fastly/settings_test.go b/fastly/settings_test.go index 0422edde1..17d414f9c 100644 --- a/fastly/settings_test.go +++ b/fastly/settings_test.go @@ -47,7 +47,7 @@ func TestClient_Settings(t *testing.T) { if us.DefaultTTL != 1800 { t.Errorf("bad default_ttl: %d", us.DefaultTTL) } - if us.StaleIfError != true { + if !us.StaleIfError { t.Errorf("bad stale_if_error: %t", us.StaleIfError) } if us.StaleIfErrorTTL != 57600 { diff --git a/fastly/sftp.go b/fastly/sftp.go index 75df4e814..f4b5a6a1b 100644 --- a/fastly/sftp.go +++ b/fastly/sftp.go @@ -37,9 +37,17 @@ type SFTP struct { // sftpsByName is a sortable list of sftps. type sftpsByName []*SFTP -// Len, Swap, and Less implement the sortable interface. -func (s sftpsByName) Len() int { return len(s) } -func (s sftpsByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s sftpsByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s sftpsByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s sftpsByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -52,7 +60,7 @@ type ListSFTPsInput struct { ServiceVersion int } -// ListSFTPs returns the list of sftps for the configuration version. +// ListSFTPs retrieves all resources. func (c *Client) ListSFTPs(i *ListSFTPsInput) ([]*SFTP, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -79,31 +87,49 @@ func (c *Client) ListSFTPs(i *ListSFTPsInput) ([]*SFTP, error) { // CreateSFTPInput is used as input to the CreateSFTP function. type CreateSFTPInput struct { - Address string `url:"address,omitempty"` - CompressionCodec string `url:"compression_codec,omitempty"` - Format string `url:"format,omitempty"` - FormatVersion uint `url:"format_version,omitempty"` - GzipLevel uint8 `url:"gzip_level,omitempty"` - MessageType string `url:"message_type,omitempty"` - Name string `url:"name,omitempty"` - Password string `url:"password,omitempty"` - Path string `url:"path,omitempty"` - Period uint `url:"period,omitempty"` - Placement string `url:"placement,omitempty"` - Port uint `url:"port,omitempty"` - PublicKey string `url:"public_key,omitempty"` + // Address is a hostname or IPv4 address. + Address string `url:"address,omitempty"` + // CompressionCodec is the codec used for compressing your logs. Valid values are zstd, snappy, and gzip. + CompressionCodec string `url:"compression_codec,omitempty"` + // Format is a Fastly log format string. + Format string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion uint `url:"format_version,omitempty"` + // GzipLevel is the level of gzip encoding when sending logs (default 0, no compression). + GzipLevel uint8 `url:"gzip_level,omitempty"` + // MessageType is how the message should be formatted (classic, loggly, logplex, blank). + MessageType string `url:"message_type,omitempty"` + // Name is the name of the loggly to update. + Name string `url:"name,omitempty"` + // Password is the password for the server. + Password string `url:"password,omitempty"` + // Path is the path to upload logs to. + Path string `url:"path,omitempty"` + // Period is how frequently log files are finalized so they can be available for reading (in seconds). + Period uint `url:"period,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement string `url:"placement,omitempty"` + // Port is the port number. + Port uint `url:"port,omitempty"` + // PublicKey is a PGP public key that Fastly will use to encrypt your log files before writing them to disk. + PublicKey string `url:"public_key,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition string `url:"response_condition,omitempty"` - SSHKnownHosts string `url:"ssh_known_hosts,omitempty"` - SecretKey string `url:"secret_key,omitempty"` + // SSHKnownHosts is a list of host keys for all hosts we can connect to over SFTP. + SSHKnownHosts string `url:"ssh_known_hosts,omitempty"` + // SecretKey is the SSH private key for the server. + SecretKey string `url:"secret_key,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). - ServiceVersion int + ServiceVersion int + // TimestampFormat is a timestamp format. TimestampFormat string `url:"timestamp_format,omitempty"` - User string `url:"user,omitempty"` + // User is the username for the server. + User string `url:"user,omitempty"` } -// CreateSFTP creates a new Fastly SFTP. +// CreateSFTP creates a new resource. func (c *Client) CreateSFTP(i *CreateSFTPInput) (*SFTP, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -137,7 +163,7 @@ type GetSFTPInput struct { ServiceVersion int } -// GetSFTP gets the SFTP configuration with the given parameters. +// GetSFTP retrieves the specified resource. func (c *Client) GetSFTP(i *GetSFTPInput) (*SFTP, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -167,33 +193,51 @@ func (c *Client) GetSFTP(i *GetSFTPInput) (*SFTP, error) { // UpdateSFTPInput is used as input to the UpdateSFTP function. type UpdateSFTPInput struct { - Address *string `url:"address,omitempty"` + // Address is a hostname or IPv4 address. + Address *string `url:"address,omitempty"` + // CompressionCodec is the codec used for compressing your logs. Valid values are zstd, snappy, and gzip. CompressionCodec *string `url:"compression_codec,omitempty"` - Format *string `url:"format,omitempty"` - FormatVersion *uint `url:"format_version,omitempty"` - GzipLevel *uint8 `url:"gzip_level,omitempty"` - MessageType *string `url:"message_type,omitempty"` - // Name is the name of the SFTP to update. - Name string - NewName *string `url:"name,omitempty"` - Password *string `url:"password,omitempty"` - Path *string `url:"path,omitempty"` - Period *uint `url:"period,omitempty"` - Placement *string `url:"placement,omitempty"` - Port *uint `url:"port,omitempty"` - PublicKey *string `url:"public_key,omitempty"` + // Format is a Fastly log format string. + Format *string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion *uint `url:"format_version,omitempty"` + // GzipLevel is the level of gzip encoding when sending logs (default 0, no compression). + GzipLevel *uint8 `url:"gzip_level,omitempty"` + // MessageType is how the message should be formatted (classic, loggly, logplex, blank). + MessageType *string `url:"message_type,omitempty"` + // Name is the name of the SFTP to update (required). + Name string + // NewName is the new name for the resource. + NewName *string `url:"name,omitempty"` + // Password is the password for the server. + Password *string `url:"password,omitempty"` + // Path is the path to upload logs to. + Path *string `url:"path,omitempty"` + // Period is how frequently log files are finalized so they can be available for reading (in seconds). + Period *uint `url:"period,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement *string `url:"placement,omitempty"` + // Port is the port number. + Port *uint `url:"port,omitempty"` + // PublicKey is a PGP public key that Fastly will use to encrypt your log files before writing them to disk. + PublicKey *string `url:"public_key,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition *string `url:"response_condition,omitempty"` - SSHKnownHosts *string `url:"ssh_known_hosts,omitempty"` - SecretKey *string `url:"secret_key,omitempty"` + // SSHKnownHosts is a list of host keys for all hosts we can connect to over SFTP. + SSHKnownHosts *string `url:"ssh_known_hosts,omitempty"` + // SecretKey is the SSH private key for the server. + SecretKey *string `url:"secret_key,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). - ServiceVersion int + ServiceVersion int + // TimestampFormat is a timestamp format. TimestampFormat *string `url:"timestamp_format,omitempty"` - User *string `url:"user,omitempty"` + // User is the username for the server. + User *string `url:"user,omitempty"` } -// UpdateSFTP updates a specific SFTP. +// UpdateSFTP updates the specified resource. func (c *Client) UpdateSFTP(i *UpdateSFTPInput) (*SFTP, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -231,7 +275,7 @@ type DeleteSFTPInput struct { ServiceVersion int } -// DeleteSFTP deletes the given SFTP version. +// DeleteSFTP deletes the specified resource. func (c *Client) DeleteSFTP(i *DeleteSFTPInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/sftp_test.go b/fastly/sftp_test.go index 3969c9cc9..16aa7d176 100644 --- a/fastly/sftp_test.go +++ b/fastly/sftp_test.go @@ -127,25 +127,25 @@ func TestClient_SFTPs(t *testing.T) { // Ensure deleted defer func() { record(t, "sftps/cleanup", func(c *Client) { - c.DeleteSFTP(&DeleteSFTPInput{ + _ = c.DeleteSFTP(&DeleteSFTPInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-sftp", }) - c.DeleteSFTP(&DeleteSFTPInput{ + _ = c.DeleteSFTP(&DeleteSFTPInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-sftp-2", }) - c.DeleteSFTP(&DeleteSFTPInput{ + _ = c.DeleteSFTP(&DeleteSFTPInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-sftp-3", }) - c.DeleteSFTP(&DeleteSFTPInput{ + _ = c.DeleteSFTP(&DeleteSFTPInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "new-test-sftp", diff --git a/fastly/splunk.go b/fastly/splunk.go index 49e0dc4e6..d5b2689e6 100644 --- a/fastly/splunk.go +++ b/fastly/splunk.go @@ -33,9 +33,17 @@ type Splunk struct { // splunkByName is a sortable list of splunks. type splunkByName []*Splunk -// Len, Swap, and Less implement the sortable interface. -func (s splunkByName) Len() int { return len(s) } -func (s splunkByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s splunkByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s splunkByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s splunkByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -48,7 +56,7 @@ type ListSplunksInput struct { ServiceVersion int } -// ListSplunks returns the list of splunks for the configuration version. +// ListSplunks retrieves all resources. func (c *Client) ListSplunks(i *ListSplunksInput) ([]*Splunk, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -75,27 +83,41 @@ func (c *Client) ListSplunks(i *ListSplunksInput) ([]*Splunk, error) { // CreateSplunkInput is used as input to the CreateSplunk function. type CreateSplunkInput struct { - Format string `url:"format,omitempty"` - FormatVersion uint `url:"format_version,omitempty"` - Name string `url:"name,omitempty"` - Placement string `url:"placement,omitempty"` - RequestMaxBytes uint `url:"request_max_bytes,omitempty"` - RequestMaxEntries uint `url:"request_max_entries,omitempty"` + // Format is a Fastly log format string. + Format string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion uint `url:"format_version,omitempty"` + // Name is the name for the real-time logging configuration. + Name string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement string `url:"placement,omitempty"` + // RequestMaxBytes is the maximum number of bytes sent in one request. Defaults 0 for unbounded. + RequestMaxBytes uint `url:"request_max_bytes,omitempty"` + // RequestMaxEntries is the maximum number of logs sent in one request. Defaults 0 for unbounded. + RequestMaxEntries uint `url:"request_max_entries,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - TLSCACert string `url:"tls_ca_cert,omitempty"` - TLSClientCert string `url:"tls_client_cert,omitempty"` - TLSClientKey string `url:"tls_client_key,omitempty"` - TLSHostname string `url:"tls_hostname,omitempty"` - Token string `url:"token,omitempty"` - URL string `url:"url,omitempty"` - UseTLS Compatibool `url:"use_tls,omitempty"` + // TLSCACert is a secure certificate to authenticate a server with. Must be in PEM format. + TLSCACert string `url:"tls_ca_cert,omitempty"` + // TLSClientCert is the client certificate used to make authenticated requests. Must be in PEM format. + TLSClientCert string `url:"tls_client_cert,omitempty"` + // TLSClientKey is the client private key used to make authenticated requests. Must be in PEM format. + TLSClientKey string `url:"tls_client_key,omitempty"` + // TLSHostname is the hostname to verify the server's certificate. This should be one of the Subject Alternative Name (SAN) fields for the certificate. Common Names (CN) are not supported. + TLSHostname string `url:"tls_hostname,omitempty"` + // Token is a Splunk token for use in posting logs over HTTP to your collector. + Token string `url:"token,omitempty"` + // URL is the URL to post logs to. + URL string `url:"url,omitempty"` + // UseTLS is whether to use TLS (0: do not use, 1: use). + UseTLS Compatibool `url:"use_tls,omitempty"` } -// CreateSplunk creates a new Fastly splunk. +// CreateSplunk creates a new resource. func (c *Client) CreateSplunk(i *CreateSplunkInput) (*Splunk, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -133,7 +155,7 @@ type GetSplunkInput struct { ServiceVersion int } -// GetSplunk gets the splunk configuration with the given parameters. +// GetSplunk retrieves the specified resource. func (c *Client) GetSplunk(i *GetSplunkInput) (*Splunk, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -163,29 +185,43 @@ func (c *Client) GetSplunk(i *GetSplunkInput) (*Splunk, error) { // UpdateSplunkInput is used as input to the UpdateSplunk function. type UpdateSplunkInput struct { - Format *string `url:"format,omitempty"` - FormatVersion *uint `url:"format_version,omitempty"` + // Format is a Fastly log format string. + Format *string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion *uint `url:"format_version,omitempty"` // Name is the name of the splunk to update. - Name string - NewName *string `url:"name,omitempty"` - Placement *string `url:"placement,omitempty"` - RequestMaxBytes *uint `url:"request_max_bytes,omitempty"` - RequestMaxEntries *uint `url:"request_max_entries,omitempty"` + Name string + // NewName is the new name for the resource. + NewName *string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement *string `url:"placement,omitempty"` + // RequestMaxBytes is the maximum number of bytes sent in one request. Defaults 0 for unbounded. + RequestMaxBytes *uint `url:"request_max_bytes,omitempty"` + // RequestMaxEntries is the maximum number of logs sent in one request. Defaults 0 for unbounded. + RequestMaxEntries *uint `url:"request_max_entries,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition *string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - TLSCACert *string `url:"tls_ca_cert,omitempty"` - TLSClientCert *string `url:"tls_client_cert,omitempty"` - TLSClientKey *string `url:"tls_client_key,omitempty"` - TLSHostname *string `url:"tls_hostname,omitempty"` - Token *string `url:"token,omitempty"` - URL *string `url:"url,omitempty"` - UseTLS *Compatibool `url:"use_tls,omitempty"` + // TLSCACert is a secure certificate to authenticate a server with. Must be in PEM format. + TLSCACert *string `url:"tls_ca_cert,omitempty"` + // TLSClientCert is the client certificate used to make authenticated requests. Must be in PEM format. + TLSClientCert *string `url:"tls_client_cert,omitempty"` + // TLSClientKey is the client private key used to make authenticated requests. Must be in PEM format. + TLSClientKey *string `url:"tls_client_key,omitempty"` + // TLSHostname is the hostname to verify the server's certificate. This should be one of the Subject Alternative Name (SAN) fields for the certificate. Common Names (CN) are not supported. + TLSHostname *string `url:"tls_hostname,omitempty"` + // Token is a Splunk token for use in posting logs over HTTP to your collector. + Token *string `url:"token,omitempty"` + // URL is the URL to post logs to. + URL *string `url:"url,omitempty"` + // UseTLS is whether to use TLS (0: do not use, 1: use). + UseTLS *Compatibool `url:"use_tls,omitempty"` } -// UpdateSplunk updates a specific splunk. +// UpdateSplunk updates the specified resource. func (c *Client) UpdateSplunk(i *UpdateSplunkInput) (*Splunk, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -227,7 +263,7 @@ type DeleteSplunkInput struct { ServiceVersion int } -// DeleteSplunk deletes the given splunk version. +// DeleteSplunk deletes the specified resource. func (c *Client) DeleteSplunk(i *DeleteSplunkInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/splunk_test.go b/fastly/splunk_test.go index 7a09ff2b2..24a4ebc9e 100644 --- a/fastly/splunk_test.go +++ b/fastly/splunk_test.go @@ -100,7 +100,7 @@ Wm7DCfrPNGVwFWUQOmsPue9rZBgO if s.Token != "super-secure-token" { t.Errorf("bad token: %q", s.Token) } - if s.UseTLS != true { + if !s.UseTLS { t.Errorf("bad use_tls: %t", s.UseTLS) } if s.TLSCACert != caCert { diff --git a/fastly/stats.go b/fastly/stats.go index b853374b3..f6a2f3214 100644 --- a/fastly/stats.go +++ b/fastly/stats.go @@ -87,12 +87,18 @@ type Stats struct { // time range (From and To), sampling rate (By) and/or Fastly region (Region) // Allowed values for the fields are described at https://developer.fastly.com/reference/api/metrics-stats/ type GetStatsInput struct { - By string - Field string - From string - Region string + // By is the duration of sample windows. + By string + // Field is the name of the stats field. + Field string + // From is the timestamp that defines the start of the window for which to fetch statistics, including the timestamp itself. + From string + // Region limits query to a specific geographic region. + Region string + // Service is the ID of the service. Service string - To string + // To is the timestamp that defines the end of the window for which to fetch statistics. + To string } // StatsResponse is a response from the service stats API endpoint @@ -111,7 +117,7 @@ type StatsFieldResponse struct { Status string `mapstructure:"status"` } -// GetStats returns stats data based on GetStatsInput +// GetStats retrieves the specified resource. func (c *Client) GetStats(i *GetStatsInput) (*StatsResponse, error) { var resp interface{} if err := c.GetStatsJSON(i, &resp); err != nil { @@ -125,7 +131,7 @@ func (c *Client) GetStats(i *GetStatsInput) (*StatsResponse, error) { return sr, nil } -// GetStatsField returns stats field data based on GetStatsInput +// GetStatsField retrieves the specified resource. func (c *Client) GetStatsField(i *GetStatsInput) (*StatsFieldResponse, error) { var resp interface{} if err := c.GetStatsJSON(i, &resp); err != nil { @@ -184,7 +190,7 @@ type Usage struct { // RegionsUsage is a list of aggregated usage data by Fastly's region type RegionsUsage map[string]*Usage -// UsageStatsResponse is a response from the account usage API endpoint +// UsageResponse is a response from the account usage API endpoint type UsageResponse struct { Data *RegionsUsage `mapstructure:"data"` Message string `mapstructure:"msg"` @@ -195,10 +201,14 @@ type UsageResponse struct { // GetUsageInput is used as an input to the GetUsage function // Value for the input are described at https://developer.fastly.com/reference/api/metrics-stats/ type GetUsageInput struct { - By string - From string + // By is the duration of sample windows. + By string + // From is the timestamp that defines the start of the window for which to fetch statistics, including the timestamp itself. + From string + // Region limits query to a specific geographic region. Region string - To string + // To is the timestamp that defines the end of the window for which to fetch statistics. + To string } // GetUsage returns usage information aggregated across all Fastly services and grouped by region. @@ -224,7 +234,7 @@ func (c *Client) GetUsage(i *GetUsageInput) (*UsageResponse, error) { return sr, nil } -// UsageStatsResponse is a response from the account usage API endpoint +// UsageByServiceResponse is a response from the account usage API endpoint type UsageByServiceResponse struct { Data *ServicesByRegionsUsage `mapstructure:"data"` Message string `mapstructure:"msg"` diff --git a/fastly/sumologic.go b/fastly/sumologic.go index 4bb3436f8..3bb1fa9ec 100644 --- a/fastly/sumologic.go +++ b/fastly/sumologic.go @@ -27,9 +27,17 @@ type Sumologic struct { // sumologicsByName is a sortable list of sumologics. type sumologicsByName []*Sumologic -// Len, Swap, and Less implement the sortable interface. -func (s sumologicsByName) Len() int { return len(s) } -func (s sumologicsByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s sumologicsByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s sumologicsByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s sumologicsByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -42,7 +50,7 @@ type ListSumologicsInput struct { ServiceVersion int } -// ListSumologics returns the list of sumologics for the configuration version. +// ListSumologics retrieves all resources. func (c *Client) ListSumologics(i *ListSumologicsInput) ([]*Sumologic, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -69,21 +77,27 @@ func (c *Client) ListSumologics(i *ListSumologicsInput) ([]*Sumologic, error) { // CreateSumologicInput is used as input to the CreateSumologic function. type CreateSumologicInput struct { - Address string `url:"address,omitempty"` - Format string `url:"format,omitempty"` - FormatVersion int `url:"format_version,omitempty"` - MessageType string `url:"message_type,omitempty"` - Name string `url:"name,omitempty"` - Placement string `url:"placement,omitempty"` + // Format is a Fastly log format string. + Format string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion int `url:"format_version,omitempty"` + // MessageType is how the message should be formatted (classic, loggly, logplex, blank). + MessageType string `url:"message_type,omitempty"` + // Name is the name for the real-time logging configuration. + Name string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement string `url:"placement,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - URL string `url:"url,omitempty"` + // URL is the URL to post logs to. + URL string `url:"url,omitempty"` } -// CreateSumologic creates a new Fastly sumologic. +// CreateSumologic creates a new resource. func (c *Client) CreateSumologic(i *CreateSumologicInput) (*Sumologic, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -117,7 +131,7 @@ type GetSumologicInput struct { ServiceVersion int } -// GetSumologic gets the sumologic configuration with the given parameters. +// GetSumologic retrieves the specified resource. func (c *Client) GetSumologic(i *GetSumologicInput) (*Sumologic, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -147,23 +161,30 @@ func (c *Client) GetSumologic(i *GetSumologicInput) (*Sumologic, error) { // UpdateSumologicInput is used as input to the UpdateSumologic function. type UpdateSumologicInput struct { - Address *string `url:"address,omitempty"` - Format *string `url:"format,omitempty"` - FormatVersion *int `url:"format_version,omitempty"` - MessageType *string `url:"message_type,omitempty"` + Address *string `url:"address,omitempty"` + // Format is a Fastly log format string. + Format *string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion *int `url:"format_version,omitempty"` + // MessageType is how the message should be formatted (classic, loggly, logplex, blank). + MessageType *string `url:"message_type,omitempty"` // Name is the name of the sumologic to update. - Name string - NewName *string `url:"name,omitempty"` - Placement *string `url:"placement,omitempty"` + Name string + // NewName is the new name for the resource. + NewName *string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement *string `url:"placement,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition *string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - URL *string `url:"url,omitempty"` + // URL is the URL to post logs to. + URL *string `url:"url,omitempty"` } -// UpdateSumologic updates a specific sumologic. +// UpdateSumologic updates the specified resource. func (c *Client) UpdateSumologic(i *UpdateSumologicInput) (*Sumologic, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -201,7 +222,7 @@ type DeleteSumologicInput struct { ServiceVersion int } -// DeleteSumologic deletes the given sumologic version. +// DeleteSumologic deletes the specified resource. func (c *Client) DeleteSumologic(i *DeleteSumologicInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/sumologic_test.go b/fastly/sumologic_test.go index e027fbe8d..cb84ceeea 100644 --- a/fastly/sumologic_test.go +++ b/fastly/sumologic_test.go @@ -34,13 +34,13 @@ func TestClient_Sumologics(t *testing.T) { // Ensure deleted defer func() { record(t, "sumologics/cleanup", func(c *Client) { - c.DeleteSumologic(&DeleteSumologicInput{ + _ = c.DeleteSumologic(&DeleteSumologicInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-sumologic", }) - c.DeleteSumologic(&DeleteSumologicInput{ + _ = c.DeleteSumologic(&DeleteSumologicInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "new-test-sumologic", diff --git a/fastly/syslog.go b/fastly/syslog.go index 4f90540c2..cab31dae3 100644 --- a/fastly/syslog.go +++ b/fastly/syslog.go @@ -35,9 +35,17 @@ type Syslog struct { // syslogsByName is a sortable list of syslogs. type syslogsByName []*Syslog -// Len, Swap, and Less implement the sortable interface. -func (s syslogsByName) Len() int { return len(s) } -func (s syslogsByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s syslogsByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s syslogsByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s syslogsByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -50,7 +58,7 @@ type ListSyslogsInput struct { ServiceVersion int } -// ListSyslogs returns the list of syslogs for the configuration version. +// ListSyslogs retrieves all resources. func (c *Client) ListSyslogs(i *ListSyslogsInput) ([]*Syslog, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -77,29 +85,45 @@ func (c *Client) ListSyslogs(i *ListSyslogsInput) ([]*Syslog, error) { // CreateSyslogInput is used as input to the CreateSyslog function. type CreateSyslogInput struct { - Address string `url:"address,omitempty"` - Format string `url:"format,omitempty"` - FormatVersion uint `url:"format_version,omitempty"` - Hostname string `url:"hostname,omitempty"` - IPV4 string `url:"ipv4,omitempty"` - MessageType string `url:"message_type,omitempty"` - Name string `url:"name,omitempty"` - Placement string `url:"placement,omitempty"` - Port uint `url:"port,omitempty"` + // Address is a hostname or IPv4 address. + Address string `url:"address,omitempty"` + // Format is a Fastly log format string. + Format string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion uint `url:"format_version,omitempty"` + // Hostname is the hostname used for the syslog endpoint. + Hostname string `url:"hostname,omitempty"` + // IPV4 is the IPv4 address used for the syslog endpoint. + IPV4 string `url:"ipv4,omitempty"` + // MessageType is how the message should be formatted (classic, loggly, logplex, blank). + MessageType string `url:"message_type,omitempty"` + // Name is the name for the real-time logging configuration. + Name string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement string `url:"placement,omitempty"` + // Port is the port number. + Port uint `url:"port,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - TLSCACert string `url:"tls_ca_cert,omitempty"` - TLSClientCert string `url:"tls_client_cert,omitempty"` - TLSClientKey string `url:"tls_client_key,omitempty"` - TLSHostname string `url:"tls_hostname,omitempty"` - Token string `url:"token,omitempty"` - UseTLS Compatibool `url:"use_tls,omitempty"` + // TLSCACert is a secure certificate to authenticate a server with. Must be in PEM format. + TLSCACert string `url:"tls_ca_cert,omitempty"` + // TLSClientCert is the client certificate used to make authenticated requests. Must be in PEM format. + TLSClientCert string `url:"tls_client_cert,omitempty"` + // TLSClientKey is the client private key used to make authenticated requests. Must be in PEM format. + TLSClientKey string `url:"tls_client_key,omitempty"` + // TLSHostname is the hostname to verify the server's certificate. This should be one of the Subject Alternative Name (SAN) fields for the certificate. Common Names (CN) are not supported. + TLSHostname string `url:"tls_hostname,omitempty"` + // Token is whether to prepend each message with a specific token. + Token string `url:"token,omitempty"` + // UseTLS is whether to use TLS (0: do not use, 1: use). + UseTLS Compatibool `url:"use_tls,omitempty"` } -// CreateSyslog creates a new Fastly syslog. +// CreateSyslog creates a new resource. func (c *Client) CreateSyslog(i *CreateSyslogInput) (*Syslog, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -133,7 +157,7 @@ type GetSyslogInput struct { ServiceVersion int } -// GetSyslog gets the syslog configuration with the given parameters. +// GetSyslog retrieves the specified resource. func (c *Client) GetSyslog(i *GetSyslogInput) (*Syslog, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -163,31 +187,47 @@ func (c *Client) GetSyslog(i *GetSyslogInput) (*Syslog, error) { // UpdateSyslogInput is used as input to the UpdateSyslog function. type UpdateSyslogInput struct { - Address *string `url:"address,omitempty"` - Format *string `url:"format,omitempty"` - FormatVersion *uint `url:"format_version,omitempty"` - Hostname *string `url:"hostname,omitempty"` - IPV4 *string `url:"ipv4,omitempty"` - MessageType *string `url:"message_type,omitempty"` + // Address is a hostname or IPv4 address. + Address *string `url:"address,omitempty"` + // Format is a Fastly log format string. + Format *string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion *uint `url:"format_version,omitempty"` + // Hostname is the hostname used for the syslog endpoint. + Hostname *string `url:"hostname,omitempty"` + // IPV4 is the IPv4 address used for the syslog endpoint. + IPV4 *string `url:"ipv4,omitempty"` + // MessageType is how the message should be formatted (classic, loggly, logplex, blank). + MessageType *string `url:"message_type,omitempty"` // Name is the name of the syslog to update. - Name string - NewName *string `url:"name,omitempty"` - Placement *string `url:"placement,omitempty"` - Port *uint `url:"port,omitempty"` + Name string + // NewName is the new name for the resource. + NewName *string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement *string `url:"placement,omitempty"` + // Port is the port number. + Port *uint `url:"port,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. ResponseCondition *string `url:"response_condition,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int - TLSCACert *string `url:"tls_ca_cert,omitempty"` - TLSClientCert *string `url:"tls_client_cert,omitempty"` - TLSClientKey *string `url:"tls_client_key,omitempty"` - TLSHostname *string `url:"tls_hostname,omitempty"` - Token *string `url:"token,omitempty"` - UseTLS *Compatibool `url:"use_tls,omitempty"` + // TLSCACert is a secure certificate to authenticate a server with. Must be in PEM format. + TLSCACert *string `url:"tls_ca_cert,omitempty"` + // TLSClientCert is the client certificate used to make authenticated requests. Must be in PEM format. + TLSClientCert *string `url:"tls_client_cert,omitempty"` + // TLSClientKey is the client private key used to make authenticated requests. Must be in PEM format. + TLSClientKey *string `url:"tls_client_key,omitempty"` + // TLSHostname is the hostname to verify the server's certificate. This should be one of the Subject Alternative Name (SAN) fields for the certificate. Common Names (CN) are not supported. + TLSHostname *string `url:"tls_hostname,omitempty"` + // Token is whether to prepend each message with a specific token. + Token *string `url:"token,omitempty"` + // UseTLS is whether to use TLS (0: do not use, 1: use). + UseTLS *Compatibool `url:"use_tls,omitempty"` } -// UpdateSyslog updates a specific syslog. +// UpdateSyslog updates the specified resource. func (c *Client) UpdateSyslog(i *UpdateSyslogInput) (*Syslog, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -225,7 +265,7 @@ type DeleteSyslogInput struct { ServiceVersion int } -// DeleteSyslog deletes the given syslog version. +// DeleteSyslog deletes the specified resource. func (c *Client) DeleteSyslog(i *DeleteSyslogInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/syslog_test.go b/fastly/syslog_test.go index 17a069086..70901d9cc 100644 --- a/fastly/syslog_test.go +++ b/fastly/syslog_test.go @@ -89,7 +89,7 @@ Wm7DCfrPNGVwFWUQOmsPue9rZBgO if s.Port != 1234 { t.Errorf("bad port: %q", s.Port) } - if s.UseTLS != true { + if !s.UseTLS { t.Errorf("bad use_tls: %t", s.UseTLS) } if s.TLSCACert != caCert { diff --git a/fastly/tls.go b/fastly/tls.go index 7fdc6fa31..b2c7ed4bc 100644 --- a/fastly/tls.go +++ b/fastly/tls.go @@ -12,6 +12,7 @@ import ( // GetPrivateKeyInput is an input to the GetPrivateKey function. // Allowed values for the fields are described at https://developer.fastly.com/reference/api/tls/platform/. type GetPrivateKeyInput struct { + // ID is an alphanumeric string identifying a private Key. ID string } @@ -28,9 +29,12 @@ type PrivateKey struct { // ListPrivateKeysInput is used as input to the ListPrivateKeys function. type ListPrivateKeysInput struct { - FilterInUse string // Limit the returned keys to those without any matching TLS certificates. - PageNumber int // The page index for pagination. - PageSize int // The number of keys per page. + // FilterInUse is the returned keys to those without any matching TLS certificates. + FilterInUse string + // PageNumber is the page index for pagination. + PageNumber int + // PageSize is the number of keys per page. + PageSize int } // formatFilters converts user input into query parameters for filtering. @@ -57,7 +61,7 @@ func (i *ListPrivateKeysInput) formatFilters() map[string]string { return result } -// ListPrivateKeys list all TLS private keys. +// ListPrivateKeys retrieves all resources. func (c *Client) ListPrivateKeys(i *ListPrivateKeysInput) ([]*PrivateKey, error) { p := "/tls/private_keys" filters := &RequestOptions{ @@ -90,7 +94,7 @@ func (c *Client) ListPrivateKeys(i *ListPrivateKeysInput) ([]*PrivateKey, error) return ppk, nil } -// GetPrivateKey show a TLS private key. +// GetPrivateKey retrieves the specified resource. func (c *Client) GetPrivateKey(i *GetPrivateKeyInput) (*PrivateKey, error) { if i.ID == "" { return nil, ErrMissingID @@ -113,11 +117,13 @@ func (c *Client) GetPrivateKey(i *GetPrivateKeyInput) (*PrivateKey, error) { // CreatePrivateKeyInput is used as input to the CreatePrivateKey function. type CreatePrivateKeyInput struct { - Key string `jsonapi:"attr,key,omitempty"` + // Key is the contents of the private key. Must be a PEM-formatted key. + Key string `jsonapi:"attr,key,omitempty"` + // Name is a customizable name for your private key. Name string `jsonapi:"attr,name,omitempty"` } -// CreatePrivateKey create a TLS private key. +// CreatePrivateKey creates a new resource. func (c *Client) CreatePrivateKey(i *CreatePrivateKeyInput) (*PrivateKey, error) { p := "/tls/private_keys" @@ -144,10 +150,11 @@ func (c *Client) CreatePrivateKey(i *CreatePrivateKeyInput) (*PrivateKey, error) // DeletePrivateKeyInput used for deleting a private key. type DeletePrivateKeyInput struct { + // ID is an alphanumeric string identifying a private Key. ID string } -// DeletePrivateKey destroy a TLS private key. Only private keys not already matched to any certificates can be deleted. +// DeletePrivateKey deletes the specified resource. func (c *Client) DeletePrivateKey(i *DeletePrivateKeyInput) error { if i.ID == "" { return ErrMissingID diff --git a/fastly/tls_subscription.go b/fastly/tls_subscription.go index 65faa030f..39da3a825 100644 --- a/fastly/tls_subscription.go +++ b/fastly/tls_subscription.go @@ -23,6 +23,7 @@ type TLSSubscription struct { UpdatedAt *time.Time `jsonapi:"attr,updated_at,iso8601"` } +// TLSSubscriptionCertificate represents a subscription certificate. type TLSSubscriptionCertificate struct { ID string `jsonapi:"primary,tls_certificate"` } @@ -104,7 +105,7 @@ func (s *ListTLSSubscriptionsInput) formatFilters() map[string]string { return result } -// ListTLSSubscriptions lists all managed TLS subscriptions +// ListTLSSubscriptions retrieves all resources. func (c *Client) ListTLSSubscriptions(i *ListTLSSubscriptionsInput) ([]*TLSSubscription, error) { resp, err := c.Get("/tls/subscriptions", &RequestOptions{ Params: i.formatFilters(), @@ -149,6 +150,7 @@ type CreateTLSSubscriptionInput struct { ID string `jsonapi:"primary,tls_subscription"` } +// CreateTLSSubscription creates a new resource. func (c *Client) CreateTLSSubscription(i *CreateTLSSubscriptionInput) (*TLSSubscription, error) { if len(i.Domains) == 0 { return nil, ErrMissingTLSDomain @@ -192,6 +194,7 @@ type GetTLSSubscriptionInput struct { Include *string } +// GetTLSSubscription retrieves the specified resource. func (c *Client) GetTLSSubscription(i *GetTLSSubscriptionInput) (*TLSSubscription, error) { if i.ID == "" { return nil, ErrMissingID @@ -238,7 +241,8 @@ type UpdateTLSSubscriptionInput struct { ID string `jsonapi:"primary,tls_subscription"` } -// UpdateTLSSubscription updates an existing TLS Subscription (Limited Availability). +// UpdateTLSSubscription updates the specified resource. +// // TLS Subscriptions can only be updated in an "issued" state, and when Force=true. func (c *Client) UpdateTLSSubscription(i *UpdateTLSSubscriptionInput) (*TLSSubscription, error) { if i.ID == "" { @@ -276,6 +280,7 @@ type DeleteTLSSubscriptionInput struct { ID string } +// DeleteTLSSubscription deletes the specified resource. func (c *Client) DeleteTLSSubscription(i *DeleteTLSSubscriptionInput) error { if i.ID == "" { return ErrMissingID diff --git a/fastly/tls_test.go b/fastly/tls_test.go index a2083e2e7..6dfa0e5b3 100644 --- a/fastly/tls_test.go +++ b/fastly/tls_test.go @@ -8,11 +8,11 @@ import ( "encoding/pem" "fmt" "math/big" + "strings" "testing" + "time" rnd "math/rand" - "strings" - "time" ) func TestClient_PrivateKey(t *testing.T) { @@ -40,7 +40,7 @@ func TestClient_PrivateKey(t *testing.T) { // Ensure deleted defer func() { - testClient.DeletePrivateKey(&DeletePrivateKeyInput{ + _ = testClient.DeletePrivateKey(&DeletePrivateKeyInput{ ID: pk.ID, }) }() diff --git a/fastly/token.go b/fastly/token.go index d8d876f29..2b8c263f3 100644 --- a/fastly/token.go +++ b/fastly/token.go @@ -39,15 +39,22 @@ type Token struct { // tokensByName is a sortable list of tokens. type tokensByName []*Token -// Len, Swap, and Less implement the sortable interface. -func (s tokensByName) Len() int { return len(s) } -func (s tokensByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s tokensByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s tokensByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s tokensByName) Less(i, j int) bool { return s[i].Name < s[j].Name } -// ListTokens returns the full list of tokens belonging to the currently -// authenticated user. +// ListTokens retrieves all resources. func (c *Client) ListTokens() ([]*Token, error) { resp, err := c.Get("/tokens", nil) if err != nil { @@ -65,11 +72,11 @@ func (c *Client) ListTokens() ([]*Token, error) { // ListCustomerTokensInput is used as input to the ListCustomerTokens function. type ListCustomerTokensInput struct { + // CustomerID is an alphanumeric string identifying the customer. CustomerID string } -// ListCustomerTokens returns the full list of tokens belonging to a specific -// customer. +// ListCustomerTokens retrieves all resources. func (c *Client) ListCustomerTokens(i *ListCustomerTokensInput) ([]*Token, error) { if i.CustomerID == "" { return nil, ErrMissingCustomerID @@ -91,8 +98,9 @@ func (c *Client) ListCustomerTokens(i *ListCustomerTokensInput) ([]*Token, error } // GetTokenSelf retrieves the token information for the the access_token used -// used to authenticate the request. Returns a 401 if the token has expired -// and a 403 for invalid access token. +// used to authenticate the request. +// +// Returns a 401 if the token has expired and a 403 for invalid access token. func (c *Client) GetTokenSelf() (*Token, error) { resp, err := c.Get("/tokens/self", nil) if err != nil { @@ -110,15 +118,21 @@ func (c *Client) GetTokenSelf() (*Token, error) { // CreateTokenInput is used as input to the Token function. type CreateTokenInput struct { + // ExpiresAt is a time-stamp (UTC) of when the token will expire ExpiresAt *time.Time `url:"expires_at,omitempty"` - Name string `url:"name,omitempty"` - Password string `url:"password,omitempty"` - Scope TokenScope `url:"scope,omitempty"` - Services []string `url:"services,brackets,omitempty"` - Username string `url:"username,omitempty"` + // Name is the name of the token. + Name string `url:"name,omitempty"` + // Password is the token password. + Password string `url:"password,omitempty"` + // Scope is a space-delimited list of authorization scope (global, purge_select, purge_all, global). + Scope TokenScope `url:"scope,omitempty"` + // Services is a list of alphanumeric strings identifying services. If no services are specified, the token will have access to all services on the account. + Services []string `url:"services,brackets,omitempty"` + // Username is the email of the user the token is assigned to. + Username string `url:"username,omitempty"` } -// CreateToken creates a new API token with the given information. +// CreateToken creates a new resource. func (c *Client) CreateToken(i *CreateTokenInput) (*Token, error) { _, err := c.PostForm("/sudo", i, nil) if err != nil { @@ -140,10 +154,11 @@ func (c *Client) CreateToken(i *CreateTokenInput) (*Token, error) { // DeleteTokenInput is used as input to the DeleteToken function. type DeleteTokenInput struct { + // TokenID is an alphanumeric string identifying a token. TokenID string } -// DeleteToken revokes a specific token by its ID. +// DeleteToken deletes the specified resource. func (c *Client) DeleteToken(i *DeleteTokenInput) error { if i.TokenID == "" { return ErrMissingTokenID @@ -162,7 +177,7 @@ func (c *Client) DeleteToken(i *DeleteTokenInput) error { return nil } -// DeleteTokenSelf revokes the token used to authorise the request. +// DeleteTokenSelf deletes the specified resource. func (c *Client) DeleteTokenSelf() error { resp, err := c.Delete("/tokens/self", nil) if err != nil { @@ -178,12 +193,14 @@ func (c *Client) DeleteTokenSelf() error { // BatchDeleteTokensInput is used as input to BatchDeleteTokens. type BatchDeleteTokensInput struct { + // Tokens is a list of alphanumeric strings, each identifying a token. Tokens []*BatchToken } // BatchToken represents the JSONAPI data to be sent to the API. // Reference: https://github.com/google/jsonapi#primary type BatchToken struct { + // ID is an alphanumeric string identifying a token. ID string `jsonapi:"primary,token,omitempty"` } diff --git a/fastly/user.go b/fastly/user.go index 0c05c2566..b8d424305 100644 --- a/fastly/user.go +++ b/fastly/user.go @@ -28,20 +28,28 @@ type User struct { // usersByLogin is a sortable list of users. type usersByName []*User -// Len, Swap, and Less implement the sortable interface. -func (s usersByName) Len() int { return len(s) } -func (s usersByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s usersByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s usersByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s usersByName) Less(i, j int) bool { return s[i].Name < s[j].Name } // ListCustomerUsersInput is used as input to the ListCustomerUsers function. type ListCustomerUsersInput struct { + // CustomerID is an alphanumeric string identifying the customer. CustomerID string } -// ListCustomerUsers returns the full list of users belonging to a specific -// customer. +// ListCustomerUsers retrieves all resources. func (c *Client) ListCustomerUsers(i *ListCustomerUsersInput) ([]*User, error) { if i.CustomerID == "" { return nil, ErrMissingCustomerID @@ -80,11 +88,13 @@ func (c *Client) GetCurrentUser() (*User, error) { // GetUserInput is used as input to the GetUser function. type GetUserInput struct { + // ID is an alphanumeric string identifying the user. ID string } -// GetUser retrieves the user information for the user with the given -// id. If no user exists for the given id, the API returns a 404 response. +// GetUser retrieves the specified resource. +// +//If no user exists for the given id, the API returns a 404 response. func (c *Client) GetUser(i *GetUserInput) (*User, error) { if i.ID == "" { return nil, ErrMissingID @@ -107,12 +117,15 @@ func (c *Client) GetUser(i *GetUserInput) (*User, error) { // CreateUserInput is used as input to the CreateUser function. type CreateUserInput struct { + // Login is the login associated with the user (typically, an email address). Login string `url:"login"` - Name string `url:"name"` - Role string `url:"role,omitempty"` + // Name is the real life name of the user. + Name string `url:"name"` + // Role is the permissions role assigned to the user. Can be user, billing, engineer, or superuser. + Role string `url:"role,omitempty"` } -// CreateUser creates a new API token with the given information. +// CreateUser creates a new resource. func (c *Client) CreateUser(i *CreateUserInput) (*User, error) { if i.Login == "" { return nil, ErrMissingLogin @@ -137,12 +150,15 @@ func (c *Client) CreateUser(i *CreateUserInput) (*User, error) { // UpdateUserInput is used as input to the UpdateUser function. type UpdateUserInput struct { - ID string `url:"-"` + // ID is an alphanumeric string identifying the user. + ID string `url:"-"` + // Name is the real life name of the user. Name *string `url:"name,omitempty"` + // Role is the permissions role assigned to the user. Can be user, billing, engineer, or superuser. Role *string `url:"role,omitempty"` } -// UpdateUser updates the user with the given input. +// UpdateUser updates the specified resource. func (c *Client) UpdateUser(i *UpdateUserInput) (*User, error) { if i.ID == "" { return nil, ErrMissingID @@ -164,10 +180,11 @@ func (c *Client) UpdateUser(i *UpdateUserInput) (*User, error) { // DeleteUserInput is used as input to the DeleteUser function. type DeleteUserInput struct { + // ID is an alphanumeric string identifying the user. ID string } -// DeleteUser revokes a specific token by its ID. +// DeleteUser deletes the specified resource. func (c *Client) DeleteUser(i *DeleteUserInput) error { if i.ID == "" { return ErrMissingID @@ -192,6 +209,7 @@ func (c *Client) DeleteUser(i *DeleteUserInput) error { // ResetUserPasswordInput is used as input to the ResetUserPassword function. type ResetUserPasswordInput struct { + // Login is the login associated with the user (typically, an email address). Login string } diff --git a/fastly/user_test.go b/fastly/user_test.go index f7badf9e3..cfa5e673c 100644 --- a/fastly/user_test.go +++ b/fastly/user_test.go @@ -40,7 +40,7 @@ func TestClient_Users(t *testing.T) { // Ensure deleted defer func() { record(t, fixtureBase+"cleanup", func(c *Client) { - c.DeleteUser(&DeleteUserInput{ + _ = c.DeleteUser(&DeleteUserInput{ ID: u.ID, }) }) diff --git a/fastly/vcl.go b/fastly/vcl.go index 53bbd3878..f9eeb4e7d 100644 --- a/fastly/vcl.go +++ b/fastly/vcl.go @@ -22,9 +22,17 @@ type VCL struct { // vclsByName is a sortable list of VCLs. type vclsByName []*VCL -// Len, Swap, and Less implement the sortable interface. -func (s vclsByName) Len() int { return len(s) } -func (s vclsByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s vclsByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s vclsByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s vclsByName) Less(i, j int) bool { return s[i].Name < s[j].Name } @@ -37,7 +45,7 @@ type ListVCLsInput struct { ServiceVersion int } -// ListVCLs returns the list of VCLs for the configuration version. +// ListVCLs retrieves all resources. func (c *Client) ListVCLs(i *ListVCLsInput) ([]*VCL, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -72,7 +80,7 @@ type GetVCLInput struct { ServiceVersion int } -// GetVCL gets the VCL configuration with the given parameters. +// GetVCL retrieves the specified resource. func (c *Client) GetVCL(i *GetVCLInput) (*VCL, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -108,7 +116,7 @@ type GetGeneratedVCLInput struct { ServiceVersion int } -// GetGeneratedVCL gets the VCL configuration with the given parameters. +// GetGeneratedVCL retrieves the specified resource. func (c *Client) GetGeneratedVCL(i *GetGeneratedVCLInput) (*VCL, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -134,16 +142,19 @@ func (c *Client) GetGeneratedVCL(i *GetGeneratedVCLInput) (*VCL, error) { // CreateVCLInput is used as input to the CreateVCL function. type CreateVCLInput struct { + // Content is the VCL code to be included. Content string `url:"content,omitempty"` - Main bool `url:"main,omitempty"` - Name string `url:"name,omitempty"` + // Main is set to true when this is the main VCL, otherwise false. + Main bool `url:"main,omitempty"` + // Name is the name of this VCL. + Name string `url:"name,omitempty"` // ServiceID is the ID of the service (required). ServiceID string // ServiceVersion is the specific configuration version (required). ServiceVersion int } -// CreateVCL creates a new Fastly VCL. +// CreateVCL creates a new resource. func (c *Client) CreateVCL(i *CreateVCLInput) (*VCL, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -169,9 +180,11 @@ func (c *Client) CreateVCL(i *CreateVCLInput) (*VCL, error) { // UpdateVCLInput is used as input to the UpdateVCL function. type UpdateVCLInput struct { + // Content is the VCL code to be included. Content *string `url:"content,omitempty"` // Name is the name of the VCL to update (required). - Name string + Name string + // NewName is the new name for the resource. NewName *string `url:"name,omitempty"` // ServiceID is the ID of the service (required). ServiceID string @@ -179,7 +192,7 @@ type UpdateVCLInput struct { ServiceVersion int } -// UpdateVCL creates a new Fastly VCL. +// UpdateVCL updates the specified resource. func (c *Client) UpdateVCL(i *UpdateVCLInput) (*VCL, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -255,7 +268,7 @@ type DeleteVCLInput struct { ServiceVersion int } -// DeleteVCL deletes the given VCL version. +// DeleteVCL deletes the specified resource. func (c *Client) DeleteVCL(i *DeleteVCLInput) error { if i.ServiceID == "" { return ErrMissingServiceID diff --git a/fastly/vcl_snippets.go b/fastly/vcl_snippets.go index 46f4f6fa8..3ef6ae480 100644 --- a/fastly/vcl_snippets.go +++ b/fastly/vcl_snippets.go @@ -45,7 +45,7 @@ const ( // SnippetType is the type of VCL Snippet type SnippetType string -// Helper function to get a pointer to string +// SnippetTypeToString is a helper function to get a pointer to string func SnippetTypeToString(b string) *SnippetType { p := SnippetType(b) return &p @@ -84,7 +84,7 @@ type CreateSnippetInput struct { Type SnippetType `url:"type"` } -// CreateSnippet creates a new snippet or dynamic snippet on a unlocked version +// CreateSnippet creates a new resource. func (c *Client) CreateSnippet(i *CreateSnippetInput) (*Snippet, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -127,7 +127,8 @@ type UpdateSnippetInput struct { // Content is the VCL code that specifies exactly what the snippet does. Content *string `url:"content,omitempty"` // Name is the name for the snippet. - Name string + Name string + // NewName is the new name for the resource. NewName *string `url:"name,omitempty"` // Priority determines the ordering for multiple snippets. Lower numbers execute first. Priority *int `url:"priority,omitempty"` @@ -139,7 +140,7 @@ type UpdateSnippetInput struct { Type *SnippetType `url:"type,omitempty"` } -// UpdateSnippet updates a snippet on a unlocked version +// UpdateSnippet updates the specified resource. func (c *Client) UpdateSnippet(i *UpdateSnippetInput) (*Snippet, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -186,7 +187,7 @@ type UpdateDynamicSnippetInput struct { ServiceID string } -// UpdateDynamicSnippet replaces the content of a Dynamic Snippet +// UpdateDynamicSnippet updates the specified resource. func (c *Client) UpdateDynamicSnippet(i *UpdateDynamicSnippetInput) (*DynamicSnippet, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -210,6 +211,7 @@ func (c *Client) UpdateDynamicSnippet(i *UpdateDynamicSnippetInput) (*DynamicSni return updateSnippet, err } +// DeleteSnippetInput is the input parameter to the DeleteSnippet function. type DeleteSnippetInput struct { // Name is the Name of the Snippet to Delete Name string @@ -219,6 +221,7 @@ type DeleteSnippetInput struct { ServiceVersion int } +// DeleteSnippet deletes the specified resource. func (c *Client) DeleteSnippet(i *DeleteSnippetInput) error { if i.ServiceID == "" { return ErrMissingServiceID @@ -260,14 +263,24 @@ type ListSnippetsInput struct { // snippetsByName is a sortable list of Snippets. type snippetsByName []*Snippet -// Len, Swap, and Less implement the sortable interface. -func (s snippetsByName) Len() int { return len(s) } -func (s snippetsByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s snippetsByName) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s snippetsByName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s snippetsByName) Less(i, j int) bool { return s[i].Name < s[j].Name } -// ListSnippets returns the list of Snippets for the configuration version. Content is not displayed for Dynmanic Snippets due to them being +// ListSnippets retrieves all resources. +// +// Content is not displayed for Dynmanic Snippets due to them being // versionless, use the GetDynamicSnippet function to show current content. func (c *Client) ListSnippets(i *ListSnippetsInput) ([]*Snippet, error) { if i.ServiceID == "" { @@ -303,8 +316,10 @@ type GetSnippetInput struct { ServiceVersion int } -// GetSnippet gets the Snippet configuration with the given parameters. Dynamic Snippets will not show content due to them -// being versionless, use GetDynamicSnippet to see content. +// GetSnippet retrieves the specified resource. +// +// Dynamic Snippets will not show content due to them being versionless, use +// GetDynamicSnippet to see content. func (c *Client) GetSnippet(i *GetSnippetInput) (*Snippet, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -340,8 +355,9 @@ type GetDynamicSnippetInput struct { ServiceID string } -// GetDynamicSnippet gets the Snippet configuration with the given parameters. This will show the current content -// associated with a Dynamic Snippet. +// GetDynamicSnippet retrieves the specified resource. +// +// This will show the current content associated with a Dynamic Snippet. func (c *Client) GetDynamicSnippet(i *GetDynamicSnippetInput) (*DynamicSnippet, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID diff --git a/fastly/vcl_test.go b/fastly/vcl_test.go index 32f430b51..1f662bbea 100644 --- a/fastly/vcl_test.go +++ b/fastly/vcl_test.go @@ -51,13 +51,13 @@ sub vcl_hash { // Ensure deleted defer func() { record(t, "vcls/cleanup", func(c *Client) { - c.DeleteVCL(&DeleteVCLInput{ + _ = c.DeleteVCL(&DeleteVCLInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "test-vcl", }) - c.DeleteVCL(&DeleteVCLInput{ + _ = c.DeleteVCL(&DeleteVCLInput{ ServiceID: testServiceID, ServiceVersion: tv.Number, Name: "new-test-vcl", @@ -135,7 +135,7 @@ sub vcl_hash { if err != nil { t.Fatal(err) } - if avcl.Main != true { + if !avcl.Main { t.Errorf("bad main: %t", avcl.Main) } diff --git a/fastly/version.go b/fastly/version.go index ec5f31178..265c4b7b4 100644 --- a/fastly/version.go +++ b/fastly/version.go @@ -25,9 +25,17 @@ type Version struct { // `List()` function to sort the API responses. type versionsByNumber []*Version -// Len, Swap, and Less implement the sortable interface. -func (s versionsByNumber) Len() int { return len(s) } -func (s versionsByNumber) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// Len implement the sortable interface. +func (s versionsByNumber) Len() int { + return len(s) +} + +// Swap implement the sortable interface. +func (s versionsByNumber) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less implement the sortable interface. func (s versionsByNumber) Less(i, j int) bool { return s[i].Number < s[j].Number } @@ -38,7 +46,7 @@ type ListVersionsInput struct { ServiceID string } -// ListVersions returns the full list of all versions of the given service. +// ListVersions retrieves all resources. func (c *Client) ListVersions(i *ListVersionsInput) ([]*Version, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -66,8 +74,9 @@ type LatestVersionInput struct { ServiceID string } -// LatestVersion fetches the latest version. If there are no versions, this -// function will return nil (but not an error). +// LatestVersion retrieves the specified resource. +// +// If there are no versions, this function will return nil (but not an error). func (c *Client) LatestVersion(i *LatestVersionInput) (*Version, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -87,14 +96,15 @@ func (c *Client) LatestVersion(i *LatestVersionInput) (*Version, error) { // CreateVersionInput is the input to the CreateVersion function. type CreateVersionInput struct { - // A personal freeform descriptive note. + // Comment is a personal freeform descriptive note. Comment string `url:"comment,omitempty"` // ServiceID is the ID of the service (required). ServiceID string } -// CreateVersion constructs a new version. Note that `CloneVersion` is -// preferred in almost all scenarios, since `Create()` creates a _blank_ +// CreateVersion creates a new resource. +// +// This is preferred in almost all scenarios, since `Create()` creates a _blank_ // configuration where `Clone()` builds off of an existing configuration. func (c *Client) CreateVersion(i *CreateVersionInput) (*Version, error) { if i.ServiceID == "" { @@ -119,11 +129,11 @@ func (c *Client) CreateVersion(i *CreateVersionInput) (*Version, error) { type GetVersionInput struct { // ServiceID is the ID of the service (required). ServiceID string - // SrrviceVersion is the version number to fetch (required). + // ServiceVersion is the version number to fetch (required). ServiceVersion int } -// GetVersion fetches a version with the given information. +// GetVersion retrieves the specified resource. func (c *Client) GetVersion(i *GetVersionInput) (*Version, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -149,7 +159,7 @@ func (c *Client) GetVersion(i *GetVersionInput) (*Version, error) { // UpdateVersionInput is the input to the UpdateVersion function. type UpdateVersionInput struct { - // A personal freeform descriptive note. + // Comment is a personal freeform descriptive note. Comment *string `url:"comment,omitempty"` // ServiceID is the ID of the service (required). ServiceID string @@ -157,7 +167,7 @@ type UpdateVersionInput struct { ServiceVersion int } -// UpdateVersion updates the given version +// UpdateVersion updates the specified resource. func (c *Client) UpdateVersion(i *UpdateVersionInput) (*Version, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -253,9 +263,10 @@ type CloneVersionInput struct { ServiceVersion int } -// CloneVersion creates a clone of the version with and returns a new -// configuration version with all the same configuration options, but an -// incremented number. +// CloneVersion creates a clone of the specified version. +// +// Returns a new configuration version with all the same configuration options, +// but an incremented number. func (c *Client) CloneVersion(i *CloneVersionInput) (*Version, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -287,7 +298,7 @@ type ValidateVersionInput struct { ServiceVersion int } -// ValidateVersion validates if the given version is okay. +// ValidateVersion validates the specified resource. func (c *Client) ValidateVersion(i *ValidateVersionInput) (bool, string, error) { var msg string diff --git a/fastly/version_test.go b/fastly/version_test.go index 6c07e8f57..d184a5eda 100644 --- a/fastly/version_test.go +++ b/fastly/version_test.go @@ -93,7 +93,7 @@ func TestClient_Versions(t *testing.T) { if err != nil { t.Fatal(err) } - if vl.Locked != true { + if !vl.Locked { t.Errorf("bad lock: %t", vl.Locked) } @@ -108,7 +108,7 @@ func TestClient_Versions(t *testing.T) { if err != nil { t.Fatal(err) } - if cv.Active != false { + if cv.Active { t.Errorf("bad clone: %t", cv.Active) } if cv.Comment != uv.Comment { diff --git a/fastly/waf.go b/fastly/waf.go index 8b8e52e6a..14072a3da 100644 --- a/fastly/waf.go +++ b/fastly/waf.go @@ -85,7 +85,7 @@ func (i *ListWAFsInput) formatFilters() map[string]string { return result } -// ListWAFs returns the list of wafs for the configuration version. +// ListWAFs retrieves all resources. func (c *Client) ListWAFs(i *ListWAFsInput) (*WAFResponse, error) { resp, err := c.Get("/waf/firewalls", &RequestOptions{ Params: i.formatFilters(), @@ -124,16 +124,19 @@ func (c *Client) ListWAFs(i *ListWAFsInput) (*WAFResponse, error) { // CreateWAFInput is used as input to the CreateWAF function. type CreateWAFInput struct { - ID string `jsonapi:"primary,waf_firewall"` + // ID is an alphanumeric string identifying a WAF Firewall. + ID string `jsonapi:"primary,waf_firewall"` + // PrefetchCondition is the name of the corresponding condition object. PrefetchCondition string `jsonapi:"attr,prefetch_condition"` - Response string `jsonapi:"attr,response"` + // Response is the name of the corresponding response object. + Response string `jsonapi:"attr,response"` // ServiceID is the ID of the service (required). ServiceID string `jsonapi:"attr,service_id"` // ServiceVersion is the specific configuration version (required). ServiceVersion int `jsonapi:"attr,service_version_number"` } -// CreateWAF creates a new Fastly WAF. +// CreateWAF creates a new resource. func (c *Client) CreateWAF(i *CreateWAFInput) (*WAF, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -167,7 +170,7 @@ type GetWAFInput struct { ServiceVersion int } -// GetWAF gets details for given WAF +// GetWAF retrieves the specified resource. func (c *Client) GetWAF(i *GetWAFInput) (*WAF, error) { if i.ServiceID == "" { return nil, ErrMissingServiceID @@ -201,17 +204,21 @@ func (c *Client) GetWAF(i *GetWAFInput) (*WAF, error) { // UpdateWAFInput is used as input to the UpdateWAF function. type UpdateWAFInput struct { - Disabled *bool `jsonapi:"attr,disabled,omitempty"` - ID string `jsonapi:"primary,waf_firewall"` + // Disabled is the status of the firewall. + Disabled *bool `jsonapi:"attr,disabled,omitempty"` + // ID is an alphanumeric string identifying a WAF Firewall. + ID string `jsonapi:"primary,waf_firewall"` + // PrefetchCondition is the name of the corresponding condition object. PrefetchCondition *string `jsonapi:"attr,prefetch_condition,omitempty"` - Response *string `jsonapi:"attr,response,omitempty"` + // Response is the name of the corresponding response object. + Response *string `jsonapi:"attr,response,omitempty"` // ServiceID is the ID of the service. ServiceID *string `jsonapi:"attr,service_id,omitempty"` // ServiceVersion is the specific configuration version. ServiceVersion *int `jsonapi:"attr,service_version_number,omitempty"` } -// UpdateWAF updates a specific WAF. +// UpdateWAF updates the specified resource. func (c *Client) UpdateWAF(i *UpdateWAFInput) (*WAF, error) { if i.ID == "" { return nil, ErrMissingID @@ -252,7 +259,7 @@ type DeleteWAFInput struct { ServiceVersion int `jsonapi:"attr,service_version_number"` } -// DeleteWAF deletes a given WAF from its service. +// DeleteWAF deletes the specified resource. func (c *Client) DeleteWAF(i *DeleteWAFInput) error { if i.ServiceVersion == 0 { return ErrMissingServiceVersion diff --git a/fastly/waf_active_rule.go b/fastly/waf_active_rule.go index a8e9088d6..c4de60477 100644 --- a/fastly/waf_active_rule.go +++ b/fastly/waf_active_rule.go @@ -79,7 +79,7 @@ func (i *ListWAFActiveRulesInput) formatFilters() map[string]string { return result } -// ListWAFActiveRules returns the list of active rules for a given WAF ID. +// ListWAFActiveRules retrieves all resources. func (c *Client) ListWAFActiveRules(i *ListWAFActiveRulesInput) (*WAFActiveRuleResponse, error) { if i.WAFID == "" { return nil, ErrMissingWAFID @@ -141,8 +141,7 @@ type ListAllWAFActiveRulesInput struct { WAFVersionNumber int } -// ListAllWAFActiveRules returns the complete list of WAF active rules for a given WAF ID. It iterates through -// all existing pages to ensure all WAF active rules are returned at once. +// ListAllWAFActiveRules retrieves all resources. func (c *Client) ListAllWAFActiveRules(i *ListAllWAFActiveRulesInput) (*WAFActiveRuleResponse, error) { if i.WAFID == "" { return nil, ErrMissingWAFID @@ -178,17 +177,17 @@ func (c *Client) ListAllWAFActiveRules(i *ListAllWAFActiveRulesInput) (*WAFActiv } } -// CreateWAFActiveRulesInput used as input for adding rules to a WAF. +// CreateWAFActiveRulesInput creates a new resource. type CreateWAFActiveRulesInput struct { - // The list of WAF active rules (ModSecID, Status and Revision are required). + // Rules is the list of WAF active rules (ModSecID, Status and Revision are required). Rules []*WAFActiveRule - // The Web Application Firewall's ID. + // WAFID is the Web Application Firewall's ID. WAFID string - // The Web Application Firewall's version number. + // WAFVersionNumber is the Web Application Firewall's version number. WAFVersionNumber int } -// CreateWAFActiveRules adds rules to a particular WAF. +// CreateWAFActiveRules creates a new resource. func (c *Client) CreateWAFActiveRules(i *CreateWAFActiveRulesInput) ([]*WAFActiveRule, error) { if i.WAFID == "" { return nil, ErrMissingWAFID @@ -228,18 +227,21 @@ func (c *Client) CreateWAFActiveRules(i *CreateWAFActiveRulesInput) ([]*WAFActiv // BatchModificationWAFActiveRulesInput is used for active rules batch modifications. type BatchModificationWAFActiveRulesInput struct { - // The batch operation to be performed (allowed operations are upsert and delete). + // OP is the batch operation to be performed (allowed operations are upsert and delete). OP BatchOperation - // The list of WAF active rules (ModSecID, Status and Revision are required for upsert, ModSecID is required for delete). + // Rules is the list of WAF active rules (ModSecID, Status and Revision are required for upsert, ModSecID is required for delete). Rules []*WAFActiveRule - // The Web Application Firewall's ID. + // WAFID is the Web Application Firewall's ID. WAFID string - // The Web Application Firewall's version number. + // WAFVersionNumber is the Web Application Firewall's version number. WAFVersionNumber int } -// BatchModificationWAFActiveRules is a generic function for creating or deleting WAF active rules in batches. -// Upsert and delete are the only operations allowed. +// BatchModificationWAFActiveRules groups create/delete operations for the +// specified resource. +// +// This is a generic function for creating or deleting WAF active rules in +// batches. Upsert and delete are the only operations allowed. func (c *Client) BatchModificationWAFActiveRules(i *BatchModificationWAFActiveRulesInput) ([]*WAFActiveRule, error) { if len(i.Rules) > BatchModifyMaximumOperations { return nil, ErrMaxExceededRules @@ -265,15 +267,15 @@ func (c *Client) BatchModificationWAFActiveRules(i *BatchModificationWAFActiveRu // DeleteWAFActiveRulesInput used as input for removing rules from a WAF. type DeleteWAFActiveRulesInput struct { - // The list of WAF active rules (ModSecID is required). + // Rules is the list of WAF active rules (ModSecID is required). Rules []*WAFActiveRule - // The Web Application Firewall's ID. + // WAFID is the Web Application Firewall's ID. WAFID string - // The Web Application Firewall's version number. + // WAFVersionNumber is the Web Application Firewall's version number. WAFVersionNumber int } -// DeleteWAFActiveRules removes rules from a particular WAF. +// DeleteWAFActiveRules deletes the specified resource. func (c *Client) DeleteWAFActiveRules(i *DeleteWAFActiveRulesInput) error { if i.WAFID == "" { return ErrMissingWAFID diff --git a/fastly/waf_rule_exclusion.go b/fastly/waf_rule_exclusion.go index 1223c6255..c9fa50b10 100644 --- a/fastly/waf_rule_exclusion.go +++ b/fastly/waf_rule_exclusion.go @@ -43,69 +43,69 @@ type WAFRuleExclusionResponse struct { // ListWAFRuleExclusionsInput used as input for listing a WAF's rule exclusions. type ListWAFRuleExclusionsInput struct { - // Limit results to exclusions with the specified exclusions type. + // FilterExclusionType limits results to exclusions with the specified exclusions type. FilterExclusionType *string - // Limit results to exclusions that represent the specified ModSecurity modsec_rule_id. + // FilterModSedID limits results to exclusions that represent the specified ModSecurity modsec_rule_id. FilterModSedID *string - // Limit results to exclusions with the specified exclusion name. + // FilterName limits results to exclusions with the specified exclusion name. FilterName *string - // Include relationships. Optional. Permitted values: waf_rules. + // Include captures relationships. Optional. Permitted values: waf_rules. Include []string - // Request a specific page of exclusions. + // PageNumber requests a specific page of exclusions. PageNumber *int - // Limit the number of returned pages. + // PageSize limits the number of returned pages. PageSize *int - // The Web Application Firewall's ID. + // WAFID is the Web Application Firewall's ID. WAFID string - // The Web Application Firewall's version number. + // WAFVersionNumber is the Web Application Firewall's version number. WAFVersionNumber int } // ListAllWAFRuleExclusionsInput used as input for listing all WAF rule exclusions. type ListAllWAFRuleExclusionsInput struct { - // Limit results to exclusions with the specified exclusions type. + // FilterExclusionType limits results to exclusions with the specified exclusions type. FilterExclusionType *string - // Limit results to exclusions that represent the specified ModSecurity modsec_rule_id. + // FilterModSedID limits results to exclusions that represent the specified ModSecurity modsec_rule_id. FilterModSedID *string - // Limit results to exclusions with the specified exclusion name. + // FilterName limits results to exclusions with the specified exclusion name. FilterName *string - // Include relationships. Optional. Permitted values: waf_rules. + // Include captures relationships. Optional. Permitted values: waf_rules. Include []string - // The Web Application Firewall's ID. + // WAFID is the Web Application Firewall's ID. WAFID string - // The Web Application Firewall's version number. + // WAFVersionNumber is the Web Application Firewall's version number. WAFVersionNumber int } -// CreateWAFRuleExclusionInput used as input to create a WAF rule exclusion. +// CreateWAFRuleExclusionInput creates a new resource. type CreateWAFRuleExclusionInput struct { - // The Web Application Firewall's ID. + // WAFID is the Web Application Firewall's ID. WAFID string - // The Web Application Firewall's exclusion + // WAFRuleExclusion is the Web Application Firewall's exclusion WAFRuleExclusion *WAFRuleExclusion - // The Web Application Firewall's version number. + // WAFVersionNumber is the Web Application Firewall's version number. WAFVersionNumber int } // UpdateWAFRuleExclusionInput is used for exclusions updates. type UpdateWAFRuleExclusionInput struct { - // The exclusion number. + // Number is the rule exclusion number. Number int - // The Web Application Firewall's ID. + // WAFID is the Web Application Firewall's ID. WAFID string - // The WAF rule exclusion + // WAFRuleExclusion is the Web Application Firewall's exclusion WAFRuleExclusion *WAFRuleExclusion - // The Web Application Firewall's version number. + // WAFVersionNumber is the Web Application Firewall's version number. WAFVersionNumber int } // DeleteWAFRuleExclusionInput used as input for removing WAF rule exclusions. type DeleteWAFRuleExclusionInput struct { - // The rule exclusion number. + // Number is the rule exclusion number. Number int - // The Web Application Firewall's ID. + // WAFID is the Web Application Firewall's ID. WAFID string - // The Web Application Firewall's version number. + // WAFVersionNumber is the Web Application Firewall's version number. WAFVersionNumber int } @@ -141,7 +141,7 @@ func (i *ListWAFRuleExclusionsInput) formatFilters() map[string]string { return result } -// ListWAFRuleExclusions returns the list of exclusions for a given WAF ID. +// ListWAFRuleExclusions retrieves all resources. func (c *Client) ListWAFRuleExclusions(i *ListWAFRuleExclusionsInput) (*WAFRuleExclusionResponse, error) { if i.WAFID == "" { return nil, ErrMissingWAFID @@ -187,8 +187,7 @@ func (c *Client) ListWAFRuleExclusions(i *ListWAFRuleExclusionsInput) (*WAFRuleE }, nil } -// ListAllWAFRuleExclusions returns the complete list of WAF rule exclusions for a given WAF ID. It iterates through -// all existing pages to ensure all WAF rule exclusions are returned at once. +// ListAllWAFRuleExclusions retrieves all resources. func (c *Client) ListAllWAFRuleExclusions(i *ListAllWAFRuleExclusionsInput) (*WAFRuleExclusionResponse, error) { if i.WAFID == "" { return nil, ErrMissingWAFID @@ -225,7 +224,7 @@ func (c *Client) ListAllWAFRuleExclusions(i *ListAllWAFRuleExclusionsInput) (*WA } } -// CreateWAFRuleExclusion used to create a particular WAF rule exclusion. +// CreateWAFRuleExclusion creates a new resource. func (c *Client) CreateWAFRuleExclusion(i *CreateWAFRuleExclusionInput) (*WAFRuleExclusion, error) { if i.WAFID == "" { return nil, ErrMissingWAFID @@ -253,7 +252,7 @@ func (c *Client) CreateWAFRuleExclusion(i *CreateWAFRuleExclusionInput) (*WAFRul return &wafExclusion, nil } -// UpdateWAFRuleExclusion used to update a particular WAF rule exclusion. +// UpdateWAFRuleExclusion updates the specified resource. func (c *Client) UpdateWAFRuleExclusion(i *UpdateWAFRuleExclusionInput) (*WAFRuleExclusion, error) { if i.WAFID == "" { return nil, ErrMissingWAFID @@ -285,7 +284,7 @@ func (c *Client) UpdateWAFRuleExclusion(i *UpdateWAFRuleExclusionInput) (*WAFRul return exc, nil } -// DeleteWAFExclusions removes rules from a particular WAF. +// DeleteWAFRuleExclusion deletes the specified resource. func (c *Client) DeleteWAFRuleExclusion(i *DeleteWAFRuleExclusionInput) error { if i.WAFID == "" { return ErrMissingWAFID diff --git a/fastly/waf_rule_exclusion_test.go b/fastly/waf_rule_exclusion_test.go index 61bdbaa13..bd9ad8b4f 100644 --- a/fastly/waf_rule_exclusion_test.go +++ b/fastly/waf_rule_exclusion_test.go @@ -315,10 +315,10 @@ func assertWAFRuleExclusionEquals(t *testing.T, actual *WAFRuleExclusion, expect t.Errorf("expected Rules to be of size %d got %d", len(actual.Rules), len(expected.Rules)) } - reflect.DeepEqual(extractModSecId(actual.Rules), extractModSecId(expected.Rules)) + reflect.DeepEqual(extractModSecID(actual.Rules), extractModSecID(expected.Rules)) } -func extractModSecId(wafRule []*WAFRule) []int { +func extractModSecID(wafRule []*WAFRule) []int { var modSecIDs []int for _, rule := range wafRule { modSecIDs = append(modSecIDs, rule.ModSecID) @@ -346,7 +346,6 @@ func createWAFWithRulesForExclusion(t *testing.T, fixtureBase string, testServic } func buildWAFRulesForExclusion(status string) []*WAFActiveRule { - return []*WAFActiveRule{ { ModSecID: 2029718, diff --git a/fastly/waf_rules.go b/fastly/waf_rules.go index eafcfa9b3..e2ffa9cab 100644 --- a/fastly/waf_rules.go +++ b/fastly/waf_rules.go @@ -45,19 +45,19 @@ type WAFRuleResponse struct { // ListWAFRulesInput used as input for listing WAF rules. type ListWAFRulesInput struct { - // Excludes individual rules by modsecurity rule IDs. + // ExcludeModSecIDs excludes individual rules by modsecurity rule IDs. ExcludeModSecIDs []int - // Limit the returned rules to a set by modsecurity rule IDs. + // FilterModSecIDs limits the returned rules to a set by modsecurity rule IDs. FilterModSecIDs []int - // Limit the returned rules to a set by publishers. + // FilterPublishers limits the returned rules to a set by publishers. FilterPublishers []string - // Limit the returned rules to a set linked to list of tags by name. + // FilterTagNames limits the returned rules to a set linked to list of tags by name. FilterTagNames []string - // Include relationships. Optional, comma-separated values. Permitted values: waf_tags and waf_rule_revisions. + // Include captures relationships. Optional, comma-separated values. Permitted values: waf_tags and waf_rule_revisions. Include string - // Request a specific page of rules. + // PageNumber requests a specific page of rules. PageNumber int - // Limit the number of returned rules. + // PageSize limits the number of returned rules. PageSize int } @@ -89,7 +89,6 @@ func (i *ListWAFRulesInput) formatFilters() map[string]string { } case "[]int": if len(value.([]int)) > 0 { - stringSlice := make([]string, len(value.([]int))) for i, id := range value.([]int) { stringSlice[i] = strconv.Itoa(id) @@ -101,7 +100,7 @@ func (i *ListWAFRulesInput) formatFilters() map[string]string { return result } -// ListWAFRules returns the list of VAF versions for a given WAF ID. +// ListWAFRules retrieves all resources. func (c *Client) ListWAFRules(i *ListWAFRulesInput) (*WAFRuleResponse, error) { resp, err := c.Get("/waf/rules", &RequestOptions{ Params: i.formatFilters(), @@ -140,20 +139,19 @@ func (c *Client) ListWAFRules(i *ListWAFRulesInput) (*WAFRuleResponse, error) { // ListAllWAFRulesInput used as input for listing all WAF rules. type ListAllWAFRulesInput struct { - // Excludes individual rules by modsecurity rule IDs. + // ExcludeMocSecIDs excludes individual rules by modsecurity rule IDs. ExcludeMocSecIDs []int - // Limit the returned rules to a set by modsecurity rule IDs. + // FilterModSecIDs limits the returned rules to a set by modsecurity rule IDs. FilterModSecIDs []int - // Limit the returned rules to a set by publishers. + // FilterPublishers limits the returned rules to a set by publishers. FilterPublishers []string - // Limit the returned rules to a set linked to a tag by name. + // FilterTagNames limits the returned rules to a set linked to a tag by name. FilterTagNames []string - // Include relationships. Optional, comma-separated values. Permitted values: waf_tags and waf_rule_revisions. + // Include captures relationships. Optional, comma-separated values. Permitted values: waf_tags and waf_rule_revisions. Include string } -// ListAllWAFRules returns the complete list of WAF rules for the given filters. It iterates through -// all existing pages to ensure all WAF rules are returned at once. +// ListAllWAFRules retrieves all resources. func (c *Client) ListAllWAFRules(i *ListAllWAFRulesInput) (*WAFRuleResponse, error) { currentPage := 1 result := &WAFRuleResponse{Items: []*WAFRule{}} diff --git a/fastly/waf_test.go b/fastly/waf_test.go index 980a3f366..bb3540d0c 100644 --- a/fastly/waf_test.go +++ b/fastly/waf_test.go @@ -59,7 +59,7 @@ func TestClient_WAFs(t *testing.T) { // Ensure deleted defer func() { record(t, fixtureBase+"/cleanup", func(c *Client) { - c.DeleteWAF(&DeleteWAFInput{ + _ = c.DeleteWAF(&DeleteWAFInput{ ServiceVersion: tv.Number, ID: waf.ID, }) diff --git a/fastly/waf_version.go b/fastly/waf_version.go index 80c57c862..064ccbb43 100644 --- a/fastly/waf_version.go +++ b/fastly/waf_version.go @@ -92,13 +92,13 @@ type WAFVersionResponse struct { // ListWAFVersionsInput used as input for listing WAF versions. type ListWAFVersionsInput struct { - // Include relationships. Optional, comma-separated values. Permitted values: waf_firewall_versions. + // Include captures relationships. Optional, comma-separated values. Permitted values: waf_firewall_versions. Include string - // Request a specific page of WAFs. + // PageNumber requests a specific page of WAFs. PageNumber int - // Limit the number records returned. + // PageSize limits the number records returned. PageSize int - // The Web Application Firewall's ID. + // WAFID is the Web Application Firewall's ID. WAFID string } @@ -125,7 +125,7 @@ func (i *ListWAFVersionsInput) formatFilters() map[string]string { return result } -// ListWAFVersions returns the list of VAF versions for a given WAF ID. +// ListWAFVersions retrieves all resources. func (c *Client) ListWAFVersions(i *ListWAFVersionsInput) (*WAFVersionResponse, error) { if i.WAFID == "" { return nil, ErrMissingWAFID @@ -169,14 +169,13 @@ func (c *Client) ListWAFVersions(i *ListWAFVersionsInput) (*WAFVersionResponse, // ListAllWAFVersionsInput used as input for listing all WAF versions. type ListAllWAFVersionsInput struct { - // Include relationships. Optional, comma-separated values. Permitted values: waf_firewall_versions. + // Include captures relationships. Optional, comma-separated values. Permitted values: waf_firewall_versions. Include string - // The Web Application Firewall's ID. + // WAFID is the Web Application Firewall's ID. WAFID string } -// ListAllWAFVersions returns the complete list of WAF versions for a given WAF ID. It iterates through -// all existing pages to ensure all WAF versions are returned at once. +// ListAllWAFVersions retrieves all resources. func (c *Client) ListAllWAFVersions(i *ListAllWAFVersionsInput) (*WAFVersionResponse, error) { if i.WAFID == "" { return nil, ErrMissingWAFID @@ -206,13 +205,13 @@ func (c *Client) ListAllWAFVersions(i *ListAllWAFVersionsInput) (*WAFVersionResp // GetWAFVersionInput used as input for GetWAFVersion function. type GetWAFVersionInput struct { - // The Web Application Firewall's ID. + // WAFID is the Web Application Firewall's ID. WAFID string - // The Web Application Firewall's version number. + // WAFVersionNumber is the Web Application Firewall's version number. WAFVersionNumber int } -// GetWAFVersion gets details for given WAF version. +// GetWAFVersion retrieves the specified resource. func (c *Client) GetWAFVersion(i *GetWAFVersionInput) (*WAFVersion, error) { if i.WAFID == "" { return nil, ErrMissingWAFID @@ -239,41 +238,70 @@ func (c *Client) GetWAFVersion(i *GetWAFVersionInput) (*WAFVersion, error) { // UpdateWAFVersionInput is used as input to the UpdateWAFVersion function. This struct uses pointers due to the problem // detailed on this issue https://github.com/opencredo/go-fastly/pull/17. type UpdateWAFVersionInput struct { - AllowedHTTPVersions *string `jsonapi:"attr,allowed_http_versions,omitempty"` - AllowedMethods *string `jsonapi:"attr,allowed_methods,omitempty"` - AllowedRequestContentType *string `jsonapi:"attr,allowed_request_content_type,omitempty"` + // AllowedHTTPVersions is allowed HTTP versions. + AllowedHTTPVersions *string `jsonapi:"attr,allowed_http_versions,omitempty"` + // AllowedMethods is a space-separated list of HTTP method names. + AllowedMethods *string `jsonapi:"attr,allowed_methods,omitempty"` + // AllowedRequestContentType is allowed request content types. + AllowedRequestContentType *string `jsonapi:"attr,allowed_request_content_type,omitempty"` + // AllowedRequestContentTypeCharset is allowed request content type charset. AllowedRequestContentTypeCharset *string `jsonapi:"attr,allowed_request_content_type_charset,omitempty"` - ArgLength *int `jsonapi:"attr,arg_length,omitempty"` - ArgNameLength *int `jsonapi:"attr,arg_name_length,omitempty"` - CRSValidateUTF8Encoding *bool `jsonapi:"attr,crs_validate_utf8_encoding,omitempty"` - CombinedFileSizes *int `jsonapi:"attr,combined_file_sizes,omitempty"` - Comment *string `jsonapi:"attr,comment,omitempty"` - CriticalAnomalyScore *int `jsonapi:"attr,critical_anomaly_score,omitempty"` - ErrorAnomalyScore *int `jsonapi:"attr,error_anomaly_score,omitempty"` - HTTPViolationScoreThreshold *int `jsonapi:"attr,http_violation_score_threshold,omitempty"` - HighRiskCountryCodes *string `jsonapi:"attr,high_risk_country_codes,omitempty"` - InboundAnomalyScoreThreshold *int `jsonapi:"attr,inbound_anomaly_score_threshold,omitempty"` - LFIScoreThreshold *int `jsonapi:"attr,lfi_score_threshold,omitempty"` - MaxFileSize *int `jsonapi:"attr,max_file_size,omitempty"` - MaxNumArgs *int `jsonapi:"attr,max_num_args,omitempty"` - NoticeAnomalyScore *int `jsonapi:"attr,notice_anomaly_score,omitempty"` - PHPInjectionScoreThreshold *int `jsonapi:"attr,php_injection_score_threshold,omitempty"` - ParanoiaLevel *int `jsonapi:"attr,paranoia_level,omitempty"` - RCEScoreThreshold *int `jsonapi:"attr,rce_score_threshold,omitempty"` - RFIScoreThreshold *int `jsonapi:"attr,rfi_score_threshold,omitempty"` - RestrictedExtensions *string `jsonapi:"attr,restricted_extensions,omitempty"` - RestrictedHeaders *string `jsonapi:"attr,restricted_headers,omitempty"` - SQLInjectionScoreThreshold *int `jsonapi:"attr,sql_injection_score_threshold,omitempty"` - SessionFixationScoreThreshold *int `jsonapi:"attr,session_fixation_score_threshold,omitempty"` - TotalArgLength *int `jsonapi:"attr,total_arg_length,omitempty"` - // The Web Application Firewall's ID. + // ArgLength is the maximum allowed length of an argument. + ArgLength *int `jsonapi:"attr,arg_length,omitempty"` + // ArgNameLength is the maximum allowed argument name length. + ArgNameLength *int `jsonapi:"attr,arg_name_length,omitempty"` + // CRSValidateUTF8Encoding is the CRS validate UTF8 encoding. + CRSValidateUTF8Encoding *bool `jsonapi:"attr,crs_validate_utf8_encoding,omitempty"` + // CombinedFileSizes is the maximum allowed size of all files (in bytes). + CombinedFileSizes *int `jsonapi:"attr,combined_file_sizes,omitempty"` + // Comment is a freeform descriptive note. + Comment *string `jsonapi:"attr,comment,omitempty"` + // CriticalAnomalyScore is the score value to add for critical anomalies. + CriticalAnomalyScore *int `jsonapi:"attr,critical_anomaly_score,omitempty"` + // ErrorAnomalyScore is the score value to add for error anomalies. + ErrorAnomalyScore *int `jsonapi:"attr,error_anomaly_score,omitempty"` + // HTTPViolationScoreThreshold is the HTTP violation threshold. + HTTPViolationScoreThreshold *int `jsonapi:"attr,http_violation_score_threshold,omitempty"` + // HighRiskCountryCodes is a space-separated list of country codes in ISO 3166-1 (two-letter) format. + HighRiskCountryCodes *string `jsonapi:"attr,high_risk_country_codes,omitempty"` + // InboundAnomalyScoreThreshold is the inbound anomaly threshold. + InboundAnomalyScoreThreshold *int `jsonapi:"attr,inbound_anomaly_score_threshold,omitempty"` + // LFIScoreThreshold is the local file inclusion attack threshold. + LFIScoreThreshold *int `jsonapi:"attr,lfi_score_threshold,omitempty"` + // MaxFileSize is the maximum allowed file size, in bytes. + MaxFileSize *int `jsonapi:"attr,max_file_size,omitempty"` + // MaxNumArgs is the maximum number of arguments allowed. + MaxNumArgs *int `jsonapi:"attr,max_num_args,omitempty"` + // NoticeAnomalyScore is the score value to add for notice anomalies. + NoticeAnomalyScore *int `jsonapi:"attr,notice_anomaly_score,omitempty"` + // PHPInjectionScoreThreshold is the PHP injection threshold. + PHPInjectionScoreThreshold *int `jsonapi:"attr,php_injection_score_threshold,omitempty"` + // ParanoiaLevel is the configured paranoia level. + ParanoiaLevel *int `jsonapi:"attr,paranoia_level,omitempty"` + // RCEScoreThreshold is the remote code execution threshold. + RCEScoreThreshold *int `jsonapi:"attr,rce_score_threshold,omitempty"` + // RFIScoreThreshold is the remote file inclusion attack threshold. + RFIScoreThreshold *int `jsonapi:"attr,rfi_score_threshold,omitempty"` + // RestrictedExtensions is a space-separated list of allowed file extensions. + RestrictedExtensions *string `jsonapi:"attr,restricted_extensions,omitempty"` + // RestrictedHeaders is a space-separated list of allowed header names. + RestrictedHeaders *string `jsonapi:"attr,restricted_headers,omitempty"` + // SQLInjectionScoreThreshold is the SQL injection attack threshold. + SQLInjectionScoreThreshold *int `jsonapi:"attr,sql_injection_score_threshold,omitempty"` + // SessionFixationScoreThreshold is the session fixation attack threshold. + SessionFixationScoreThreshold *int `jsonapi:"attr,session_fixation_score_threshold,omitempty"` + // TotalArgLength is the maximum size of argument names and values. + TotalArgLength *int `jsonapi:"attr,total_arg_length,omitempty"` + // WAFID is the Web Application Firewall's ID. WAFID *string - // The Web Application Firewall's version ID. + // WAFVersionID is the Web Application Firewall's version ID. WAFVersionID *string `jsonapi:"primary,waf_firewall_version"` - // The Web Application Firewall's version number. - WAFVersionNumber *int + // WAFVersionNumber is the Web Application Firewall's version number. + WAFVersionNumber *int + // WarningAnomalyScore is the score value to add for warning anomalies. WarningAnomalyScore *int `jsonapi:"attr,warning_anomaly_score,omitempty"` - XSSScoreThreshold *int `jsonapi:"attr,xss_score_threshold,omitempty"` + // XSSScoreThreshold is the XSS attack threshold. + XSSScoreThreshold *int `jsonapi:"attr,xss_score_threshold,omitempty"` } // HasChanges checks that UpdateWAFVersionInput has changed in terms of configuration, which means - if it has configuration fields populated. @@ -287,7 +315,7 @@ func (i UpdateWAFVersionInput) HasChanges() bool { } } -// UpdateWAFVersion updates a specific WAF version. +// UpdateWAFVersion updates the specified resource. func (c *Client) UpdateWAFVersion(i *UpdateWAFVersionInput) (*WAFVersion, error) { if i.WAFID == nil || *i.WAFID == "" { return nil, ErrMissingWAFID @@ -317,9 +345,9 @@ func (c *Client) UpdateWAFVersion(i *UpdateWAFVersionInput) (*WAFVersion, error) // LockWAFVersionInput used as input for locking a WAF version. type LockWAFVersionInput struct { - // The Web Application Firewall's ID. + // WAFID is the Web Application Firewall's ID. WAFID string - // The Web Application Firewall's version number. + // WAFVersionNumber is the Web Application Firewall's version number. WAFVersionNumber int } @@ -351,9 +379,9 @@ func (c *Client) LockWAFVersion(i *LockWAFVersionInput) (*WAFVersion, error) { // CloneWAFVersionInput used as input for cloning a WAF version. type CloneWAFVersionInput struct { - // The Web Application Firewall's ID. + // WAFID is the Web Application Firewall's ID. WAFID string - // The Web Application Firewall's version number. + // WAFVersionNumber is the Web Application Firewall's version number. WAFVersionNumber int } @@ -383,9 +411,9 @@ func (c *Client) CloneWAFVersion(i *CloneWAFVersionInput) (*WAFVersion, error) { // DeployWAFVersionInput used as input for deploying a WAF version. type DeployWAFVersionInput struct { - // The Web Application Firewall's ID. + // WAFID is the Web Application Firewall's ID. WAFID string - // The Web Application Firewall's version number. + // WAFVersionNumber is the Web Application Firewall's version number. WAFVersionNumber int } @@ -407,14 +435,15 @@ func (c *Client) DeployWAFVersion(i *DeployWAFVersionInput) error { return nil } -// CreateEmptyWAFVersionInput used as input for creating an empty WAF version. +// CreateEmptyWAFVersionInput creates a new resource. type CreateEmptyWAFVersionInput struct { - // The Web Application Firewall's ID. + // WAFID is the Web Application Firewall's ID. WAFID string } -// CreateEmptyWAFVersion creates an empty WAF version, -// which means a version without rules and all config options set to their default values. +// CreateEmptyWAFVersion creates a new resource. +// +// There are no rules and all config options are set to their default values. func (c *Client) CreateEmptyWAFVersion(i *CreateEmptyWAFVersionInput) (*WAFVersion, error) { if i.WAFID == "" { return nil, ErrMissingWAFID diff --git a/fastly/waf_version_test.go b/fastly/waf_version_test.go index c4c53447a..8eb11825c 100644 --- a/fastly/waf_version_test.go +++ b/fastly/waf_version_test.go @@ -88,7 +88,6 @@ func TestClient_WAF_Versions(t *testing.T) { }) if err != nil { t.Fatal(err) - break } if wafVerPD == nil { t.Error("expected waf, got nil") @@ -195,7 +194,6 @@ func TestClient_WAF_Versions(t *testing.T) { } func verifyWAFVersionUpdate(t *testing.T, i *UpdateWAFVersionInput, o *WAFVersion) { - if *i.WAFVersionID != o.ID { t.Errorf("expected %s waf: got %s", *i.WAFVersionID, o.ID) } @@ -286,7 +284,6 @@ func verifyWAFVersionUpdate(t *testing.T, i *UpdateWAFVersionInput, o *WAFVersio } func verifyEmptyWAFVersion(t *testing.T, o *WAFVersion) { - threshold := 999 if threshold != o.HTTPViolationScoreThreshold { t.Errorf("expected %d HTTPViolationScoreThreshold: got %d", threshold, o.HTTPViolationScoreThreshold) @@ -506,7 +503,6 @@ func TestClient_DeployWAFVersion_validation(t *testing.T) { } func TestClient_UpdateWAFVersionInput_HasChanges(t *testing.T) { - cases := []struct { in UpdateWAFVersionInput out bool