mirror of https://github.com/grafana/grafana
Zanzana: reconcile generic schema (#95492)
* Rename to CheckObject * Implement authz.AccessClient * Move folder tree to reconciler and use new schema * Move shared functionality to common package * Add reconciler for managed permissions and resource translations * Add support for folder resourcespull/95508/head
parent
7b5c84f366
commit
e0163c93c2
@ -0,0 +1,34 @@ |
||||
package common |
||||
|
||||
import ( |
||||
"github.com/grafana/grafana/pkg/apimachinery/utils" |
||||
|
||||
folderalpha1 "github.com/grafana/grafana/pkg/apis/folder/v0alpha1" |
||||
) |
||||
|
||||
type TypeInfo struct { |
||||
Type string |
||||
} |
||||
|
||||
var typedResources = map[string]TypeInfo{ |
||||
NewNamespaceResourceIdent( |
||||
folderalpha1.FolderResourceInfo.GroupResource().Group, |
||||
folderalpha1.FolderResourceInfo.GroupResource().Resource, |
||||
): TypeInfo{Type: "folder2"}, |
||||
} |
||||
|
||||
func GetTypeInfo(group, resource string) (TypeInfo, bool) { |
||||
info, ok := typedResources[NewNamespaceResourceIdent(group, resource)] |
||||
return info, ok |
||||
} |
||||
|
||||
var VerbMapping = map[string]string{ |
||||
utils.VerbGet: "read", |
||||
utils.VerbList: "read", |
||||
utils.VerbWatch: "read", |
||||
utils.VerbCreate: "create", |
||||
utils.VerbUpdate: "write", |
||||
utils.VerbPatch: "write", |
||||
utils.VerbDelete: "delete", |
||||
utils.VerbDeleteCollection: "delete", |
||||
} |
@ -0,0 +1,86 @@ |
||||
package common |
||||
|
||||
import ( |
||||
"fmt" |
||||
|
||||
openfgav1 "github.com/openfga/api/proto/openfga/v1" |
||||
"google.golang.org/protobuf/types/known/structpb" |
||||
) |
||||
|
||||
const ( |
||||
resourceType = "resource" |
||||
namespaceType = "namespace" |
||||
folderResourceType = "folder_resource" |
||||
) |
||||
|
||||
func NewTypedIdent(typ string, name string) string { |
||||
return fmt.Sprintf("%s:%s", typ, name) |
||||
} |
||||
|
||||
func NewResourceIdent(group, resource, name string) string { |
||||
return fmt.Sprintf("%s:%s/%s", resourceType, FormatGroupResource(group, resource), name) |
||||
} |
||||
|
||||
func NewFolderResourceIdent(group, resource, folder string) string { |
||||
return fmt.Sprintf("%s:%s/%s", folderResourceType, FormatGroupResource(group, resource), folder) |
||||
} |
||||
|
||||
func NewNamespaceResourceIdent(group, resource string) string { |
||||
return fmt.Sprintf("%s:%s", namespaceType, FormatGroupResource(group, resource)) |
||||
} |
||||
|
||||
func FormatGroupResource(group, resource string) string { |
||||
return fmt.Sprintf("%s/%s", group, resource) |
||||
} |
||||
|
||||
func NewResourceTuple(subject, relation, group, resource, name string) *openfgav1.TupleKey { |
||||
return &openfgav1.TupleKey{ |
||||
User: subject, |
||||
Relation: relation, |
||||
Object: NewResourceIdent(group, resource, name), |
||||
Condition: &openfgav1.RelationshipCondition{ |
||||
Name: "group_filter", |
||||
Context: &structpb.Struct{ |
||||
Fields: map[string]*structpb.Value{ |
||||
"resource_group": structpb.NewStringValue(FormatGroupResource(group, resource)), |
||||
}, |
||||
}, |
||||
}, |
||||
} |
||||
} |
||||
|
||||
func NewFolderResourceTuple(subject, relation, group, resource, folder string) *openfgav1.TupleKey { |
||||
return &openfgav1.TupleKey{ |
||||
User: subject, |
||||
Relation: relation, |
||||
Object: NewFolderResourceIdent(group, resource, folder), |
||||
Condition: &openfgav1.RelationshipCondition{ |
||||
Name: "group_filter", |
||||
Context: &structpb.Struct{ |
||||
Fields: map[string]*structpb.Value{ |
||||
"resource_group": structpb.NewStringValue(FormatGroupResource(group, resource)), |
||||
}, |
||||
}, |
||||
}, |
||||
} |
||||
} |
||||
|
||||
func NewNamespaceResourceTuple(subject, relation, group, resource string) *openfgav1.TupleKey { |
||||
return &openfgav1.TupleKey{ |
||||
User: subject, |
||||
Relation: relation, |
||||
Object: NewNamespaceResourceIdent(group, resource), |
||||
} |
||||
} |
||||
|
||||
func NewFolderTuple(subject, relation, name string) *openfgav1.TupleKey { |
||||
return NewTypedTuple("folder2", subject, relation, name) |
||||
} |
||||
|
||||
func NewTypedTuple(typ, subject, relation, name string) *openfgav1.TupleKey { |
||||
return &openfgav1.TupleKey{ |
||||
User: subject, |
||||
Relation: relation, |
||||
Object: NewTypedIdent(typ, name), |
||||
} |
||||
} |
Loading…
Reference in new issue