Move datasource scopes and actions to access control package (#46334)
* create scope provider * move datasource actions and scopes to datasource package + add provider * change usages to use datasource scopes and update data source name resolver to use provider * move folder permissions to dashboard package and update usages
This commit is contained in:
@@ -22,6 +22,14 @@ func GetResourceScope(resource string, resourceID string) string {
|
||||
return Scope(resource, "id", resourceID)
|
||||
}
|
||||
|
||||
func GetResourceScopeUID(resource string, resourceID string) string {
|
||||
return Scope(resource, "uid", resourceID)
|
||||
}
|
||||
|
||||
func GetResourceScopeName(resource string, resourceID string) string {
|
||||
return Scope(resource, "name", resourceID)
|
||||
}
|
||||
|
||||
func GetResourceAllScope(resource string) string {
|
||||
return Scope(resource, "*")
|
||||
}
|
||||
@@ -165,3 +173,48 @@ func ScopeInjector(params ScopeParams) ScopeMutator {
|
||||
return buf.String(), nil
|
||||
}
|
||||
}
|
||||
|
||||
// ScopeProvider provides methods that construct scopes
|
||||
type ScopeProvider interface {
|
||||
GetResourceScope(resourceID string) string
|
||||
GetResourceScopeUID(resourceID string) string
|
||||
GetResourceScopeName(resourceID string) string
|
||||
GetResourceAllScope() string
|
||||
GetResourceAllIDScope() string
|
||||
}
|
||||
|
||||
type scopeProviderImpl struct {
|
||||
root string
|
||||
}
|
||||
|
||||
// NewScopeProvider creates a new ScopeProvider that is configured with specific root scope
|
||||
func NewScopeProvider(root string) ScopeProvider {
|
||||
return &scopeProviderImpl{
|
||||
root: root,
|
||||
}
|
||||
}
|
||||
|
||||
// GetResourceScope returns scope that has the format "<rootScope>:id:<resourceID>"
|
||||
func (s scopeProviderImpl) GetResourceScope(resourceID string) string {
|
||||
return GetResourceScope(s.root, resourceID)
|
||||
}
|
||||
|
||||
// GetResourceScopeUID returns scope that has the format "<rootScope>:uid:<resourceID>"
|
||||
func (s scopeProviderImpl) GetResourceScopeUID(resourceID string) string {
|
||||
return GetResourceScopeUID(s.root, resourceID)
|
||||
}
|
||||
|
||||
// GetResourceScopeName returns scope that has the format "<rootScope>:name:<resourceID>"
|
||||
func (s scopeProviderImpl) GetResourceScopeName(resourceID string) string {
|
||||
return GetResourceScopeName(s.root, resourceID)
|
||||
}
|
||||
|
||||
// GetResourceAllScope returns scope that has the format "<rootScope>:*"
|
||||
func (s scopeProviderImpl) GetResourceAllScope() string {
|
||||
return GetResourceAllScope(s.root)
|
||||
}
|
||||
|
||||
// GetResourceAllIDScope returns scope that has the format "<rootScope>:id:*"
|
||||
func (s scopeProviderImpl) GetResourceAllIDScope() string {
|
||||
return GetResourceAllIDScope(s.root)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user