mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 16:52:54 +08:00
Chore: Replace entity GRN with infra/grn GRN (#74198)
replace entity GRN with infra/grn GRN
This commit is contained in:
3
Makefile
3
Makefile
@ -263,6 +263,9 @@ devenv-mysql:
|
||||
protobuf: ## Compile protobuf definitions
|
||||
bash scripts/protobuf-check.sh
|
||||
bash pkg/plugins/backendplugin/pluginextensionv2/generate.sh
|
||||
bash pkg/plugins/backendplugin/secretsmanagerplugin/generate.sh
|
||||
bash pkg/services/store/entity/generate.sh
|
||||
bash pkg/infra/grn/generate.sh
|
||||
|
||||
clean: ## Clean up intermediate build artifacts.
|
||||
@echo "cleaning"
|
||||
|
24
pkg/infra/grn/generate.sh
Executable file
24
pkg/infra/grn/generate.sh
Executable file
@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
|
||||
# To compile all protobuf files in this repository, run
|
||||
# "make protobuf" at the top-level.
|
||||
|
||||
set -eu
|
||||
|
||||
DST_DIR=./
|
||||
|
||||
SOURCE="${BASH_SOURCE[0]}"
|
||||
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
|
||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||
|
||||
cd "$DIR"
|
||||
|
||||
protoc \
|
||||
-I ./ \
|
||||
-I ../../../ \
|
||||
--go_out=${DST_DIR} \
|
||||
--go_opt=paths=source_relative \
|
||||
--go-grpc_out=${DST_DIR} \
|
||||
--go-grpc_opt=paths=source_relative \
|
||||
--go-grpc_opt=require_unimplemented_servers=false \
|
||||
*.proto
|
@ -6,32 +6,10 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Grafana resource name. See also:
|
||||
// https://github.com/grafana/grafana/blob/main/pkg/services/store/entity/entity.proto#L6
|
||||
// NOTE: This structure/format is still under active development and is subject to change
|
||||
type GRN struct {
|
||||
// TenantID contains the ID of the tenant (in hosted grafana) or
|
||||
// organization (in other environments) the resource belongs to. This field
|
||||
// may be omitted for global Grafana resources which are not associated with
|
||||
// an organization.
|
||||
TenantID int64
|
||||
|
||||
// The kind of resource being identified, for e.g. "dashboard" or "user".
|
||||
// The caller is responsible for validating the value.
|
||||
ResourceKind string
|
||||
|
||||
// ResourceIdentifier is used by the underlying service to identify the
|
||||
// resource.
|
||||
ResourceIdentifier string
|
||||
|
||||
// GRN can not be extended
|
||||
_ any
|
||||
}
|
||||
|
||||
// ParseStr attempts to parse a string into a GRN. It returns an error if the
|
||||
// given string does not match the GRN format, but does not validate the values.
|
||||
func ParseStr(str string) (GRN, error) {
|
||||
ret := GRN{}
|
||||
func ParseStr(str string) (*GRN, error) {
|
||||
ret := &GRN{}
|
||||
parts := strings.Split(str, ":")
|
||||
|
||||
if len(parts) != 3 {
|
||||
@ -65,7 +43,7 @@ func ParseStr(str string) (GRN, error) {
|
||||
|
||||
// MustParseStr is a wrapper around ParseStr that panics if the given input is
|
||||
// not a valid GRN. This is intended for use in tests.
|
||||
func MustParseStr(str string) GRN {
|
||||
func MustParseStr(str string) *GRN {
|
||||
grn, err := ParseStr(str)
|
||||
if err != nil {
|
||||
panic("bad grn!")
|
||||
@ -73,8 +51,19 @@ func MustParseStr(str string) GRN {
|
||||
return grn
|
||||
}
|
||||
|
||||
// String returns a string representation of a grn in the format
|
||||
// ToGRNString returns a string representation of a grn in the format
|
||||
// grn:tenantID:kind/resourceIdentifier
|
||||
func (g *GRN) String() string {
|
||||
func (g *GRN) ToGRNString() string {
|
||||
return fmt.Sprintf("grn:%d:%s/%s", g.TenantID, g.ResourceKind, g.ResourceIdentifier)
|
||||
}
|
||||
|
||||
// Check if the two GRNs reference to the same object
|
||||
// we can not use simple `*x == *b` because of the internal settings
|
||||
func (g *GRN) Equal(b *GRN) bool {
|
||||
if b == nil {
|
||||
return false
|
||||
}
|
||||
return g == b || (g.TenantID == b.TenantID &&
|
||||
g.ResourceKind == b.ResourceKind &&
|
||||
g.ResourceIdentifier == b.ResourceIdentifier)
|
||||
}
|
||||
|
172
pkg/infra/grn/grn.pb.go
Normal file
172
pkg/infra/grn/grn.pb.go
Normal file
@ -0,0 +1,172 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.30.0
|
||||
// protoc v4.23.4
|
||||
// source: grn.proto
|
||||
|
||||
package grn
|
||||
|
||||
import (
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
const (
|
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
type GRN struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
// TenantID contains the ID of the tenant (in hosted grafana) or
|
||||
// organization (in other environments) the resource belongs to. This field
|
||||
// may be omitted for global Grafana resources which are not associated with
|
||||
// an organization.
|
||||
TenantID int64 `protobuf:"varint,1,opt,name=TenantID,proto3" json:"TenantID,omitempty"`
|
||||
// The kind of resource being identified, for e.g. "dashboard" or "user".
|
||||
// The caller is responsible for validating the value.
|
||||
ResourceKind string `protobuf:"bytes,3,opt,name=ResourceKind,proto3" json:"ResourceKind,omitempty"`
|
||||
// ResourceIdentifier is used by the underlying service to identify the
|
||||
// resource.
|
||||
ResourceIdentifier string `protobuf:"bytes,4,opt,name=ResourceIdentifier,proto3" json:"ResourceIdentifier,omitempty"`
|
||||
}
|
||||
|
||||
func (x *GRN) Reset() {
|
||||
*x = GRN{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_grn_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *GRN) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*GRN) ProtoMessage() {}
|
||||
|
||||
func (x *GRN) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_grn_proto_msgTypes[0]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use GRN.ProtoReflect.Descriptor instead.
|
||||
func (*GRN) Descriptor() ([]byte, []int) {
|
||||
return file_grn_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *GRN) GetTenantID() int64 {
|
||||
if x != nil {
|
||||
return x.TenantID
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *GRN) GetResourceKind() string {
|
||||
if x != nil {
|
||||
return x.ResourceKind
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *GRN) GetResourceIdentifier() string {
|
||||
if x != nil {
|
||||
return x.ResourceIdentifier
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
var File_grn_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_grn_proto_rawDesc = []byte{
|
||||
0x0a, 0x09, 0x67, 0x72, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x03, 0x67, 0x72, 0x6e,
|
||||
0x22, 0x75, 0x0a, 0x03, 0x47, 0x52, 0x4e, 0x12, 0x1a, 0x0a, 0x08, 0x54, 0x65, 0x6e, 0x61, 0x6e,
|
||||
0x74, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x54, 0x65, 0x6e, 0x61, 0x6e,
|
||||
0x74, 0x49, 0x44, 0x12, 0x22, 0x0a, 0x0c, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x4b,
|
||||
0x69, 0x6e, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x52, 0x65, 0x73, 0x6f, 0x75,
|
||||
0x72, 0x63, 0x65, 0x4b, 0x69, 0x6e, 0x64, 0x12, 0x2e, 0x0a, 0x12, 0x52, 0x65, 0x73, 0x6f, 0x75,
|
||||
0x72, 0x63, 0x65, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x18, 0x04, 0x20,
|
||||
0x01, 0x28, 0x09, 0x52, 0x12, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x49, 0x64, 0x65,
|
||||
0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x42, 0x2a, 0x5a, 0x28, 0x67, 0x69, 0x74, 0x68, 0x75,
|
||||
0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x72, 0x61, 0x66, 0x61, 0x6e, 0x61, 0x2f, 0x67, 0x72,
|
||||
0x61, 0x66, 0x61, 0x6e, 0x61, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x2f,
|
||||
0x67, 0x72, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
file_grn_proto_rawDescOnce sync.Once
|
||||
file_grn_proto_rawDescData = file_grn_proto_rawDesc
|
||||
)
|
||||
|
||||
func file_grn_proto_rawDescGZIP() []byte {
|
||||
file_grn_proto_rawDescOnce.Do(func() {
|
||||
file_grn_proto_rawDescData = protoimpl.X.CompressGZIP(file_grn_proto_rawDescData)
|
||||
})
|
||||
return file_grn_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_grn_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
|
||||
var file_grn_proto_goTypes = []interface{}{
|
||||
(*GRN)(nil), // 0: grn.GRN
|
||||
}
|
||||
var file_grn_proto_depIdxs = []int32{
|
||||
0, // [0:0] is the sub-list for method output_type
|
||||
0, // [0:0] is the sub-list for method input_type
|
||||
0, // [0:0] is the sub-list for extension type_name
|
||||
0, // [0:0] is the sub-list for extension extendee
|
||||
0, // [0:0] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_grn_proto_init() }
|
||||
func file_grn_proto_init() {
|
||||
if File_grn_proto != nil {
|
||||
return
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_grn_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*GRN); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_grn_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 1,
|
||||
NumExtensions: 0,
|
||||
NumServices: 0,
|
||||
},
|
||||
GoTypes: file_grn_proto_goTypes,
|
||||
DependencyIndexes: file_grn_proto_depIdxs,
|
||||
MessageInfos: file_grn_proto_msgTypes,
|
||||
}.Build()
|
||||
File_grn_proto = out.File
|
||||
file_grn_proto_rawDesc = nil
|
||||
file_grn_proto_goTypes = nil
|
||||
file_grn_proto_depIdxs = nil
|
||||
}
|
20
pkg/infra/grn/grn.proto
Normal file
20
pkg/infra/grn/grn.proto
Normal file
@ -0,0 +1,20 @@
|
||||
syntax = "proto3";
|
||||
package grn;
|
||||
|
||||
option go_package = "github.com/grafana/grafana/pkg/infra/grn";
|
||||
|
||||
message GRN {
|
||||
// TenantID contains the ID of the tenant (in hosted grafana) or
|
||||
// organization (in other environments) the resource belongs to. This field
|
||||
// may be omitted for global Grafana resources which are not associated with
|
||||
// an organization.
|
||||
int64 TenantID = 1;
|
||||
|
||||
// The kind of resource being identified, for e.g. "dashboard" or "user".
|
||||
// The caller is responsible for validating the value.
|
||||
string ResourceKind = 3;
|
||||
|
||||
// ResourceIdentifier is used by the underlying service to identify the
|
||||
// resource.
|
||||
string ResourceIdentifier = 4;
|
||||
}
|
@ -3,57 +3,59 @@ package grn
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
)
|
||||
|
||||
func TestParseGRNStr(t *testing.T) {
|
||||
tests := []struct {
|
||||
input string
|
||||
expect GRN
|
||||
expect *GRN
|
||||
expectErr bool
|
||||
}{
|
||||
{ // empty
|
||||
"",
|
||||
GRN{},
|
||||
&GRN{},
|
||||
true,
|
||||
},
|
||||
{ // too few parts
|
||||
"grn:dashboards",
|
||||
GRN{},
|
||||
&GRN{},
|
||||
true,
|
||||
},
|
||||
{ // too many parts
|
||||
"grn::dashboards:user:orgs:otherthings:hello:stillgoing",
|
||||
GRN{},
|
||||
&GRN{},
|
||||
true,
|
||||
},
|
||||
{ // Does not look like a GRN
|
||||
"hrn:grafana::123:dashboards/foo",
|
||||
GRN{},
|
||||
&GRN{},
|
||||
true,
|
||||
},
|
||||
{ // Missing Kind
|
||||
"grn::foo",
|
||||
GRN{},
|
||||
&GRN{},
|
||||
true,
|
||||
},
|
||||
{ // good!
|
||||
"grn::roles/Admin",
|
||||
GRN{TenantID: 0, ResourceKind: "roles", ResourceIdentifier: "Admin"},
|
||||
&GRN{TenantID: 0, ResourceKind: "roles", ResourceIdentifier: "Admin"},
|
||||
false,
|
||||
},
|
||||
{ // good!
|
||||
"grn::roles/Admin/with/some/slashes",
|
||||
GRN{TenantID: 0, ResourceKind: "roles", ResourceIdentifier: "Admin/with/some/slashes"},
|
||||
&GRN{TenantID: 0, ResourceKind: "roles", ResourceIdentifier: "Admin/with/some/slashes"},
|
||||
false,
|
||||
},
|
||||
{ // good!
|
||||
"grn:123456789:roles/Admin/with/some/slashes",
|
||||
GRN{TenantID: 123456789, ResourceKind: "roles", ResourceIdentifier: "Admin/with/some/slashes"},
|
||||
&GRN{TenantID: 123456789, ResourceKind: "roles", ResourceIdentifier: "Admin/with/some/slashes"},
|
||||
false,
|
||||
},
|
||||
{ // Weird, but valid.
|
||||
"grn::roles///Admin/with/leading/slashes",
|
||||
GRN{TenantID: 0, ResourceKind: "roles", ResourceIdentifier: "//Admin/with/leading/slashes"},
|
||||
&GRN{TenantID: 0, ResourceKind: "roles", ResourceIdentifier: "//Admin/with/leading/slashes"},
|
||||
false,
|
||||
},
|
||||
}
|
||||
@ -69,7 +71,7 @@ func TestParseGRNStr(t *testing.T) {
|
||||
t.Fatalf("wrong result. Expected success, got error %s", err.Error())
|
||||
}
|
||||
|
||||
if got != test.expect {
|
||||
if !cmp.Equal(test.expect, got) {
|
||||
t.Fatalf("wrong result. Wanted %s, got %s\n", test.expect.String(), got.String())
|
||||
}
|
||||
})
|
||||
|
@ -1,21 +1,20 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.26.0
|
||||
// protoc v3.21.4
|
||||
// protoc-gen-go v1.30.0
|
||||
// protoc v4.23.4
|
||||
// source: rendererv2.proto
|
||||
|
||||
package pluginextensionv2
|
||||
|
||||
import (
|
||||
context "context"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -1,21 +1,20 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.28.0
|
||||
// protoc v3.19.4
|
||||
// protoc-gen-go v1.30.0
|
||||
// protoc v4.23.4
|
||||
// source: sanitizer.proto
|
||||
|
||||
package pluginextensionv2
|
||||
|
||||
import (
|
||||
context "context"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -192,7 +191,7 @@ func file_sanitizer_proto_rawDescGZIP() []byte {
|
||||
}
|
||||
|
||||
var file_sanitizer_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
|
||||
var file_sanitizer_proto_goTypes = []any{
|
||||
var file_sanitizer_proto_goTypes = []interface{}{
|
||||
(*SanitizeRequest)(nil), // 0: pluginextensionv2.SanitizeRequest
|
||||
(*SanitizeResponse)(nil), // 1: pluginextensionv2.SanitizeResponse
|
||||
}
|
||||
@ -212,7 +211,7 @@ func file_sanitizer_proto_init() {
|
||||
return
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_sanitizer_proto_msgTypes[0].Exporter = func(v any, i int) any {
|
||||
file_sanitizer_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*SanitizeRequest); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@ -224,7 +223,7 @@ func file_sanitizer_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_sanitizer_proto_msgTypes[1].Exporter = func(v any, i int) any {
|
||||
file_sanitizer_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*SanitizeResponse); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@ -306,7 +305,7 @@ func RegisterSanitizerServer(s *grpc.Server, srv SanitizerServer) {
|
||||
s.RegisterService(&_Sanitizer_serviceDesc, srv)
|
||||
}
|
||||
|
||||
func _Sanitizer_Sanitize_Handler(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) {
|
||||
func _Sanitizer_Sanitize_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(SanitizeRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
@ -318,7 +317,7 @@ func _Sanitizer_Sanitize_Handler(srv any, ctx context.Context, dec func(any) err
|
||||
Server: srv,
|
||||
FullMethod: "/pluginextensionv2.Sanitizer/Sanitize",
|
||||
}
|
||||
handler := func(ctx context.Context, req any) (any, error) {
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(SanitizerServer).Sanitize(ctx, req.(*SanitizeRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
|
@ -1,3 +1,18 @@
|
||||
#!/bin/bash
|
||||
|
||||
# To compile all protobuf files in this repository, run
|
||||
# "make protobuf" at the top-level.
|
||||
|
||||
set -eu
|
||||
|
||||
DST_DIR=../genproto/pluginv2
|
||||
|
||||
SOURCE="${BASH_SOURCE[0]}"
|
||||
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
|
||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||
|
||||
cd "$DIR"
|
||||
|
||||
protoc --go_out=. --go_opt=paths=source_relative \
|
||||
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
|
||||
secretsmanager.proto
|
||||
*.proto
|
@ -1,17 +1,16 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.28.0
|
||||
// protoc v3.19.4
|
||||
// protoc-gen-go v1.30.0
|
||||
// protoc v4.23.4
|
||||
// source: secretsmanager.proto
|
||||
|
||||
package secretsmanagerplugin
|
||||
|
||||
import (
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -893,7 +892,7 @@ func file_secretsmanager_proto_rawDescGZIP() []byte {
|
||||
}
|
||||
|
||||
var file_secretsmanager_proto_msgTypes = make([]protoimpl.MessageInfo, 14)
|
||||
var file_secretsmanager_proto_goTypes = []any{
|
||||
var file_secretsmanager_proto_goTypes = []interface{}{
|
||||
(*Key)(nil), // 0: secretsmanagerplugin.Key
|
||||
(*Item)(nil), // 1: secretsmanagerplugin.Item
|
||||
(*GetSecretRequest)(nil), // 2: secretsmanagerplugin.GetSecretRequest
|
||||
@ -943,7 +942,7 @@ func file_secretsmanager_proto_init() {
|
||||
return
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_secretsmanager_proto_msgTypes[0].Exporter = func(v any, i int) any {
|
||||
file_secretsmanager_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*Key); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@ -955,7 +954,7 @@ func file_secretsmanager_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_secretsmanager_proto_msgTypes[1].Exporter = func(v any, i int) any {
|
||||
file_secretsmanager_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*Item); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@ -967,7 +966,7 @@ func file_secretsmanager_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_secretsmanager_proto_msgTypes[2].Exporter = func(v any, i int) any {
|
||||
file_secretsmanager_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*GetSecretRequest); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@ -979,7 +978,7 @@ func file_secretsmanager_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_secretsmanager_proto_msgTypes[3].Exporter = func(v any, i int) any {
|
||||
file_secretsmanager_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*GetSecretResponse); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@ -991,7 +990,7 @@ func file_secretsmanager_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_secretsmanager_proto_msgTypes[4].Exporter = func(v any, i int) any {
|
||||
file_secretsmanager_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*SetSecretRequest); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@ -1003,7 +1002,7 @@ func file_secretsmanager_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_secretsmanager_proto_msgTypes[5].Exporter = func(v any, i int) any {
|
||||
file_secretsmanager_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*SetSecretResponse); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@ -1015,7 +1014,7 @@ func file_secretsmanager_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_secretsmanager_proto_msgTypes[6].Exporter = func(v any, i int) any {
|
||||
file_secretsmanager_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*DeleteSecretRequest); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@ -1027,7 +1026,7 @@ func file_secretsmanager_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_secretsmanager_proto_msgTypes[7].Exporter = func(v any, i int) any {
|
||||
file_secretsmanager_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*DeleteSecretResponse); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@ -1039,7 +1038,7 @@ func file_secretsmanager_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_secretsmanager_proto_msgTypes[8].Exporter = func(v any, i int) any {
|
||||
file_secretsmanager_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*ListSecretsRequest); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@ -1051,7 +1050,7 @@ func file_secretsmanager_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_secretsmanager_proto_msgTypes[9].Exporter = func(v any, i int) any {
|
||||
file_secretsmanager_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*ListSecretsResponse); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@ -1063,7 +1062,7 @@ func file_secretsmanager_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_secretsmanager_proto_msgTypes[10].Exporter = func(v any, i int) any {
|
||||
file_secretsmanager_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*GetAllSecretsRequest); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@ -1075,7 +1074,7 @@ func file_secretsmanager_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_secretsmanager_proto_msgTypes[11].Exporter = func(v any, i int) any {
|
||||
file_secretsmanager_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*GetAllSecretsResponse); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@ -1087,7 +1086,7 @@ func file_secretsmanager_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_secretsmanager_proto_msgTypes[12].Exporter = func(v any, i int) any {
|
||||
file_secretsmanager_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*RenameSecretRequest); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@ -1099,7 +1098,7 @@ func file_secretsmanager_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_secretsmanager_proto_msgTypes[13].Exporter = func(v any, i int) any {
|
||||
file_secretsmanager_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*RenameSecretResponse); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
|
@ -1,14 +1,13 @@
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.2.0
|
||||
// - protoc v3.19.4
|
||||
// - protoc-gen-go-grpc v1.3.0
|
||||
// - protoc v4.23.4
|
||||
// source: secretsmanager.proto
|
||||
|
||||
package secretsmanagerplugin
|
||||
|
||||
import (
|
||||
context "context"
|
||||
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
@ -19,6 +18,15 @@ import (
|
||||
// Requires gRPC-Go v1.32.0 or later.
|
||||
const _ = grpc.SupportPackageIsVersion7
|
||||
|
||||
const (
|
||||
SecretsManager_GetSecret_FullMethodName = "/secretsmanagerplugin.SecretsManager/GetSecret"
|
||||
SecretsManager_SetSecret_FullMethodName = "/secretsmanagerplugin.SecretsManager/SetSecret"
|
||||
SecretsManager_DeleteSecret_FullMethodName = "/secretsmanagerplugin.SecretsManager/DeleteSecret"
|
||||
SecretsManager_ListSecrets_FullMethodName = "/secretsmanagerplugin.SecretsManager/ListSecrets"
|
||||
SecretsManager_RenameSecret_FullMethodName = "/secretsmanagerplugin.SecretsManager/RenameSecret"
|
||||
SecretsManager_GetAllSecrets_FullMethodName = "/secretsmanagerplugin.SecretsManager/GetAllSecrets"
|
||||
)
|
||||
|
||||
// SecretsManagerClient is the client API for SecretsManager service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
@ -41,7 +49,7 @@ func NewSecretsManagerClient(cc grpc.ClientConnInterface) SecretsManagerClient {
|
||||
|
||||
func (c *secretsManagerClient) GetSecret(ctx context.Context, in *GetSecretRequest, opts ...grpc.CallOption) (*GetSecretResponse, error) {
|
||||
out := new(GetSecretResponse)
|
||||
err := c.cc.Invoke(ctx, "/secretsmanagerplugin.SecretsManager/GetSecret", in, out, opts...)
|
||||
err := c.cc.Invoke(ctx, SecretsManager_GetSecret_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -50,7 +58,7 @@ func (c *secretsManagerClient) GetSecret(ctx context.Context, in *GetSecretReque
|
||||
|
||||
func (c *secretsManagerClient) SetSecret(ctx context.Context, in *SetSecretRequest, opts ...grpc.CallOption) (*SetSecretResponse, error) {
|
||||
out := new(SetSecretResponse)
|
||||
err := c.cc.Invoke(ctx, "/secretsmanagerplugin.SecretsManager/SetSecret", in, out, opts...)
|
||||
err := c.cc.Invoke(ctx, SecretsManager_SetSecret_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -59,7 +67,7 @@ func (c *secretsManagerClient) SetSecret(ctx context.Context, in *SetSecretReque
|
||||
|
||||
func (c *secretsManagerClient) DeleteSecret(ctx context.Context, in *DeleteSecretRequest, opts ...grpc.CallOption) (*DeleteSecretResponse, error) {
|
||||
out := new(DeleteSecretResponse)
|
||||
err := c.cc.Invoke(ctx, "/secretsmanagerplugin.SecretsManager/DeleteSecret", in, out, opts...)
|
||||
err := c.cc.Invoke(ctx, SecretsManager_DeleteSecret_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -68,7 +76,7 @@ func (c *secretsManagerClient) DeleteSecret(ctx context.Context, in *DeleteSecre
|
||||
|
||||
func (c *secretsManagerClient) ListSecrets(ctx context.Context, in *ListSecretsRequest, opts ...grpc.CallOption) (*ListSecretsResponse, error) {
|
||||
out := new(ListSecretsResponse)
|
||||
err := c.cc.Invoke(ctx, "/secretsmanagerplugin.SecretsManager/ListSecrets", in, out, opts...)
|
||||
err := c.cc.Invoke(ctx, SecretsManager_ListSecrets_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -77,7 +85,7 @@ func (c *secretsManagerClient) ListSecrets(ctx context.Context, in *ListSecretsR
|
||||
|
||||
func (c *secretsManagerClient) RenameSecret(ctx context.Context, in *RenameSecretRequest, opts ...grpc.CallOption) (*RenameSecretResponse, error) {
|
||||
out := new(RenameSecretResponse)
|
||||
err := c.cc.Invoke(ctx, "/secretsmanagerplugin.SecretsManager/RenameSecret", in, out, opts...)
|
||||
err := c.cc.Invoke(ctx, SecretsManager_RenameSecret_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -86,7 +94,7 @@ func (c *secretsManagerClient) RenameSecret(ctx context.Context, in *RenameSecre
|
||||
|
||||
func (c *secretsManagerClient) GetAllSecrets(ctx context.Context, in *GetAllSecretsRequest, opts ...grpc.CallOption) (*GetAllSecretsResponse, error) {
|
||||
out := new(GetAllSecretsResponse)
|
||||
err := c.cc.Invoke(ctx, "/secretsmanagerplugin.SecretsManager/GetAllSecrets", in, out, opts...)
|
||||
err := c.cc.Invoke(ctx, SecretsManager_GetAllSecrets_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -141,7 +149,7 @@ func RegisterSecretsManagerServer(s grpc.ServiceRegistrar, srv SecretsManagerSer
|
||||
s.RegisterService(&SecretsManager_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _SecretsManager_GetSecret_Handler(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) {
|
||||
func _SecretsManager_GetSecret_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetSecretRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
@ -151,15 +159,15 @@ func _SecretsManager_GetSecret_Handler(srv any, ctx context.Context, dec func(an
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/secretsmanagerplugin.SecretsManager/GetSecret",
|
||||
FullMethod: SecretsManager_GetSecret_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req any) (any, error) {
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(SecretsManagerServer).GetSecret(ctx, req.(*GetSecretRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _SecretsManager_SetSecret_Handler(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) {
|
||||
func _SecretsManager_SetSecret_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(SetSecretRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
@ -169,15 +177,15 @@ func _SecretsManager_SetSecret_Handler(srv any, ctx context.Context, dec func(an
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/secretsmanagerplugin.SecretsManager/SetSecret",
|
||||
FullMethod: SecretsManager_SetSecret_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req any) (any, error) {
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(SecretsManagerServer).SetSecret(ctx, req.(*SetSecretRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _SecretsManager_DeleteSecret_Handler(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) {
|
||||
func _SecretsManager_DeleteSecret_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(DeleteSecretRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
@ -187,15 +195,15 @@ func _SecretsManager_DeleteSecret_Handler(srv any, ctx context.Context, dec func
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/secretsmanagerplugin.SecretsManager/DeleteSecret",
|
||||
FullMethod: SecretsManager_DeleteSecret_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req any) (any, error) {
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(SecretsManagerServer).DeleteSecret(ctx, req.(*DeleteSecretRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _SecretsManager_ListSecrets_Handler(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) {
|
||||
func _SecretsManager_ListSecrets_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ListSecretsRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
@ -205,15 +213,15 @@ func _SecretsManager_ListSecrets_Handler(srv any, ctx context.Context, dec func(
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/secretsmanagerplugin.SecretsManager/ListSecrets",
|
||||
FullMethod: SecretsManager_ListSecrets_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req any) (any, error) {
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(SecretsManagerServer).ListSecrets(ctx, req.(*ListSecretsRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _SecretsManager_RenameSecret_Handler(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) {
|
||||
func _SecretsManager_RenameSecret_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(RenameSecretRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
@ -223,15 +231,15 @@ func _SecretsManager_RenameSecret_Handler(srv any, ctx context.Context, dec func
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/secretsmanagerplugin.SecretsManager/RenameSecret",
|
||||
FullMethod: SecretsManager_RenameSecret_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req any) (any, error) {
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(SecretsManagerServer).RenameSecret(ctx, req.(*RenameSecretRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _SecretsManager_GetAllSecrets_Handler(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) {
|
||||
func _SecretsManager_GetAllSecrets_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetAllSecretsRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
@ -241,9 +249,9 @@ func _SecretsManager_GetAllSecrets_Handler(srv any, ctx context.Context, dec fun
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/secretsmanagerplugin.SecretsManager/GetAllSecrets",
|
||||
FullMethod: SecretsManager_GetAllSecrets_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req any) (any, error) {
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(SecretsManagerServer).GetAllSecrets(ctx, req.(*GetAllSecretsRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/appcontext"
|
||||
"github.com/grafana/grafana/pkg/infra/grn"
|
||||
"github.com/grafana/grafana/pkg/services/playlist"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/session"
|
||||
"github.com/grafana/grafana/pkg/services/store/entity"
|
||||
@ -55,10 +56,10 @@ func (s *entityStoreImpl) sync() {
|
||||
}
|
||||
body, _ := json.Marshal(dto)
|
||||
_, _ = s.store.Write(ctx, &entity.WriteEntityRequest{
|
||||
GRN: &entity.GRN{
|
||||
TenantId: info.OrgID,
|
||||
UID: info.UID,
|
||||
Kind: entity.StandardKindPlaylist,
|
||||
GRN: &grn.GRN{
|
||||
TenantID: info.OrgID,
|
||||
ResourceIdentifier: info.UID,
|
||||
ResourceKind: entity.StandardKindPlaylist,
|
||||
},
|
||||
Body: body,
|
||||
})
|
||||
@ -73,9 +74,9 @@ func (s *entityStoreImpl) Create(ctx context.Context, cmd *playlist.CreatePlayli
|
||||
return rsp, fmt.Errorf("unable to write playlist to store")
|
||||
}
|
||||
_, err = s.store.Write(ctx, &entity.WriteEntityRequest{
|
||||
GRN: &entity.GRN{
|
||||
Kind: entity.StandardKindPlaylist,
|
||||
UID: rsp.UID,
|
||||
GRN: &grn.GRN{
|
||||
ResourceKind: entity.StandardKindPlaylist,
|
||||
ResourceIdentifier: rsp.UID,
|
||||
},
|
||||
Body: body,
|
||||
})
|
||||
@ -94,9 +95,9 @@ func (s *entityStoreImpl) Update(ctx context.Context, cmd *playlist.UpdatePlayli
|
||||
return rsp, fmt.Errorf("unable to write playlist to store")
|
||||
}
|
||||
_, err = s.store.Write(ctx, &entity.WriteEntityRequest{
|
||||
GRN: &entity.GRN{
|
||||
UID: rsp.Uid,
|
||||
Kind: entity.StandardKindPlaylist,
|
||||
GRN: &grn.GRN{
|
||||
ResourceIdentifier: rsp.Uid,
|
||||
ResourceKind: entity.StandardKindPlaylist,
|
||||
},
|
||||
Body: body,
|
||||
})
|
||||
@ -111,9 +112,9 @@ func (s *entityStoreImpl) Delete(ctx context.Context, cmd *playlist.DeletePlayli
|
||||
err := s.sqlimpl.store.Delete(ctx, cmd)
|
||||
if err == nil {
|
||||
_, err = s.store.Delete(ctx, &entity.DeleteEntityRequest{
|
||||
GRN: &entity.GRN{
|
||||
UID: cmd.UID,
|
||||
Kind: entity.StandardKindPlaylist,
|
||||
GRN: &grn.GRN{
|
||||
ResourceIdentifier: cmd.UID,
|
||||
ResourceKind: entity.StandardKindPlaylist,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@ -142,9 +143,9 @@ func (s *entityStoreImpl) GetWithoutItems(ctx context.Context, q *playlist.GetPl
|
||||
|
||||
func (s *entityStoreImpl) Get(ctx context.Context, q *playlist.GetPlaylistByUidQuery) (*playlist.PlaylistDTO, error) {
|
||||
rsp, err := s.store.Read(ctx, &entity.ReadEntityRequest{
|
||||
GRN: &entity.GRN{
|
||||
UID: q.UID,
|
||||
Kind: entity.StandardKindPlaylist,
|
||||
GRN: &grn.GRN{
|
||||
ResourceIdentifier: q.UID,
|
||||
ResourceKind: entity.StandardKindPlaylist,
|
||||
},
|
||||
WithBody: true,
|
||||
})
|
||||
@ -178,7 +179,7 @@ func (s *entityStoreImpl) Search(ctx context.Context, q *playlist.GetPlaylistsQu
|
||||
err = json.Unmarshal(res.Body, found)
|
||||
}
|
||||
playlists = append(playlists, &playlist.Playlist{
|
||||
UID: res.GRN.UID,
|
||||
UID: res.GRN.ResourceIdentifier,
|
||||
Name: res.Name,
|
||||
Interval: found.Interval,
|
||||
})
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,25 +1,14 @@
|
||||
syntax = "proto3";
|
||||
package entity;
|
||||
|
||||
option go_package = "./;entity";
|
||||
option go_package = "github.com/grafana/grafana/pkg/services/store/entity";
|
||||
|
||||
message GRN {
|
||||
// the tenant/org id
|
||||
int64 tenant_id = 1;
|
||||
|
||||
// Identify the entity kind. This kind will be used to apply a schema to the body and
|
||||
// will trigger additional indexing behavior.
|
||||
string kind = 3;
|
||||
|
||||
// Unique ID
|
||||
// 40 characters or less, no slashes or other special characters
|
||||
string UID = 4;
|
||||
}
|
||||
import "pkg/infra/grn/grn.proto";
|
||||
|
||||
// The canonical entity/document data -- this represents the raw bytes and storage level metadata
|
||||
message Entity {
|
||||
// Entity identifier
|
||||
GRN GRN = 1;
|
||||
// Entity identifier -- tenant_id, kind, uid
|
||||
grn.GRN GRN = 1;
|
||||
|
||||
// The version will change when the entity is saved. It is not necessarily sortable
|
||||
string version = 2;
|
||||
@ -109,7 +98,7 @@ message EntityVersionInfo {
|
||||
|
||||
message ReadEntityRequest {
|
||||
// Entity identifier
|
||||
GRN GRN = 1;
|
||||
grn.GRN GRN = 1;
|
||||
|
||||
// Fetch an explicit version
|
||||
string version = 2;
|
||||
@ -139,7 +128,7 @@ message BatchReadEntityResponse {
|
||||
|
||||
message WriteEntityRequest {
|
||||
// Entity identifier
|
||||
GRN GRN = 1;
|
||||
grn.GRN GRN = 1;
|
||||
|
||||
// Where to save the entity (empty will leave it unchanged)
|
||||
string folder = 2;
|
||||
@ -159,7 +148,7 @@ message WriteEntityRequest {
|
||||
// This process can bypass the forced checks that
|
||||
message AdminWriteEntityRequest {
|
||||
// Entity identifier
|
||||
GRN GRN = 1;
|
||||
grn.GRN GRN = 1;
|
||||
|
||||
// Where to save the entity (empty will leave it unchanged)
|
||||
string folder = 2;
|
||||
@ -207,7 +196,7 @@ message WriteEntityResponse {
|
||||
EntityErrorInfo error = 1;
|
||||
|
||||
// Entity identifier
|
||||
GRN GRN = 2;
|
||||
grn.GRN GRN = 2;
|
||||
|
||||
// Entity details with the body removed
|
||||
EntityVersionInfo entity = 3;
|
||||
@ -233,7 +222,7 @@ message WriteEntityResponse {
|
||||
|
||||
message DeleteEntityRequest {
|
||||
// Entity identifier
|
||||
GRN GRN = 1;
|
||||
grn.GRN GRN = 1;
|
||||
|
||||
// Used for optimistic locking. If missing, the previous version will be replaced regardless
|
||||
string previous_version = 3;
|
||||
@ -249,7 +238,7 @@ message DeleteEntityResponse {
|
||||
|
||||
message EntityHistoryRequest {
|
||||
// Entity identifier
|
||||
GRN GRN = 1;
|
||||
grn.GRN GRN = 1;
|
||||
|
||||
// Maximum number of items to return
|
||||
int64 limit = 3;
|
||||
@ -260,7 +249,7 @@ message EntityHistoryRequest {
|
||||
|
||||
message EntityHistoryResponse {
|
||||
// Entity identifier
|
||||
GRN GRN = 1;
|
||||
grn.GRN GRN = 1;
|
||||
|
||||
// Entity metadata without the raw bytes
|
||||
repeated EntityVersionInfo versions = 2;
|
||||
@ -309,7 +298,7 @@ message EntitySearchRequest {
|
||||
// Search result metadata for each entity
|
||||
message EntitySearchResult {
|
||||
// Entity identifier
|
||||
GRN GRN = 1;
|
||||
grn.GRN GRN = 1;
|
||||
|
||||
// The current version of this entity
|
||||
string version = 2;
|
||||
@ -368,7 +357,7 @@ message EntityWatchRequest {
|
||||
int64 since = 1;
|
||||
|
||||
// Watch sppecific entities
|
||||
repeated GRN GRN = 2;
|
||||
repeated grn.GRN GRN = 2;
|
||||
|
||||
// limit to a specific kind (empty is all)
|
||||
repeated string kind = 3;
|
||||
|
@ -1,14 +1,13 @@
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.2.0
|
||||
// - protoc v3.21.12
|
||||
// - protoc-gen-go-grpc v1.3.0
|
||||
// - protoc v4.23.4
|
||||
// source: entity.proto
|
||||
|
||||
package entity
|
||||
|
||||
import (
|
||||
context "context"
|
||||
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
@ -19,6 +18,17 @@ import (
|
||||
// Requires gRPC-Go v1.32.0 or later.
|
||||
const _ = grpc.SupportPackageIsVersion7
|
||||
|
||||
const (
|
||||
EntityStore_Read_FullMethodName = "/entity.EntityStore/Read"
|
||||
EntityStore_BatchRead_FullMethodName = "/entity.EntityStore/BatchRead"
|
||||
EntityStore_Write_FullMethodName = "/entity.EntityStore/Write"
|
||||
EntityStore_Delete_FullMethodName = "/entity.EntityStore/Delete"
|
||||
EntityStore_History_FullMethodName = "/entity.EntityStore/History"
|
||||
EntityStore_Search_FullMethodName = "/entity.EntityStore/Search"
|
||||
EntityStore_Watch_FullMethodName = "/entity.EntityStore/Watch"
|
||||
EntityStore_AdminWrite_FullMethodName = "/entity.EntityStore/AdminWrite"
|
||||
)
|
||||
|
||||
// EntityStoreClient is the client API for EntityStore service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
@ -44,7 +54,7 @@ func NewEntityStoreClient(cc grpc.ClientConnInterface) EntityStoreClient {
|
||||
|
||||
func (c *entityStoreClient) Read(ctx context.Context, in *ReadEntityRequest, opts ...grpc.CallOption) (*Entity, error) {
|
||||
out := new(Entity)
|
||||
err := c.cc.Invoke(ctx, "/entity.EntityStore/Read", in, out, opts...)
|
||||
err := c.cc.Invoke(ctx, EntityStore_Read_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -53,7 +63,7 @@ func (c *entityStoreClient) Read(ctx context.Context, in *ReadEntityRequest, opt
|
||||
|
||||
func (c *entityStoreClient) BatchRead(ctx context.Context, in *BatchReadEntityRequest, opts ...grpc.CallOption) (*BatchReadEntityResponse, error) {
|
||||
out := new(BatchReadEntityResponse)
|
||||
err := c.cc.Invoke(ctx, "/entity.EntityStore/BatchRead", in, out, opts...)
|
||||
err := c.cc.Invoke(ctx, EntityStore_BatchRead_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -62,7 +72,7 @@ func (c *entityStoreClient) BatchRead(ctx context.Context, in *BatchReadEntityRe
|
||||
|
||||
func (c *entityStoreClient) Write(ctx context.Context, in *WriteEntityRequest, opts ...grpc.CallOption) (*WriteEntityResponse, error) {
|
||||
out := new(WriteEntityResponse)
|
||||
err := c.cc.Invoke(ctx, "/entity.EntityStore/Write", in, out, opts...)
|
||||
err := c.cc.Invoke(ctx, EntityStore_Write_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -71,7 +81,7 @@ func (c *entityStoreClient) Write(ctx context.Context, in *WriteEntityRequest, o
|
||||
|
||||
func (c *entityStoreClient) Delete(ctx context.Context, in *DeleteEntityRequest, opts ...grpc.CallOption) (*DeleteEntityResponse, error) {
|
||||
out := new(DeleteEntityResponse)
|
||||
err := c.cc.Invoke(ctx, "/entity.EntityStore/Delete", in, out, opts...)
|
||||
err := c.cc.Invoke(ctx, EntityStore_Delete_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -80,7 +90,7 @@ func (c *entityStoreClient) Delete(ctx context.Context, in *DeleteEntityRequest,
|
||||
|
||||
func (c *entityStoreClient) History(ctx context.Context, in *EntityHistoryRequest, opts ...grpc.CallOption) (*EntityHistoryResponse, error) {
|
||||
out := new(EntityHistoryResponse)
|
||||
err := c.cc.Invoke(ctx, "/entity.EntityStore/History", in, out, opts...)
|
||||
err := c.cc.Invoke(ctx, EntityStore_History_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -89,7 +99,7 @@ func (c *entityStoreClient) History(ctx context.Context, in *EntityHistoryReques
|
||||
|
||||
func (c *entityStoreClient) Search(ctx context.Context, in *EntitySearchRequest, opts ...grpc.CallOption) (*EntitySearchResponse, error) {
|
||||
out := new(EntitySearchResponse)
|
||||
err := c.cc.Invoke(ctx, "/entity.EntityStore/Search", in, out, opts...)
|
||||
err := c.cc.Invoke(ctx, EntityStore_Search_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -97,7 +107,7 @@ func (c *entityStoreClient) Search(ctx context.Context, in *EntitySearchRequest,
|
||||
}
|
||||
|
||||
func (c *entityStoreClient) Watch(ctx context.Context, in *EntityWatchRequest, opts ...grpc.CallOption) (EntityStore_WatchClient, error) {
|
||||
stream, err := c.cc.NewStream(ctx, &EntityStore_ServiceDesc.Streams[0], "/entity.EntityStore/Watch", opts...)
|
||||
stream, err := c.cc.NewStream(ctx, &EntityStore_ServiceDesc.Streams[0], EntityStore_Watch_FullMethodName, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -130,7 +140,7 @@ func (x *entityStoreWatchClient) Recv() (*EntityWatchResponse, error) {
|
||||
|
||||
func (c *entityStoreClient) AdminWrite(ctx context.Context, in *AdminWriteEntityRequest, opts ...grpc.CallOption) (*WriteEntityResponse, error) {
|
||||
out := new(WriteEntityResponse)
|
||||
err := c.cc.Invoke(ctx, "/entity.EntityStore/AdminWrite", in, out, opts...)
|
||||
err := c.cc.Invoke(ctx, EntityStore_AdminWrite_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -192,7 +202,7 @@ func RegisterEntityStoreServer(s grpc.ServiceRegistrar, srv EntityStoreServer) {
|
||||
s.RegisterService(&EntityStore_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _EntityStore_Read_Handler(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) {
|
||||
func _EntityStore_Read_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ReadEntityRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
@ -202,15 +212,15 @@ func _EntityStore_Read_Handler(srv any, ctx context.Context, dec func(any) error
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/entity.EntityStore/Read",
|
||||
FullMethod: EntityStore_Read_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req any) (any, error) {
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(EntityStoreServer).Read(ctx, req.(*ReadEntityRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _EntityStore_BatchRead_Handler(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) {
|
||||
func _EntityStore_BatchRead_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(BatchReadEntityRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
@ -220,15 +230,15 @@ func _EntityStore_BatchRead_Handler(srv any, ctx context.Context, dec func(any)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/entity.EntityStore/BatchRead",
|
||||
FullMethod: EntityStore_BatchRead_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req any) (any, error) {
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(EntityStoreServer).BatchRead(ctx, req.(*BatchReadEntityRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _EntityStore_Write_Handler(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) {
|
||||
func _EntityStore_Write_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(WriteEntityRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
@ -238,15 +248,15 @@ func _EntityStore_Write_Handler(srv any, ctx context.Context, dec func(any) erro
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/entity.EntityStore/Write",
|
||||
FullMethod: EntityStore_Write_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req any) (any, error) {
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(EntityStoreServer).Write(ctx, req.(*WriteEntityRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _EntityStore_Delete_Handler(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) {
|
||||
func _EntityStore_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(DeleteEntityRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
@ -256,15 +266,15 @@ func _EntityStore_Delete_Handler(srv any, ctx context.Context, dec func(any) err
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/entity.EntityStore/Delete",
|
||||
FullMethod: EntityStore_Delete_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req any) (any, error) {
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(EntityStoreServer).Delete(ctx, req.(*DeleteEntityRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _EntityStore_History_Handler(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) {
|
||||
func _EntityStore_History_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(EntityHistoryRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
@ -274,15 +284,15 @@ func _EntityStore_History_Handler(srv any, ctx context.Context, dec func(any) er
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/entity.EntityStore/History",
|
||||
FullMethod: EntityStore_History_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req any) (any, error) {
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(EntityStoreServer).History(ctx, req.(*EntityHistoryRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _EntityStore_Search_Handler(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) {
|
||||
func _EntityStore_Search_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(EntitySearchRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
@ -292,15 +302,15 @@ func _EntityStore_Search_Handler(srv any, ctx context.Context, dec func(any) err
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/entity.EntityStore/Search",
|
||||
FullMethod: EntityStore_Search_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req any) (any, error) {
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(EntityStoreServer).Search(ctx, req.(*EntitySearchRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _EntityStore_Watch_Handler(srv any, stream grpc.ServerStream) error {
|
||||
func _EntityStore_Watch_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||
m := new(EntityWatchRequest)
|
||||
if err := stream.RecvMsg(m); err != nil {
|
||||
return err
|
||||
@ -321,7 +331,7 @@ func (x *entityStoreWatchServer) Send(m *EntityWatchResponse) error {
|
||||
return x.ServerStream.SendMsg(m)
|
||||
}
|
||||
|
||||
func _EntityStore_AdminWrite_Handler(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) {
|
||||
func _EntityStore_AdminWrite_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(AdminWriteEntityRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
@ -331,9 +341,9 @@ func _EntityStore_AdminWrite_Handler(srv any, ctx context.Context, dec func(any)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/entity.EntityStore/AdminWrite",
|
||||
FullMethod: EntityStore_AdminWrite_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req any) (any, error) {
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(EntityStoreServer).AdminWrite(ctx, req.(*AdminWriteEntityRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
@ -385,6 +395,10 @@ var EntityStore_ServiceDesc = grpc.ServiceDesc{
|
||||
Metadata: "entity.proto",
|
||||
}
|
||||
|
||||
const (
|
||||
EntityStoreAdmin_AdminWrite_FullMethodName = "/entity.EntityStoreAdmin/AdminWrite"
|
||||
)
|
||||
|
||||
// EntityStoreAdminClient is the client API for EntityStoreAdmin service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
@ -402,7 +416,7 @@ func NewEntityStoreAdminClient(cc grpc.ClientConnInterface) EntityStoreAdminClie
|
||||
|
||||
func (c *entityStoreAdminClient) AdminWrite(ctx context.Context, in *AdminWriteEntityRequest, opts ...grpc.CallOption) (*WriteEntityResponse, error) {
|
||||
out := new(WriteEntityResponse)
|
||||
err := c.cc.Invoke(ctx, "/entity.EntityStoreAdmin/AdminWrite", in, out, opts...)
|
||||
err := c.cc.Invoke(ctx, EntityStoreAdmin_AdminWrite_FullMethodName, in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -435,7 +449,7 @@ func RegisterEntityStoreAdminServer(s grpc.ServiceRegistrar, srv EntityStoreAdmi
|
||||
s.RegisterService(&EntityStoreAdmin_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _EntityStoreAdmin_AdminWrite_Handler(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) {
|
||||
func _EntityStoreAdmin_AdminWrite_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(AdminWriteEntityRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
@ -445,9 +459,9 @@ func _EntityStoreAdmin_AdminWrite_Handler(srv any, ctx context.Context, dec func
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/entity.EntityStoreAdmin/AdminWrite",
|
||||
FullMethod: EntityStoreAdmin_AdminWrite_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req any) (any, error) {
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(EntityStoreAdminServer).AdminWrite(ctx, req.(*AdminWriteEntityRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
|
@ -1,11 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
# To compile all protobuf files in this repository, run
|
||||
# "mage protobuf" at the top-level.
|
||||
# "make protobuf" at the top-level.
|
||||
|
||||
set -eu
|
||||
|
||||
#DST_DIR=../genproto/entity
|
||||
DST_DIR=./
|
||||
|
||||
SOURCE="${BASH_SOURCE[0]}"
|
||||
@ -14,8 +13,12 @@ DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||
|
||||
cd "$DIR"
|
||||
|
||||
protoc -I ./ \
|
||||
protoc \
|
||||
-I ./ \
|
||||
-I ../../../../ \
|
||||
--go_out=${DST_DIR} \
|
||||
--go-grpc_out=${DST_DIR} --go-grpc_opt=require_unimplemented_servers=false \
|
||||
entity.proto
|
||||
|
||||
--go_opt=paths=source_relative \
|
||||
--go-grpc_out=${DST_DIR} \
|
||||
--go-grpc_opt=paths=source_relative \
|
||||
--go-grpc_opt=require_unimplemented_servers=false \
|
||||
*.proto
|
||||
|
@ -1,21 +0,0 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Check if the two GRNs reference to the same object
|
||||
// we can not use simple `*x == *b` because of the internal settings
|
||||
func (x *GRN) Equals(b *GRN) bool {
|
||||
if b == nil {
|
||||
return false
|
||||
}
|
||||
return x == b || (x.TenantId == b.TenantId &&
|
||||
x.Kind == b.Kind &&
|
||||
x.UID == b.UID)
|
||||
}
|
||||
|
||||
// Set an OID based on the GRN
|
||||
func (x *GRN) ToGRNString() string {
|
||||
return fmt.Sprintf("grn:%d/%s/%s", x.TenantId, x.Kind, x.UID)
|
||||
}
|
@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/infra/grn"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
@ -59,7 +60,7 @@ func (s *httpEntityStore) RegisterHTTPRoutes(route routing.RouteRegister) {
|
||||
// This function will extract UID+Kind from the requested path "*" in our router
|
||||
// This is far from ideal! but is at least consistent for these endpoints.
|
||||
// This will quickly be revisited as we explore how to encode UID+Kind in a "GRN" format
|
||||
func (s *httpEntityStore) getGRNFromRequest(c *contextmodel.ReqContext) (*entity.GRN, map[string]string, error) {
|
||||
func (s *httpEntityStore) getGRNFromRequest(c *contextmodel.ReqContext) (*grn.GRN, map[string]string, error) {
|
||||
params := web.Params(c.Req)
|
||||
// Read parameters that are encoded in the URL
|
||||
vals := c.Req.URL.Query()
|
||||
@ -68,10 +69,10 @@ func (s *httpEntityStore) getGRNFromRequest(c *contextmodel.ReqContext) (*entity
|
||||
params[k] = v[0]
|
||||
}
|
||||
}
|
||||
return &entity.GRN{
|
||||
TenantId: c.OrgID,
|
||||
Kind: params[":kind"],
|
||||
UID: params[":uid"],
|
||||
return &grn.GRN{
|
||||
TenantID: c.OrgID,
|
||||
ResourceKind: params[":kind"],
|
||||
ResourceIdentifier: params[":uid"],
|
||||
}, params, nil
|
||||
}
|
||||
|
||||
@ -124,7 +125,7 @@ func (s *httpEntityStore) doGetRawEntity(c *contextmodel.ReqContext) response.Re
|
||||
if err != nil {
|
||||
return response.Error(500, "?", err)
|
||||
}
|
||||
info, err := s.kinds.GetInfo(grn.Kind)
|
||||
info, err := s.kinds.GetInfo(grn.ResourceKind)
|
||||
if err != nil {
|
||||
return response.Error(400, "Unsupported kind", err)
|
||||
}
|
||||
@ -263,10 +264,10 @@ func (s *httpEntityStore) doUpload(c *contextmodel.ReqContext) response.Response
|
||||
return response.Error(500, "Internal Server Error", err)
|
||||
}
|
||||
|
||||
grn := &entity.GRN{
|
||||
UID: uid,
|
||||
Kind: kind.ID,
|
||||
TenantId: c.OrgID,
|
||||
grn := &grn.GRN{
|
||||
ResourceIdentifier: uid,
|
||||
ResourceKind: kind.ID,
|
||||
TenantID: c.OrgID,
|
||||
}
|
||||
|
||||
if !overwriteExistingFile {
|
||||
|
@ -7,6 +7,8 @@ import (
|
||||
"unsafe"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/grn"
|
||||
)
|
||||
|
||||
func init() { //nolint:gochecknoinits
|
||||
@ -128,7 +130,7 @@ func readEntity(iter *jsoniter.Iterator, raw *Entity) {
|
||||
for l1Field := iter.ReadObject(); l1Field != ""; l1Field = iter.ReadObject() {
|
||||
switch l1Field {
|
||||
case "GRN":
|
||||
raw.GRN = &GRN{}
|
||||
raw.GRN = &grn.GRN{}
|
||||
iter.ReadVal(raw.GRN)
|
||||
case "updatedAt":
|
||||
raw.UpdatedAt = iter.ReadInt64()
|
||||
|
@ -5,6 +5,8 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/grn"
|
||||
)
|
||||
|
||||
func TestRawEncoders(t *testing.T) {
|
||||
@ -15,9 +17,9 @@ func TestRawEncoders(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
raw := &Entity{
|
||||
GRN: &GRN{
|
||||
UID: "a",
|
||||
Kind: "b",
|
||||
GRN: &grn.GRN{
|
||||
ResourceIdentifier: "a",
|
||||
ResourceKind: "b",
|
||||
},
|
||||
Version: "c",
|
||||
ETag: "d",
|
||||
@ -31,8 +33,8 @@ func TestRawEncoders(t *testing.T) {
|
||||
|
||||
require.JSONEq(t, `{
|
||||
"GRN": {
|
||||
"kind": "b",
|
||||
"UID": "a"
|
||||
"ResourceKind": "b",
|
||||
"ResourceIdentifier": "a"
|
||||
},
|
||||
"version": "c",
|
||||
"body": {
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/grn"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/session"
|
||||
"github.com/grafana/grafana/pkg/services/store/entity"
|
||||
)
|
||||
@ -140,12 +141,12 @@ func setMPTTOrder(folder *folderInfo, stack []*folderInfo, idx int32) (int32, er
|
||||
|
||||
func insertFolderInfo(ctx context.Context, tx *session.SessionTx, tenant int64, folder *folderInfo, isDetached bool) error {
|
||||
js, _ := json.Marshal(folder.stack)
|
||||
grn := entity.GRN{TenantId: tenant, Kind: entity.StandardKindFolder, UID: folder.UID}
|
||||
grn2 := grn.GRN{TenantID: tenant, ResourceKind: entity.StandardKindFolder, ResourceIdentifier: folder.UID}
|
||||
_, err := tx.Exec(ctx,
|
||||
`INSERT INTO entity_folder `+
|
||||
"(grn, tenant_id, uid, slug_path, tree, depth, left, right, detached) "+
|
||||
`VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
grn.ToGRNString(),
|
||||
grn2.ToGRNString(),
|
||||
tenant,
|
||||
folder.UID,
|
||||
folder.Slug,
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/appcontext"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/grn"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/infra/slugify"
|
||||
"github.com/grafana/grafana/pkg/services/grpcserver"
|
||||
@ -63,13 +64,13 @@ func getReadSelect(r *entity.ReadEntityRequest) string {
|
||||
|
||||
func (s *sqlEntityServer) rowToReadEntityResponse(ctx context.Context, rows *sql.Rows, r *entity.ReadEntityRequest) (*entity.Entity, error) {
|
||||
raw := &entity.Entity{
|
||||
GRN: &entity.GRN{},
|
||||
GRN: &grn.GRN{},
|
||||
Origin: &entity.EntityOriginInfo{},
|
||||
}
|
||||
|
||||
summaryjson := &summarySupport{}
|
||||
args := []any{
|
||||
&raw.GRN.TenantId, &raw.GRN.Kind, &raw.GRN.UID, &raw.Folder,
|
||||
&raw.GRN.TenantID, &raw.GRN.ResourceKind, &raw.GRN.ResourceIdentifier, &raw.Folder,
|
||||
&raw.Version, &raw.Size, &raw.ETag, &summaryjson.errors,
|
||||
&raw.CreatedAt, &raw.CreatedBy,
|
||||
&raw.UpdatedAt, &raw.UpdatedBy,
|
||||
@ -106,7 +107,7 @@ func (s *sqlEntityServer) rowToReadEntityResponse(ctx context.Context, rows *sql
|
||||
return raw, nil
|
||||
}
|
||||
|
||||
func (s *sqlEntityServer) validateGRN(ctx context.Context, grn *entity.GRN) (*entity.GRN, error) {
|
||||
func (s *sqlEntityServer) validateGRN(ctx context.Context, grn *grn.GRN) (*grn.GRN, error) {
|
||||
if grn == nil {
|
||||
return nil, fmt.Errorf("missing GRN")
|
||||
}
|
||||
@ -114,22 +115,22 @@ func (s *sqlEntityServer) validateGRN(ctx context.Context, grn *entity.GRN) (*en
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if grn.TenantId == 0 {
|
||||
grn.TenantId = user.OrgID
|
||||
} else if grn.TenantId != user.OrgID {
|
||||
if grn.TenantID == 0 {
|
||||
grn.TenantID = user.OrgID
|
||||
} else if grn.TenantID != user.OrgID {
|
||||
return nil, fmt.Errorf("tenant ID does not match userID")
|
||||
}
|
||||
|
||||
if grn.Kind == "" {
|
||||
return nil, fmt.Errorf("GRN missing kind")
|
||||
if grn.ResourceKind == "" {
|
||||
return nil, fmt.Errorf("GRN missing ResourceKind")
|
||||
}
|
||||
if grn.UID == "" {
|
||||
return nil, fmt.Errorf("GRN missing UID")
|
||||
if grn.ResourceIdentifier == "" {
|
||||
return nil, fmt.Errorf("GRN missing ResourceIdentifier")
|
||||
}
|
||||
if len(grn.UID) > 40 {
|
||||
return nil, fmt.Errorf("GRN UID is too long (>40)")
|
||||
if len(grn.ResourceIdentifier) > 64 {
|
||||
return nil, fmt.Errorf("GRN ResourceIdentifier is too long (>64)")
|
||||
}
|
||||
if strings.ContainsAny(grn.UID, "/#$@?") {
|
||||
if strings.ContainsAny(grn.ResourceIdentifier, "/#$@?") {
|
||||
return nil, fmt.Errorf("invalid character in GRN")
|
||||
}
|
||||
return grn, nil
|
||||
@ -199,9 +200,9 @@ func (s *sqlEntityServer) readFromHistory(ctx context.Context, r *entity.ReadEnt
|
||||
|
||||
// Dynamically create the summary
|
||||
if r.WithSummary {
|
||||
builder := s.kinds.GetSummaryBuilder(r.GRN.Kind)
|
||||
builder := s.kinds.GetSummaryBuilder(r.GRN.ResourceKind)
|
||||
if builder != nil {
|
||||
val, out, err := builder(ctx, r.GRN.UID, raw.Body)
|
||||
val, out, err := builder(ctx, r.GRN.ResourceIdentifier, raw.Body)
|
||||
if err == nil {
|
||||
raw.Body = out // cleaned up
|
||||
raw.SummaryJson, err = json.Marshal(val)
|
||||
@ -438,7 +439,7 @@ func (s *sqlEntityServer) AdminWrite(ctx context.Context, r *entity.AdminWriteEn
|
||||
" ?, ?, ?, "+
|
||||
" ?, ?, ?, "+
|
||||
" ?, ?, ?)",
|
||||
oid, grn.TenantId, grn.Kind, grn.UID, r.Folder,
|
||||
oid, grn.TenantID, grn.ResourceKind, grn.ResourceIdentifier, r.Folder,
|
||||
versionInfo.Size, body, etag, versionInfo.Version,
|
||||
updatedAt, createdBy, createdAt, createdBy,
|
||||
summary.model.Name, summary.model.Description, summary.model.Slug,
|
||||
@ -446,8 +447,8 @@ func (s *sqlEntityServer) AdminWrite(ctx context.Context, r *entity.AdminWriteEn
|
||||
origin.Source, origin.Key, origin.Time,
|
||||
)
|
||||
}
|
||||
if err == nil && entity.StandardKindFolder == r.GRN.Kind {
|
||||
err = updateFolderTree(ctx, tx, grn.TenantId)
|
||||
if err == nil && entity.StandardKindFolder == r.GRN.ResourceKind {
|
||||
err = updateFolderTree(ctx, tx, grn.TenantID)
|
||||
}
|
||||
if err == nil {
|
||||
summary.folder = r.Folder
|
||||
@ -514,7 +515,7 @@ func (s *sqlEntityServer) selectForUpdate(ctx context.Context, tx *session.Sessi
|
||||
func (s *sqlEntityServer) writeSearchInfo(
|
||||
ctx context.Context,
|
||||
tx *session.SessionTx,
|
||||
grn string,
|
||||
grn2 string,
|
||||
summary *summarySupport,
|
||||
) error {
|
||||
parent_grn := summary.getParentGRN()
|
||||
@ -525,7 +526,7 @@ func (s *sqlEntityServer) writeSearchInfo(
|
||||
`INSERT INTO entity_labels `+
|
||||
"(grn, label, value, parent_grn) "+
|
||||
`VALUES (?, ?, ?, ?)`,
|
||||
grn, k, v, parent_grn,
|
||||
grn2, k, v, parent_grn,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -542,7 +543,7 @@ func (s *sqlEntityServer) writeSearchInfo(
|
||||
"grn, parent_grn, family, type, id, "+
|
||||
"resolved_ok, resolved_to, resolved_warning, resolved_time) "+
|
||||
`VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
grn, parent_grn, ref.Family, ref.Type, ref.Identifier,
|
||||
grn2, parent_grn, ref.Family, ref.Type, ref.Identifier,
|
||||
resolved.OK, resolved.Key, resolved.Warning, resolved.Timestamp,
|
||||
)
|
||||
if err != nil {
|
||||
@ -553,10 +554,10 @@ func (s *sqlEntityServer) writeSearchInfo(
|
||||
// Traverse entities and insert refs
|
||||
if summary.model.Nested != nil {
|
||||
for _, childModel := range summary.model.Nested {
|
||||
grn = (&entity.GRN{
|
||||
TenantId: summary.parent_grn.TenantId,
|
||||
Kind: childModel.Kind,
|
||||
UID: childModel.UID, // append???
|
||||
grn2 = (&grn.GRN{
|
||||
TenantID: summary.parent_grn.TenantID,
|
||||
ResourceKind: childModel.Kind,
|
||||
ResourceIdentifier: childModel.UID, // append???
|
||||
}).ToGRNString()
|
||||
|
||||
child, err := newSummarySupport(childModel)
|
||||
@ -577,17 +578,16 @@ func (s *sqlEntityServer) writeSearchInfo(
|
||||
" ?, ?, ?, ?,"+
|
||||
" ?, ?,"+
|
||||
" ?, ?, ?)",
|
||||
*parent_grn, grn,
|
||||
summary.parent_grn.TenantId, childModel.Kind, childModel.UID, summary.folder,
|
||||
*parent_grn, grn2,
|
||||
summary.parent_grn.TenantID, childModel.Kind, childModel.UID, summary.folder,
|
||||
child.name, child.description,
|
||||
child.labels, child.fields, child.errors,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = s.writeSearchInfo(ctx, tx, grn, child)
|
||||
err = s.writeSearchInfo(ctx, tx, grn2, child)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -598,13 +598,12 @@ func (s *sqlEntityServer) writeSearchInfo(
|
||||
}
|
||||
|
||||
func (s *sqlEntityServer) prepare(ctx context.Context, r *entity.AdminWriteEntityRequest) (*summarySupport, []byte, error) {
|
||||
grn := r.GRN
|
||||
builder := s.kinds.GetSummaryBuilder(grn.Kind)
|
||||
builder := s.kinds.GetSummaryBuilder(r.GRN.ResourceKind)
|
||||
if builder == nil {
|
||||
return nil, nil, fmt.Errorf("unsupported kind")
|
||||
}
|
||||
|
||||
summary, body, err := builder(ctx, grn.UID, r.Body)
|
||||
summary, body, err := builder(ctx, r.GRN.ResourceIdentifier, r.Body)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@ -613,7 +612,7 @@ func (s *sqlEntityServer) prepare(ctx context.Context, r *entity.AdminWriteEntit
|
||||
if summary.Slug == "" {
|
||||
t := summary.Name
|
||||
if t == "" {
|
||||
t = r.GRN.UID
|
||||
t = r.GRN.ResourceIdentifier
|
||||
}
|
||||
summary.Slug = slugify.Slugify(t)
|
||||
}
|
||||
@ -627,21 +626,21 @@ func (s *sqlEntityServer) prepare(ctx context.Context, r *entity.AdminWriteEntit
|
||||
}
|
||||
|
||||
func (s *sqlEntityServer) Delete(ctx context.Context, r *entity.DeleteEntityRequest) (*entity.DeleteEntityResponse, error) {
|
||||
grn, err := s.validateGRN(ctx, r.GRN)
|
||||
grn2, err := s.validateGRN(ctx, r.GRN)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rsp := &entity.DeleteEntityResponse{}
|
||||
err = s.sess.WithTransaction(ctx, func(tx *session.SessionTx) error {
|
||||
rsp.OK, err = doDelete(ctx, tx, grn)
|
||||
rsp.OK, err = doDelete(ctx, tx, grn2)
|
||||
return err
|
||||
})
|
||||
return rsp, err
|
||||
}
|
||||
|
||||
func doDelete(ctx context.Context, tx *session.SessionTx, grn *entity.GRN) (bool, error) {
|
||||
str := grn.ToGRNString()
|
||||
func doDelete(ctx context.Context, tx *session.SessionTx, grn2 *grn.GRN) (bool, error) {
|
||||
str := grn2.ToGRNString()
|
||||
results, err := tx.Exec(ctx, "DELETE FROM entity WHERE grn=?", str)
|
||||
if err != nil {
|
||||
return false, err
|
||||
@ -669,18 +668,18 @@ func doDelete(ctx context.Context, tx *session.SessionTx, grn *entity.GRN) (bool
|
||||
return false, err
|
||||
}
|
||||
|
||||
if grn.Kind == entity.StandardKindFolder {
|
||||
err = updateFolderTree(ctx, tx, grn.TenantId)
|
||||
if grn2.ResourceKind == entity.StandardKindFolder {
|
||||
err = updateFolderTree(ctx, tx, grn2.TenantID)
|
||||
}
|
||||
return rows > 0, err
|
||||
}
|
||||
|
||||
func (s *sqlEntityServer) History(ctx context.Context, r *entity.EntityHistoryRequest) (*entity.EntityHistoryResponse, error) {
|
||||
grn, err := s.validateGRN(ctx, r.GRN)
|
||||
grn2, err := s.validateGRN(ctx, r.GRN)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
oid := grn.ToGRNString()
|
||||
oid := grn2.ToGRNString()
|
||||
|
||||
page := ""
|
||||
args := []any{oid}
|
||||
@ -789,12 +788,12 @@ func (s *sqlEntityServer) Search(ctx context.Context, r *entity.EntitySearchRequ
|
||||
rsp := &entity.EntitySearchResponse{}
|
||||
for rows.Next() {
|
||||
result := &entity.EntitySearchResult{
|
||||
GRN: &entity.GRN{},
|
||||
GRN: &grn.GRN{},
|
||||
}
|
||||
summaryjson := summarySupport{}
|
||||
|
||||
args := []any{
|
||||
&oid, &result.GRN.TenantId, &result.GRN.Kind, &result.GRN.UID,
|
||||
&oid, &result.GRN.TenantID, &result.GRN.ResourceKind, &result.GRN.ResourceIdentifier,
|
||||
&result.Version, &result.Folder, &result.Slug, &summaryjson.errors,
|
||||
&result.Size, &result.UpdatedAt, &result.UpdatedBy,
|
||||
&result.Name, &summaryjson.description,
|
||||
|
@ -3,6 +3,7 @@ package sqlstash
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/grn"
|
||||
"github.com/grafana/grafana/pkg/services/store/entity"
|
||||
)
|
||||
|
||||
@ -17,7 +18,7 @@ type summarySupport struct {
|
||||
marshaled []byte
|
||||
|
||||
// metadata for nested objects
|
||||
parent_grn *entity.GRN
|
||||
parent_grn *grn.GRN
|
||||
folder string
|
||||
isNested bool // set when this is for a nested item
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/grpc/metadata"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/grn"
|
||||
"github.com/grafana/grafana/pkg/services/store"
|
||||
"github.com/grafana/grafana/pkg/services/store/entity"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
@ -24,7 +25,7 @@ var (
|
||||
)
|
||||
|
||||
type rawEntityMatcher struct {
|
||||
grn *entity.GRN
|
||||
grn *grn.GRN
|
||||
createdRange []time.Time
|
||||
updatedRange []time.Time
|
||||
createdBy string
|
||||
@ -53,14 +54,14 @@ func requireEntityMatch(t *testing.T, obj *entity.Entity, m rawEntityMatcher) {
|
||||
|
||||
mismatches := ""
|
||||
if m.grn != nil {
|
||||
if m.grn.TenantId > 0 && m.grn.TenantId != obj.GRN.TenantId {
|
||||
mismatches += fmt.Sprintf("expected tenant: %d, actual: %d\n", m.grn.TenantId, obj.GRN.TenantId)
|
||||
if m.grn.TenantID > 0 && m.grn.TenantID != obj.GRN.TenantID {
|
||||
mismatches += fmt.Sprintf("expected tenant: %d, actual: %d\n", m.grn.TenantID, obj.GRN.TenantID)
|
||||
}
|
||||
if m.grn.Kind != "" && m.grn.Kind != obj.GRN.Kind {
|
||||
mismatches += fmt.Sprintf("expected Kind: %s, actual: %s\n", m.grn.Kind, obj.GRN.Kind)
|
||||
if m.grn.ResourceKind != "" && m.grn.ResourceKind != obj.GRN.ResourceKind {
|
||||
mismatches += fmt.Sprintf("expected ResourceKind: %s, actual: %s\n", m.grn.ResourceKind, obj.GRN.ResourceKind)
|
||||
}
|
||||
if m.grn.UID != "" && m.grn.UID != obj.GRN.UID {
|
||||
mismatches += fmt.Sprintf("expected UID: %s, actual: %s\n", m.grn.UID, obj.GRN.UID)
|
||||
if m.grn.ResourceIdentifier != "" && m.grn.ResourceIdentifier != obj.GRN.ResourceIdentifier {
|
||||
mismatches += fmt.Sprintf("expected ResourceIdentifier: %s, actual: %s\n", m.grn.ResourceIdentifier, obj.GRN.ResourceIdentifier)
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,15 +135,15 @@ func TestIntegrationEntityServer(t *testing.T) {
|
||||
fakeUser := store.GetUserIDString(testCtx.user)
|
||||
firstVersion := "1"
|
||||
kind := entity.StandardKindJSONObj
|
||||
grn := &entity.GRN{
|
||||
Kind: kind,
|
||||
UID: "my-test-entity",
|
||||
testGrn := &grn.GRN{
|
||||
ResourceKind: kind,
|
||||
ResourceIdentifier: "my-test-entity",
|
||||
}
|
||||
body := []byte("{\"name\":\"John\"}")
|
||||
|
||||
t.Run("should not retrieve non-existent objects", func(t *testing.T) {
|
||||
resp, err := testCtx.client.Read(ctx, &entity.ReadEntityRequest{
|
||||
GRN: grn,
|
||||
GRN: testGrn,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -153,7 +154,7 @@ func TestIntegrationEntityServer(t *testing.T) {
|
||||
t.Run("should be able to read persisted objects", func(t *testing.T) {
|
||||
before := time.Now()
|
||||
writeReq := &entity.WriteEntityRequest{
|
||||
GRN: grn,
|
||||
GRN: testGrn,
|
||||
Body: body,
|
||||
Comment: "first entity!",
|
||||
}
|
||||
@ -169,7 +170,7 @@ func TestIntegrationEntityServer(t *testing.T) {
|
||||
requireVersionMatch(t, writeResp.Entity, versionMatcher)
|
||||
|
||||
readResp, err := testCtx.client.Read(ctx, &entity.ReadEntityRequest{
|
||||
GRN: grn,
|
||||
GRN: testGrn,
|
||||
Version: "",
|
||||
WithBody: true,
|
||||
})
|
||||
@ -179,12 +180,12 @@ func TestIntegrationEntityServer(t *testing.T) {
|
||||
|
||||
foundGRN := readResp.GRN
|
||||
require.NotNil(t, foundGRN)
|
||||
require.Equal(t, testCtx.user.OrgID, foundGRN.TenantId) // orgId becomes the tenant id when not set
|
||||
require.Equal(t, grn.Kind, foundGRN.Kind)
|
||||
require.Equal(t, grn.UID, foundGRN.UID)
|
||||
require.Equal(t, testCtx.user.OrgID, foundGRN.TenantID) // orgId becomes the tenant id when not set
|
||||
require.Equal(t, testGrn.ResourceKind, foundGRN.ResourceKind)
|
||||
require.Equal(t, testGrn.ResourceIdentifier, foundGRN.ResourceIdentifier)
|
||||
|
||||
objectMatcher := rawEntityMatcher{
|
||||
grn: grn,
|
||||
grn: testGrn,
|
||||
createdRange: []time.Time{before, time.Now()},
|
||||
updatedRange: []time.Time{before, time.Now()},
|
||||
createdBy: fakeUser,
|
||||
@ -195,14 +196,14 @@ func TestIntegrationEntityServer(t *testing.T) {
|
||||
requireEntityMatch(t, readResp, objectMatcher)
|
||||
|
||||
deleteResp, err := testCtx.client.Delete(ctx, &entity.DeleteEntityRequest{
|
||||
GRN: grn,
|
||||
GRN: testGrn,
|
||||
PreviousVersion: writeResp.Entity.Version,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.True(t, deleteResp.OK)
|
||||
|
||||
readRespAfterDelete, err := testCtx.client.Read(ctx, &entity.ReadEntityRequest{
|
||||
GRN: grn,
|
||||
GRN: testGrn,
|
||||
Version: "",
|
||||
WithBody: true,
|
||||
})
|
||||
@ -212,13 +213,13 @@ func TestIntegrationEntityServer(t *testing.T) {
|
||||
|
||||
t.Run("should be able to update an object", func(t *testing.T) {
|
||||
before := time.Now()
|
||||
grn := &entity.GRN{
|
||||
Kind: kind,
|
||||
UID: util.GenerateShortUID(),
|
||||
testGrn := &grn.GRN{
|
||||
ResourceKind: kind,
|
||||
ResourceIdentifier: util.GenerateShortUID(),
|
||||
}
|
||||
|
||||
writeReq1 := &entity.WriteEntityRequest{
|
||||
GRN: grn,
|
||||
GRN: testGrn,
|
||||
Body: body,
|
||||
Comment: "first entity!",
|
||||
}
|
||||
@ -229,7 +230,7 @@ func TestIntegrationEntityServer(t *testing.T) {
|
||||
body2 := []byte("{\"name\":\"John2\"}")
|
||||
|
||||
writeReq2 := &entity.WriteEntityRequest{
|
||||
GRN: grn,
|
||||
GRN: testGrn,
|
||||
Body: body2,
|
||||
Comment: "update1",
|
||||
}
|
||||
@ -247,7 +248,7 @@ func TestIntegrationEntityServer(t *testing.T) {
|
||||
|
||||
body3 := []byte("{\"name\":\"John3\"}")
|
||||
writeReq3 := &entity.WriteEntityRequest{
|
||||
GRN: grn,
|
||||
GRN: testGrn,
|
||||
Body: body3,
|
||||
Comment: "update3",
|
||||
}
|
||||
@ -256,7 +257,7 @@ func TestIntegrationEntityServer(t *testing.T) {
|
||||
require.NotEqual(t, writeResp3.Entity.Version, writeResp2.Entity.Version)
|
||||
|
||||
latestMatcher := rawEntityMatcher{
|
||||
grn: grn,
|
||||
grn: testGrn,
|
||||
createdRange: []time.Time{before, time.Now()},
|
||||
updatedRange: []time.Time{before, time.Now()},
|
||||
createdBy: fakeUser,
|
||||
@ -265,7 +266,7 @@ func TestIntegrationEntityServer(t *testing.T) {
|
||||
version: &writeResp3.Entity.Version,
|
||||
}
|
||||
readRespLatest, err := testCtx.client.Read(ctx, &entity.ReadEntityRequest{
|
||||
GRN: grn,
|
||||
GRN: testGrn,
|
||||
Version: "", // latest
|
||||
WithBody: true,
|
||||
})
|
||||
@ -274,7 +275,7 @@ func TestIntegrationEntityServer(t *testing.T) {
|
||||
requireEntityMatch(t, readRespLatest, latestMatcher)
|
||||
|
||||
readRespFirstVer, err := testCtx.client.Read(ctx, &entity.ReadEntityRequest{
|
||||
GRN: grn,
|
||||
GRN: testGrn,
|
||||
Version: writeResp1.Entity.Version,
|
||||
WithBody: true,
|
||||
})
|
||||
@ -283,7 +284,7 @@ func TestIntegrationEntityServer(t *testing.T) {
|
||||
require.Nil(t, readRespFirstVer.SummaryJson)
|
||||
require.NotNil(t, readRespFirstVer)
|
||||
requireEntityMatch(t, readRespFirstVer, rawEntityMatcher{
|
||||
grn: grn,
|
||||
grn: testGrn,
|
||||
createdRange: []time.Time{before, time.Now()},
|
||||
updatedRange: []time.Time{before, time.Now()},
|
||||
createdBy: fakeUser,
|
||||
@ -293,7 +294,7 @@ func TestIntegrationEntityServer(t *testing.T) {
|
||||
})
|
||||
|
||||
history, err := testCtx.client.History(ctx, &entity.EntityHistoryRequest{
|
||||
GRN: grn,
|
||||
GRN: testGrn,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []*entity.EntityVersionInfo{
|
||||
@ -303,7 +304,7 @@ func TestIntegrationEntityServer(t *testing.T) {
|
||||
}, history.Versions)
|
||||
|
||||
deleteResp, err := testCtx.client.Delete(ctx, &entity.DeleteEntityRequest{
|
||||
GRN: grn,
|
||||
GRN: testGrn,
|
||||
PreviousVersion: writeResp3.Entity.Version,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
@ -316,33 +317,33 @@ func TestIntegrationEntityServer(t *testing.T) {
|
||||
uid4 := "uid4"
|
||||
kind2 := entity.StandardKindPlaylist
|
||||
w1, err := testCtx.client.Write(ctx, &entity.WriteEntityRequest{
|
||||
GRN: grn,
|
||||
GRN: testGrn,
|
||||
Body: body,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
w2, err := testCtx.client.Write(ctx, &entity.WriteEntityRequest{
|
||||
GRN: &entity.GRN{
|
||||
UID: uid2,
|
||||
Kind: kind,
|
||||
GRN: &grn.GRN{
|
||||
ResourceIdentifier: uid2,
|
||||
ResourceKind: kind,
|
||||
},
|
||||
Body: body,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
w3, err := testCtx.client.Write(ctx, &entity.WriteEntityRequest{
|
||||
GRN: &entity.GRN{
|
||||
UID: uid3,
|
||||
Kind: kind2,
|
||||
GRN: &grn.GRN{
|
||||
ResourceIdentifier: uid3,
|
||||
ResourceKind: kind2,
|
||||
},
|
||||
Body: body,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
w4, err := testCtx.client.Write(ctx, &entity.WriteEntityRequest{
|
||||
GRN: &entity.GRN{
|
||||
UID: uid4,
|
||||
Kind: kind2,
|
||||
GRN: &grn.GRN{
|
||||
ResourceIdentifier: uid4,
|
||||
ResourceKind: kind2,
|
||||
},
|
||||
Body: body,
|
||||
})
|
||||
@ -359,8 +360,8 @@ func TestIntegrationEntityServer(t *testing.T) {
|
||||
kinds := make([]string, 0, len(search.Results))
|
||||
version := make([]string, 0, len(search.Results))
|
||||
for _, res := range search.Results {
|
||||
uids = append(uids, res.GRN.UID)
|
||||
kinds = append(kinds, res.GRN.Kind)
|
||||
uids = append(uids, res.GRN.ResourceIdentifier)
|
||||
kinds = append(kinds, res.GRN.ResourceKind)
|
||||
version = append(version, res.Version)
|
||||
}
|
||||
require.Equal(t, []string{"my-test-entity", "uid2", "uid3", "uid4"}, uids)
|
||||
@ -381,8 +382,8 @@ func TestIntegrationEntityServer(t *testing.T) {
|
||||
kinds = make([]string, 0, len(searchKind1.Results))
|
||||
version = make([]string, 0, len(searchKind1.Results))
|
||||
for _, res := range searchKind1.Results {
|
||||
uids = append(uids, res.GRN.UID)
|
||||
kinds = append(kinds, res.GRN.Kind)
|
||||
uids = append(uids, res.GRN.ResourceIdentifier)
|
||||
kinds = append(kinds, res.GRN.ResourceKind)
|
||||
version = append(version, res.Version)
|
||||
}
|
||||
require.Equal(t, []string{"my-test-entity", "uid2"}, uids)
|
||||
@ -396,18 +397,18 @@ func TestIntegrationEntityServer(t *testing.T) {
|
||||
t.Run("should be able to filter objects based on their labels", func(t *testing.T) {
|
||||
kind := entity.StandardKindDashboard
|
||||
_, err := testCtx.client.Write(ctx, &entity.WriteEntityRequest{
|
||||
GRN: &entity.GRN{
|
||||
Kind: kind,
|
||||
UID: "blue-green",
|
||||
GRN: &grn.GRN{
|
||||
ResourceKind: kind,
|
||||
ResourceIdentifier: "blue-green",
|
||||
},
|
||||
Body: []byte(dashboardWithTagsBlueGreen),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = testCtx.client.Write(ctx, &entity.WriteEntityRequest{
|
||||
GRN: &entity.GRN{
|
||||
Kind: kind,
|
||||
UID: "red-green",
|
||||
GRN: &grn.GRN{
|
||||
ResourceKind: kind,
|
||||
ResourceIdentifier: "red-green",
|
||||
},
|
||||
Body: []byte(dashboardWithTagsRedGreen),
|
||||
})
|
||||
@ -424,7 +425,7 @@ func TestIntegrationEntityServer(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, search)
|
||||
require.Len(t, search.Results, 1)
|
||||
require.Equal(t, search.Results[0].GRN.UID, "red-green")
|
||||
require.Equal(t, search.Results[0].GRN.ResourceIdentifier, "red-green")
|
||||
|
||||
search, err = testCtx.client.Search(ctx, &entity.EntitySearchRequest{
|
||||
Kind: []string{kind},
|
||||
@ -438,7 +439,7 @@ func TestIntegrationEntityServer(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, search)
|
||||
require.Len(t, search.Results, 1)
|
||||
require.Equal(t, search.Results[0].GRN.UID, "red-green")
|
||||
require.Equal(t, search.Results[0].GRN.ResourceIdentifier, "red-green")
|
||||
|
||||
search, err = testCtx.client.Search(ctx, &entity.EntitySearchRequest{
|
||||
Kind: []string{kind},
|
||||
|
Reference in New Issue
Block a user