mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/yunionio/cloudpods.git
synced 2026-09-20 08:03:53 +08:00
fix(climc,webconsole): use OS_AUTH_TOKEN for cloud shell running inside compose environment (#20650)
This commit is contained in:
@@ -6,6 +6,14 @@ fi
|
||||
|
||||
test -f /etc/yunion/rcadmin && source /etc/yunion/rcadmin
|
||||
|
||||
if [ -n "$OS_AUTH_TOKEN" ]; then
|
||||
test -n "$OS_USERNAME" && unset OS_USERNAME
|
||||
test -n "$OS_PASSWORD" && unset OS_PASSWORD
|
||||
test -n "$OS_DOMAIN_NAME" && unset OS_DOMAIN_NAME
|
||||
test -n "$OS_ACCESS_KEY" && unset OS_ACCESS_KEY
|
||||
test -n "$OS_SECRET_KEY" && unset OS_SECRET_KEY
|
||||
fi
|
||||
|
||||
source <(climc --completion bash)
|
||||
source <(kubectl completion bash)
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
@@ -66,12 +67,27 @@ func NewClimcSshCommand(info *ClimcSshInfo, s *mcclient.ClientSession) (*ClimcSs
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
name := "bash"
|
||||
args := []string{
|
||||
"-c",
|
||||
fmt.Sprintf("ssh -o StrictHostKeyChecking=no -i %s %s@%s", filename, info.Username, info.IpAddr),
|
||||
env := map[string]string{
|
||||
"OS_AUTH_TOKEN": s.GetToken().GetTokenString(),
|
||||
"OS_PROJECT_NAME": s.GetProjectName(),
|
||||
"OS_PROJECT_DOMAIN": s.GetProjectDomain(),
|
||||
"YUNION_USE_CACHED_TOKEN": "false",
|
||||
"OS_TRY_TERM_WIDTH": "false",
|
||||
}
|
||||
bCmd := NewBaseCommand(s, name, args...)
|
||||
envCmd := ""
|
||||
for k, v := range env {
|
||||
envCmd = fmt.Sprintf("%s export %s=%s", envCmd, k, v)
|
||||
}
|
||||
sshArgs := []string{
|
||||
"-t", // force pseudo-terminal allocation
|
||||
"-o", "StrictHostKeyChecking=no",
|
||||
"-i", filename,
|
||||
fmt.Sprintf("%s@%s", info.Username, info.IpAddr),
|
||||
fmt.Sprintf("'%s && exec bash'", envCmd),
|
||||
}
|
||||
sshCmd := fmt.Sprintf("ssh %s", strings.Join(sshArgs, " "))
|
||||
args := []string{"-c", sshCmd}
|
||||
bCmd := NewBaseCommand(s, "bash", args...)
|
||||
cmd := &ClimcSshCommand{
|
||||
BaseCommand: bCmd,
|
||||
Info: info,
|
||||
|
||||
Reference in New Issue
Block a user