Skip to content
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
10 changes: 5 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,14 @@ You can then use the examples code to create assets (see examples directory):
# of an asset or event creation - the default is 1200 seconds but one can optionally
# specify a different value here particularly when creating assets on SIMPLE_HASH
# (rather than KHIPU) as confirmation times are much shorter in this case.
arch = Archivist(
with arch = Archivist(
"https://app.rkvst.io",
(client_id, client_secret),
max_time=300,
)
# Create a new asset
asset = create_asset(arch)
print("Asset", asset)
) as arch:
# Create a new asset
asset = create_asset(arch)
print("Asset", asset)


if __name__ == "__main__":
Expand Down
11 changes: 10 additions & 1 deletion archivist/archivistpublic.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ def __getattr__(self, value: str) -> object:
super().__setattr__(value, c)
return c

def __enter__(self):
"""Just return self on entering - the session property will
create the session when needed
"""
return self

def __exit__(self, exc_type, exc_val, exc_tb):
self.close()

@property
def session(self) -> requests.Session:
"""creates and returns session"""
Expand All @@ -117,7 +126,7 @@ def session(self) -> requests.Session:
return self._session

def close(self):
"""closes current session"""
"""closes current session if open"""
if self._session is not None:
self._session.close()
self._session = None
Expand Down
68 changes: 34 additions & 34 deletions docs/sbom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<bom xmlns="http://cyclonedx.org/schema/bom/1.4" version="1" serialNumber="urn:uuid:6972b5d7-57e4-4402-99db-518f80ba0468">
<bom xmlns="http://cyclonedx.org/schema/bom/1.4" version="1" serialNumber="urn:uuid:ebc73b17-27cf-4997-9272-4982748494c3">
<metadata>
<timestamp>2022-10-25T07:52:58.134553+00:00</timestamp>
<timestamp>2022-10-27T13:48:21.177994+00:00</timestamp>
<tools>
<tool>
<vendor>CycloneDX</vendor>
Expand Down Expand Up @@ -36,87 +36,87 @@
</tools>
</metadata>
<components>
<component type="library" bom-ref="f42e1c06-d324-4af2-9262-e68bac47357b">
<component type="library" bom-ref="bf6097e4-22b4-4f69-a8ca-ec37ce193da0">
<name>backoff</name>
<version>1.11.1</version>
</component>
<component type="library" bom-ref="e73e8672-2a6b-4dd9-847d-9aa929dfa397">
<component type="library" bom-ref="7fe0a24d-224a-4880-ba57-6dfe526199a5">
<name>certifi</name>
<version>2022.9.24</version>
</component>
<component type="library" bom-ref="736703d4-ef3f-4fe4-ab1d-13b467f69b70">
<component type="library" bom-ref="0d321065-99c4-4735-8ff4-e9bfa7270bfe">
<name>charset-normalizer</name>
<version>2.1.1</version>
</component>
<component type="library" bom-ref="bf8b417d-0c6b-451b-9faa-cdadf630742d">
<component type="library" bom-ref="74236533-4d8a-47e7-bfdc-1b0f4953a060">
<name>flatten-dict</name>
<version>0.4.2</version>
</component>
<component type="library" bom-ref="23e74d9f-a4f6-49ea-80e4-620604bc449e">
<component type="library" bom-ref="42a1eed0-b6ea-4084-8f75-5dbf4d6c7a7b">
<name>idna</name>
<version>3.4</version>
</component>
<component type="library" bom-ref="d34906a1-bdd4-4262-8c57-c82664ca7762">
<component type="library" bom-ref="615df6ab-099d-4cb5-a312-9d7405fc24d3">
<name>iso8601</name>
<version>1.1.0</version>
</component>
<component type="library" bom-ref="d81490aa-3685-4a63-81d6-3acb0ec51f81">
<component type="library" bom-ref="f8a614a8-71c6-4bc1-bd08-3dce9f341bf8">
<name>jinja2</name>
<version>3.1.2</version>
</component>
<component type="library" bom-ref="f84107c9-c7b7-4581-ae90-70db7bd14b24">
<component type="library" bom-ref="be8dc6b5-b70e-46aa-8362-1461e4e77d56">
<name>markupsafe</name>
<version>2.1.1</version>
</component>
<component type="library" bom-ref="41c40d92-ce65-4fc5-a01b-9a17655dec55">
<component type="library" bom-ref="ea01e6de-967a-4fdb-92e4-cc1705200a97">
<name>pyaml-env</name>
<version>1.1.5</version>
</component>
<component type="library" bom-ref="f8f7daab-f7b2-48e9-b440-be220bfbb00e">
<component type="library" bom-ref="704fc3b9-cdd6-4314-bafe-e4fb904f3a8a">
<name>pyyaml</name>
<version>5.4.1</version>
</component>
<component type="library" bom-ref="d6d52049-e8d7-4a9c-9d28-4b15dac8a087">
<component type="library" bom-ref="4b92b578-21d6-482a-814f-1f3886902c2a">
<name>requests</name>
<version>2.28.1</version>
</component>
<component type="library" bom-ref="2f26a6c5-384e-4f61-88cc-763d4c264e22">
<component type="library" bom-ref="1fa3b64f-fc1a-4060-93ef-cf1316ac90e1">
<name>requests-toolbelt</name>
<version>0.10.1</version>
</component>
<component type="library" bom-ref="0289bf5b-b99b-4f49-8e23-4d0a4bd648c6">
<component type="library" bom-ref="2e31ffec-c165-40cd-8265-c1a88c0f57df">
<name>rfc3339</name>
<version>6.2</version>
</component>
<component type="library" bom-ref="d505de3d-67ff-4117-bbb4-dfb967a7d380">
<component type="library" bom-ref="19d385b1-bd6f-41b6-b15c-6cdd88f112d1">
<name>six</name>
<version>1.16.0</version>
</component>
<component type="library" bom-ref="0ad0be84-0a8d-4e3f-9a04-82552bca0f8a">
<component type="library" bom-ref="6371f9dd-3fd5-4d49-a22b-665f8f241b38">
<name>urllib3</name>
<version>1.26.12</version>
</component>
<component type="library" bom-ref="7b5f3013-0842-4f70-a248-ff8fd73ccf5e">
<component type="library" bom-ref="7977c6a6-064e-4e87-9758-015e23a57b52">
<name>xmltodict</name>
<version>0.13.0</version>
</component>
</components>
<dependencies>
<dependency ref="f42e1c06-d324-4af2-9262-e68bac47357b"/>
<dependency ref="e73e8672-2a6b-4dd9-847d-9aa929dfa397"/>
<dependency ref="736703d4-ef3f-4fe4-ab1d-13b467f69b70"/>
<dependency ref="bf8b417d-0c6b-451b-9faa-cdadf630742d"/>
<dependency ref="23e74d9f-a4f6-49ea-80e4-620604bc449e"/>
<dependency ref="d34906a1-bdd4-4262-8c57-c82664ca7762"/>
<dependency ref="d81490aa-3685-4a63-81d6-3acb0ec51f81"/>
<dependency ref="f84107c9-c7b7-4581-ae90-70db7bd14b24"/>
<dependency ref="41c40d92-ce65-4fc5-a01b-9a17655dec55"/>
<dependency ref="f8f7daab-f7b2-48e9-b440-be220bfbb00e"/>
<dependency ref="d6d52049-e8d7-4a9c-9d28-4b15dac8a087"/>
<dependency ref="2f26a6c5-384e-4f61-88cc-763d4c264e22"/>
<dependency ref="0289bf5b-b99b-4f49-8e23-4d0a4bd648c6"/>
<dependency ref="d505de3d-67ff-4117-bbb4-dfb967a7d380"/>
<dependency ref="0ad0be84-0a8d-4e3f-9a04-82552bca0f8a"/>
<dependency ref="7b5f3013-0842-4f70-a248-ff8fd73ccf5e"/>
<dependency ref="bf6097e4-22b4-4f69-a8ca-ec37ce193da0"/>
<dependency ref="7fe0a24d-224a-4880-ba57-6dfe526199a5"/>
<dependency ref="0d321065-99c4-4735-8ff4-e9bfa7270bfe"/>
<dependency ref="74236533-4d8a-47e7-bfdc-1b0f4953a060"/>
<dependency ref="42a1eed0-b6ea-4084-8f75-5dbf4d6c7a7b"/>
<dependency ref="615df6ab-099d-4cb5-a312-9d7405fc24d3"/>
<dependency ref="f8a614a8-71c6-4bc1-bd08-3dce9f341bf8"/>
<dependency ref="be8dc6b5-b70e-46aa-8362-1461e4e77d56"/>
<dependency ref="ea01e6de-967a-4fdb-92e4-cc1705200a97"/>
<dependency ref="704fc3b9-cdd6-4314-bafe-e4fb904f3a8a"/>
<dependency ref="4b92b578-21d6-482a-814f-1f3886902c2a"/>
<dependency ref="1fa3b64f-fc1a-4060-93ef-cf1316ac90e1"/>
<dependency ref="2e31ffec-c165-40cd-8265-c1a88c0f57df"/>
<dependency ref="19d385b1-bd6f-41b6-b15c-6cdd88f112d1"/>
<dependency ref="6371f9dd-3fd5-4d49-a22b-665f8f241b38"/>
<dependency ref="7977c6a6-064e-4e87-9758-015e23a57b52"/>
</dependencies>
</bom>
36 changes: 19 additions & 17 deletions examples/access_policies_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,27 @@ def main():
)

# Initialize connection to Archivist
arch = Archivist(
with Archivist(
"https://app.rkvst.io",
auth,
)

# count access_policies...
print(
"no.of access_policies",
arch.access_policies.count(display_name="Some display name"),
)

# iterate through the generator....
for access_policy in arch.access_policies.list(display_name="Some display name"):
print("access_policy", access_policy)

# alternatively one could pull the list for all access policies and cache locally...
access_policies = list(arch.access_policies.list())
for access_policy in access_policies:
print("access_policy", access_policy)
) as arch:

# count access_policies...
print(
"no.of access_policies",
arch.access_policies.count(display_name="Some display name"),
)

# iterate through the generator....
for access_policy in arch.access_policies.list(
display_name="Some display name"
):
print("access_policy", access_policy)

# alternatively one could pull the list for all access policies and cache locally...
access_policies = list(arch.access_policies.list())
for access_policy in access_policies:
print("access_policy", access_policy)


if __name__ == "__main__":
Expand Down
98 changes: 49 additions & 49 deletions examples/access_policy_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,59 +34,59 @@ def main():
with open(client_secret_file, mode="r", encoding="utf-8") as tokenfile:
client_secret = tokenfile.read().strip()

arch = Archivist(
with Archivist(
"https://app.rkvst.io",
(client_id, client_secret),
)
) as arch:

props = {
"display_name": "Friendly name of the policy",
"description": "Description of the policy",
}
filters = [
{
"or": [
"attributes.arc_home_location_identity="
"locations/5ea815f0-4de1-4a84-9377-701e880fe8ae",
"attributes.arc_home_location_identity="
"locations/27eed70b-9e2b-4db1-b8c4-e36505350dcc",
]
},
{
"or": [
"attributes.arc_display_type=Valve",
"attributes.arc_display_type=Pump",
]
},
{
"or": [
"attributes.ext_vendor_name=SynsationIndustries",
]
},
]
access_permissions = [
{
"asset_attributes_read": ["toner_colour", "toner_type"],
"asset_attributes_write": ["toner_colour"],
"behaviours": ASSET_BEHAVIOURS,
"event_arc_display_type_read": ["toner_type", "toner_colour"],
"event_arc_display_type_write": ["toner_replacement"],
"include_attributes": [
"arc_display_name",
"arc_display_type",
"arc_firmware_version",
],
"subjects": [
"subjects/6a951b62-0a26-4c22-a886-1082297b063b",
"subjects/a24306e5-dc06-41ba-a7d6-2b6b3e1df48d",
],
"user_attributes": [
{"or": ["group:maintainers", "group:supervisors"]},
],
props = {
"display_name": "Friendly name of the policy",
"description": "Description of the policy",
}
]
access_policy = arch.access_policies.create(props, filters, access_permissions)
print("access Policy", access_policy)
filters = [
{
"or": [
"attributes.arc_home_location_identity="
"locations/5ea815f0-4de1-4a84-9377-701e880fe8ae",
"attributes.arc_home_location_identity="
"locations/27eed70b-9e2b-4db1-b8c4-e36505350dcc",
]
},
{
"or": [
"attributes.arc_display_type=Valve",
"attributes.arc_display_type=Pump",
]
},
{
"or": [
"attributes.ext_vendor_name=SynsationIndustries",
]
},
]
access_permissions = [
{
"asset_attributes_read": ["toner_colour", "toner_type"],
"asset_attributes_write": ["toner_colour"],
"behaviours": ASSET_BEHAVIOURS,
"event_arc_display_type_read": ["toner_type", "toner_colour"],
"event_arc_display_type_write": ["toner_replacement"],
"include_attributes": [
"arc_display_name",
"arc_display_type",
"arc_firmware_version",
],
"subjects": [
"subjects/6a951b62-0a26-4c22-a886-1082297b063b",
"subjects/a24306e5-dc06-41ba-a7d6-2b6b3e1df48d",
],
"user_attributes": [
{"or": ["group:maintainers", "group:supervisors"]},
],
}
]
access_policy = arch.access_policies.create(props, filters, access_permissions)
print("access Policy", access_policy)


if __name__ == "__main__":
Expand Down
Loading