From e8492489098ef5f8566214e083cd2c2d1d449f5a Mon Sep 17 00:00:00 2001 From: Matthias Baumgartner Date: Thu, 8 Dec 2022 16:36:19 +0100 Subject: sparql triple store and graph (nodes, mostly) --- bsfs/graph/ac/__init__.py | 20 ++++++++++++++ bsfs/graph/ac/base.py | 67 +++++++++++++++++++++++++++++++++++++++++++++++ bsfs/graph/ac/null.py | 53 +++++++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 bsfs/graph/ac/__init__.py create mode 100644 bsfs/graph/ac/base.py create mode 100644 bsfs/graph/ac/null.py (limited to 'bsfs/graph/ac') diff --git a/bsfs/graph/ac/__init__.py b/bsfs/graph/ac/__init__.py new file mode 100644 index 0000000..420de01 --- /dev/null +++ b/bsfs/graph/ac/__init__.py @@ -0,0 +1,20 @@ +""" + +Part of the BlackStar filesystem (bsfs) module. +A copy of the license is provided with the project. +Author: Matthias Baumgartner, 2022 +""" +# imports +import typing + +# inner-module imports +from .base import AccessControlBase +from .null import NullAC + +# exports +__all__: typing.Sequence[str] = ( + 'AccessControlBase', + 'NullAC', + ) + +## EOF ## diff --git a/bsfs/graph/ac/base.py b/bsfs/graph/ac/base.py new file mode 100644 index 0000000..70475d2 --- /dev/null +++ b/bsfs/graph/ac/base.py @@ -0,0 +1,67 @@ +""" + +Part of the BlackStar filesystem (bsfs) module. +A copy of the license is provided with the project. +Author: Matthias Baumgartner, 2022 +""" +# imports +import abc +import typing + +# bsfs imports +from bsfs import schema as _schema +from bsfs.triple_store import TripleStoreBase +from bsfs.utils import URI + +# exports +__all__: typing.Sequence[str] = ( + 'AccessControlBase', + ) + + +## code ## + +class AccessControlBase(abc.ABC): + """ + """ + + # + __backend: TripleStoreBase + + # + __user: URI + + def __init__( + self, + backend: TripleStoreBase, + user: URI, + ): + self.__backend = backend + self.__user = URI(user) + + @abc.abstractmethod + def is_protected_predicate(self, pred: _schema.Predicate) -> bool: + """Return True if a predicate cannot be modified manually.""" + + @abc.abstractmethod + def create(self, node_type: _schema.Node, guids: typing.Iterable[URI]): + """Perform post-creation operations on nodes, e.g. ownership information.""" + + @abc.abstractmethod + def link_from_node(self, node_type: _schema.Node, guids: typing.Iterable[URI]) -> typing.Iterable[URI]: + """Return nodes for which outbound links can be written.""" + + @abc.abstractmethod + def link_to_node(self, node_type: _schema.Node, guids: typing.Iterable[URI]) -> typing.Iterable[URI]: + """Return nodes for which inbound links can be written.""" + + @abc.abstractmethod + def write_literal(self, node_type: _schema.Node, guids: typing.Iterable[URI]) -> typing.Iterable[URI]: + """Return nodes to which literals can be attached.""" + + @abc.abstractmethod + def createable(self, node_type: _schema.Node, guids: typing.Iterable[URI]) -> typing.Iterable[URI]: + """Return nodes that are allowed to be created.""" + + +## EOF ## diff --git a/bsfs/graph/ac/null.py b/bsfs/graph/ac/null.py new file mode 100644 index 0000000..a39b7b9 --- /dev/null +++ b/bsfs/graph/ac/null.py @@ -0,0 +1,53 @@ +""" + +Part of the BlackStar filesystem (bsfs) module. +A copy of the license is provided with the project. +Author: Matthias Baumgartner, 2022 +""" +# imports +import typing + +# bsfs imports +from bsfs import schema as _schema +from bsfs.namespace import ns +from bsfs.utils import URI + +# inner-module imports +from . import base + +# exports +__all__: typing.Sequence[str] = ( + 'NullAC', + ) + + +## code ## + +class NullAC(base.AccessControlBase): + """ + """ + + def is_protected_predicate(self, pred: _schema.Predicate) -> bool: + """Return True if a predicate cannot be modified manually.""" + return pred.uri == ns.bsm.t_created + + def create(self, node_type: _schema.Node, guids: typing.Iterable[URI]): + """Perform post-creation operations on nodes, e.g. ownership information.""" + + def link_from_node(self, node_type: _schema.Node, guids: typing.Iterable[URI]) -> typing.Iterable[URI]: + """Return nodes for which outbound links can be written.""" + return guids + + def link_to_node(self, node_type: _schema.Node, guids: typing.Iterable[URI]) -> typing.Iterable[URI]: + """Return nodes for which inbound links can be written.""" + return guids + + def write_literal(self, node_type: _schema.Node, guids: typing.Iterable[URI]) -> typing.Iterable[URI]: + """Return nodes to which literals can be attached.""" + return guids + + def createable(self, node_type: _schema.Node, guids: typing.Iterable[URI]) -> typing.Iterable[URI]: + """Return nodes that are allowed to be created.""" + return guids + +## EOF ## -- cgit v1.2.3 From ebc3ccb5fdce950649bfcbf18f88ecb4a9dbcad0 Mon Sep 17 00:00:00 2001 From: Matthias Baumgartner Date: Sun, 18 Dec 2022 13:53:34 +0100 Subject: import fixes --- bsfs/graph/ac/base.py | 14 +++++++------- bsfs/graph/ac/null.py | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) (limited to 'bsfs/graph/ac') diff --git a/bsfs/graph/ac/base.py b/bsfs/graph/ac/base.py index 70475d2..eef444b 100644 --- a/bsfs/graph/ac/base.py +++ b/bsfs/graph/ac/base.py @@ -9,7 +9,7 @@ import abc import typing # bsfs imports -from bsfs import schema as _schema +from bsfs import schema from bsfs.triple_store import TripleStoreBase from bsfs.utils import URI @@ -40,27 +40,27 @@ class AccessControlBase(abc.ABC): self.__user = URI(user) @abc.abstractmethod - def is_protected_predicate(self, pred: _schema.Predicate) -> bool: + def is_protected_predicate(self, pred: schema.Predicate) -> bool: """Return True if a predicate cannot be modified manually.""" @abc.abstractmethod - def create(self, node_type: _schema.Node, guids: typing.Iterable[URI]): + def create(self, node_type: schema.Node, guids: typing.Iterable[URI]): """Perform post-creation operations on nodes, e.g. ownership information.""" @abc.abstractmethod - def link_from_node(self, node_type: _schema.Node, guids: typing.Iterable[URI]) -> typing.Iterable[URI]: + def link_from_node(self, node_type: schema.Node, guids: typing.Iterable[URI]) -> typing.Iterable[URI]: """Return nodes for which outbound links can be written.""" @abc.abstractmethod - def link_to_node(self, node_type: _schema.Node, guids: typing.Iterable[URI]) -> typing.Iterable[URI]: + def link_to_node(self, node_type: schema.Node, guids: typing.Iterable[URI]) -> typing.Iterable[URI]: """Return nodes for which inbound links can be written.""" @abc.abstractmethod - def write_literal(self, node_type: _schema.Node, guids: typing.Iterable[URI]) -> typing.Iterable[URI]: + def write_literal(self, node_type: schema.Node, guids: typing.Iterable[URI]) -> typing.Iterable[URI]: """Return nodes to which literals can be attached.""" @abc.abstractmethod - def createable(self, node_type: _schema.Node, guids: typing.Iterable[URI]) -> typing.Iterable[URI]: + def createable(self, node_type: schema.Node, guids: typing.Iterable[URI]) -> typing.Iterable[URI]: """Return nodes that are allowed to be created.""" diff --git a/bsfs/graph/ac/null.py b/bsfs/graph/ac/null.py index a39b7b9..288a0da 100644 --- a/bsfs/graph/ac/null.py +++ b/bsfs/graph/ac/null.py @@ -8,7 +8,7 @@ Author: Matthias Baumgartner, 2022 import typing # bsfs imports -from bsfs import schema as _schema +from bsfs import schema from bsfs.namespace import ns from bsfs.utils import URI @@ -27,26 +27,26 @@ class NullAC(base.AccessControlBase): """ """ - def is_protected_predicate(self, pred: _schema.Predicate) -> bool: + def is_protected_predicate(self, pred: schema.Predicate) -> bool: """Return True if a predicate cannot be modified manually.""" return pred.uri == ns.bsm.t_created - def create(self, node_type: _schema.Node, guids: typing.Iterable[URI]): + def create(self, node_type: schema.Node, guids: typing.Iterable[URI]): """Perform post-creation operations on nodes, e.g. ownership information.""" - def link_from_node(self, node_type: _schema.Node, guids: typing.Iterable[URI]) -> typing.Iterable[URI]: + def link_from_node(self, node_type: schema.Node, guids: typing.Iterable[URI]) -> typing.Iterable[URI]: """Return nodes for which outbound links can be written.""" return guids - def link_to_node(self, node_type: _schema.Node, guids: typing.Iterable[URI]) -> typing.Iterable[URI]: + def link_to_node(self, node_type: schema.Node, guids: typing.Iterable[URI]) -> typing.Iterable[URI]: """Return nodes for which inbound links can be written.""" return guids - def write_literal(self, node_type: _schema.Node, guids: typing.Iterable[URI]) -> typing.Iterable[URI]: + def write_literal(self, node_type: schema.Node, guids: typing.Iterable[URI]) -> typing.Iterable[URI]: """Return nodes to which literals can be attached.""" return guids - def createable(self, node_type: _schema.Node, guids: typing.Iterable[URI]) -> typing.Iterable[URI]: + def createable(self, node_type: schema.Node, guids: typing.Iterable[URI]) -> typing.Iterable[URI]: """Return nodes that are allowed to be created.""" return guids -- cgit v1.2.3 From edd5390b6db1550f6a80a46f0eaf5f3916997532 Mon Sep 17 00:00:00 2001 From: Matthias Baumgartner Date: Sun, 18 Dec 2022 14:06:58 +0100 Subject: information hiding --- bsfs/graph/ac/base.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'bsfs/graph/ac') diff --git a/bsfs/graph/ac/base.py b/bsfs/graph/ac/base.py index eef444b..80742d7 100644 --- a/bsfs/graph/ac/base.py +++ b/bsfs/graph/ac/base.py @@ -25,19 +25,19 @@ class AccessControlBase(abc.ABC): """ """ - # - __backend: TripleStoreBase + # The triple store backend. + _backend: TripleStoreBase - # - __user: URI + # The current user. + _user: URI def __init__( self, backend: TripleStoreBase, user: URI, ): - self.__backend = backend - self.__user = URI(user) + self._backend = backend + self._user = URI(user) @abc.abstractmethod def is_protected_predicate(self, pred: schema.Predicate) -> bool: -- cgit v1.2.3 From e19c8f9d0818a147832df0945188ea14de9c7690 Mon Sep 17 00:00:00 2001 From: Matthias Baumgartner Date: Sun, 18 Dec 2022 14:15:18 +0100 Subject: documentation, types, and style fixes --- bsfs/graph/ac/base.py | 6 +++++- bsfs/graph/ac/null.py | 3 +-- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'bsfs/graph/ac') diff --git a/bsfs/graph/ac/base.py b/bsfs/graph/ac/base.py index 80742d7..bc9aeb3 100644 --- a/bsfs/graph/ac/base.py +++ b/bsfs/graph/ac/base.py @@ -22,7 +22,11 @@ __all__: typing.Sequence[str] = ( ## code ## class AccessControlBase(abc.ABC): - """ + """Defines the interface for access control policies. + + An access control policy governs which actions a user may take to query + or to manipulate a graph. + """ # The triple store backend. diff --git a/bsfs/graph/ac/null.py b/bsfs/graph/ac/null.py index 288a0da..36838bd 100644 --- a/bsfs/graph/ac/null.py +++ b/bsfs/graph/ac/null.py @@ -24,8 +24,7 @@ __all__: typing.Sequence[str] = ( ## code ## class NullAC(base.AccessControlBase): - """ - """ + """The NULL access control implements a dummy policy that allows any action to any user.""" def is_protected_predicate(self, pred: schema.Predicate) -> bool: """Return True if a predicate cannot be modified manually.""" -- cgit v1.2.3