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

check if there is a better way to extract resource linked by accessTo #151

Open
github-actions bot opened this issue Oct 24, 2022 · 0 comments
Open
Labels
enhancement New feature or request todo
Milestone

Comments

@github-actions
Copy link
Contributor

# TODO deal with this better.

acl = Namespace("http://www.w3.org/ns/auth/acl#")
oc_acl = Namespace("http://voc.orchestracities.io/oc-acl#")


def parse_rdf_graph(data):
    g = Graph()
    g.bind("acl", acl)
    g.bind("oc_acl", oc_acl)
    g.parse(data=data)
    nm = NamespaceManager(g)
    policies = {}
    for subj, pred, obj in g:
        policy = str(subj).split("/")[-1]
        if not policies.get(policy):
            policies[policy] = {}
        if pred == acl.agentClass:
            policies[policy]["agentClass"] = redux(str(nm.normalizeUri(obj)))
        if pred == acl.mode:
            policies[policy]["mode"] = redux(str(nm.normalizeUri(obj)))
        # TODO deal with this better.
        if pred == acl.accessTo:
            policies[policy]["accessTo"] = str(obj).split("/")[-1]
        if pred == acl.default:
            policies[policy]["accessTo"] = "default"
        if pred == acl.accessToClass:
            policies[policy]["accessToClass"] = str(
                nm.normalizeUri(obj)).split(":")[-1]
    return policies


def redux(uri: str):
    if "http://www.w3.org/ns/auth/acl#" in uri:
        return "acl:" + uri[len("http://www.w3.org/ns/auth/acl#") + 1:-1]
    if "http://voc.orchestracities.io/oc-acl#" in uri:
        return "oc-acl:" + \
            uri[len("http://voc.orchestracities.io/oc-acl#") + 1:-1]
    if "http://xmlns.com/foaf/0.1/" in uri:
        return "foaf:" + uri[len("http://xmlns.com/foaf/0.1/") + 1:-1]
    if "<" in uri[0] and ">" in uri[-1]:
        return uri[1:-1]
    return uri


def serialize(
        db: Session,
        fiware_service: [str],
@github-actions github-actions bot added the todo label Oct 24, 2022
@chicco785 chicco785 added this to the 1.0 milestone Oct 27, 2022
@chicco785 chicco785 changed the title deal with this better. check if there is a better way to extract resource linked by accessTo Oct 27, 2022
@chicco785 chicco785 added the enhancement New feature or request label Oct 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request todo
Projects
None yet
Development

No branches or pull requests

1 participant