Skip to content

Commit 77d131e

Browse files
author
jitsuineccles
authored
Dev/paul/3532 push code to GitHub (#1)
* first trial commit to github * .gitignore * First tested commit * Publishing now works correctly * exponential backoff * latest code and line endings * alpha3
1 parent 55731c0 commit 77d131e

38 files changed

Lines changed: 5710 additions & 0 deletions

.gitattributes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
* text=auto
2+
*.py text
3+
*.yaml text
4+
*.md text

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
**/__pycache__
2+
build/
3+
dist/
4+
*egg-info/
5+
.coverage
6+
*,cover
7+
*.xml
8+
htmlcov/
9+
.pylint.d/

Dockerfile-builder

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM python:3.6-buster
2+
3+
COPY requirements.txt requirements-dev.txt /tmp/
4+
5+
RUN pip3 install -r /tmp/requirements-dev.txt \
6+
&& rm -f /tmp/requirements-dev.txt \
7+
&& rm -f /tmp/requirements.txt
8+
9+
ENV USER=builder
10+
ENV HOME=/home/${USER}
11+
ENV PATH=${HOME}/.local/bin:${PATH}
12+
RUN mkdir -p ${HOME}
13+
WORKDIR ${HOME}
14+
15+

LICENSE

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Copyright (c) 2021 Jitsuin Inc
2+
3+
Permission is hereby granted, free of charge,
4+
to any person obtaining a copy of this software and associated documentation files (the "Software"),
5+
to deal in the Software without restriction, including without limitation the rights to use,
6+
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
7+
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8+
9+
The above copyright notice and this permission notice shall be included in all copies or
10+
substantial portions of the Software.
11+
12+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
15+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
16+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Jitsuin Archivist Client
2+
3+
The standard Jitsuin Archivist python client.
4+
5+
Please note that the canonical API for Jitsuin Archivist is always the REST API
6+
documented at https://jitsuin-archivist.readthedocs.io
7+
8+
# Development
9+
10+
## Pre-requisites
11+
12+
Required tools for this repo are task-runner and docker-ce.
13+
14+
Install task runner: https://github.com/go-task/task
15+
Install docker-ce: https://docs.docker.com/get-docker/
16+
17+
## Workflow
18+
19+
To see what options are available simply execute:
20+
21+
```bash
22+
task
23+
```
24+
25+
All development is done using a docker image. To create the image execute
26+
the following command. This command only has to be repeated if requirements.txt
27+
or requirements-dev.txt change.
28+
29+
Dependencies are defined in requirements.txt for the archivist package and
30+
requirements-dev.txt for the tools used to build, test and publish the
31+
archivist package.
32+
33+
To build the docker builder image:
34+
```bash
35+
task builder
36+
```
37+
38+
Make a change to the code and validate the changes:
39+
40+
```bash
41+
task check
42+
```
43+
44+
If ok run the unittests:
45+
46+
```bash
47+
task unittests
48+
```
49+
50+
If 100% coverage and no test failures generate the wheel:
51+
52+
```bash
53+
task wheel
54+
```
55+
56+
Lastly to publish the package to PyPi:
57+
58+
```bash
59+
task publish
60+
```
61+
62+
Note that this requires credentials and will only normally be done by a Jitsuin
63+
representative.
64+
65+

Taskfile.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
version: '3'
2+
3+
tasks:
4+
5+
builder:
6+
desc: Build a docker environment with the right dependencies and utilities
7+
cmds:
8+
- docker build --no-cache -f Dockerfile-builder -t jitsuin-archivist-python-builder .
9+
10+
check:
11+
desc: Check the style, bug and quality of the code
12+
cmds:
13+
- ./scripts/builder.sh pycodestyle --format=pylint archivist unittests examples
14+
- ./scripts/builder.sh python3 -m pylint --rcfile=pylintrc archivist unittests examples
15+
16+
clean:
17+
desc: Clean git repo
18+
cmds:
19+
- find -name '*,cover' -type f -delete
20+
- git clean -fdX
21+
22+
unittests:
23+
desc: Run unittests
24+
cmds:
25+
- ./scripts/builder.sh ./scripts/unittests.sh
26+
27+
publish:
28+
desc: pubish wheel package (will require username and password)
29+
cmds:
30+
- ./scripts/builder.sh python3 -m twine upload --repository pypi dist/*
31+
32+
wheel:
33+
desc: Builds python wheel package
34+
cmds:
35+
- rm -rf *egg-info
36+
- rm -rf build
37+
- rm -f dist/*
38+
- python3 setup.py bdist_wheel

archivist/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"""Archivist SDK
2+
"""

archivist/access_policies.py

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
"""access_policies interface
2+
3+
NOT TESTED
4+
"""
5+
6+
from .constants import (
7+
SEP,
8+
ACCESS_POLICIES_SUBPATH,
9+
ACCESS_POLICIES_LABEL,
10+
ASSETS_LABEL,
11+
)
12+
13+
DEFAULT_PAGE_SIZE=500
14+
15+
16+
class _AccessPoliciesClient:
17+
"""docstring
18+
"""
19+
def __init__(self, archivist):
20+
"""docstring
21+
"""
22+
self._archivist = archivist
23+
24+
def create(self, request):
25+
"""docstring
26+
"""
27+
28+
return AccessPolicy(**self._archivist.post(
29+
f"{ACCESS_POLICIES_SUBPATH}/{ACCESS_POLICIES_LABEL}",
30+
request,
31+
))
32+
33+
def read(self, identity):
34+
"""docstring
35+
"""
36+
return AccessPolicy(**self._archivist.get(
37+
ACCESS_POLICIES_SUBPATH,
38+
identity,
39+
))
40+
41+
def update(self, identity, request):
42+
"""docstring
43+
"""
44+
return AccessPolicy(**self._archivist.patch(
45+
ACCESS_POLICIES_SUBPATH,
46+
identity,
47+
request,
48+
))
49+
50+
def delete(self, identity):
51+
"""docstring
52+
"""
53+
return self._archivist.delete(ACCESS_POLICIES_SUBPATH, identity)
54+
55+
@staticmethod
56+
def __query(props):
57+
"""docstring
58+
"""
59+
query = props or {}
60+
return query
61+
62+
def count(self, *, query=None):
63+
"""docstring
64+
"""
65+
return self._archivist.count(
66+
f"{ACCESS_POLICIES_SUBPATH}/{ACCESS_POLICIES_LABEL}",
67+
query=self.__query(query)
68+
)
69+
70+
def list(self, *, page_size=DEFAULT_PAGE_SIZE, query=None):
71+
"""docstring
72+
"""
73+
return (
74+
AccessPolicy(**a) for a in self._archivist.list(
75+
f"{ACCESS_POLICIES_SUBPATH}/{ACCESS_POLICIES_LABEL}",
76+
ACCESS_POLICIES_LABEL,
77+
page_size=page_size,
78+
query=self.__query(query)
79+
)
80+
)
81+
82+
# additional queries on different endpoints
83+
def count_matching_assets(self, access_policy_id, *, query=None):
84+
"""docstring
85+
"""
86+
return self._archivist.count(
87+
SEP.join((ACCESS_POLICIES_SUBPATH, access_policy_id, ASSETS_LABEL)),
88+
ASSETS_LABEL,
89+
query=self.__query(query)
90+
)
91+
92+
def list_matching_assets(self, access_policy_id, *, page_size=DEFAULT_PAGE_SIZE, query=None):
93+
"""docstring
94+
"""
95+
return (
96+
AccessPolicy(**a) for a in self._archivist.list(
97+
SEP.join((ACCESS_POLICIES_SUBPATH, access_policy_id, ASSETS_LABEL)),
98+
ASSETS_LABEL,
99+
page_size=page_size,
100+
query=self.__query(query)
101+
)
102+
)
103+
104+
def count_matching_access_policies(self, asset_id, *, query=None):
105+
"""docstring
106+
"""
107+
return self._archivist.count(
108+
SEP.join((ACCESS_POLICIES_SUBPATH, asset_id, ACCESS_POLICIES_LABEL)),
109+
ACCESS_POLICIES_LABEL,
110+
query=self.__query(query)
111+
)
112+
113+
def list_matching_access_policies(self, asset_id, *, page_size=DEFAULT_PAGE_SIZE, query=None):
114+
"""docstring
115+
"""
116+
return (
117+
AccessPolicy(**a) for a in self._archivist.list(
118+
SEP.join((ACCESS_POLICIES_SUBPATH, asset_id, ASSETS_LABEL)),
119+
ACCESS_POLICIES_LABEL,
120+
page_size=page_size,
121+
query=self.__query(query)
122+
)
123+
)
124+
125+
126+
class AccessPolicy(dict):
127+
"""AccessPolicy object
128+
"""

0 commit comments

Comments
 (0)