diff --git a/pkg/apimachinery/identity/context_test.go b/pkg/apimachinery/identity/context_test.go index 87f31a17763..6464a7360fb 100644 --- a/pkg/apimachinery/identity/context_test.go +++ b/pkg/apimachinery/identity/context_test.go @@ -17,10 +17,126 @@ func TestRequesterFromContext(t *testing.T) { }) t.Run("should return user set by ContextWithUser", func(t *testing.T) { - expected := &identity.StaticRequester{UserUID: "AAA"} + expected := &dummyUser{UID: "AAA"} ctx := identity.WithRequester(context.Background(), expected) actual, err := identity.GetRequester(ctx) require.NoError(t, err) require.Equal(t, expected.GetUID(), actual.GetUID()) }) } + +type dummyUser struct { + UID string +} + +// GetAuthID implements identity.Requester. +func (d *dummyUser) GetAuthID() string { + panic("unimplemented") +} + +// GetAuthenticatedBy implements identity.Requester. +func (d *dummyUser) GetAuthenticatedBy() string { + panic("unimplemented") +} + +// GetCacheKey implements identity.Requester. +func (d *dummyUser) GetCacheKey() string { + panic("unimplemented") +} + +// GetDisplayName implements identity.Requester. +func (d *dummyUser) GetDisplayName() string { + panic("unimplemented") +} + +// GetEmail implements identity.Requester. +func (d *dummyUser) GetEmail() string { + panic("unimplemented") +} + +// GetGlobalPermissions implements identity.Requester. +func (d *dummyUser) GetGlobalPermissions() map[string][]string { + panic("unimplemented") +} + +// GetID implements identity.Requester. +func (d *dummyUser) GetID() identity.NamespaceID { + panic("unimplemented") +} + +// GetIDToken implements identity.Requester. +func (d *dummyUser) GetIDToken() string { + panic("unimplemented") +} + +// GetIsGrafanaAdmin implements identity.Requester. +func (d *dummyUser) GetIsGrafanaAdmin() bool { + panic("unimplemented") +} + +// GetLogin implements identity.Requester. +func (d *dummyUser) GetLogin() string { + panic("unimplemented") +} + +// GetNamespacedID implements identity.Requester. +func (d *dummyUser) GetNamespacedID() (namespace identity.Namespace, identifier string) { + panic("unimplemented") +} + +// GetOrgID implements identity.Requester. +func (d *dummyUser) GetOrgID() int64 { + panic("unimplemented") +} + +// GetOrgName implements identity.Requester. +func (d *dummyUser) GetOrgName() string { + panic("unimplemented") +} + +// GetOrgRole implements identity.Requester. +func (d *dummyUser) GetOrgRole() identity.RoleType { + panic("unimplemented") +} + +// GetPermissions implements identity.Requester. +func (d *dummyUser) GetPermissions() map[string][]string { + panic("unimplemented") +} + +// GetTeams implements identity.Requester. +func (d *dummyUser) GetTeams() []int64 { + panic("unimplemented") +} + +// GetUID implements identity.Requester. +func (d *dummyUser) GetUID() identity.NamespaceID { + return identity.NewNamespaceIDString(identity.NamespaceUser, d.UID) +} + +// HasRole implements identity.Requester. +func (d *dummyUser) HasRole(role identity.RoleType) bool { + panic("unimplemented") +} + +// HasUniqueId implements identity.Requester. +func (d *dummyUser) HasUniqueId() bool { + panic("unimplemented") +} + +// IsAuthenticatedBy implements identity.Requester. +func (d *dummyUser) IsAuthenticatedBy(providers ...string) bool { + panic("unimplemented") +} + +// IsEmailVerified implements identity.Requester. +func (d *dummyUser) IsEmailVerified() bool { + panic("unimplemented") +} + +// IsNil implements identity.Requester. +func (d *dummyUser) IsNil() bool { + return false +} + +var _ identity.Requester = &dummyUser{} diff --git a/pkg/apimachinery/utils/meta.go b/pkg/apimachinery/utils/meta.go index b693ebc9a63..ac5079a2a8e 100644 --- a/pkg/apimachinery/utils/meta.go +++ b/pkg/apimachinery/utils/meta.go @@ -3,7 +3,6 @@ package utils import ( "fmt" "reflect" - "strconv" "time" "k8s.io/apimachinery/pkg/api/meta" @@ -53,8 +52,6 @@ type GrafanaMetaAccessor interface { metav1.Object GetGroupVersionKind() schema.GroupVersionKind - GetResourceVersionInt64() (int64, error) - SetResourceVersionInt64(int64) GetUpdatedTimestamp() (*time.Time, error) SetUpdatedTimestamp(v *time.Time) @@ -65,8 +62,6 @@ type GrafanaMetaAccessor interface { SetUpdatedBy(user string) GetFolder() string SetFolder(uid string) - SetAnnotation(key string, val string) - GetSlug() string SetSlug(v string) @@ -104,7 +99,7 @@ func MetaAccessor(raw interface{}) (GrafanaMetaAccessor, error) { return nil, err } - // reflection to find title and other non object properties + // look for Spec.Title or Spec.Name r := reflect.ValueOf(raw) if r.Kind() == reflect.Ptr || r.Kind() == reflect.Interface { r = r.Elem() @@ -112,19 +107,11 @@ func MetaAccessor(raw interface{}) (GrafanaMetaAccessor, error) { return &grafanaMetaAccessor{raw, obj, r}, nil } -func (m *grafanaMetaAccessor) GetResourceVersionInt64() (int64, error) { - v := m.obj.GetResourceVersion() - if v == "" { - return 0, nil - } - return strconv.ParseInt(v, 10, 64) +func (m *grafanaMetaAccessor) Object() metav1.Object { + return m.obj } -func (m *grafanaMetaAccessor) SetResourceVersionInt64(rv int64) { - m.obj.SetResourceVersion(strconv.FormatInt(rv, 10)) -} - -func (m *grafanaMetaAccessor) SetAnnotation(key string, val string) { +func (m *grafanaMetaAccessor) set(key string, val string) { anno := m.obj.GetAnnotations() if val == "" { if anno != nil { @@ -161,7 +148,7 @@ func (m *grafanaMetaAccessor) SetUpdatedTimestampMillis(v int64) { t := time.UnixMilli(v) m.SetUpdatedTimestamp(&t) } else { - m.SetAnnotation(AnnoKeyUpdatedTimestamp, "") // will clear the annotation + m.set(AnnoKeyUpdatedTimestamp, "") // will clear the annotation } } @@ -170,7 +157,7 @@ func (m *grafanaMetaAccessor) SetUpdatedTimestamp(v *time.Time) { if v != nil && v.Unix() != 0 { txt = v.UTC().Format(time.RFC3339) } - m.SetAnnotation(AnnoKeyUpdatedTimestamp, txt) + m.set(AnnoKeyUpdatedTimestamp, txt) } func (m *grafanaMetaAccessor) GetCreatedBy() string { @@ -178,7 +165,7 @@ func (m *grafanaMetaAccessor) GetCreatedBy() string { } func (m *grafanaMetaAccessor) SetCreatedBy(user string) { - m.SetAnnotation(AnnoKeyCreatedBy, user) + m.set(AnnoKeyCreatedBy, user) } func (m *grafanaMetaAccessor) GetUpdatedBy() string { @@ -186,7 +173,7 @@ func (m *grafanaMetaAccessor) GetUpdatedBy() string { } func (m *grafanaMetaAccessor) SetUpdatedBy(user string) { - m.SetAnnotation(AnnoKeyUpdatedBy, user) + m.set(AnnoKeyUpdatedBy, user) } func (m *grafanaMetaAccessor) GetFolder() string { @@ -194,7 +181,7 @@ func (m *grafanaMetaAccessor) GetFolder() string { } func (m *grafanaMetaAccessor) SetFolder(uid string) { - m.SetAnnotation(AnnoKeyFolder, uid) + m.set(AnnoKeyFolder, uid) } func (m *grafanaMetaAccessor) GetSlug() string { @@ -202,7 +189,7 @@ func (m *grafanaMetaAccessor) GetSlug() string { } func (m *grafanaMetaAccessor) SetSlug(v string) { - m.SetAnnotation(AnnoKeySlug, v) + m.set(AnnoKeySlug, v) } func (m *grafanaMetaAccessor) SetOriginInfo(info *ResourceOriginInfo) { diff --git a/pkg/services/store/entity/db/migrations/resource_mig.go b/pkg/services/store/entity/db/migrations/resource_mig.go index 8510d35955e..c443fdd633a 100644 --- a/pkg/services/store/entity/db/migrations/resource_mig.go +++ b/pkg/services/store/entity/db/migrations/resource_mig.go @@ -74,7 +74,7 @@ func initResourceTables(mg *migrator.Migrator) string { {Cols: []string{"operation"}, Type: migrator.IndexType}, {Cols: []string{"namespace"}, Type: migrator.IndexType}, {Cols: []string{"group", "resource", "name"}, Type: migrator.IndexType}, - {Cols: []string{"blob_path"}, Type: migrator.IndexType}, + {Cols: []string{"blob_path_hash"}, Type: migrator.IndexType}, }, })