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
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* text=auto
*.py text
*.yaml text
*.md text
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
**/__pycache__
build/
dist/
*egg-info/
.coverage
*,cover
*.xml
htmlcov/
.pylint.d/
15 changes: 15 additions & 0 deletions Dockerfile-builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM python:3.6-buster

COPY requirements.txt requirements-dev.txt /tmp/

RUN pip3 install -r /tmp/requirements-dev.txt \
&& rm -f /tmp/requirements-dev.txt \
&& rm -f /tmp/requirements.txt

ENV USER=builder
ENV HOME=/home/${USER}
ENV PATH=${HOME}/.local/bin:${PATH}
RUN mkdir -p ${HOME}
WORKDIR ${HOME}


17 changes: 17 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Copyright (c) 2021 Jitsuin Inc

Permission is hereby granted, free of charge,
to any person obtaining a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Jitsuin Archivist Client

The standard Jitsuin Archivist python client.

Please note that the canonical API for Jitsuin Archivist is always the REST API
documented at https://jitsuin-archivist.readthedocs.io

# Development

## Pre-requisites

Required tools for this repo are task-runner and docker-ce.

Install task runner: https://github.com/go-task/task
Install docker-ce: https://docs.docker.com/get-docker/

## Workflow

To see what options are available simply execute:

```bash
task
```

All development is done using a docker image. To create the image execute
the following command. This command only has to be repeated if requirements.txt
or requirements-dev.txt change.

Dependencies are defined in requirements.txt for the archivist package and
requirements-dev.txt for the tools used to build, test and publish the
archivist package.

To build the docker builder image:
```bash
task builder
```

Make a change to the code and validate the changes:

```bash
task check
```

If ok run the unittests:

```bash
task unittests
```

If 100% coverage and no test failures generate the wheel:

```bash
task wheel
```

Lastly to publish the package to PyPi:

```bash
task publish
```

Note that this requires credentials and will only normally be done by a Jitsuin
representative.


38 changes: 38 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: '3'

tasks:

builder:
desc: Build a docker environment with the right dependencies and utilities
cmds:
- docker build --no-cache -f Dockerfile-builder -t jitsuin-archivist-python-builder .

check:
desc: Check the style, bug and quality of the code
cmds:
- ./scripts/builder.sh pycodestyle --format=pylint archivist unittests examples
- ./scripts/builder.sh python3 -m pylint --rcfile=pylintrc archivist unittests examples

clean:
desc: Clean git repo
cmds:
- find -name '*,cover' -type f -delete
- git clean -fdX

unittests:
desc: Run unittests
cmds:
- ./scripts/builder.sh ./scripts/unittests.sh

publish:
desc: pubish wheel package (will require username and password)
cmds:
- ./scripts/builder.sh python3 -m twine upload --repository pypi dist/*

wheel:
desc: Builds python wheel package
cmds:
- rm -rf *egg-info
- rm -rf build
- rm -f dist/*
- python3 setup.py bdist_wheel
2 changes: 2 additions & 0 deletions archivist/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"""Archivist SDK
"""
128 changes: 128 additions & 0 deletions archivist/access_policies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
"""access_policies interface

NOT TESTED
"""

from .constants import (
SEP,
ACCESS_POLICIES_SUBPATH,
ACCESS_POLICIES_LABEL,
ASSETS_LABEL,
)

DEFAULT_PAGE_SIZE=500


class _AccessPoliciesClient:
"""docstring
"""
def __init__(self, archivist):
"""docstring
"""
self._archivist = archivist

def create(self, request):
"""docstring
"""

return AccessPolicy(**self._archivist.post(
f"{ACCESS_POLICIES_SUBPATH}/{ACCESS_POLICIES_LABEL}",
request,
))

def read(self, identity):
"""docstring
"""
return AccessPolicy(**self._archivist.get(
ACCESS_POLICIES_SUBPATH,
identity,
))

def update(self, identity, request):
"""docstring
"""
return AccessPolicy(**self._archivist.patch(
ACCESS_POLICIES_SUBPATH,
identity,
request,
))

def delete(self, identity):
"""docstring
"""
return self._archivist.delete(ACCESS_POLICIES_SUBPATH, identity)

@staticmethod
def __query(props):
"""docstring
"""
query = props or {}
return query

def count(self, *, query=None):
"""docstring
"""
return self._archivist.count(
f"{ACCESS_POLICIES_SUBPATH}/{ACCESS_POLICIES_LABEL}",
query=self.__query(query)
)

def list(self, *, page_size=DEFAULT_PAGE_SIZE, query=None):
"""docstring
"""
return (
AccessPolicy(**a) for a in self._archivist.list(
f"{ACCESS_POLICIES_SUBPATH}/{ACCESS_POLICIES_LABEL}",
ACCESS_POLICIES_LABEL,
page_size=page_size,
query=self.__query(query)
)
)

# additional queries on different endpoints
def count_matching_assets(self, access_policy_id, *, query=None):
"""docstring
"""
return self._archivist.count(
SEP.join((ACCESS_POLICIES_SUBPATH, access_policy_id, ASSETS_LABEL)),
ASSETS_LABEL,
query=self.__query(query)
)

def list_matching_assets(self, access_policy_id, *, page_size=DEFAULT_PAGE_SIZE, query=None):
"""docstring
"""
return (
AccessPolicy(**a) for a in self._archivist.list(
SEP.join((ACCESS_POLICIES_SUBPATH, access_policy_id, ASSETS_LABEL)),
ASSETS_LABEL,
page_size=page_size,
query=self.__query(query)
)
)

def count_matching_access_policies(self, asset_id, *, query=None):
"""docstring
"""
return self._archivist.count(
SEP.join((ACCESS_POLICIES_SUBPATH, asset_id, ACCESS_POLICIES_LABEL)),
ACCESS_POLICIES_LABEL,
query=self.__query(query)
)

def list_matching_access_policies(self, asset_id, *, page_size=DEFAULT_PAGE_SIZE, query=None):
"""docstring
"""
return (
AccessPolicy(**a) for a in self._archivist.list(
SEP.join((ACCESS_POLICIES_SUBPATH, asset_id, ASSETS_LABEL)),
ACCESS_POLICIES_LABEL,
page_size=page_size,
query=self.__query(query)
)
)


class AccessPolicy(dict):
"""AccessPolicy object
"""
Loading