Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PROD-2352 helper: get_urn_list method #5192

Merged
merged 10 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The types of changes are:
- Adds user_read scope to approver role so that they can update their own password [#5178](https://github.com/ethyca/fides/pull/5178)
- Added PATCH endpoint for partially updating connection secrets [#5172](https://github.com/ethyca/fides/pull/5172)
- Add success toast on confirming classification in data discovery tables [#5182](https://github.com/ethyca/fides/pull/5182)
- Add function to return list of StagedResource objs according to list of URNs [#5192](https://github.com/ethyca/fides/pull/5192)

### Fixed
- Fixed the OAuth2 configuration for the Snap integration [#5158](https://github.com/ethyca/fides/pull/5158)
Expand Down
11 changes: 10 additions & 1 deletion src/fides/api/models/detection_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from enum import Enum
from typing import Any, Dict, Iterable, Optional, Type

from sqlalchemy import ARRAY, Boolean, Column, DateTime, ForeignKey, String
from sqlalchemy import ARRAY, Boolean, Column, DateTime, ForeignKey, String, select
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.ext.mutable import MutableDict
from sqlalchemy.orm import Session, relationship
Expand Down Expand Up @@ -280,6 +280,15 @@ class StagedResource(Base):
def get_urn(cls, db: Session, urn: str) -> Optional[StagedResource]:
"""Utility to retrieve the staged resource with the given URN"""
return cls.get_by(db=db, field="urn", value=urn)

@classmethod
def get_urn_list(cls, db: Session, urns: Iterable[str]) -> Iterable[StagedResource]:
"""
Utility to retrieve all staged resources with the given URNs
"""

results = db.execute(select(StagedResource).where(StagedResource.urn.in_(urns)))
return results.scalars().all()

def add_child_diff_status(self, diff_status: DiffStatus) -> None:
"""Increments the specified child diff status"""
Expand Down
5 changes: 5 additions & 0 deletions tests/ops/models/test_detection_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ def create_staged_resource(self, db: Session):
},
)
return resource

def test_get_urn_list(self, db: Session, create_staged_resource) -> None:
urn_list = [create_staged_resource.urn]
from_db = StagedResource.get_urn_list(db, urn_list)
assert len(from_db) == len(urn_list)
thingscouldbeworse marked this conversation as resolved.
Show resolved Hide resolved

def test_create_staged_resource(self, db: Session, create_staged_resource) -> None:
"""
Expand Down
Loading