Skip to content

Commit

Permalink
Rename Country to Jurisdiction (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
magicjohnson committed Aug 11, 2020
1 parent cc7de14 commit 8f08974
Show file tree
Hide file tree
Showing 43 changed files with 216 additions and 221 deletions.
8 changes: 4 additions & 4 deletions DEPLOYMENT.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ If you want to run integration tests:
docker-compose run tests-unit sh -c "cd /src && py.test tests/integration"
If you want to run another installation (like second country) use demo-dc-cn.yml file
If you want to run another installation (like second jurisdiction) use demo-dc-cn.yml file
and create ``demo-local-cn.env`` file (git excluded, feel free to add your settings):

IGL_COUNTRY=CN
IGL_JURISDICTION=CN
IGL_DEFAULT_S3_HOST=cnminio.cnint
IGL_DEFAULT_SQS_HOST=cnelasticmq
IGL_DEFAULT_POSTGRES_HOST=cnpostgresql
Expand All @@ -64,6 +64,6 @@ Configuration
Is done using env variables.
Boolean values must be strings and either true or false. JSON values must be rendered objects as a string. Everything else is a string. Lack of value uses default one, which is item-specific, or None if no default is provided.

* IGL_COUNTRY_DOCUMENT_REPORTS - string with JSON dict, keys are 2 character countries names, values are repo urs (http://.../..)
* IGL_JURISDICTION_DOCUMENT_REPORTS - string with JSON dict, keys are 2 character jurisdictions names, values are repo urs (http://.../..)
* IGL_DEBUG - enable/disable DEBUG for Flask instances
* IGL_TESTIG - enable/disable TESTING for Flask instances.
* IGL_TESTING - enable/disable TESTING for Flask instances.
2 changes: 1 addition & 1 deletion docker/demo-cn.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
IGL_COUNTRY=CN
IGL_JURISDICTION=CN
6 changes: 3 additions & 3 deletions docker/node.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Please ensure that the country is supported by the doc api table
# Please ensure that the jurisdiction is supported by the doc api table
# if you change it
PYTHONPATH=/src/:/src/intergov/libtrustbridge/
PYTHONUNBUFFERED=1
Expand Down Expand Up @@ -27,9 +27,9 @@ IGL_DEFAULT_POSTGRES_HOST=postgresql
IGL_DEFAULT_POSTGRES_USER=intergovuser
IGL_DEFAULT_POSTGRES_PASSWORD=intergovpassword
# you can change the db name if you want
# IGL_DEFAULT_POSTGRES_DBNAME=otherdbforcountry
# IGL_DEFAULT_POSTGRES_DBNAME=otherdbforjurisdiction

IGL_COUNTRY_DOCUMENT_REPORTS={"AU": "http://AU_ig_document_api:5000/","CN": "http://CN_ig_document_api:5000/","SG": "http://sg_ig_document_api:5000/"}
IGL_JURISDICTION_DOCUMENT_REPORTS={"AU": "http://AU_ig_document_api:5000/","CN": "http://CN_ig_document_api:5000/","SG": "http://sg_ig_document_api:5000/"}

# Separate settings for unit and integration tests,
# so it doesn't affect the main installation
Expand Down
4 changes: 2 additions & 2 deletions docker/node.igl-node-au.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
IGL_COUNTRY=AU
IGL_JURISDICTION=AU

# IGL_DEFAULT_SQS_HOST=auelasticmq
# IGL_DEFAULT_S3_HOST=auminio
Expand All @@ -11,7 +11,7 @@ DOCUMENT_API_BIND_HOST_PORT=18003
MESSAGE_RX_API_BIND_HOST_PORT=18009
IGL_PROC_BCH_MESSAGE_RX_API_URL=http://172.17.0.1:18009

IGL_COUNTRY_DOCUMENT_REPORTS={"AU": "http://172.17.0.1:18003/","SG": "http://172.17.0.1:18103"}
IGL_JURISDICTION_DOCUMENT_REPORTS={"AU": "http://172.17.0.1:18003/","SG": "http://172.17.0.1:18103"}

# This env variable...
IGL_MCHR_ROUTING_TABLE=[{"Id": "077a81bc-536e-4797-a26f-67f60f222b48", "Name": "shared db channel to Singapore", "Jurisdiction": "SG", "Predicate": "UN.CEFACT.", "ChannelUrl": "http://172.17.0.1:8180/", "ChannelAuth": "None"}, {"Id": "9e587efe-401a-42f3-813a-e6101ddfbb2a", "Name": "Local FR channel", "Jurisdiction": "FR", "Predicate": "UN.CEFACT.", "ChannelUrl": "http://docker-host:7500/", "ChannelAuth": "None"}]
Expand Down
4 changes: 2 additions & 2 deletions docker/node.igl-node-sg.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
IGL_COUNTRY=SG
IGL_JURISDICTION=SG

# IGL_DEFAULT_SQS_HOST=auelasticmq
# IGL_DEFAULT_S3_HOST=auminio
Expand All @@ -11,7 +11,7 @@ DOCUMENT_API_BIND_HOST_PORT=18103
MESSAGE_RX_API_BIND_HOST_PORT=18109
IGL_PROC_BCH_MESSAGE_RX_API_URL=http://172.17.0.1:18109

IGL_COUNTRY_DOCUMENT_REPORTS={"AU": "http://172.17.0.1:18003/","SG": "http://172.17.0.1:18103"}
IGL_JURISDICTION_DOCUMENT_REPORTS={"AU": "http://172.17.0.1:18003/","SG": "http://172.17.0.1:18103"}

# This env variable...
IGL_MCHR_ROUTING_TABLE=[{"Id": "b079bf38-c03d-4239-952b-d53b712bb07b", "Name": "shared db channel to Australia", "Jurisdiction": "AU", "Predicate": "UN.CEFACT.", "ChannelUrl": "http://172.17.0.1:8181/", "ChannelAuth": "None"}, {"Id": "9e587efe-401a-42f3-813a-e6101ddfbb2a", "Name": "Local FR channel", "Jurisdiction": "FR", "Predicate": "UN.CEFACT.", "ChannelUrl": "http://docker-host:7500/", "ChannelAuth": "None"}]
Expand Down
22 changes: 11 additions & 11 deletions docs/architecture_decision_notes/multichannel_architecture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ that all messages pass through.
This logical Hub could be a distributed ledger,
traditional database, paper clearinghouse,
so some other technology.
The basic idea is that countries
The basic idea is that jurisdictions
send their messages to this hub
and receive their messages from it too.

Expand Down Expand Up @@ -163,13 +163,13 @@ The above illustration shows a multi-channel scenario where:

* Country A and Country E have a bilateral arrangement for exchanging messages on any topic
* There is a multilateral arrangement
between Countries B, E and F
between Jurisdictions B, E and F
that supports messages on any topic
* There is a multilateral arrangement
between Countries A, B, C, F and G
between Jurisdictions A, B, C, F and G
that supports messages on a specific topic
* There is a multilateral arrangement
between Countries B, C, D, F, G and others (...)
between Jurisdictions B, C, D, F, G and others (...)
that supports messages on any topic
* There is an arrangement between Country D and others
supporting messages on some specific topic.
Expand All @@ -186,7 +186,7 @@ why a multi-channel architecture is necessary.
Support for Variable Topology
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Agreements between Countries are inherently bespoke.
Agreements between Jurisdictions are inherently bespoke.
Some are bilateral (links),
others are multilateral (networks).
The scope and details are customised
Expand All @@ -197,7 +197,7 @@ and new arrangements are made.

Even if a hub model is theoretically better
(no such theory is offered here),
the idea of asking almost 200 countries
the idea of asking almost 200 jurisdictions
to agree on a precise scope and details
for sharing cross-border trade documents
seems like it would be slow,
Expand All @@ -214,7 +214,7 @@ will involve a similar process of negotiation
to other international agreements.

While technical standardisation may reduce waste,
free countries will always ultimately determine
free jurisdictions will always ultimately determine
who they share what with, when and how;
and those arrangements will change over time
with policy and circumstance.
Expand Down Expand Up @@ -252,7 +252,7 @@ a universal "best technology"
to implement cross-border trade document sharing,
that would be a fleeting anomaly.

Any design that does not allow countries
Any design that does not allow jurisdictions
to negotiate technology choices
(and mutually agree to update or upgrade technology)
seems incongruent with
Expand All @@ -271,7 +271,7 @@ Support for Variable Protocols
The current proof of concept
supports a wire protocol that
we called "Discrete Generic Message" (DGM).
Each communication packet between countries
Each communication packet between jurisdictions
contains a single ("discrete") message,
and there is no limit to
the taxonomy of message types
Expand Down Expand Up @@ -330,8 +330,8 @@ could be very difficult or perhaps impossible.
The strategy of allowing multiple channels
might make the solution seem more complicated
from some perspectives,
but if countries can route messages over multiple channels
then it should be possible for a country
but if jurisdictions can route messages over multiple channels
then it should be possible for a jurisdiction
to maintain integration with the collection of channels
that best fit their needs.

Expand Down
2 changes: 1 addition & 1 deletion docs/backing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ of any implementation (backing service).
This intent of this technical detail
is to simplify the implementation of backing services
using whatever technology is most appropriate
for the country operating the ICL node.
for the jurisdiction operating the IGL node.
4 changes: 2 additions & 2 deletions docs/inbound.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ There is one of these workers for each distinct channel.

They are like listening posts.
They observe every message on the channel,
filter out the ones that originate from this country,
filter out the ones that originate from this jurisdiction,
and send the rest to the Private Message API for processing.

This way the rest of the system can know about new messages,
Expand Down Expand Up @@ -55,7 +55,7 @@ and does not need to know about the configuration of channels.
Private Message API
-------------------

When a message is sent by another country to this one,
When a message is sent by another jurisdiction to this one,
the Channel Observer component
associated with that channel
uses this private API to process the mesaages.
Expand Down
4 changes: 2 additions & 2 deletions docs/outbound.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ It is responsible for routing messages between Governments
.. autoclass:: intergov.processors.multichannel_router.MultichannelWorker

Note: channels abstract over topology, technology and wire protocols.
This means that countries are free
This means that jurisdictions are free
to determine bilaterally or multilaterally
agreeable channels.
This component will be configured to use the channels
as per the operating countries agreements.
as per the operating jurisdictions agreements.

.. uml::

Expand Down
8 changes: 4 additions & 4 deletions docs/purpose.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ Purpose

The TrustBridge InterGov codebase is
a Proof Of Concept (POC) implementation
of the edi3 Inter Government Ledger (ICL) Specification.
of the edi3 Inter Government Ledger (IGL) Specification.

The specific goal of this codebase
is to create infrastructure for
an independant ICL "Node".
an independant IGL "Node".

This node is as it would be operated by a Country.
It provides the interfaces required by the regulated community,
(i.e. B2G interfaces)
and it interfaces with "Channels"
which are are used for communicating with other countries
which are are used for communicating with other jurisdictions
(i.e. G2G interfaces).
It provides a suite of microservices
that reliably route and deliver messages between the two.
Expand All @@ -39,7 +39,7 @@ There are three basic types of deployable component:
* Worker Processes, which perform asynchronous tasks.

A very high level description of the design looks like this;
Each country operates a suite of services,
Each jurisdiction operates a suite of services,
that provides the following types of integration surface:

* Government to Government (G2G) "channels",
Expand Down
10 changes: 5 additions & 5 deletions intergov/apis/document/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ content, which may be JSON, ZIP, PDF document or something else. Read the EDI3 s

Auth:
* demo only - JWTBODY - just pass the JWT payload, unsigned, to the application
+ ``Authorization: JWTBODY {"sub": "documents-api", "party": "spider", "country": "AU"}``
+ ``Authorization: JWTBODY {"sub": "documents-api", "party": "spider", "jurisdiction": "AU"}``
+ parties may be "spider", "app" (chambers or importers) and so on
+ other fields may be present
+ ``country`` is the most important and used to allow or deny the access
+ ``jurisdiction`` is the most important and used to allow or deny the access
* OIDC - use standard OIDC protocol and add meaningful fields to the JWT
+ must provide at least country, given our documents are shared on country basis
+ must provide at least jurisdiction, given our documents are shared on jurisdiction basis

Endpoints
---------
Expand All @@ -26,15 +26,15 @@ Post document

Must be a multipart/form-data request with single file provided.

URL is `/countries/{receiver}/`
URL is `/jurisdictions/{receiver}/`

Response is multihash of the file uploaded. Client may calculate the multihash itself and compare
it with the returned one to ensure no data corruption occured. We use sha256 as the hash function.

No extra parameters are supported currently, but they may be provided as POST request (for backwards
compatibility with current API version and future clients).

curl -XPOST http://127.0.0.1:5103/countries/US \
curl -XPOST http://127.0.0.1:5103/jurisdictions/US \
-S -F "someextra=parameter" -F "file=@img.jpg;type=image/jpg" \
-H "Accept: application/json"

Expand Down
28 changes: 14 additions & 14 deletions intergov/apis/document/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Blueprint, Response, request,
)

from intergov.domain.country import Country
from intergov.domain.jurisdiction import Jurisdiction
from intergov.domain.uri import URI
from intergov.apis.common.errors import (
InternalServerError
Expand All @@ -25,7 +25,7 @@
from .exceptions import (
TooManyFilesError,
NoInputFileError,
BadCountryNameError,
BadJurisdictionNameError,
InvalidURIError,
DocumentNotFoundError
)
Expand All @@ -35,14 +35,14 @@
blueprint = Blueprint('documents', __name__)


@blueprint.route('/countries/<country_name>', methods=['POST'])
@blueprint.route('/jurisdictions/<jurisdiction_name>', methods=['POST'])
@routing.mimetype(['multipart/form-data'])
@statsd_timer("api.document.endpoint.document_post")
def document_post(country_name):
def document_post(jurisdiction_name):
try:
target_country = Country(country_name)
target_jurisdiction = Jurisdiction(jurisdiction_name)
except Exception as e:
raise BadCountryNameError(e)
raise BadJurisdictionNameError(e)

object_lake_repo = ObjectLakeRepo(Config.OBJECT_LAKE_CONN)
object_acl_repo = ObjectACLRepo(Config.OBJECT_ACL_CONN)
Expand All @@ -61,7 +61,7 @@ def document_post(country_name):
)

try:
multihash = use_case.execute(fobj=file, target_country=target_country)
multihash = use_case.execute(fobj=file, target_jurisdiction=target_jurisdiction)
except Exception as e:
logger.exception(e)
raise InternalServerError(e)
Expand Down Expand Up @@ -91,22 +91,22 @@ def document_fetch(uri):
)

request_auth = getattr(request, "auth", None)
if request_auth and 'country' in request_auth:
if request_auth and 'jurisdiction' in request_auth:
try:
auth_country = Country(request_auth['country'])
auth_jurisdiction = Jurisdiction(request_auth['jurisdiction'])
except Exception as e:
raise BadCountryNameError(e)
raise BadJurisdictionNameError(e)
else:
# no auth is provided, trust the GET request
# assuming JWT will handle it
# TODO: ensure that the auth provided allows access from that country
try:
auth_country = Country(request.args["as_country"])
auth_jurisdiction = Jurisdiction(request.args["as_jurisdiction"])
except Exception as e:
raise BadCountryNameError(e)
raise BadJurisdictionNameError(e)

try:
document_body = use_case.execute(uri, auth_country)
document_body = use_case.execute(uri, auth_jurisdiction)
except Exception as e:
logger.exception(e)
raise InternalServerError(e)
Expand All @@ -119,4 +119,4 @@ def document_fetch(uri):
# TODO: some information about the file content?
)
else:
raise DocumentNotFoundError(uri, auth_country)
raise DocumentNotFoundError(uri, auth_jurisdiction)
12 changes: 6 additions & 6 deletions intergov/apis/document/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
)


class BadCountryNameError(ValidationError):
class BadJurisdictionNameError(ValidationError):

detail = 'Received invalid/unknown country name'
detail = 'Received invalid/unknown jurisdiction name'

@property
def source(self):
Expand Down Expand Up @@ -43,16 +43,16 @@ class InvalidURIError(ValidationError):
detail = 'URI is not multihash'


def DocumentNotFoundError(uri, country):
def DocumentNotFoundError(uri, jurisdiction):
return GenericHTTPError(
HTTPStatus.NOT_FOUND,
detail='Document with uri:{} for country:{} not found'.format(
uri, country
detail='Document with uri:{} for jurisdiction:{} not found'.format(
uri, jurisdiction
),
source=[
{
'uri': uri,
'country': str(country)
'jurisdiction': str(jurisdiction)
}
]
)
2 changes: 1 addition & 1 deletion intergov/apis/message/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ to get the message by reference ID or post message to API inbox.
Typical users will be exporter app, importer app and so on.

Standard auth is required (actor should be entitled to view the message or send it
from given country/etc).
from given jurisdiction/etc).

Don't confuse it with message_rx_api, which is just another abstraction layer. This
one is a real API with auth, GET/POST endpoints and so on.
Expand Down
4 changes: 2 additions & 2 deletions intergov/apis/message/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

blueprint = Blueprint('messages', __name__)
logger = logging.getLogger(__name__)
IGL_COUNTRY = env('IGL_COUNTRY', default=None)
IGL_JURISDICTION = env('IGL_JURISDICTION', default=None)


@statsd_timer("api.message.endpoint.message_retrieve")
Expand Down Expand Up @@ -146,7 +146,7 @@ def message_post():
if not message.sender_ref:
message.kwargs["sender_ref"] = str(uuid.uuid4())

if str(IGL_COUNTRY) == str(message.sender):
if str(IGL_JURISDICTION) == str(message.sender):
# because we are first who see that message
message.kwargs["status"] = "pending"
else:
Expand Down

0 comments on commit 8f08974

Please sign in to comment.