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

feat(prism-agent): add connect/issue doc + allow local execution of multiple Prism Agent instances #178

Merged
merged 6 commits into from
Nov 29, 2022
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
48 changes: 33 additions & 15 deletions infrastructure/local/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ services:
POSTGRES_DB: castor
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
volumes:
- pg_data_castor_db:/var/lib/postgresql/data

Expand All @@ -36,8 +34,6 @@ services:
POSTGRES_DB: pollux
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- 5433:5432
volumes:
- pg_data_pollux_db:/var/lib/postgresql/data

Expand All @@ -49,6 +45,28 @@ services:
db_pollux:
condition: service_started

##########################
# Connect Database
Copy link
Member

Choose a reason for hiding this comment

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

let's keep it as it is, but I'm concerned that we currently have a database per building block or even per product.
probably, it's ok, but I want any ADR that defines this architecture.
having castor, pollux, mercury, connect DBs and 3 roles holder, issuer, verifier we might come to the exposure of dbs :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO we'd better have a single Postgres instance for everything, and even a single DB containing all BB tables. But let's discuss that later on yes 👍

Copy link

Choose a reason for hiding this comment

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

When it is deployed to a real environmnet [non-local] it is a single instance of PG with multiple databases - which will suit us well if they ever become microservices of their own / when we face scaling issues

##########################

db_connect:
image: postgres:13
restart: always
environment:
POSTGRES_DB: connect
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
volumes:
- pg_data_connect_db:/var/lib/postgresql/data

# delay to ensure DB is up before applying migrations
db_connect_init_delay:
image: alpine:3
command: sleep 5
depends_on:
db_connect:
condition: service_started

##########################
# Iris Database
##########################
Expand All @@ -60,8 +78,6 @@ services:
POSTGRES_DB: iris
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- 5434:5432
volumes:
- pg_data_iris_db:/var/lib/postgresql/data

Expand All @@ -78,20 +94,18 @@ services:
# Services
##########################
mediator:
image: ghcr.io/input-output-hk/mercury-mediator:0.1.0-SNAPSHOT
image: ghcr.io/input-output-hk/mercury-mediator:0.2.0

iris:
image: ghcr.io/input-output-hk/iris-service:0.1.0-SNAPSHOT
ports:
- 8081:8081
image: ghcr.io/input-output-hk/iris-service:0.1.0
Copy link
Member

Choose a reason for hiding this comment

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

one more question for architecture meeting: how to template the component versions
probably, we can move this to config file or some other args

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, good point. I will add that as a next AOH topic 👍

Copy link

Choose a reason for hiding this comment

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

I've done this in the local running script in this PR #153 - I'll finalise it today

environment:
IRIS_DB_HOST: db_iris
IRIS_DB_PORT: 5432
IRIS_DB_NAME: iris
IRIS_DB_USER: postgres

prism-agent:
image: ghcr.io/input-output-hk/prism-agent:0.2.0-SNAPSHOT
image: ghcr.io/input-output-hk/prism-agent:0.6.0-SNAPSHOT
environment:
IRIS_HOST: iris
IRIS_PORT: 8081
Expand All @@ -105,9 +119,12 @@ services:
POLLUX_DB_NAME: pollux
POLLUX_DB_USER: postgres
POLLUX_DB_PASSWORD: postgres
ports:
- "8085:8085"
- "8080:8080"
CONNECT_DB_HOST: db_connect
CONNECT_DB_PORT: 5432
CONNECT_DB_NAME: connect
CONNECT_DB_USER: postgres
CONNECT_DB_PASSWORD: postgres
DIDCOMM_SERVICE_URL: http://host.docker.internal:${PORT}/didcomm/

swagger-ui:
image: swaggerapi/swagger-ui:v4.14.0
Expand All @@ -121,7 +138,7 @@ services:
haproxy:
image: haproxy:2.6.5
ports:
- "80:80" # Http
- "${PORT}:80" # Http
depends_on:
- mediator
- prism-agent
Expand All @@ -132,4 +149,5 @@ services:
volumes:
pg_data_castor_db:
pg_data_pollux_db:
pg_data_connect_db:
pg_data_iris_db:
16 changes: 12 additions & 4 deletions infrastructure/local/haproxy/haproxy.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ frontend https-in
option httplog
option logasap

use_backend mediator if { path_beg -i /mediator }
use_backend swagger-ui if { path_beg -i /apidocs }
use_backend prism-agent if { path_beg -i /prism-agent }
use_backend prism-agent-tapir if { path_beg -i /tapir }
use_backend mediator if { path_beg -i /mediator }
use_backend swagger-ui if { path_beg -i /apidocs }
use_backend prism-agent if { path_beg -i /prism-agent }
use_backend prism-agent-didcomm if { path_beg -i /didcomm }
use_backend prism-agent-tapir if { path_beg -i /tapir }

backend mediator
balance roundrobin
Expand All @@ -43,6 +44,13 @@ backend prism-agent
option forwardfor
server s1 prism-agent:8080 maxconn 32

backend prism-agent-didcomm
balance roundrobin
http-request set-uri %[url,regsub(^/didcomm,,)] if { path_beg /didcomm }
option httpclose
option forwardfor
server s1 prism-agent:8090 maxconn 32

backend prism-agent-tapir
balance roundrobin
http-request set-uri %[url,regsub(^/tapir,,)] if { path_beg /tapir }
Expand Down
7 changes: 7 additions & 0 deletions prism-agent/service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ Similar to [Indy Wallet SDK - secret API](https://github.com/hyperledger/indy-sd
*it does not expose a private-key* for external use, instead it provide functions to perform cryptographic actions using internally stored private-keys.

---
## Connect flow
Basic documentation on how to execute the Connect flow from command line can be found [here](./connect.md).

---
## Issue flow
Basic documentation on how to execute the Issue flow from the command line can be found [here](./issue.md).

---
## Known limitations

### Castor `worker` process embedded inside `prism-agent` runnable
Expand Down
51 changes: 51 additions & 0 deletions prism-agent/service/connect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
### Running multiple instances of Prism Agent
---

#### Starting an instance for `Inviter` on port `8080`

```bash
# From the root directory
PORT=8080 docker-compose -p inviter -f infrastructure/local/docker-compose.yml up
Copy link
Member

Choose a reason for hiding this comment

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

can we redefine the roles in the next PR to holder, verifier, and issuer?
from my point of view, inviter and invitee are little bit abstract

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would keep Inviter and Invitee given we don't know the protocol/flow the connected parties will later execute using that connection. It could be two physical persons - Alice & Bob - just willing to execute "basic messaging". Nothing related to VC.

```

#### Starting an instance for `Invitee` on port `8090`

```bash
# From the root directory
PORT=8090 docker-compose -p invitee -f infrastructure/local/docker-compose.yml up
```

### Executing the `Connect` flow
---

- **Inviter** - Create a connection record containing the invitation
```bash
curl -X 'POST' \
'http://localhost:8080/prism-agent/connections' \
-H 'Content-Type: application/json' \
-d '{
"label": "Connect with Alice"
}' | jq
```

- **Inviter** - Retrieving the list of connections
```bash
curl -X 'GET' 'http://localhost:8080/prism-agent/connections' | jq
```

- **Invitee** - Accept OOB invitation

Replace `{RAW_INVITATION}` with the value of the '_oob' query string parameter from the invitation URL above
```bash
curl -X 'POST' \
'http://localhost:8090/prism-agent/connection-invitations' \
-H 'Content-Type: application/json' \
-d '{
"invitation": "{RAW_INVITATION}"
}' | jq
```

- **Invitee** - Retrieving the list of connections
```bash
curl -X 'GET' 'http://localhost:8090/prism-agent/connections' | jq
```
65 changes: 65 additions & 0 deletions prism-agent/service/issue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
### Running multiple instances of Prism Agent
---

#### Starting an instance for `Issuer` on port `8080`

```bash
# From the root directory
PORT=8080 docker-compose -p issuer -f infrastructure/local/docker-compose.yml up
```

#### Starting an instance for `Holder` on port `8090`

```bash
# From the root directory
PORT=8090 docker-compose -p holder -f infrastructure/local/docker-compose.yml up
```

### Executing the `Issue` flow
---

- **Issuer** - Initiate a new issue credential flow

Replace `{SUBJECT_ID}` with the DID of the holder displayed at startup in the his Prism Agent console logs
```bash
curl -X 'POST' \
'http://localhost:8080/prism-agent/issue-credentials/credential-offers' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"schemaId": "schema:1234",
"subjectId": "{SUBJECT_ID}",
"validityPeriod": 3600,
"automaticIssuance": false,
"awaitConfirmation": false,
"claims": {
"firstname": "Alice",
"lastname": "Wonderland",
"birthdate": "01/01/2000"
}
}' | jq
```

- **Holder** - Retrieving the list of issue records
```bash
curl -X 'GET' 'http://localhost:8090/prism-agent/issue-credentials/records' | jq
```

- **Holder** - Accepting the credential offer

Replace `{RECORD_ID}` with the UUID of the record from the previous list
```bash
curl -X 'POST' 'http://localhost:8090/prism-agent/issue-credentials/records/{RECORD_ID}/accept-offer' | jq
```

- **Issuer** - Retrieving the list of issue records
```bash
curl -X 'GET' 'http://localhost:8080/prism-agent/issue-credentials/records' | jq
```

- **Issuer** - Issuing the credential

Replace `{RECORD_ID}` with the UUID of the record from the previous list
```bash
curl -X 'POST' 'http://localhost:8080/prism-agent/issue-credentials/records/{RECORD_ID}/issue-credential' | jq
```
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ object Main extends ZIOAppDefault {
.provide(RepoModule.connectDbConfigLayer >>> ConnectMigrations.layer)

agentDID <- for {
peer <- ZIO.succeed(PeerDID.makePeerDid(serviceEndpoint = Some(s"$didCommServiceUrl:$didCommServicePort")))
peer <- ZIO.succeed(PeerDID.makePeerDid(serviceEndpoint = Some(didCommServiceUrl)))
_ <- ZIO.logInfo(s"New DID: ${peer.did}") *>
ZIO.logInfo(s"JWK for KeyAgreement: ${peer.jwkForKeyAgreement.toJSONString}") *>
ZIO.logInfo(s"JWK for KeyAuthentication: ${peer.jwkForKeyAuthentication.toJSONString}")
Expand Down
2 changes: 1 addition & 1 deletion prism-agent/service/version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ThisBuild / version := "0.5.0-SNAPSHOT"
ThisBuild / version := "0.6.0-SNAPSHOT"
Copy link
Member

Choose a reason for hiding this comment

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

as far as I remember, @antonbaliasnikov and @FabioPinheiro added the guard that protects version.sbt files from manual edition

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@antonbaliasnikov I thought it would be automatically overridden by the release process. If 0.5.0 is released then that file should be updated automatically to the next version 0.6.0-SNAPSHOT, no?

Choose a reason for hiding this comment

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

We should never edit these files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, but will that file be updated automatically by the release pipeline then?