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

Removes SSH and GCP command builders #1786

Merged
merged 3 commits into from
Aug 12, 2024
Merged
Changes from 2 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
99 changes: 6 additions & 93 deletions integration-tests/pkg/executor/executor_docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strings"

"github.com/pkg/errors"
"github.com/stackrox/collector/integration-tests/pkg/common"
"github.com/stackrox/collector/integration-tests/pkg/config"
)

Expand All @@ -24,60 +23,20 @@ type dockerExecutor struct {
builder CommandBuilder
}

type sshCommandBuilder struct {
user string
address string
keyPath string
}

type gcloudCommandBuilder struct {
user string
instance string
options string
vmType string
}

type localCommandBuilder struct {
}

func newSSHCommandBuilder() CommandBuilder {
host_info := config.HostInfo()
return &sshCommandBuilder{
user: host_info.User,
address: host_info.Address,
keyPath: host_info.Options,
}
}

func newGcloudCommandBuilder() CommandBuilder {
host_info := config.HostInfo()
gcb := &gcloudCommandBuilder{
user: host_info.User,
instance: host_info.Address,
options: host_info.Options,
vmType: config.VMInfo().Config,
}
if gcb.user == "" && (strings.Contains(gcb.vmType, "coreos") || strings.Contains(gcb.vmType, "flatcar")) {
gcb.user = "core"
}
return gcb
}

func newLocalCommandBuilder() CommandBuilder {
return &localCommandBuilder{}
}

func newDockerExecutor() (*dockerExecutor, error) {
e := dockerExecutor{}
switch config.HostInfo().Kind {
case "ssh":
e.builder = newSSHCommandBuilder()
case "gcloud":
e.builder = newGcloudCommandBuilder()
case "local":
e.builder = newLocalCommandBuilder()
}
return &e, nil
// While this function can't fail, to conform to the
// same construction API as other executors, we keep the
// error return value.
return &dockerExecutor{
builder: newLocalCommandBuilder(),
}, nil
}

// Exec executes the provided command with retries on non-zero error from the command.
Expand Down Expand Up @@ -254,49 +213,3 @@ func (e *localCommandBuilder) RemoteCopyCommand(remoteSrc string, localDst strin
}
return nil
}

func (e *gcloudCommandBuilder) ExecCommand(args ...string) *exec.Cmd {
cmdArgs := []string{"compute", "ssh"}
if len(e.options) > 0 {
opts := strings.Split(e.options, " ")
cmdArgs = append(cmdArgs, opts...)
}
userInstance := e.instance
if e.user != "" {
userInstance = e.user + "@" + e.instance
}

cmdArgs = append(cmdArgs, userInstance, "--", "-T")
cmdArgs = append(cmdArgs, common.QuoteArgs(args)...)
return exec.Command("gcloud", cmdArgs...)
}

func (e *gcloudCommandBuilder) RemoteCopyCommand(remoteSrc string, localDst string) *exec.Cmd {
cmdArgs := []string{"compute", "scp"}
if len(e.options) > 0 {
opts := strings.Split(e.options, " ")
cmdArgs = append(cmdArgs, opts...)
}
userInstance := e.instance
if e.user != "" {
userInstance = e.user + "@" + e.instance
}
cmdArgs = append(cmdArgs, userInstance+":"+remoteSrc, localDst)
return exec.Command("gcloud", cmdArgs...)
}

func (e *sshCommandBuilder) ExecCommand(args ...string) *exec.Cmd {
cmdArgs := []string{
"-o", "StrictHostKeyChecking=no", "-i", e.keyPath,
e.user + "@" + e.address}

cmdArgs = append(cmdArgs, common.QuoteArgs(args)...)
return exec.Command("ssh", cmdArgs...)
}

func (e *sshCommandBuilder) RemoteCopyCommand(remoteSrc string, localDst string) *exec.Cmd {
args := []string{
"-o", "StrictHostKeyChecking=no", "-i", e.keyPath,
e.user + "@" + e.address + ":" + remoteSrc, localDst}
return exec.Command("scp", args...)
}
Loading