Skip to content

Commit

Permalink
evolving code, particularly with SCURLer ability to execute SFTP "quo…
Browse files Browse the repository at this point in the history
…te" commands
  • Loading branch information
ndenny committed Apr 14, 2025
1 parent 07efe9b commit 1bf509e
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 88 deletions.
5 changes: 2 additions & 3 deletions lib/Bastion/CARP.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Bastion.CARP
Common Action-Result/Report Protocol
Common Action-Request/Result/Report Protocol
Basic concepts...
requests (instances of isRequest or subclasses) encapsulates details of the action requested.
Expand Down Expand Up @@ -354,7 +354,7 @@ def toJDN(self, **kwargs):
raise NotImplementedError(".toJDN is subclass responsibility")


class isBagReceipt:
class isBagReceipt(isReceipt):
"""
I am a thin wrapper around a sequence of results.
"""
Expand All @@ -370,7 +370,6 @@ def append(self, result, *args):
def __iter__(self):
return iter(self.results)


def __getitem__(self, i):
return self.results[i]

Expand Down
24 changes: 16 additions & 8 deletions lib/Bastion/Model.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ def badge(self):
return Slug40(str(self.CURIE))


class isActor:
class isPerformer:
"""
Abstract class for actors.
Actors are the "do-ers" in the model.
Abstract class for performers.
Performers are the "do-ers" in the model.
All action methods should return an instance of Bastion.CARP.Report
"""
def perform(self, request):
Expand All @@ -109,24 +109,24 @@ def __init__(self, name, **kwargs):
self.name = name

#----------------------------------------------------------------------------
#-- BEGIN ACTOR ACCESSORS |
#-- BEGIN PERFORMER ACCESSORS |
#↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
@property
def clerk(self):
#-- Answers the clerk for this vault.
#-- Answers the (possibly delegated) clerk performer for this vault.
raise NotImplementedError

@property
def mover(self):
#-- Answers a mover for this vault.
#-- Answers the (possibly delegated) mover performer for this vault.
raise NotImplementedError

@property
def packer(self):
#-- Answers a packer (if needed) for this vault.
#-- Answers the (possibly delegated) packer peformer (if needed) for this vault.
raise NotImplementedError
#↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
#-- END ACTOR ACCESSORS |
#-- END PERFOMER ACCESSORS |
#----------------------------------------------------------------------------

#----------------------------------------------------------------------------
Expand Down Expand Up @@ -192,6 +192,14 @@ def get(self, tag, halo, **kwargs):
download the object and store it in the local file designated by halo.
"""
return self.mover.get(tag, halo, **kwargs)

def remove(self, tag, **kwargs):
"""
Given a tag (the path relative to the root of this vault),
remove the object from the (remote) storage.
"""
return self.mover.remove(tag, **kwargs)

#↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
#-- END MOVER DELEGATES |
#----------------------------------------------------------------------------
Expand Down
37 changes: 37 additions & 0 deletions lib/Bastion/Movers/CARP.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@ def toJDN(self, **kwargs):
return jdn


class RemoveReceipt(isReceipt):
def __init__(self, rendpoint, tag):
assert isinstance(tag, (pathlib.PurePosixPath, str)), "tag must be an instance of str or PurePosixPath"
self.target = Thing(endpoint = rendpoint, tag = tag)

def toJDN(self, **kwargs):
jdn = {
'target': {
'endpoint': toJDN(self.target.endpoint),
'tag': toJDN(self.target.tag)
}
}
return jdn



class PutRequest(isRequest):
"""
A request for putting a given file into a target endpoint.
Expand Down Expand Up @@ -142,3 +158,24 @@ def __init__(self, rendpoint, tag, halo):
}

isRequest.__init__(self, "GetRequest", **xtras)


class RemoveRequest(isRequest):
"""
A request for removing a given object from an endpoint (remote storage).
"""
def __init__(self, rendpoint, tag):
"""
rednpoint - is a string or object that describes the remote endpoint.
tag - the tag that selects the object for removal, this is typically a path relative to the (remote) storage root.
"""
assert isinstance(tag, (pathlib.PurePosixPath, str)), "tag must be an instance of str or PurePosixPath"

self.bank = Thing(endpoint = rendpoint, tag = tag)

xtras = {
"bank.endpoint": toJDN(self.bank.endpoint),
"bank.tag": toJDN(self.bank.tag)
}

isRequest.__init__(self, "RemoveRequest", **xtras)
Loading

0 comments on commit 1bf509e

Please sign in to comment.