Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
cmdをreturnするように変更
Browse files Browse the repository at this point in the history
  • Loading branch information
wim-web committed Apr 16, 2023
1 parent 6301ed5 commit 4ea55e5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
8 changes: 6 additions & 2 deletions internal/handler/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func ExecHandler(cmd string) error {
return err
}

_, err = command.ExecCommand(
exeCmd, err := command.ExecCommand(
context.Background(),
ecsService,
cluster,
Expand All @@ -37,5 +37,9 @@ func ExecHandler(cmd string) error {
cfg.Region,
)

return err
if err != nil {
return err
}

return exeCmd.Run()
}
8 changes: 6 additions & 2 deletions internal/handler/portforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func PortforwardHandler(doc command.DocumentName, params map[string][]string) er

taskId := strings.Split(*task.TaskArn, "/")[2]

_, err = command.PortForwardCommand(
cmd, err := command.PortForwardCommand(
context.Background(),
ssmService,
cluster,
Expand All @@ -43,5 +43,9 @@ func PortforwardHandler(doc command.DocumentName, params map[string][]string) er
params,
)

return err
if err != nil {
return err
}

return cmd.Run()
}
5 changes: 3 additions & 2 deletions pkg/command/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"context"
"encoding/json"
"os"
"os/exec"

"github.com/aws/aws-sdk-go-v2/service/ecs"
"github.com/aws/aws-sdk-go/aws"
"github.com/wim-web/tonneeeeel/internal/session_manager"
)

func ExecCommand(ctx context.Context, c *ecs.Client, cluster string, task string, command string, container *string, region string) ([]byte, error) {
func ExecCommand(ctx context.Context, c *ecs.Client, cluster string, task string, command string, container *string, region string) (*exec.Cmd, error) {
input := &ecs.ExecuteCommandInput{
Cluster: aws.String(cluster),
Task: aws.String(task),
Expand All @@ -37,5 +38,5 @@ func ExecCommand(ctx context.Context, c *ecs.Client, cluster string, task string
cmd.Stdin = os.Stdin
cmd.Stderr = os.Stderr

return cmd.Output()
return cmd, nil
}
5 changes: 3 additions & 2 deletions pkg/command/portforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"os"
"os/exec"

"github.com/aws/aws-sdk-go-v2/service/ssm"
"github.com/aws/aws-sdk-go/aws"
Expand All @@ -18,7 +19,7 @@ const (
REMOTE_PORT_FORWARD_DOCUMENT_NAME DocumentName = "AWS-StartPortForwardingSessionToRemoteHost"
)

func PortForwardCommand(ctx context.Context, c *ssm.Client, cluster string, taskId string, containerId string, region string, doc DocumentName, params map[string][]string) ([]byte, error) {
func PortForwardCommand(ctx context.Context, c *ssm.Client, cluster string, taskId string, containerId string, region string, doc DocumentName, params map[string][]string) (*exec.Cmd, error) {
input := &ssm.StartSessionInput{
Target: aws.String(fmt.Sprintf("ecs:%s_%s_%s", cluster, taskId, containerId)),
DocumentName: aws.String(string(doc)),
Expand All @@ -43,5 +44,5 @@ func PortForwardCommand(ctx context.Context, c *ssm.Client, cluster string, task
cmd.Stdin = os.Stdin
cmd.Stderr = os.Stderr

return cmd.Output()
return cmd, nil
}

0 comments on commit 4ea55e5

Please sign in to comment.