package models import "time" // LogSource 日志查询数据源。 // cluster-svc: 经目标集群 kube-apiserver 的 service proxy 访问(无需直通 ClusterIP/DNS), // // 覆盖「本平台部署的 Loki」与「接入集群中已有的外部 Loki」两类场景; // // url: 直连地址(host-binary 部署或网络可达的 Loki)。 type LogSource struct { ID uint `json:"id"` Name string `json:"name"` TargetType string `json:"targetType"` // cluster-svc | url ClusterID *uint `json:"clusterID,omitempty"` Namespace string `json:"namespace"` Service string `json:"service"` Port int `json:"port"` URL string `json:"url"` AuthType string `json:"authType"` // none | basic | bearer BasicUser string `json:"basicUser"` BasicPass string `json:"basicPass"` // ENC: 加密存储,不外发 BearerToken string `json:"bearerToken"` Headers map[string]string `json:"headers,omitempty"` SkipTLSVerify bool `json:"skipTLSVerify"` IsDefault bool `json:"isDefault"` Access []LogSourceAccess `json:"access,omitempty"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` } func (s *LogSource) Sanitized() map[string]interface{} { return map[string]interface{}{ "id": s.ID, "name": s.Name, "targetType": s.TargetType, "clusterID": s.ClusterID, "namespace": s.Namespace, "service": s.Service, "port": s.Port, "url": s.URL, "authType": s.AuthType, "basicUser": s.BasicUser, "hasBasicPass": s.BasicPass != "", "isDefault": s.IsDefault, "hasBearerToken": s.BearerToken != "", "headerNames": headerNames(s.Headers), "skipTLSVerify": s.SkipTLSVerify, "access": s.Access, "createdAt": s.CreatedAt, "updatedAt": s.UpdatedAt, } } func headerNames(headers map[string]string) []string { names := make([]string, 0, len(headers)) for name := range headers { names = append(names, name) } return names } // LogSourceAccess grants one user access to a source, optionally restricted to exact stream labels. type LogSourceAccess struct { UserID uint `json:"userId"` Labels map[string]string `json:"labels,omitempty"` }