Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
[ENHANCEMENT]: Implement Access Validation
Browse files Browse the repository at this point in the history
  • Loading branch information
amadolid committed Aug 30, 2024
1 parent 2ef73cf commit e18c8cb
Show file tree
Hide file tree
Showing 7 changed files with 667 additions and 40 deletions.
7 changes: 4 additions & 3 deletions jaclang/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ def enter(
base = base if base else "./"
mod = mod[:-4]

jctx = ExecutionContext.create(session=session, root=root, entry=node)

if filename.endswith(".jac"):
ret_module = jac_import(
target=mod,
Expand All @@ -270,18 +272,17 @@ def enter(
override_name="__main__" if main else None,
)
else:
jctx.close()
JacMachine.detach()
raise ValueError("Not a valid file!\nOnly supports `.jac` and `.jir`")

jctx = ExecutionContext.create(session=session, root=root, entry=node)

if ret_module:
(loaded_mod,) = ret_module
if not loaded_mod:
print("Errors occurred while importing the module.")
else:
architype = getattr(loaded_mod, entrypoint)(*args)
if isinstance(architype, WalkerArchitype):
if isinstance(architype, WalkerArchitype) and jctx.validate_access():
Jac.spawn_call(jctx.entry.architype, architype)

jctx.close()
Expand Down
4 changes: 4 additions & 0 deletions jaclang/plugin/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,18 +483,22 @@ def disconnect(
(source := anchor.source)
and (target := anchor.target)
and (not filter_func or filter_func([anchor.architype]))
and source.architype
and target.architype
):
if (
dir in [EdgeDir.OUT, EdgeDir.ANY]
and node == source
and target.architype in right
and source.has_write_access(target)
):
anchor.destroy() if anchor.persistent else anchor.detach()
disconnect_occurred = True
if (
dir in [EdgeDir.IN, EdgeDir.ANY]
and node == target
and source.architype in right
and target.has_write_access(source)
):
anchor.destroy() if anchor.persistent else anchor.detach()
disconnect_occurred = True
Expand Down
82 changes: 82 additions & 0 deletions jaclang/plugin/tests/fixtures/other_root_access.jac
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import:py from jaclang.runtimelib.architype {Anchor}
import:py from uuid {UUID}

node A {
has val: int;
}

walker check_node {
can enter with `root entry {
visit [-->];
}

can enter2 with A entry {
print(here);
}
}

walker update_node {
has val: int;

can enter2 with A entry {
here.val = self.val;
}
}

walker create_node {
has val: int;

can enter with `root entry {
a = A(val=self.val);
here ++> a;
print(a.__jac__.id);
}
}

walker create_other_root {
can enter with `root entry {
other_root = `root().__jac__;
other_root.save();
print(other_root.id);
}
}

walker allow_other_root_access {
has root_id: str, level: int | str = 1, via_all: bool = False;

can enter_root with `root entry {
if self.via_all {
here.__jac__.unrestrict(self.level);
} else {
here.__jac__.allow_root(UUID(self.root_id), self.level);
}
}

can enter_nested with A entry {
if self.via_all {
here.__jac__.unrestrict(self.level);
} else {
here.__jac__.allow_root(UUID(self.root_id), self.level);
}
}
}

walker disallow_other_root_access {
has root_id: str, via_all: bool = False;

can enter_root with `root entry {
if self.via_all {
here.__jac__.restrict();
} else {
here.__jac__.disallow_root(UUID(self.root_id));
}
}

can enter_nested with A entry {
if self.via_all {
here.__jac__.restrict();
} else {
here.__jac__.disallow_root(UUID(self.root_id));
}
}
}
Loading

0 comments on commit e18c8cb

Please sign in to comment.