-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b215307
commit 2cac917
Showing
5 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package deploymentfreezes | ||
|
||
import ( | ||
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/resources" | ||
"time" | ||
) | ||
|
||
type DeploymentFreezes resources.Resources[DeploymentFreeze] | ||
|
||
type DeploymentFreeze struct { | ||
Name string `json:"Name" validate:"required"` | ||
Start *time.Time `json:"Start,required"` | ||
End *time.Time `json:"End,required"` | ||
ProjectEnvironmentScope map[string][]string `json:"ProjectEnvironmentScope,omitempty"` | ||
|
||
resources.Resource | ||
} | ||
|
||
func (d *DeploymentFreeze) GetName() string { | ||
return d.Name | ||
} | ||
|
||
func (d *DeploymentFreeze) SetName(name string) { | ||
d.Name = name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package deploymentfreezes | ||
|
||
type DeploymentFreezeQuery struct { | ||
IncludeComplete bool `uri:"includeComplete,omitempty"` | ||
ProjectIds []string `uri:"projectIds,omitempty"` | ||
EnvironmentIds []string `uri:"environmentIds,omitempty"` | ||
IDs []string `uri:"ids,omitempty"` | ||
Skip int `uri:"skip,omitempty"` | ||
Take int `uri:"take,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package deploymentfreezes | ||
|
||
import ( | ||
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/newclient" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func createClient() newclient.Client { | ||
return newclient.NewClient(&newclient.HttpSession{}) | ||
} | ||
|
||
func TestAddParameterValidation(t *testing.T) { | ||
client := createClient() | ||
_, err := Add(client, nil) | ||
require.Error(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package deploymentfreezes | ||
|
||
import ( | ||
"math" | ||
|
||
"github.com/OctopusDeploy/go-octopusdeploy/v2/internal" | ||
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/newclient" | ||
) | ||
|
||
const template = "/api/deploymentfreezes{/id}{?skip,take,ids,projectIds,tenantIds,environmentIds,includeComplete,status}" | ||
|
||
type DeploymentFreezeService struct { | ||
} | ||
|
||
func Get(client newclient.Client, deploymentFreezesQuery *DeploymentFreezeQuery) (*DeploymentFreezes, error) { | ||
path, err := client.URITemplateCache().Expand(template, deploymentFreezesQuery) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
res, err := newclient.Get[DeploymentFreezes](client.HttpSession(), path) | ||
if err != nil { | ||
return &DeploymentFreezes{}, err | ||
} | ||
|
||
return res, nil | ||
} | ||
|
||
func GetById(client newclient.Client, id string) (*DeploymentFreeze, error) { | ||
path, err := client.URITemplateCache().Expand(template, map[string]any{ | ||
"id": id, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
res, err := newclient.Get[DeploymentFreeze](client.HttpSession(), path) | ||
if err != nil { | ||
return &DeploymentFreeze{}, err | ||
} | ||
|
||
return res, nil | ||
|
||
} | ||
|
||
func GetAll(client newclient.Client) ([]*DeploymentFreeze, error) { | ||
path, err := client.URITemplateCache().Expand(template, &DeploymentFreezeQuery{Skip: 0, Take: math.MaxInt32}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
res, err := newclient.Get[DeploymentFreezes](client.HttpSession(), path) | ||
|
||
freezes := make([]*DeploymentFreeze, 0) | ||
for _, freeze := range res.Items { | ||
freezes = append(freezes, &freeze) | ||
} | ||
|
||
return freezes, nil | ||
} | ||
|
||
func Add(client newclient.Client, deploymentFreeze *DeploymentFreeze) (*DeploymentFreeze, error) { | ||
if deploymentFreeze == nil { | ||
return nil, internal.CreateRequiredParameterIsEmptyOrNilError("deploymentFreeze") | ||
} | ||
|
||
path, err := client.URITemplateCache().Expand(template, deploymentFreeze) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
res, err := newclient.Post[DeploymentFreeze](client.HttpSession(), path, deploymentFreeze) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return res, nil | ||
} | ||
|
||
func Update(client newclient.Client, deploymentFreeze *DeploymentFreeze) (*DeploymentFreeze, error) { | ||
if deploymentFreeze == nil { | ||
return nil, internal.CreateRequiredParameterIsEmptyOrNilError("deploymentFreeze") | ||
} | ||
|
||
path, err := client.URITemplateCache().Expand(template, map[string]any{"id": deploymentFreeze.ID}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
res, err := newclient.Put[DeploymentFreeze](client.HttpSession(), path, deploymentFreeze) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return res, nil | ||
} | ||
|
||
func Delete(client newclient.Client, deploymentFreeze *DeploymentFreeze) error { | ||
if deploymentFreeze == nil { | ||
return internal.CreateRequiredParameterIsEmptyOrNilError("deploymentFreeze") | ||
} | ||
|
||
path, err := client.URITemplateCache().Expand(template, map[string]any{"id": deploymentFreeze.ID}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = newclient.Delete(client.HttpSession(), path) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |