Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cordra client #10

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
39 changes: 39 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Python CircleCI 2.0 configuration file
version: 2.1
jobs:
cordrapy_develop:
docker:
- image: continuumio/miniconda3

working_directory: ~/repo-test-cordrapy

steps:
# Step 1: obtain repo from GitHub
- checkout
# Step 2: Get and run cordra
- run:
name: Get Cordra
command: |
ls
set -e
apt-get --yes update
apt-get --yes upgrade
apt-get --yes install curl unzip default-jre
curl https://www.cordra.org/assets/sw/cordra-2.4.0-distribution.zip > cordra-2.4.0-distribution.zip
unzip cordra-2.4.0-distribution.zip
cd cordra-2.4.0
rm data/repoInit.json
echo '{"adminPassword": "admin","prefix": ""}' > data/repoInit.json
(./bin/startup &) | grep -q "Startup complete."
cd ../
pip install -r requirements.txt
pip install Pillow
pip install -e ./
python tests/CRUD_CordraClient.py


workflows:
version: 2
test:
jobs:
- cordrapy_develop
5 changes: 4 additions & 1 deletion cordra/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"""

from .cordra import CordraObject, Token
from .cordraClient import CordraClient


def get_version():
"""Get the version of the code from egg_info.
Expand All @@ -22,6 +24,7 @@ def get_version():

__all__ = [
"__version__",
"Token",
"CordraObject",
"Token"
"CordraClient"
]
57 changes: 45 additions & 12 deletions cordra/cordra.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import requests
import json
from warnings import warn

from requests.packages.urllib3.exceptions import InsecureRequestWarning
from urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

# global variables
Expand All @@ -13,6 +14,7 @@
token_grant_type = 'password'
token_type = 'Bearer'


def endpoint_url(host, endpoint):
return host.strip('/') + '/' + endpoint

Expand All @@ -29,7 +31,7 @@ def check_response(response):
try:
return response.json()
except BaseException:
return response.text
return response.content


def set_auth(username, password):
Expand All @@ -39,6 +41,7 @@ def set_auth(username, password):
auth = None
return auth


def get_token_value(token):
if isinstance(token, str):
return token
Expand All @@ -59,7 +62,11 @@ def set_headers(token):
headers = None
return headers


class CordraObject:
warn("CordraObject may be moved to a new module with a new name in future releases.")

@staticmethod
def create(
host,
obj_json,
Expand All @@ -73,7 +80,8 @@ def create(
verify=None,
full=False,
payloads=None,
acls=None
acls=None,
**kwargs
):
'''Create a Cordra object'''

Expand Down Expand Up @@ -135,6 +143,7 @@ def create(
else:
return obj_r

@staticmethod
def read(
host,
obj_id,
Expand All @@ -144,7 +153,8 @@ def read(
verify=None,
jsonPointer=None,
jsonFilter=None,
full=False
full=False,
**kwargs
):
'''Retrieve a Cordra object JSON by identifer.'''

Expand All @@ -165,13 +175,15 @@ def read(
verify=verify))
return r

@staticmethod
def read_payload_info(
host,
obj_id,
username=None,
password=None,
token=None,
verify=None
verify=None,
**kwargs
):
'''Retrieve a Cordra object payload names by identifer.'''

Expand All @@ -188,14 +200,16 @@ def read_payload_info(
verify=verify))
return r['payloads']

@staticmethod
def read_payload(
host,
obj_id,
payload,
username=None,
password=None,
token=None,
verify=None
verify=None,
**kwargs
):
'''Retrieve a Cordra object payload by identifer and payload name.'''

Expand All @@ -212,6 +226,7 @@ def read_payload(
verify=verify))
return r

@staticmethod
def update(
host,
obj_id,
Expand All @@ -226,7 +241,8 @@ def update(
full=False,
payloads=None,
payloadToDelete=None,
acls=None
acls=None,
**kwargs
):
'''Update a Cordra object'''

Expand Down Expand Up @@ -289,14 +305,16 @@ def update(
return r


@staticmethod
def delete(
host,
obj_id,
jsonPointer=None,
username=None,
password=None,
token=None,
verify=None
verify=None,
**kwargs
):
'''Delete a Cordra object'''

Expand All @@ -316,6 +334,7 @@ def delete(
)
return r

@staticmethod
def find(
host,
query,
Expand All @@ -325,13 +344,19 @@ def find(
verify=None,
ids=False,
jsonFilter=None,
full=False
full=False,
pageNum=None,
pageSize=None,
**kwargs
):
'''Find a Cordra object by query'''

params = dict()
params['query'] = query
params['full'] = full
if pageNum: params["pageNum"] = pageNum
if pageSize: params["pageSize"] = pageSize

if jsonFilter:
params['filter'] = str(jsonFilter)
if ids:
Expand All @@ -348,12 +373,16 @@ def find(
return r

class Token:
warn("Token may be moved to a new module with a new name in future releases.")

@staticmethod
def create(
host,
username,
password,
verify=None,
full=False
full=False,
**kwargs
):
'''Create an access Token'''

Expand All @@ -373,11 +402,13 @@ def create(
verify=verify))
return r

@staticmethod
def read(
host,
token,
verify=None,
full=False
full=False,
**kwargs
):
'''Read an access Token'''

Expand All @@ -396,10 +427,12 @@ def read(
))
return r

@staticmethod
def delete(
host,
token,
verify=None
verify=None,
**kwargs
):
'''Delete an access Token'''

Expand Down
Loading