Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add action templates and community action templates #27

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion octopusdeploy/action_template_parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package octopusdeploy
type ActionTemplateParameter struct {

// default value
DefaultValue PropertyValueResource `json:"DefaultValue,omitempty"`
DefaultValue string `json:"DefaultValue,omitempty"`

// display settings
DisplaySettings map[string]string `json:"DisplaySettings,omitempty"`
Expand Down
155 changes: 155 additions & 0 deletions octopusdeploy/action_templates.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
package octopusdeploy

import (
"fmt"

"github.com/dghubble/sling"
"gopkg.in/go-playground/validator.v9"
)

type ActionTemplateService struct {
sling *sling.Sling
}

func NewActionTemplateService(sling *sling.Sling) *ActionTemplateService {
return &ActionTemplateService{
sling: sling,
}
}

type ActionTemplates struct {
Items []ActionTemplate `json:"Items"`
PagedResults
}

type ActionTemplate struct {
ID string `json:"Id"`
Name string `json:"Name"`
Description string `json:"Description"`
ActionType string `json:"ActionType"`
Version int `json:"Version"`
CommunityActionTemplateId string `json:"CommunityActionTemplateId"`
Properties *ActionTemplateProperties `json:"Properties,omitempty"`
Parameters []ActionTemplateParameter `json:"Parameters,omitempty"`
}

type ActionTemplateProperties struct {
ManualInstructions string `json:"Octopus.Action.Manual.Instructions,omitempty"`
ManualResponsibleTeamIds string `json:"Octopus.Action.Manual.ResponsibleTeamIds,omitempty"`
ManualBlockConcurrentDeployments bool `json:"Octopus.Action.Manual.BlockConcurrentDeployments,string,omitempty"`
RunOnServer string `json:"Octopus.Action.RunOnServer,omitempty"`
ScriptSyntax string `json:"Octopus.Action.Script.Syntax,omitempty"`
ScriptSource string `json:"Octopus.Action.Script.ScriptSource,omitempty"`
ScriptBody string `json:"Octopus.Action.Script.ScriptBody,omitempty"`
}

func (p *ActionTemplate) Validate() error {
validate := validator.New()

err := validate.Struct(p)

if err != nil {
return err
}

return nil
}

func NewActionTemplate(name string, description string, actionType string) *ActionTemplate {
return &ActionTemplate{
Name: name,
Description: description,
ActionType: actionType,
}
}

func (s *ActionTemplateService) Get(actionTemplateID string) (*ActionTemplate, error) {
path := fmt.Sprintf("actiontemplates/%s", actionTemplateID)
resp, err := apiGet(s.sling, new(ActionTemplate), path)

if err != nil {
return nil, err
}

return resp.(*ActionTemplate), nil
}

func (s *ActionTemplateService) GetAll() (*[]ActionTemplate, error) {
var at []ActionTemplate

path := "actiontemplates"

loadNextPage := true

for loadNextPage {
resp, err := apiGet(s.sling, new(ActionTemplates), path)

if err != nil {
return nil, err
}

r := resp.(*ActionTemplates)

for _, item := range r.Items {
at = append(at, item)
}

path, loadNextPage = LoadNextPage(r.PagedResults)
}

return &at, nil
}

func (s *ActionTemplateService) GetByName(actionTemplateName string) (*ActionTemplate, error) {
var notFound ActionTemplate
ats, err := s.GetAll()

if err != nil {
return nil, err
}

for _, at := range *ats {
if at.Name == actionTemplateName {
return &at, nil
}
}

return &notFound, fmt.Errorf("no actiontemplate found with name %s", actionTemplateName)
}

func (s *ActionTemplateService) Add(actionTemplate *ActionTemplate) (*ActionTemplate, error) {
err := actionTemplate.Validate()
if err != nil {
return nil, err
}

resp, err := apiAdd(s.sling, actionTemplate, new(ActionTemplate), "actiontemplates")

if err != nil {
return nil, err
}

return resp.(*ActionTemplate), nil
}

func (s *ActionTemplateService) Delete(actionTemplateID string) error {
path := fmt.Sprintf("actiontemplates/%s", actionTemplateID)
err := apiDelete(s.sling, path)

if err != nil {
return err
}

return nil
}

func (s *ActionTemplateService) Update(actionTemplate *ActionTemplate) (*ActionTemplate, error) {
path := fmt.Sprintf("actiontemplates/%s", actionTemplate.ID)
resp, err := apiUpdate(s.sling, actionTemplate, new(ActionTemplate), path)

if err != nil {
return nil, err
}

return resp.(*ActionTemplate), nil
}
116 changes: 116 additions & 0 deletions octopusdeploy/community_action_templates.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package octopusdeploy

import (
"fmt"

"github.com/dghubble/sling"
"gopkg.in/go-playground/validator.v9"
)

type CommunityActionTemplateService struct {
sling *sling.Sling
spaceID string
}

func NewCommunityActionTemplateService(sling *sling.Sling, spaceID string) *CommunityActionTemplateService {
return &CommunityActionTemplateService{
sling: sling,
spaceID: spaceID,
}
}

type CommunityActionTemplates struct {
Items []CommunityActionTemplate `json:"Items"`
PagedResults
}

type CommunityActionTemplate struct {
ID string `json:"Id"`
Name string `json:"Name,omitempty"`
Label string `json:"Label,omitempty"`
HelpText string `json:"HelpText,omitempty"`
DefaultValue string `json:"DefaultValue"`
}

func (p *CommunityActionTemplate) Validate() error {
validate := validator.New()

err := validate.Struct(p)

if err != nil {
return err
}

return nil
}

func NewCommunityActionTemplate(id string) *CommunityActionTemplate {
return &CommunityActionTemplate{
ID: id,
}
}

func (s *CommunityActionTemplateService) Get(communityActionTemplateID string) (*CommunityActionTemplate, error) {
path := fmt.Sprintf("communityactiontemplates/%s", communityActionTemplateID)
resp, err := apiGet(s.sling, new(CommunityActionTemplate), path)

if err != nil {
return nil, err
}

return resp.(*CommunityActionTemplate), nil
}

func (s *CommunityActionTemplateService) GetAll() (*[]CommunityActionTemplate, error) {
var cat []CommunityActionTemplate

path := "communityactiontemplates"

loadNextPage := true

for loadNextPage {
resp, err := apiGet(s.sling, new(CommunityActionTemplates), path)

if err != nil {
return nil, err
}

r := resp.(*CommunityActionTemplates)

for _, item := range r.Items {
cat = append(cat, item)
}

path, loadNextPage = LoadNextPage(r.PagedResults)
}

return &cat, nil
}

func (s *CommunityActionTemplateService) GetByName(communityActionTemplateName string) (*CommunityActionTemplate, error) {
var notFound CommunityActionTemplate
cats, err := s.GetAll()

if err != nil {
return nil, err
}

for _, cat := range *cats {
if cat.Name == communityActionTemplateName {
return &cat, nil
}
}

return &notFound, fmt.Errorf("no communityactiontemplate found with name %s", communityActionTemplateName)
}

func (s *CommunityActionTemplateService) Add(communityActionTemplateID string) (*CommunityActionTemplate, error) {
create := fmt.Sprintf("communityactiontemplates/%s/installation/%s", communityActionTemplateID, s.spaceID)
resp, err := apiAdd(s.sling, nil, new(CommunityActionTemplate), create)

if err != nil {
return nil, err
}

return resp.(*CommunityActionTemplate), nil
}
6 changes: 3 additions & 3 deletions octopusdeploy/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ func (s *EnvironmentService) GetByName(environmentName string) (*Environment, er
return nil, err
}

for _, project := range *environments {
if project.Name == environmentName {
return &project, nil
for _, env := range *environments {
if env.Name == environmentName {
return &env, nil
}
}

Expand Down
2 changes: 1 addition & 1 deletion octopusdeploy/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type MachineEndpointAuthentication struct {
type MachineEndpoint struct {
ID string `json:"Id"`
CommunicationStyle string `json:"CommunicationStyle"`
ProxyID *string `json:"ProxyId"`
ProxyID string `json:"ProxyId,omitempty"`
Thumbprint string `json:"Thumbprint"`
TentacleVersionDetails MachineTentacleVersionDetails `json:"TentacleVersionDetails"`
LastModifiedOn *string `json:"LastModifiedOn,omitempty"`
Expand Down
Loading