Skip to content

Commit

Permalink
Add support for 'environments' while activating and deactivating serv…
Browse files Browse the repository at this point in the history
…ice-versions.

Add 'environments' details to service and service-version API responses.
  • Loading branch information
simonwistow authored and kpfleming committed Sep 9, 2024
1 parent 94c0e63 commit 20d8b59
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 34 deletions.
44 changes: 23 additions & 21 deletions fastly/service_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,33 @@ import (

// Service represents a server response from the Fastly API.
type Service struct {
ActiveVersion *int `mapstructure:"version"`
Comment *string `mapstructure:"comment"`
CreatedAt *time.Time `mapstructure:"created_at"`
CustomerID *string `mapstructure:"customer_id"`
DeletedAt *time.Time `mapstructure:"deleted_at"`
ServiceID *string `mapstructure:"id"`
Name *string `mapstructure:"name"`
Type *string `mapstructure:"type"`
UpdatedAt *time.Time `mapstructure:"updated_at"`
Versions []*Version `mapstructure:"versions"`
ActiveVersion *int `mapstructure:"version"`
Comment *string `mapstructure:"comment"`
CreatedAt *time.Time `mapstructure:"created_at"`
CustomerID *string `mapstructure:"customer_id"`
DeletedAt *time.Time `mapstructure:"deleted_at"`
ServiceID *string `mapstructure:"id"`
Name *string `mapstructure:"name"`
Type *string `mapstructure:"type"`
UpdatedAt *time.Time `mapstructure:"updated_at"`
Versions []*Version `mapstructure:"versions"`
Environments []*Environment `mapstructure:"environments"`
}

// ServiceDetail represents a server response from the Fastly API.
type ServiceDetail struct {
ActiveVersion *Version `mapstructure:"active_version"`
Comment *string `mapstructure:"comment"`
CreatedAt *time.Time `mapstructure:"created_at"`
CustomerID *string `mapstructure:"customer_id"`
DeletedAt *time.Time `mapstructure:"deleted_at"`
ServiceID *string `mapstructure:"id"`
Name *string `mapstructure:"name"`
Type *string `mapstructure:"type"`
UpdatedAt *time.Time `mapstructure:"updated_at"`
Version *Version `mapstructure:"version"`
Versions []*Version `mapstructure:"versions"`
ActiveVersion *Version `mapstructure:"active_version"`
Comment *string `mapstructure:"comment"`
CreatedAt *time.Time `mapstructure:"created_at"`
CustomerID *string `mapstructure:"customer_id"`
DeletedAt *time.Time `mapstructure:"deleted_at"`
ServiceID *string `mapstructure:"id"`
Name *string `mapstructure:"name"`
Type *string `mapstructure:"type"`
UpdatedAt *time.Time `mapstructure:"updated_at"`
Version *Version `mapstructure:"version"`
Versions []*Version `mapstructure:"versions"`
Environments []*Environment `mapstructure:"environments"`
}

// ServiceDomain represents a server response from the Fastly API.
Expand Down
50 changes: 37 additions & 13 deletions fastly/service_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,25 @@ import (

// Version represents a distinct configuration version.
type Version struct {
Active *bool `mapstructure:"active"`
Comment *string `mapstructure:"comment"`
CreatedAt *time.Time `mapstructure:"created_at"`
DeletedAt *time.Time `mapstructure:"deleted_at"`
Deployed *bool `mapstructure:"deployed"`
Locked *bool `mapstructure:"locked"`
Number *int `mapstructure:"number"`
ServiceID *string `mapstructure:"service_id"`
Staging *bool `mapstructure:"staging"`
Testing *bool `mapstructure:"testing"`
UpdatedAt *time.Time `mapstructure:"updated_at"`
Active *bool `mapstructure:"active"`
Comment *string `mapstructure:"comment"`
CreatedAt *time.Time `mapstructure:"created_at"`
DeletedAt *time.Time `mapstructure:"deleted_at"`
Deployed *bool `mapstructure:"deployed"`
Locked *bool `mapstructure:"locked"`
Number *int `mapstructure:"number"`
ServiceID *string `mapstructure:"service_id"`
Staging *bool `mapstructure:"staging"`
Testing *bool `mapstructure:"testing"`
UpdatedAt *time.Time `mapstructure:"updated_at"`
Environments []*Environment `mapstructure:"environments"`
}

// Environment represents a distinct deployment environment.
type Environment struct {
ServiceVersion *int64 `mapstructure:"active_version"`
Name *string `mapstructure:"name"`
ServiceID *string `mapstructure:"service_id"`
}

// ListVersionsInput is the input to the ListVersions function.
Expand Down Expand Up @@ -176,6 +184,8 @@ type ActivateVersionInput struct {
ServiceID string
// ServiceVersion is the specific configuration version (required).
ServiceVersion int
// Environment is the Fastly environment to activate this version to (optional).
Environment string
}

// ActivateVersion activates the given version.
Expand All @@ -187,7 +197,13 @@ func (c *Client) ActivateVersion(i *ActivateVersionInput) (*Version, error) {
return nil, ErrMissingServiceVersion
}

path := ToSafeURL("service", i.ServiceID, "version", strconv.Itoa(i.ServiceVersion), "activate")
components := []string{"service", i.ServiceID, "version", strconv.Itoa(i.ServiceVersion), "activate"}
if i.Environment != "" {
components = append(components, i.Environment)
}

path := ToSafeURL(components...)

resp, err := c.Put(path, nil)
if err != nil {
return nil, err
Expand All @@ -207,6 +223,8 @@ type DeactivateVersionInput struct {
ServiceID string
// ServiceVersion is the specific configuration version (required).
ServiceVersion int
// Environment is the Fastly environment to deactivate this version from (optional).
Environment string
}

// DeactivateVersion deactivates the given version.
Expand All @@ -218,7 +236,13 @@ func (c *Client) DeactivateVersion(i *DeactivateVersionInput) (*Version, error)
return nil, ErrMissingServiceVersion
}

path := ToSafeURL("service", i.ServiceID, "version", strconv.Itoa(i.ServiceVersion), "deactivate")
components := []string{"service", i.ServiceID, "version", strconv.Itoa(i.ServiceVersion), "deactivate"}
if i.Environment != "" {
components = append(components, i.Environment)
}

path := ToSafeURL(components...)

resp, err := c.Put(path, nil)
if err != nil {
return nil, err
Expand Down

0 comments on commit 20d8b59

Please sign in to comment.