Skip to content

Commit

Permalink
doc + endpoint update
Browse files Browse the repository at this point in the history
Signed-off-by: Shaanjot Gill <[email protected]>
  • Loading branch information
shaangill025 committed Jul 24, 2023
1 parent 1dc452b commit 3e15149
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 26 deletions.
43 changes: 37 additions & 6 deletions Multiledger.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,37 @@ If `--genesis-transactions-list` is specified, then `--genesis-url, --genesis-fi
genesis_url: 'http://test.bcovrin.vonx.io/genesis'
```

```
- id: localVON
is_production: false
genesis_url: 'http://host.docker.internal:9000/genesis'
- id: bcorvinTest
is_production: true
is_write: true
genesis_url: 'http://test.bcovrin.vonx.io/genesis'
- id: greenlightDev
is_production: true
is_write: true
genesis_url: 'http://dev.greenlight.bcovrin.vonx.io/genesis'
```

Note: `is_write` property means that the ledger is write configurable. With reference to the above config example, both `bcorvinTest` and `greenlightDev` ledgers are write configurable. By default, on startup `bcorvinTest` will be the write ledger as it is the topmost write configurable production ledger, [more details](#write-requests) regarding the selection rule. Using `PUT /ledger/{ledger_id}/set-write-ledger` endpoint, either `greenlightDev` and `bcorvinTest` can be set as the write ledger.

```
- id: localVON
is_production: false
is_write: true
genesis_url: 'http://host.docker.internal:9000/genesis'
- id: bcorvinTest
is_production: true
genesis_url: 'http://test.bcovrin.vonx.io/genesis'
- id: greenlightDev
is_production: true
genesis_url: 'http://dev.greenlight.bcovrin.vonx.io/genesis'
```

Note: For instance with regards to example config above, `localVON` will be the write ledger, as there are no production ledgers which are configurable it will choose the topmost write configurable non production ledger.

### Config properties
For each ledger, the required properties are as following:

Expand All @@ -52,20 +83,20 @@ Optional properties:
- `pool_name`: name of the indy pool to be opened
- `keepalive`: how many seconds to keep the ledger open
- `socks_proxy`
- `is_write`: Whether this ledger is writable/can be write configurable. Multiple write ledgers can be specified in config.
- `is_write`: Whether this ledger is writable. It requires atleast one write ledger specified. Multiple write ledgers can be specified in config.


## Multi-ledger Admin API

Multi-ledger related actions are grouped under the `ledger` topic in the SwaggerUI or under `/ledger/multiple` path.
Multi-ledger related actions are grouped under the `ledger` topic in the SwaggerUI.

- `/ledger/multiple/config`:
- GET `/ledger/config`:
Returns the multiple ledger configuration currently in use
- `/ledger/multiple/get-write-ledger`:
- GET `/ledger/get-write-ledger`:
Returns the current active/set `write_ledger's` `ledger_id`
- `/ledger/multiple/get-write-ledgers`:
- GET `/ledger/get-write-ledgers`:
Returns list of available `write_ledger's` `ledger_id`
- `/ledger/multiple/{ledger_id}/set-write-ledger`:
- PUT `/ledger/{ledger_id}/set-write-ledger`:
Set active `write_ledger's` `ledger_id`

## Ledger Selection
Expand Down
19 changes: 7 additions & 12 deletions aries_cloudagent/ledger/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,8 +683,7 @@ async def get_write_ledgers(request: web.BaseRequest):
async with context.profile.session() as session:
multiledger_mgr = session.inject_or(BaseMultipleLedgerManager)
if not multiledger_mgr:
reason = "Multiple ledger support not enabled"
raise web.HTTPForbidden(reason=reason)
return web.json_response(["default"])
available_write_ledgers = await multiledger_mgr.get_write_ledgers()
return web.json_response(available_write_ledgers)

Expand All @@ -707,8 +706,7 @@ async def get_write_ledger(request: web.BaseRequest):
multiledger_mgr = session.inject_or(BaseMultipleLedgerManager)
write_ledger = session.inject(BaseLedger)
if not multiledger_mgr:
reason = "Multiple ledger support not enabled"
raise web.HTTPForbidden(reason=reason)
return web.json_response({"ledger_id": "default"})
ledger_id = await multiledger_mgr.get_ledger_id_by_ledger_pool_name(
write_ledger.pool_name
)
Expand All @@ -733,8 +731,7 @@ async def set_write_ledger(request: web.BaseRequest):
async with context.profile.session() as session:
multiledger_mgr = session.inject_or(BaseMultipleLedgerManager)
if not multiledger_mgr:
reason = "Multiple ledger support not enabled"
raise web.HTTPForbidden(reason=reason)
return web.json_response({"write_ledger": "default"})
req_ledger_id = request.match_info.get("ledger_id")
try:
set_ledger_id = await multiledger_mgr.set_profile_write_ledger(
Expand Down Expand Up @@ -808,16 +805,14 @@ async def register(app: web.Application):
web.get("/ledger/did-endpoint", get_did_endpoint, allow_head=False),
web.get("/ledger/taa", ledger_get_taa, allow_head=False),
web.post("/ledger/taa/accept", ledger_accept_taa),
web.get("/ledger/get-write-ledger", get_write_ledger, allow_head=False),
web.put("/ledger/{ledger_id}/set-write-ledger", set_write_ledger),
web.get(
"/ledger/multiple/get-write-ledger", get_write_ledger, allow_head=False
),
web.put("/ledger/multiple/{ledger_id}/set-write-ledger", set_write_ledger),
web.get(
"/ledger/multiple/get-write-ledgers",
"/ledger/get-write-ledgers",
get_write_ledgers,
allow_head=False,
),
web.get("/ledger/multiple/config", get_ledger_config, allow_head=False),
web.get("/ledger/config", get_ledger_config, allow_head=False),
]
)

Expand Down
15 changes: 11 additions & 4 deletions aries_cloudagent/ledger/tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,10 +793,17 @@ async def test_get_write_ledger(self):
)
assert result is json_response.return_value

async def test_get_write_ledger_x(self):
with self.assertRaises(test_module.web.HTTPForbidden) as cm:
await test_module.get_write_ledger(self.request)
assert "No instance provided for BaseMultipleLedgerManager" in cm
async def test_get_write_ledger_single_ledger(self):
with async_mock.patch.object(
test_module.web, "json_response", async_mock.Mock()
) as json_response:
result = await test_module.get_write_ledger(self.request)
json_response.assert_called_once_with(
{
"ledger_id": "default",
}
)
assert result is json_response.return_value

async def test_get_ledger_config(self):
self.profile.context.injector.bind_instance(
Expand Down
54 changes: 52 additions & 2 deletions open-api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2773,7 +2773,7 @@
"tags" : [ "ledger" ]
}
},
"/ledger/multiple/config" : {
"/ledger/config" : {
"get" : {
"responses" : {
"200" : {
Expand All @@ -2791,7 +2791,49 @@
"tags" : [ "ledger" ]
}
},
"/ledger/multiple/get-write-ledger" : {
"/ledger/get-write-ledgers" : {
"get" : {
"tags" : [ "ledger" ],
"summary" : "Fetch list of available write ledger",
"produces" : [ "application/json" ],
"parameters" : [ ],
"responses" : {
"200" : {
"description" : "",
"type" : "array",
"items" : {
"type" : "string",
"example" : "ledger id"
}
}
}
}
},
"/ledger/set-write-ledger" : {
"put" : {
"tags" : [ "ledger" ],
"summary" : "Set write ledger",
"produces" : [ "application/json" ],
"parameters" : [
{
"name" : "ledger_id",
"in" : "path",
"description" : "Ledger identifier",
"required" : true,
"type" : "string"
}
],
"responses" : {
"200" : {
"description" : "",
"schema" : {
"$ref" : "#/definitions/WriteLedgerResponse"
}
}
}
}
},
"/ledger/get-write-ledger" : {
"get" : {
"responses" : {
"200" : {
Expand Down Expand Up @@ -13023,6 +13065,14 @@
},
"type" : "object"
},
"WriteLedgerResponse" : {
"type" : "object",
"properties" : {
"write_ledger" : {
"type" : "string"
}
}
},
"UpdateProfileSettingsRequest" : {
"type" : "object",
"properties" : {
Expand Down
54 changes: 52 additions & 2 deletions open-api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2276,7 +2276,7 @@
}
}
},
"/ledger/multiple/config" : {
"/ledger/config" : {
"get" : {
"tags" : [ "ledger" ],
"summary" : "Fetch the multiple ledger configuration currently in use",
Expand All @@ -2292,7 +2292,49 @@
}
}
},
"/ledger/multiple/get-write-ledger" : {
"/ledger/get-write-ledgers" : {
"get" : {
"tags" : [ "ledger" ],
"summary" : "Fetch list of available write ledger",
"produces" : [ "application/json" ],
"parameters" : [ ],
"responses" : {
"200" : {
"description" : "",
"type" : "array",
"items" : {
"type" : "string",
"example" : "ledger id"
}
}
}
}
},
"/ledger/set-write-ledger" : {
"put" : {
"tags" : [ "ledger" ],
"summary" : "Set write ledger",
"produces" : [ "application/json" ],
"parameters" : [
{
"name" : "ledger_id",
"in" : "path",
"description" : "Ledger identifier",
"required" : true,
"type" : "string"
}
],
"responses" : {
"200" : {
"description" : "",
"schema" : {
"$ref" : "#/definitions/WriteLedgerResponse"
}
}
}
}
},
"/ledger/get-write-ledger" : {
"get" : {
"tags" : [ "ledger" ],
"summary" : "Fetch the current write ledger",
Expand Down Expand Up @@ -11949,6 +11991,14 @@
}
}
},
"WriteLedgerResponse" : {
"type" : "object",
"properties" : {
"write_ledger" : {
"type" : "string"
}
}
},
"UpdateProfileSettingsRequest" : {
"type" : "object",
"properties" : {
Expand Down

0 comments on commit 3e15149

Please sign in to comment.