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

Upgrade BigchainDB Server to 0.9 and COALA IP-related dependencies #25

Merged
merged 9 commits into from
Feb 17, 2017
1 change: 0 additions & 1 deletion .env_template
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ API_PORT=3000
# Settings for the BigchainDB node that the API server should connect to
BDB_NODE_HOST=
BDB_NODE_PORT=
BDB_NODE_API_PATH=

##### Docker settings #####
# Externally exposed port for accessing BigchainDB's API
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ install:

before_script:
- rethinkdb --daemon
- bigchaindb -y configure
- bigchaindb -y configure rethinkdb
# Start BigchainDB in the background and ignore any output
- bigchaindb start >/dev/null 2>&1 &

Expand Down
29 changes: 14 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ The API server can be configured with a number of environment variables [see
### Create Users

This call will not store any data on the running instance of BigchainDB.
It simply generates a verifying and signing key-pair that can be used in a
It simply generates a public/private key-pair that can be used in a
POST-manifestation call.

```
Expand All @@ -151,17 +151,17 @@ PAYLOAD: None

RETURNS:
{
"verifyingKey": "<base58 string>",
"signingKey": "<base58 string>",
"publicKey": "<base58 string>",
"privateKey": "<base58 string>",
}
```


### Register a Manifestation

In order to register the manifestation on BigchainDB as transactions on a
specific copyright holder's name, the copyright holder's `verifyingKey` and
`signingKey` must be provided here.
specific copyright holder's name, the copyright holder's `publicKey` and
`privateKey` must be provided here.

Note that the attributes shown for `manifestation` and `work` can be much more
diverse; for this, see their [COALA IP models definition](https://github.com/COALAIP/specs/tree/master/data-structure#rrm-creation).
Expand All @@ -178,8 +178,8 @@ PAYLOAD:
"url": "<URI pointing to a media blob>"
},
"copyrightHolder": {
"verifyingKey": "<base58 string>",
"signingKey": "<base58 string>"
"publicKey": "<base58 string>",
"privateKey": "<base58 string>"
},
"work": {
"name": "The Lord of the Rings Triology",
Expand All @@ -192,7 +192,7 @@ RETURNS:
{
"work": {
"@id": "<Relative URI with the ID of the entity on BigchainDB>",
"@type": "CreativeWork",
"@type": "AbstractWork",
"name": "The Lord of the Rings Trilogy",
"author": "J. R. R. Tolkien"
},
Expand All @@ -202,8 +202,7 @@ RETURNS:
"name": "The Fellowship of the Ring",
"manifestationOfWork": "<URI pointing to the Work's transaction ../<txid>",
"datePublished": "29-07-1954",
"url": "<URI pointing to a media blob>",
"isManifestation": true
"url": "<URI pointing to a media blob>"
},
"copyright": {
"@id": "<Relative URI with the ID of the entity on BigchainDB>",
Expand Down Expand Up @@ -264,8 +263,8 @@ part of the new Right's chain of provenance.
Note that the attributes for the `right` may be much more diverse; see its [COALA
IP models definition](https://github.com/COALAIP/specs/tree/master/data-structure#rrm-right).

Also see transferring a Right on how to transfer a registered Right to new
holders.
Also see [transferring a Right](#transfer-a-right) on how to transfer a
registered Right to new holders.

```
POST /api/v1/rights/
Expand All @@ -277,8 +276,8 @@ PAYLOAD:
"license": "<Legal license text or URI pointing to a license document>"
},
"currentHolder": {
"verifyingKey": "<base58 string>",
"signingKey": "<base58 string>"
"publicKey": "<base58 string>",
"privateKey": "<base58 string>"
},
"sourceRightId": "<ID of an existing Right that allows for the creation of this new Right>"
}
Expand All @@ -288,7 +287,7 @@ RETURNS:
"right": {
"@id": "<Relative URI with the ID of the entity on BigchainDB>",
"@type": "Right",
"allowedBy": <The sourceRightId>,
"source": "<sourceRightId>",
"license": "<Legal license text or URI pointing to a license document>",
}
}
Expand Down
4 changes: 2 additions & 2 deletions compose/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM python:3.5

RUN apt-get update && apt-get install -y vim
RUN apt-get update
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥇


RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
Expand All @@ -9,4 +9,4 @@ RUN pip install --upgrade pip

COPY . /usr/src/app/

RUN pip install --no-cache-dir --process-dependency-links -e .
RUN pip install --no-cache-dir --process-dependency-links -r requirements_dev.txt
2 changes: 1 addition & 1 deletion compose/bigchaindb/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ WORKDIR /usr/src/app
RUN pip install --upgrade pip

RUN pip install bigchaindb
RUN bigchaindb -y configure
RUN bigchaindb -y configure rethinkdb
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ services:
- .env
environment:
API_HOST: api
BDB_NODE_HOST: "${BDB_NODE_HOST}"
BDB_NODE_PORT: "${BDB_NODE_PORT}"
BDB_NODE_HOST: bigchaindb
BDB_NODE_PORT: 9984
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this earlier when it was changed, but this shouldn't be breaking anything. bigchaindb is the service name of the container running the BigchainDB server so docker should know to hook up to it directly.

ports:
- "${API_PORT}:3000"
command: python web/server.py
Expand Down
2 changes: 1 addition & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pip==8.1.2
pip==9.0.1
bumpversion==0.5.3
wheel==0.29.0

Expand Down
7 changes: 3 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
from setuptools import setup, find_packages

install_requires = [
'coalaip>=0.0.1.dev3',
'coalaip-bigchaindb>=0.0.1.dev3',
'bigchaindb==0.8.0',
'bigchaindb-driver==0.1.2',
'coalaip==0.0.1',
'coalaip-bigchaindb==0.0.1',
'bigchaindb~=0.9.1',
'flask>=0.11.1',
'flask-restful>=0.3.5',
'gunicorn>=19.6.0',
Expand Down
26 changes: 26 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,29 @@ def app():
@pytest.fixture
def user(client):
return client.post(url_for('user_views.userapi')).json


@pytest.fixture
def created_manifestation_resp(client, user):
import json
from time import sleep
payload = {
'manifestation': {
'name': 'The Fellowship of the Ring',
'datePublished': '29-07-1954',
'url': 'http://localhost/lordoftherings.txt',
},
'copyrightHolder': user,
'work': {
'name': 'The Lord of the Rings Triology',
'author': 'J. R. R. Tolkien',
},
}

resp = client.post(url_for('manifestation_views.manifestationapi'),
data=json.dumps(payload),
headers={'Content-Type': 'application/json'})

# Sleep for a bit to let the transaction become valid
sleep(3)
return resp.json
16 changes: 9 additions & 7 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
def test_create_user(client):
resp = client.post(url_for('user_views.userapi'))
assert resp.status_code == 200
assert resp.json['verifyingKey']
assert resp.json['signingKey']
assert resp.json['publicKey']
assert resp.json['privateKey']


def test_create_manifestation(client, user):
Expand All @@ -27,7 +27,7 @@ def test_create_manifestation(client, user):
expected = {
'work': {
'@context': ['<coalaip placeholder>', 'http://schema.org/'],
'@type': 'CreativeWork',
'@type': 'AbstractWork',
'name': 'The Lord of the Rings Triology',
'author': 'J. R. R. Tolkien',
},
Expand All @@ -37,7 +37,6 @@ def test_create_manifestation(client, user):
'name': 'The Fellowship of the Ring',
'datePublished': '29-07-1954',
'url': 'http://localhost/lordoftherings.txt',
'isManifestation': True,
},
'copyright': {
'@context': ['<coalaip placeholder>', 'http://schema.org/'],
Expand Down Expand Up @@ -109,20 +108,23 @@ def test_create_manifestation_missing_argument_in_body(client):
'Missing required parameter in the JSON body'


def test_create_right(client, user):
def test_create_right(client, user, created_manifestation_resp):
copyright_id = created_manifestation_resp['copyright']['@id']
copyright_id = copyright_id.split('../rights/')[1]

payload = {
'currentHolder': user,
'right': {
'license': 'http://www.ascribe.io/terms',
},
'sourceRightId': 'mockId',
'sourceRightId': copyright_id,
}

expected = {
'right': {
'@context': ['<coalaip placeholder>', 'http://schema.org/'],
'@type': 'Right',
'allowedBy': payload['sourceRightId'],
'source': payload['sourceRightId'],
'license': 'http://www.ascribe.io/terms',
}
}
Expand Down
2 changes: 1 addition & 1 deletion web/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from web.utils import parse_model


user_model = parse_model(['verifyingKey', 'signingKey'])
user_model = parse_model(['publicKey', 'privateKey'])
manifestation_model = parse_model(['name', 'datePublished', 'url'])
work_model = parse_model(['name', 'author'])
right_model = parse_model(['license'])
13 changes: 3 additions & 10 deletions web/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
BigchainDBConfiguration = namedtuple('BigchainDBConfiguration', [
'hostname',
'port',
'api_path'
])


Expand All @@ -19,20 +18,14 @@
if not BDB_PORT:
BDB_PORT = '9984'

BDB_API_PATH = os.environ.get('BDB_NODE_API_PATH', None)
if not BDB_API_PATH:
BDB_API_PATH = 'api/v1'


def get_bigchaindb_configuration():
return BigchainDBConfiguration(BDB_HOST, BDB_PORT, BDB_API_PATH)
return BigchainDBConfiguration(BDB_HOST, BDB_PORT)


def get_bigchaindb_api_url():
hostname, port, api_path = get_bigchaindb_configuration()
return 'http://{hostname}:{port}/{api_path}'.format(hostname=hostname,
port=port,
api_path=api_path)
hostname, port = get_bigchaindb_configuration()
return 'http://{hostname}:{port}'.format(hostname=hostname, port=port)


def parse_model(required_fields):
Expand Down
4 changes: 2 additions & 2 deletions web/views/manifestations.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def post(self):

copyright_holder = args['copyrightHolder']
copyright_holder = {
'verifying_key': copyright_holder.pop('verifyingKey'),
'signing_key': copyright_holder.pop('signingKey')
'public_key': copyright_holder.pop('publicKey'),
'private_key': copyright_holder.pop('privateKey')
}

copyright_, manifestation, work = coalaip.register_manifestation(
Expand Down
6 changes: 3 additions & 3 deletions web/views/rights.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ def post(self):

source_right_id = args['sourceRightId']
right = args['right']
right['allowedBy'] = source_right_id
right['source'] = source_right_id

current_holder = args['currentHolder']
current_holder['verifying_key'] = current_holder.pop('verifyingKey')
current_holder['signing_key'] = current_holder.pop('signingKey')
current_holder['public_key'] = current_holder.pop('publicKey')
current_holder['private_key'] = current_holder.pop('privateKey')

right = coalaip.derive_right(right_data=right,
current_holder=current_holder)
Expand Down
6 changes: 3 additions & 3 deletions web/views/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ def post(self):
"""API endpoint to create a new keypair for a user

Return:
A dict containing the verifying_key and signing_key.
A dict containing the publicKey and privateKey.
"""
# TODO FOR COALA IP: Return CamelCase key names
user = coalaip.generate_user()
# TODO: We might want to have a generic function for this at one point.
user['verifyingKey'] = user.pop('verifying_key')
user['signingKey'] = user.pop('signing_key')
user['publicKey'] = user.pop('public_key')
user['privateKey'] = user.pop('private_key')
return user


Expand Down