Skip to content

Commit

Permalink
refactor the magic constant for signaling back to tunneled command lines
Browse files Browse the repository at this point in the history
  • Loading branch information
csquared committed Dec 3, 2015
1 parent 6dc3f9c commit 04578cf
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions api/models/app.go
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/convox/rack/api/helpers"
"github.com/convox/rack/client"

"github.com/convox/rack/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws"
"github.com/convox/rack/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/awserr"
Expand All @@ -20,6 +21,8 @@ import (

var CustomTopic = os.Getenv("CUSTOM_TOPIC")

var StatusCodePrefix = client.StatusCodePrefix

type App struct {
Name string `json:"name"`
Release string `json:"release"`
Expand Down Expand Up @@ -340,7 +343,7 @@ func (a *App) ExecAttached(pid, command string, rw io.ReadWriter) error {
return err
}

_, err = rw.Write([]byte(fmt.Sprintf("F1E49A85-0AD7-4AEF-A618-C249C6E6568D:%d\n", ires.ExitCode)))
_, err = rw.Write([]byte(fmt.Sprintf("%s%d\n", StatusCodePrefix, ires.ExitCode)))

if err != nil {
return err
Expand Down Expand Up @@ -475,7 +478,7 @@ func (a *App) RunAttached(process, command string, rw io.ReadWriter) error {
return err
}

_, err = rw.Write([]byte(fmt.Sprintf("F1E49A85-0AD7-4AEF-A618-C249C6E6568D:%d\n", code)))
_, err = rw.Write([]byte(fmt.Sprintf("%s%d\n", StatusCodePrefix, code)))

if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion api/models/instances.go
Expand Up @@ -139,7 +139,7 @@ func InstanceSSH(id, command, term string, height, width int, rw io.ReadWriter)
code = exitCode(err)
}

_, err = rw.Write([]byte(fmt.Sprintf("F1E49A85-0AD7-4AEF-A618-C249C6E6568D:%d\n", code)))
_, err = rw.Write([]byte(fmt.Sprintf("%s%d\n", StatusCodePrefix, code)))

if err != nil {
return err
Expand Down
3 changes: 3 additions & 0 deletions client/client.go
Expand Up @@ -19,6 +19,9 @@ import (

var MinimumServerVersion = "20151023042141"

//this just needs to be random enough to never show up again in a byte stream
var StatusCodePrefix = "F1E49A85-0AD7-4AEF-A618-C249C6E6568D:"

type Client struct {
Host string
Password string
Expand Down
2 changes: 1 addition & 1 deletion client/processes.go
Expand Up @@ -129,7 +129,7 @@ func copyWithExit(w io.Writer, r io.Reader, ch chan int) {
isTerminalRaw = true
}

if s := string(buf[0:n]); strings.HasPrefix(s, "F1E49A85-0AD7-4AEF-A618-C249C6E6568D:") {
if s := string(buf[0:n]); strings.HasPrefix(s, StatusCodePrefix) {
code, _ := strconv.Atoi(strings.TrimSpace(s[37:]))
ch <- code
return
Expand Down

0 comments on commit 04578cf

Please sign in to comment.