K8s/IAM: Move identity.grafana.app to iam.grafana.app (#92929)

This commit is contained in:
Ryan McKinley
2024-09-05 09:43:54 +03:00
committed by GitHub
parent aae788ae46
commit 9338e40dc3
85 changed files with 142 additions and 143 deletions
+25
View File
@@ -0,0 +1,25 @@
package common
import (
"strconv"
identityv0 "github.com/grafana/grafana/pkg/apis/iam/v0alpha1"
"github.com/grafana/grafana/pkg/services/team"
)
// OptonalFormatInt formats num as a string. If num is less or equal than 0
// an empty string is returned.
func OptionalFormatInt(num int64) string {
if num > 0 {
return strconv.FormatInt(num, 10)
}
return ""
}
func MapTeamPermission(p team.PermissionType) identityv0.TeamPermission {
if p == team.PermissionTypeAdmin {
return identityv0.TeamPermissionAdmin
} else {
return identityv0.TeamPermissionMember
}
}
@@ -0,0 +1,48 @@
package common
import (
"net/url"
"strconv"
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
)
type Pagination struct {
Limit int64
Continue int64
}
func PaginationFromListOptions(options *internalversion.ListOptions) Pagination {
limit := options.Limit
if limit < 1 {
limit = 50
}
return Pagination{
Limit: limit,
Continue: parseIntWithFallback(options.Continue, 0, 0),
}
}
func PaginationFromListQuery(query url.Values) Pagination {
return Pagination{
Limit: parseIntWithFallback(query.Get("limit"), 1, 50),
Continue: parseIntWithFallback(query.Get("continue"), 0, 0),
}
}
func parseIntWithFallback(original string, min int64, fallback int64) int64 {
if original == "" {
return fallback
}
v, err := strconv.ParseInt(original, 10, 64)
if err != nil {
return fallback
}
if v < min {
return fallback
}
return v
}