-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
27 - Middleware for distributed policies (#139)
* Endpoint for listing managed resources (i.e. resources for which there is an `acl:Control` policy) * Middleware for policy distribution * Basic CI test for policy distribution Co-authored-by: Cerfoglg <[email protected]> Co-authored-by: Federico M. Facca <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
8fe3cb3
commit d7a7e7f
Showing
41 changed files
with
18,400 additions
and
38 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
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
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
Empty file.
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,68 @@ | ||
from sqlalchemy.orm import Session | ||
|
||
import anubis.default as default | ||
from ..policies import models as pm | ||
from ..tenants import models as tm | ||
|
||
|
||
# TODO it would be good to have also the list of owners, but query needs | ||
# to be defined | ||
def get_resources( | ||
db: Session, | ||
tenant: str = None, | ||
service_path: str = None, | ||
resource: str = None, | ||
resource_type: str = None, | ||
owner: str = None, | ||
skip: int = 0, | ||
limit: int = 100): | ||
db_policies = db.query( | ||
pm.Policy.access_to, | ||
pm.Policy.resource_type, | ||
tm.ServicePath.path, | ||
tm.Tenant.name).distinct().join( | ||
pm.Policy.mode).filter( | ||
pm.Mode.iri == default.CONTROL_MODE_IRI).join( | ||
pm.Policy.service_path).join( | ||
tm.ServicePath.tenant) | ||
if resource: | ||
db_policies = db_policies.filter( | ||
pm.Policy.access_to == resource) | ||
if resource_type: | ||
db_policies = db_policies.filter( | ||
pm.Policy.resource_type == resource_type) | ||
if tenant: | ||
db_policies = db_policies.filter( | ||
tm.Tenant.name == tenant) | ||
if service_path: | ||
db_policies = db_policies.filter( | ||
tm.ServicePath.path == service_path) | ||
if owner: | ||
db_policies = db_policies.join( | ||
pm.Policy.agent).filter(pm.Agent.iri == owner) | ||
return db_policies.offset(skip).limit(limit).all() | ||
|
||
|
||
def get_policies( | ||
db: Session, | ||
tenant: str = None, | ||
service_path: str = None, | ||
resource: str = None, | ||
resource_type: str = None, | ||
skip: int = 0, | ||
limit: int = 100): | ||
db_policies = db.query(pm.Policy) | ||
if resource: | ||
db_policies = db_policies.filter( | ||
pm.Policy.access_to == resource) | ||
if resource_type: | ||
db_policies = db_policies.filter( | ||
pm.Policy.resource_type == resource_type) | ||
if tenant: | ||
db_policies = db_policies.join(pm.Policy.service_path).join( | ||
tm.ServicePath.tenant).filter( | ||
tm.Tenant.name == tenant) | ||
if service_path: | ||
db_policies = db_policies.join(pm.Policy.service_path).filter( | ||
tm.ServicePath.path == service_path) | ||
return db_policies.offset(skip).limit(limit).all() |
Oops, something went wrong.