diff --git a/pkg/environments/v2/environments/environment.go b/pkg/environments/v2/environments/environment.go new file mode 100644 index 00000000..da3381ec --- /dev/null +++ b/pkg/environments/v2/environments/environment.go @@ -0,0 +1,24 @@ +package environments + +import ( + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/extensions" +) + +type Environment struct { + ID string `json:"Id"` + Name string `json:"Name"` + SpaceID string `json:"SpaceId"` + Slug string `json:"Slug"` + Description string `json:"Description,omitempty"` + Type string `json:"Type"` + SortOrder int `json:"SortOrder"` + UseGuidedFailure bool `json:"UseGuidedFailure"` + EnvironmentTags []string `json:"EnvironmentTags,omitempty"` + + // Fields for Static environments + AllowDynamicInfrastructure *bool `json:"AllowDynamicInfrastructure,omitempty"` + ExtensionSettings []extensions.ExtensionSettings `json:"ExtensionSettings,omitempty"` + + // Fields for Ephemeral environments + ParentEnvironmentId string `json:"ParentEnvironmentId,omitempty"` +} diff --git a/pkg/environments/v2/environments/environment_query.go b/pkg/environments/v2/environments/environment_query.go new file mode 100644 index 00000000..07687396 --- /dev/null +++ b/pkg/environments/v2/environments/environment_query.go @@ -0,0 +1,9 @@ +package environments + +type EnvironmentQuery struct { + Ids []string `uri:"ids,omitempty" url:"ids,omitempty"` + PartialName string `uri:"partialName,omitempty" url:"partialName,omitempty"` + Skip int `uri:"skip" url:"skip"` + Take int `uri:"take" url:"take"` + Type []string `uri:"type,omitempty" url:"type,omitempty"` +} diff --git a/pkg/environments/v2/environments/environment_service.go b/pkg/environments/v2/environments/environment_service.go new file mode 100644 index 00000000..03b1c5c2 --- /dev/null +++ b/pkg/environments/v2/environments/environment_service.go @@ -0,0 +1,14 @@ +package environments + +import ( + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/environments/v2" + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/newclient" + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/resources" +) + +// Get returns a collection of environments based on the criteria defined by +// its input query parameter. If an error occurs, an empty collection is +// returned along with the associated error. +func Get(client newclient.Client, spaceID string, environmentsQuery EnvironmentQuery) (*resources.Resources[*Environment], error) { + return newclient.GetByQuery[Environment](client, v2.Template, spaceID, environmentsQuery) +} diff --git a/pkg/environments/v2/ephemeralenvironments/ephemeral_environment.go b/pkg/environments/v2/ephemeralenvironments/ephemeral_environment.go new file mode 100644 index 00000000..7f6f632f --- /dev/null +++ b/pkg/environments/v2/ephemeralenvironments/ephemeral_environment.go @@ -0,0 +1,13 @@ +package ephemeralenvironments + +type EphemeralEnvironment struct { + ID string `json:"Id"` + Name string `json:"Name"` + SpaceID string `json:"SpaceId"` + Slug string `json:"Slug"` + Description string `json:"Description"` + Type string `json:"Type"` + SortOrder int `json:"SortOrder"` + UseGuidedFailure bool `json:"UseGuidedFailure"` + ParentEnvironmentId string `json:"ParentEnvironmentId"` +} diff --git a/pkg/environments/v2/ephemeralenvironments/ephemeral_environment_service.go b/pkg/environments/v2/ephemeralenvironments/ephemeral_environment_service.go new file mode 100644 index 00000000..167c501c --- /dev/null +++ b/pkg/environments/v2/ephemeralenvironments/ephemeral_environment_service.go @@ -0,0 +1,20 @@ +package ephemeralenvironments + +import ( + "math" + + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/environments/v2" + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/environments/v2/environments" + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/newclient" + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/resources" +) + +func GetAllEphemeralEnvironments(client newclient.Client, spaceID string) (*resources.Resources[*environments.Environment], error) { + query := &environments.EnvironmentQuery{ + Skip: 0, + Take: math.MaxInt32, + Type: []string{"Ephemeral"}, + } + + return newclient.GetByQuery[environments.Environment](client, v2.Template, spaceID, query) +} diff --git a/pkg/environments/parentenvironments/parent_environment.go b/pkg/environments/v2/parentenvironments/parent_environment.go similarity index 100% rename from pkg/environments/parentenvironments/parent_environment.go rename to pkg/environments/v2/parentenvironments/parent_environment.go diff --git a/pkg/environments/parentenvironments/parent_environment_service.go b/pkg/environments/v2/parentenvironments/parent_environment_service.go similarity index 100% rename from pkg/environments/parentenvironments/parent_environment_service.go rename to pkg/environments/v2/parentenvironments/parent_environment_service.go diff --git a/pkg/environments/v2/route.go b/pkg/environments/v2/route.go new file mode 100644 index 00000000..1780a799 --- /dev/null +++ b/pkg/environments/v2/route.go @@ -0,0 +1,3 @@ +package v2 + +const Template = "/api/{spaceId}/environments/v2{/id}{?name,skip,ids,take,partialName,type}"