in src/sessionmanagerplugin/session/session.go [130:218]
func ValidateInputAndStartSession(args []string, out io.Writer) {
var (
err error
session Session
startSessionOutput ssm.StartSessionOutput
response []byte
region string
operationName string
profile string
ssmEndpoint string
target string
)
log := log.Logger(true, "session-manager-plugin")
uuid.SwitchFormat(uuid.CleanHyphen)
if len(args) == 1 {
fmt.Fprint(out, "\nThe Session Manager plugin was installed successfully. "+
"Use the AWS CLI to start a session.\n\n")
return
} else if len(args) == 2 && args[1] == "--version" {
fmt.Fprintf(out, "%s\n", string(version.Version))
return
} else if len(args) >= 2 && len(args) < LegacyArgumentLength {
fmt.Fprintf(out, "\nUnknown operation %s. \nUse "+
"session-manager-plugin --version to check the version.\n\n", string(args[1]))
return
} else if len(args) == LegacyArgumentLength {
// If arguments do not have Profile passed from AWS CLI to Session-Manager-Plugin then
// should be upgraded to use Session Manager encryption feature
session.IsAwsCliUpgradeNeeded = true
}
for argsIndex := 1; argsIndex < len(args); argsIndex++ {
switch argsIndex {
case 1:
if strings.HasPrefix(args[1], "AWS_SSM_START_SESSION_RESPONSE") == true {
response = []byte(os.Getenv(args[1]))
if err = os.Unsetenv(args[1]); err != nil {
log.Errorf("Failed to remove temporary session env parameter: %v", err)
}
} else {
response = []byte(args[1])
}
case 2:
region = args[2]
case 3:
operationName = args[3]
case 4:
profile = args[4]
case 5:
// args[5] is parameters input to aws cli for StartSession api call
startSessionRequest := make(map[string]interface{})
json.Unmarshal([]byte(args[5]), &startSessionRequest)
target = startSessionRequest["Target"].(string)
case 6:
ssmEndpoint = args[6]
}
}
sdkutil.SetRegionAndProfile(region, profile)
clientId := uuid.NewV4().String()
switch operationName {
case StartSessionOperation:
if err = json.Unmarshal(response, &startSessionOutput); err != nil {
log.Errorf("Cannot perform start session: %v", err)
fmt.Fprintf(out, "Cannot perform start session: %v\n", err)
return
}
session.SessionId = *startSessionOutput.SessionId
session.StreamUrl = *startSessionOutput.StreamUrl
session.TokenValue = *startSessionOutput.TokenValue
session.Endpoint = ssmEndpoint
session.ClientId = clientId
session.TargetId = target
session.DataChannel = &datachannel.DataChannel{}
default:
fmt.Fprint(out, "Invalid Operation")
return
}
if err = startSession(&session, log); err != nil {
log.Errorf("Cannot perform start session: %v", err)
fmt.Fprintf(out, "Cannot perform start session: %v\n", err)
return
}
}