Skip to content

Commit c2feebf

Browse files
elenaizaguirrepetermetz
authored andcommitted
fix: add optional auth token to api-client and consortium-manual
relationed with #1579 Signed-off-by: Elena Izaguirre <[email protected]>
1 parent 531956c commit c2feebf

File tree

8 files changed

+23
-7
lines changed

8 files changed

+23
-7
lines changed

examples/cactus-example-supply-chain-frontend/src/app/bamboo-harvest/bamboo-harvest-list/bamboo-harvest-list.page.ts

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export class BambooHarvestListPage implements OnInit {
4242
this._supplyChainApi = await this.baseClient.ofLedger(
4343
this.quorumLedgerId,
4444
SupplyChainApi,
45+
{},
4546
);
4647
await this.loadData();
4748
}

examples/cactus-example-supply-chain-frontend/src/app/bookshelf/bookshelf-detail/bookshelf-detail.page.ts

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export class BookshelfDetailPage implements OnInit {
5252
this._supplyChainApi = await this.baseClient.ofLedger(
5353
this.quorumLedgerId,
5454
SupplyChainApi,
55+
{},
5556
);
5657

5758
if (!this.bookshelf) {

examples/cactus-example-supply-chain-frontend/src/app/bookshelf/bookshelf-list/bookshelf-list.page.ts

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export class BookshelfListPage implements OnInit {
4242
this._supplyChainApi = await this.baseClient.ofLedger(
4343
this.ledgerId,
4444
SupplyChainApi,
45+
{},
4546
);
4647
await this.loadData();
4748
}

examples/cactus-example-supply-chain-frontend/src/app/shipment/shipment-detail/shipment-detail.page.ts

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export class ShipmentDetailPage implements OnInit {
5252
this._supplyChainApi = await this.baseClient.ofLedger(
5353
this.quorumLedgerId,
5454
SupplyChainApi,
55+
{},
5556
);
5657

5758
if (!this.shipment) {

examples/cactus-example-supply-chain-frontend/src/app/shipment/shipment-list/shipment-list.page.ts

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export class ShipmentListPage implements OnInit {
4242
this._supplyChainApi = await this.baseClient.ofLedger(
4343
this.ledgerId,
4444
SupplyChainApi,
45+
{},
4546
);
4647
await this.loadData();
4748
}

packages/cactus-api-client/src/main/typescript/api-client.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export class ApiClient extends BaseAPI {
8282
public async ofLedger<T>(
8383
ledgerOrId: string | Ledger,
8484
ctor: new (configuration?: Configuration) => T,
85+
ctorArgs: Record<string, unknown>,
8586
): Promise<ApiClient & T>;
8687
/**
8788
* Constructs a new `ApiClient` object that is tied to whichever Cactus node
@@ -103,6 +104,7 @@ export class ApiClient extends BaseAPI {
103104
public async ofLedger<T extends any>(
104105
ledgerOrId: string | Ledger,
105106
ctor: new (configuration?: Configuration) => T,
107+
ctorArgs: Record<string, unknown>,
106108
consortiumDbProvider?: IAsyncProvider<ConsortiumDatabase>,
107109
): Promise<ApiClient & T> {
108110
const fnTags = "ApiClient#forLedgerId()";
@@ -127,12 +129,13 @@ export class ApiClient extends BaseAPI {
127129
// pick a random element from the array of nodes that have a connection to
128130
// the target ledger (based on the ledger ID)
129131
const randomIdx = Math.floor(Math.random() * nodes.length);
130-
131132
const randomNode = nodes[randomIdx];
132133

133-
const configuration = new Configuration({
134-
basePath: randomNode.nodeApiHost,
135-
});
134+
// overwrite basePath with randomNode api host
135+
ctorArgs.basePath = randomNode.nodeApiHost;
136+
137+
// create the ApiClient configuration object
138+
const configuration = new Configuration(ctorArgs);
136139

137140
return new ApiClient(configuration).extendWith(ctor);
138141
}

packages/cactus-plugin-consortium-manual/src/main/typescript/plugin-consortium-manual.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export interface IPluginConsortiumManualOptions extends ICactusPluginOptions {
4848
prometheusExporter?: PrometheusExporter;
4949
pluginRegistry?: PluginRegistry;
5050
logLevel?: LogLevelDesc;
51+
ctorArgs?: Record<string, unknown>;
5152
}
5253

5354
export class PluginConsortiumManual
@@ -217,9 +218,16 @@ export class PluginConsortiumManual
217218
public async getConsortiumJws(): Promise<JWSGeneral> {
218219
const nodes = this.repo.allNodes;
219220

221+
const ctorArgs = this.options.ctorArgs || {};
222+
220223
const requests = nodes
221224
.map((cnm) => cnm.nodeApiHost)
222-
.map((host) => new Configuration({ basePath: host }))
225+
.map(function (host) {
226+
// overwrite basePath with node api host
227+
ctorArgs.basePath = host;
228+
// return the ApiClient configuration object
229+
return new Configuration(ctorArgs);
230+
})
223231
.map((configuration) => new DefaultApi(configuration))
224232
.map((apiClient) => apiClient.getNodeJwsV1());
225233

packages/cactus-test-api-client/src/test/typescript/integration/api-client-routing-node-to-node.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ test(testCase, async (t: Test) => {
254254
});
255255

256256
test("ApiClient #1 Routes based on Ledger ID #1", async (t2: Test) => {
257-
const apiClient1 = await mainApiClient.ofLedger(ledger1.id, QuorumApi);
257+
const apiClient1 = await mainApiClient.ofLedger(ledger1.id, QuorumApi, {});
258258

259259
// send money to the test account on ledger 1
260260
const res = await apiClient1.runTransactionV1({
@@ -278,7 +278,7 @@ test(testCase, async (t: Test) => {
278278
});
279279

280280
test("ApiClient #1 Routes based on Ledger ID #2", async (t2: Test) => {
281-
const apiClient2 = await mainApiClient.ofLedger(ledger2.id, QuorumApi);
281+
const apiClient2 = await mainApiClient.ofLedger(ledger2.id, QuorumApi, {});
282282

283283
// send money to the test account on ledger 1
284284
const res = await apiClient2.runTransactionV1({

0 commit comments

Comments
 (0)