Skip to content

Commit

Permalink
Persist Evaluation objects (#196)
Browse files Browse the repository at this point in the history
* Add evaluation to api and map to sql model

* Call evaluation endpoint from evaluation.py

* Fix orm_mode for Evaluation model

* Evaluation output message

* add a timestamp to the end of the uuid, allow a user to pass a message through from the CLI

Co-authored-by: Eduardo Armendariz <eduardo@ethyca.com>
Co-authored-by: Thomas La Piana <tal103020@icloud.com>
  • Loading branch information
3 people authored Oct 29, 2021
1 parent acd4f1a commit b6fd951
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/fides/docs/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The `fidesctl` API is exceedingly formulaic, so much so that it's easier to gras
| Completely overwrite the `fides_key` resource. |`POST /policy/{fides_key}`| `200` |
| Delete the `fides_key` resource. | `DELETE /policy/{fides_key}`| `204`|

* The URLs of the endpoints emulate the names of the resources: `/organization`, `/policy`, `/registry`, `/system`, `/dataset`, `/data_category`, `/data_use`, `/data_subject`, `/data_qualifier`.
* The URLs of the endpoints emulate the names of the resources: `/organization`, `/policy`, `/registry`, `/system`, `/dataset`, `/data_category`, `/data_use`, `/data_subject`, `/data_qualifier`, `/evaluation`.

* Except for the `DELETE`, the endpoints accept and/or return JSON objects that represent the named resource. The structure of these objects is given in the [Fides Language: Resources chapter](../language/resources.html) -- it's the same structure that's used in the resource manifest files.

Expand Down
1 change: 1 addition & 0 deletions fidesctl/src/fidesapi/sql_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,5 @@ class System(SqlAlchemyBase, FidesBase):
"policy": Policy,
"registry": Registry,
"system": System,
"evaluation": Evaluation,
}
20 changes: 17 additions & 3 deletions fidesctl/src/fidesctl/core/evaluate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Module for evaluating policies."""
from typing import Dict, List, Optional, Callable, cast

import uuid
import time
from pydantic import AnyHttpUrl

from fidesctl.cli.utils import handle_cli_response, pretty_echo
Expand Down Expand Up @@ -461,7 +463,14 @@ def execute_evaluation(taxonomy: Taxonomy) -> Evaluation:
status_enum = (
StatusEnum.FAIL if len(evaluation_detail_list) > 0 else StatusEnum.PASS
)
evaluation = Evaluation(status=status_enum, details=evaluation_detail_list)
new_uuid = str(uuid.uuid4()).replace("-", "_")
timestamp = str(time.time()).split(".")[0]
generated_key = f"{new_uuid}_{timestamp}"
evaluation = Evaluation(
fides_key=generated_key,
status=status_enum,
details=evaluation_detail_list,
)
return evaluation


Expand Down Expand Up @@ -531,10 +540,15 @@ def evaluate(
echo_green("Executing evaluations...")
evaluation = execute_evaluation(taxonomy)
evaluation.message = message

# TODO: add the evaluations endpoint to the API
if not dry:
echo_green("Sending the evaluation results to the server...")
response = api.create(
url=url,
resource_type="evaluation",
json_resource=evaluation.json(exclude_none=True),
headers=headers,
)
handle_cli_response(response, verbose=False)

if evaluation.status == "FAIL":
pretty_echo(evaluation.dict(), color="red")
Expand Down
6 changes: 4 additions & 2 deletions fidesctl/src/fideslang/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Exports various fideslang objects for easier use elsewhere.
"""

from typing import Dict, Type
from typing import Dict, Type, Union

# Export the Models
from .models import (
Expand All @@ -25,7 +25,8 @@
)
from .default_taxonomy import DEFAULT_TAXONOMY

model_map: Dict[str, Type[FidesModel]] = {
ModelTypeUnion = Union[Type[FidesModel], Type[Evaluation]]
model_map: Dict[str, ModelTypeUnion] = {
"data_category": DataCategory,
"data_qualifier": DataQualifier,
"data_subject": DataSubject,
Expand All @@ -35,5 +36,6 @@
"policy": Policy,
"registry": Registry,
"system": System,
"evaluation": Evaluation,
}
model_list = list(model_map.keys())
6 changes: 6 additions & 0 deletions fidesctl/src/fideslang/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,16 @@ class Evaluation(BaseModel):
This resource is created after an evaluation is executed.
"""

fides_key: FidesKey
status: StatusEnum
details: List[str]
message: str = ""

class Config:
"Config for the Evaluation"
extra = "ignore"
orm_mode = True


# Organization
class Organization(FidesModel):
Expand Down

0 comments on commit b6fd951

Please sign in to comment.