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 custom endpoint support #38

Open
wants to merge 3 commits into
base: mainline
Choose a base branch
from
Open
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
20 changes: 20 additions & 0 deletions src/sessionmanagerplugin/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import (
"fmt"
"io"
"os"
"os/exec"
"regexp"
"strings"
"time"

"github.com/aws/SSMCLI/src/config"
Expand Down Expand Up @@ -191,6 +194,23 @@ func ValidateInputAndStartSession(args []string, out io.Writer) {

session.SessionId = *startSessionOutput.SessionId
session.StreamUrl = *startSessionOutput.StreamUrl

if len(profile) > 0 {
// Lookup for a custom endpoint inside the profile
ssmmsgEndpointRes, err := exec.Command("aws", "configure", "get", "aws_ssmmessages_endpoint", "--profile", profile).Output()
if err == nil && ssmmsgEndpointRes != nil {
ssmmsgEndpoint := string(ssmmsgEndpointRes)
streamUrl := string(*startSessionOutput.StreamUrl)
// Cleanup Windows/Linux line feeds
ssmmsgEndpoint = strings.TrimSuffix(strings.TrimSuffix(strings.TrimSuffix(ssmmsgEndpoint, "\n"), "\r"), "\n")
if strings.HasSuffix(ssmmsgEndpoint, ".vpce.amazonaws.com") {
// Looks like a legit endpoint, patch the WSS url
fmt.Printf("Custom endpoint detected %s\n", ssmmsgEndpoint)
m := regexp.MustCompile(`ssmmessages.*amazonaws.com`)
session.StreamUrl = m.ReplaceAllString(streamUrl, ssmmsgEndpoint)
}
}
}
session.TokenValue = *startSessionOutput.TokenValue
session.Endpoint = ssmEndpoint
session.ClientId = clientId
Expand Down