37 Star 411 Fork 76

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
formatter.go 1.42 KB
一键复制 编辑 原始数据 按行查看 历史
Dan Ramich 提交于 2019-06-12 13:38 . goimport linting changes
package nodetemplate
import (
"strings"
"github.com/rancher/norman/httperror"
"github.com/rancher/norman/types"
v3 "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
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.2.10-rc1

搜索帮助

0d507c66 1850385 C8b1a773 1850385