K8s: Add resource type helper to avoid so many hardcoded names (#79344)
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"k8s.io/apiserver/pkg/endpoints/request"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/appcontext"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
@@ -75,3 +76,16 @@ func ParseNamespace(ns string) (NamespaceInfo, error) {
|
||||
}
|
||||
return info, nil
|
||||
}
|
||||
|
||||
func OrgIDForList(ctx context.Context) (int64, error) {
|
||||
ns := request.NamespaceValue(ctx)
|
||||
if ns == "" {
|
||||
user, err := appcontext.User(ctx)
|
||||
if user != nil {
|
||||
return user.OrgID, err
|
||||
}
|
||||
return -1, err
|
||||
}
|
||||
info, err := ParseNamespace(ns)
|
||||
return info.OrgID, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user