Skip to content

Commit

Permalink
Ordering added for consistency (#212)
Browse files Browse the repository at this point in the history
* Ordering added for consistency

* Update RELEASE_NOTES.md

* autopep8 action fixes (#213)

Co-authored-by: Cerfoglg <[email protected]>

* Middleware op ordering

* autopep8 action fixes (#214)

Co-authored-by: Cerfoglg <[email protected]>

* Revert "Middleware op ordering"

This reverts commit 82c74d9.

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Cerfoglg <[email protected]>
  • Loading branch information
3 people authored Mar 17, 2023
1 parent 214da8a commit 2e69fad
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- Fix potential issue in LUA script for policy creation on entity creation
- Added counter header in responses to policy GETs
- Fixed issues with /me endpoint not retrieving policies correctly
- Ordering for polciies and tenants to avoid pagination issues

### Documentation

Expand Down
16 changes: 11 additions & 5 deletions anubis-management-api/anubis/policies/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def get_policies_by_service_path(
db_policies = filter_policies_by_user_profile(
db_policies, tenant, user_info)
counter = db_policies.count()
return db_policies.offset(skip).limit(limit).all(), counter
return db_policies.order_by(models.Policy.id.asc()).offset(
skip).limit(limit).all(), counter
elif mode is None and agent is not None:
return get_policies_by_agent(
db=db,
Expand Down Expand Up @@ -114,7 +115,8 @@ def get_policies_by_mode(
db_policies = filter_policies_by_user_profile(
db_policies, tenant, user_info)
counter = db_policies.count()
return db_policies.offset(skip).limit(limit).all(), counter
return db_policies.order_by(models.Policy.id.asc()).offset(
skip).limit(limit).all(), counter


def get_policies_by_agent(
Expand Down Expand Up @@ -142,7 +144,8 @@ def get_policies_by_agent(
db_policies = filter_policies_by_user_profile(
db_policies, tenant, user_info)
counter = db_policies.count()
return db_policies.offset(skip).limit(limit).all(), counter
return db_policies.order_by(models.Policy.id.asc()).offset(
skip).limit(limit).all(), counter


def _get_policies_by_service_path(
Expand Down Expand Up @@ -177,15 +180,18 @@ def _get_policies_by_service_path(
db_policies = filter_policies_by_user_profile(
db_policies, tenant, user_info)
counter = db_policies.count()
return db_policies.offset(skip).limit(limit).all(), counter
return db_policies.order_by(models.Policy.id.asc()).offset(
skip).limit(limit).all(), counter


def get_policy_by_access_to(db: Session, access_to: str):
return db.query(models.Policy).filter(models.Policy.access_to == access_to)


def get_policies(db: Session, skip: int = 0, limit: int = defaultLimit):
return db.query(models.Policy).offset(skip).limit(limit).all()
return db.query(
models.Policy).order_by(
models.Policy.id.asc()).offset(skip).limit(limit).all()


def filter_policies_by_user_profile(db_policies, tenant, user_info):
Expand Down
16 changes: 11 additions & 5 deletions anubis-management-api/anubis/tenants/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def get_tenant_by_name(db: Session, name: str):


def get_tenants(db: Session, skip: int = 0, limit: int = 100):
return db.query(models.Tenant).offset(skip).limit(limit).all()
return db.query(
models.Tenant).order_by(
models.Tenant.name.asc()).offset(skip).limit(limit).all()


def create_tenant(
Expand Down Expand Up @@ -69,7 +71,8 @@ def delete_tenant(db: Session, tenant: models.Tenant):


def get_service_paths(db: Session, skip: int = 0, limit: int = 100):
return db.query(models.ServicePath).offset(skip).limit(limit).all()
return db.query(models.ServicePath).order_by(
models.ServicePath.path.asc()).offset(skip).limit(limit).all()


def get_tenant_service_paths(
Expand All @@ -83,7 +86,8 @@ def get_tenant_service_paths(
if name:
db_service_paths = db_service_paths.filter(
models.ServicePath.path.startswith(name))
return db_service_paths.offset(skip).limit(limit).all()
return db_service_paths.order_by(
models.ServicePath.path.asc()).offset(skip).limit(limit).all()


def get_db_service_path(db: Session, tenant: str, service_path: str):
Expand All @@ -105,12 +109,14 @@ def get_tenant_service_path_by_path(db: Session, tenant_id: str, path: str):
return db.query(
models.ServicePath).filter(
models.ServicePath.tenant_id == tenant_id).filter(
models.ServicePath.path.like(queryPath)).all()
models.ServicePath.path.like(queryPath)).order_by(
models.ServicePath.path.asc()).all()
else:
return db.query(
models.ServicePath).filter(
models.ServicePath.tenant_id == tenant_id).filter(
models.ServicePath.path == path).all()
models.ServicePath.path == path).order_by(
models.ServicePath.path.asc()).all()


def get_tenant_service_path(db: Session, service_path_id: str, tenant_id: str):
Expand Down

0 comments on commit 2e69fad

Please sign in to comment.