Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Replace fidesctl package with fideslang package #454

Merged
merged 3 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ emails
fastapi-caching[redis]
fastapi-pagination[sqlalchemy]~= 0.8.3
fastapi[all]==0.68.1
fidesctl==0.9.8.4
fideslang==1.0.0
multidimensional_urlencode==0.0.4
pandas==1.3.3
passlib[bcrypt]==1.7.2
Expand Down
5 changes: 2 additions & 3 deletions src/fidesops/schemas/dataset.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Dict, List, Optional

from fideslang.models import Dataset, DatasetCollection, DatasetField
from fideslang.models import Dataset, DatasetCollection, DatasetFieldBase
from pydantic import BaseModel, ConstrainedStr, validator

from fidesops.common_exceptions import (
Expand Down Expand Up @@ -121,11 +121,10 @@ def valid_length(cls, v: Optional[int]) -> Optional[int]:
return _valid_data_length(v)


class FidesopsDatasetField(DatasetField):
class FidesopsDatasetField(DatasetFieldBase):
"""Extends fideslang DatasetField model with additional Fidesops annotations"""

fidesops_meta: Optional[FidesopsMeta]

fields: Optional[List["FidesopsDatasetField"]] = []

@validator("data_categories")
Expand Down
2 changes: 1 addition & 1 deletion src/fidesops/schemas/shared_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def validate(cls, value: Optional[str]) -> Optional[str]:
"""Throws ValueError if val is not a valid FidesKey"""
if value is not None and not cls.regex.match(value):
raise ValueError(
"FidesKey must only contain alphanumeric characters, '.' or '_'."
"FidesKey must only contain alphanumeric characters, '.', '_' or '-'."
)

return value
4 changes: 2 additions & 2 deletions tests/api/v1/endpoints/test_policy_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def test_create_policy_with_invalid_key(
generate_auth_header,
storage_config,
):
key = "here-is-an-invalid-key"
key = "here*is*an*invalid*key"
data = [
{
"name": "test create policy api",
Expand All @@ -537,7 +537,7 @@ def test_create_policy_with_invalid_key(
assert resp.status_code == 422
assert (
json.loads(resp.text)["detail"][0]["msg"]
== "FidesKey must only contain alphanumeric characters, '.' or '_'."
== "FidesKey must only contain alphanumeric characters, '.', '_' or '-'."
)

def test_create_policy_already_exists(
Expand Down
2 changes: 1 addition & 1 deletion tests/api/v1/endpoints/test_storage_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def test_put_storage_config_with_invalid_key(
assert 422 == response.status_code
assert (
json.loads(response.text)["detail"][0]["msg"]
== "FidesKey must only contain alphanumeric characters, '.' or '_'."
== "FidesKey must only contain alphanumeric characters, '.', '_' or '-'."
)

@mock.patch(
Expand Down
10 changes: 8 additions & 2 deletions tests/models/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,27 @@ def test_get_key_from_data_method() -> None:
key = get_key_from_data({"key": "test_key", "name": "config name"}, "StorageConfig")
assert key == "test_key"


def test_get_key_from_data_method_no_key() -> None:
# Test no key
key = get_key_from_data({"name": "config name"}, "StorageConfig")
assert key == "config_name"


def test_get_key_from_data_method_no_data() -> None:
# Test no data
with pytest.raises(KeyValidationError) as exc:
get_key_from_data({}, "StorageConfig")
assert str(exc.value) == "StorageConfig requires a name."


def test_get_key_from_data_method_invalid_key() -> None:
# Test key not valid
with pytest.raises(ValueError) as exc:
get_key_from_data({"key": "test-key", "name": "config name"}, "StorageConfig")
get_key_from_data({"key": "test*key", "name": "config name"}, "StorageConfig")
assert (
str(exc.value)
== "FidesKey must only contain alphanumeric characters, '.' or '_'."
== "FidesKey must only contain alphanumeric characters, '.', '_' or '-'."
)


Expand Down
11 changes: 6 additions & 5 deletions tests/util/test_dataset_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
- name: submitter
"""
example_bad_dataset_nested_yaml = """dataset:
- fides_key: mongo_nested_test
- fides_key: mongo_nested_test
name: Mongo Example Nested Test Dataset
description: Example of a Mongo dataset that contains nested data
collections:
Expand All @@ -117,7 +117,7 @@
data_type: string
- name: submitter
data_type: string
data_categories: [user.provided.identifiable]
data_categories: [user.provided.identifiable]
"""


Expand Down Expand Up @@ -155,12 +155,13 @@ def test_dataset_yaml_format_invalid_fides_keys():
dataset = __to_dataset__(example_dataset_yaml)
dataset.get("collections")[0].get("fidesops_meta").get("after")[
0
] = "invalid-dataset-name.invalid-collection-name"
] = "invalid*dataset*name.invalid*collection*name"
with pytest.raises(ValueError) as exc:
d: FidesopsDataset = FidesopsDataset.parse_obj(dataset)
convert_dataset_to_graph(d, "ignore")
assert "FidesKey must only contain alphanumeric characters, '.' or '_'." in str(
exc.value
assert (
"FidesKey must only contain alphanumeric characters, '.', '_' or '-'."
in str(exc.value)
)


Expand Down