Skip to content

Commit

Permalink
feat: create ssh deployment target
Browse files Browse the repository at this point in the history
Co-authored-by: John Bristowe <john.bristowe@octopus.com>
  • Loading branch information
benPearce1 and jbristowe authored Nov 15, 2022
1 parent 0d81e00 commit a169d2e
Show file tree
Hide file tree
Showing 9 changed files with 625 additions and 18 deletions.
15 changes: 1 addition & 14 deletions pkg/cmd/target/listening-tentacle/create/create.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package create

import (
"errors"
"fmt"
"github.com/AlecAivazis/survey/v2"
"github.com/MakeNowJust/heredoc/v2"
Expand All @@ -15,10 +14,8 @@ import (
"github.com/OctopusDeploy/cli/pkg/util/flag"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/environments"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machines"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/proxies"
"github.com/spf13/cobra"
"net/url"
"strings"
)

const (
Expand Down Expand Up @@ -126,20 +123,10 @@ func createRun(opts *CreateOptions) error {

endpoint := machines.NewListeningTentacleEndpoint(url, opts.Thumbprint.Value)
if opts.Proxy.Value != "" {
allProxy, err := opts.Client.Proxies.GetAll()
proxy, err := shared.FindProxy(opts.CreateTargetProxyOptions, opts.CreateTargetProxyFlags)
if err != nil {
return err
}
var proxy *proxies.Proxy
for _, p := range allProxy {
if strings.EqualFold(p.GetID(), opts.Proxy.Value) || strings.EqualFold(p.GetName(), opts.Proxy.Value) {
proxy = p
break
}
}
if proxy == nil {
return errors.New(fmt.Sprintf("Cannot find proxy '%s'", opts.Proxy.Value))
}
endpoint.ProxyID = proxy.GetID()
}

Expand Down
20 changes: 20 additions & 0 deletions pkg/cmd/target/shared/proxy.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package shared

import (
"fmt"
"github.com/AlecAivazis/survey/v2"
"github.com/OctopusDeploy/cli/pkg/cmd"
"github.com/OctopusDeploy/cli/pkg/question/selectors"
"github.com/OctopusDeploy/cli/pkg/util/flag"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/proxies"
"github.com/spf13/cobra"
"strings"
)

type GetAllProxiesCallback func() ([]*proxies.Proxy, error)
Expand Down Expand Up @@ -58,6 +60,24 @@ func RegisterCreateTargetProxyFlags(cmd *cobra.Command, proxyFlags *CreateTarget
cmd.Flags().StringVar(&proxyFlags.Proxy.Value, FlagProxy, "", "Select whether to use a proxy to connect to this Tentacle. If omitted, will connect directly.")
}

func FindProxy(opts *CreateTargetProxyOptions, flags *CreateTargetProxyFlags) (*proxies.Proxy, error) {
allProxy, err := opts.Client.Proxies.GetAll()
if err != nil {
return nil, err
}
var proxy *proxies.Proxy
for _, p := range allProxy {
if strings.EqualFold(p.GetID(), flags.Proxy.Value) || strings.EqualFold(p.GetName(), flags.Proxy.Value) {
proxy = p
break
}
}
if proxy == nil {
return nil, fmt.Errorf("cannot find proxy '%s'", flags.Proxy.Value)
}
return proxy, nil
}

func getAllProxies(client client.Client) ([]*proxies.Proxy, error) {
res, err := client.Proxies.GetAll()
if err != nil {
Expand Down
Loading

0 comments on commit a169d2e

Please sign in to comment.