37 Star 404 Fork 74

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
formatter.go 1.42 KB
一键复制 编辑 原始数据 按行查看 历史
package nodetemplate
import (
"strings"
"github.com/rancher/norman/httperror"
"github.com/rancher/norman/types"
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/labels"
)
type Formatter struct {
NodePoolLister v3.NodePoolLister
}
func (ntf *Formatter) Formatter(request *types.APIContext, resource *types.RawResource) {
if !filterToOwnNamespace(request, resource) {
return
}
pools, err := ntf.NodePoolLister.List("", labels.Everything())
if err != nil {
logrus.Warnf("Failed to determine if Node Template is being used. Error: %v", err)
return
}
for _, pool := range pools {
if pool.Spec.NodeTemplateName == resource.ID {
delete(resource.Links, "remove")
return
}
}
}
// TODO: This should go away, it is simply a hack to get the watch on nodetemplates to filter appropriately until that system is refactored
func filterToOwnNamespace(request *types.APIContext, resource *types.RawResource) bool {
user := request.Request.Header.Get("Impersonate-User")
if user == "" {
logrus.Errorf(
"%v",
httperror.NewAPIError(httperror.ServerError, "There was an error authorizing the user"))
return false
}
if !strings.HasPrefix(resource.ID, user+":") {
resource.ID = ""
resource.Values = map[string]interface{}{}
resource.Links = map[string]string{}
resource.Actions = map[string]string{}
resource.Type = ""
return false
}
return true
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.1.0-rc4

搜索帮助