37 Star 411 Fork 76

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
import.go 1.02 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
TokenKey string
Token string
URL string
URLPlain string
}
func SystemTemplate(resp io.Writer, agentImage, token, url string) error {
d := md5.Sum([]byte(token))
tokenKey := hex.EncodeToString(d[:])[:7]
context := &context{
CAChecksum: CAChecksum(),
AgentImage: agentImage,
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 ""
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.1.7-rc2

搜索帮助

0d507c66 1850385 C8b1a773 1850385