-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
because the insights rbac client use other Filter Data type, we need to reimplement the rbac client for inventory needs. FIXES: https://issues.redhat.com/browse/THEEDGE-3624 FIXES: https://issues.redhat.com/browse/THEEDGE-3734
- Loading branch information
Showing
7 changed files
with
346 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package rbac | ||
|
||
import "strings" | ||
|
||
const permissionDelimiter = ":" | ||
|
||
// AccessList is a slice of Accesses and is generally used to represent a principal's | ||
// full set of permissions for an application | ||
type AccessList []Access | ||
|
||
// Access represents a permission and an optional resource definition | ||
type Access struct { | ||
ResourceDefinitions []ResourceDefinition `json:"resourceDefinitions,omitempty"` | ||
Permission string `json:"permission"` | ||
} | ||
|
||
// ResourceDefinition limits an Access to specific resources | ||
type ResourceDefinition struct { | ||
Filter ResourceDefinitionFilter `json:"attributeFilter"` | ||
} | ||
|
||
// ResourceDefinitionFilter represents the key/values used for filtering | ||
type ResourceDefinitionFilter struct { | ||
Key string `json:"key"` | ||
Operation string `json:"operation"` | ||
Value []*string `json:"value"` | ||
} | ||
|
||
// Application returns the name of the application in the permission | ||
func (a Access) Application() string { | ||
return permIndex(a.Permission, 0) | ||
} | ||
|
||
// Resource returns the name of the resource in the permission | ||
func (a Access) Resource() string { | ||
return permIndex(a.Permission, 1) | ||
} | ||
|
||
// AccessType returns the access type in the permission | ||
func (a Access) AccessType() string { | ||
return permIndex(a.Permission, 2) | ||
} | ||
|
||
// permIndex return the permission item value at index when splitting by permission delimiter | ||
// the permission looks like "inventory:hosts:read" where: | ||
// inventory is the application name and locate at index 0 | ||
// hosts is the resource and located at index 1 | ||
// read is the access type and located at index 2 | ||
func permIndex(permission string, index int) string { | ||
permissionItems := strings.Split(permission, permissionDelimiter) | ||
// a correct permission must have 3 items application:resource:access-type | ||
if len(permissionItems) == 3 { | ||
return permissionItems[index] | ||
} | ||
return "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.