37 Star 407 Fork 75

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
import.go 1.14 KB
一键复制 编辑 原始数据 按行查看 历史
package systemtemplate
import (
"crypto/md5"
"encoding/base64"
"encoding/hex"
"text/template"
"io"
"crypto/sha256"
"strings"
"github.com/rancher/rancher/pkg/settings"
)
var (
t = template.Must(template.New("import").Parse(templateSource))
)
type context struct {
CAChecksum string
AgentImage string
AuthImage string
TokenKey string
Token string
URL string
URLPlain string
}
func SystemTemplate(resp io.Writer, agentImage, authImage, token, url string) error {
d := md5.Sum([]byte(token))
tokenKey := hex.EncodeToString(d[:])[:7]
if authImage == "fixed" {
authImage = settings.AuthImage.Get()
}
context := &context{
CAChecksum: CAChecksum(),
AgentImage: agentImage,
AuthImage: authImage,
TokenKey: tokenKey,
Token: base64.StdEncoding.EncodeToString([]byte(token)),
URL: base64.StdEncoding.EncodeToString([]byte(url)),
URLPlain: url,
}
return t.Execute(resp, context)
}
func CAChecksum() string {
ca := settings.CACerts.Get()
if ca != "" {
if !strings.HasSuffix(ca, "\n") {
ca += "\n"
}
digest := sha256.Sum256([]byte(ca))
return hex.EncodeToString(digest[:])
}
return ""
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.2.0-rc7

搜索帮助