Skip to content

Commit

Permalink
feat: agent config interface (#290)
Browse files Browse the repository at this point in the history
* feat: agent config interface

* test: linting

* test: local config iurls [skip ci]

* build: dev5 keria

* prettier
  • Loading branch information
iFergal authored Dec 2, 2024
1 parent 2bf0df1 commit e8a4047
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
strategy:
matrix:
os: ['ubuntu-latest']
keria-version: ['0.2.0-dev4']
keria-version: ['0.2.0-dev5']
node-version: ['20']
env:
KERIA_IMAGE_TAG: ${{ matrix.keria-version }}
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ services:
- 7723:7723

keria:
image: ${KERIA_IMAGE:-weboftrust/keria}:${KERIA_IMAGE_TAG:-0.2.0-dev4}
image: ${KERIA_IMAGE:-weboftrust/keria}:${KERIA_IMAGE_TAG:-0.2.0-dev5}
environment:
- KERI_AGENT_CORS=1
- KERI_URL=http://keria:3902
Expand Down
29 changes: 29 additions & 0 deletions examples/integration-scripts/test-setup-single-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('test-setup-single-client', () => {
'EB3UGWwIMq7ppzcQ697ImQIuXlBG5jzh-baSx-YG3-tY'
);
});

test('step2', async () => {
const env = resolveEnvironment();
const oobi = await client.oobis().get('name1', 'witness');
Expand Down Expand Up @@ -62,4 +63,32 @@ describe('test-setup-single-client', () => {
break;
}
});

test('validate config', async () => {
const env = resolveEnvironment();
const config = await client.config().get();
switch (env.preset) {
case 'local':
expect(config).toEqual({
iurls: [
'http://127.0.0.1:5642/oobi/BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha/controller?name=Wan&tag=witness',
'http://127.0.0.1:5643/oobi/BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM/controller?name=Wes&tag=witness',
'http://127.0.0.1:5644/oobi/BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX/controller?name=Wil&tag=witness',
],
});
break;
case 'docker':
expect(config).toEqual({
iurls: [
'http://witness-demo:5642/oobi/BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha/controller',
'http://witness-demo:5643/oobi/BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM/controller',
'http://witness-demo:5644/oobi/BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX/controller',
'http://witness-demo:5645/oobi/BM35JN8XeJSEfpxopjn5jr7tAHCE5749f0OobhMLCorE/controller',
'http://witness-demo:5646/oobi/BIj15u5V11bkbtAxMA7gcNJZcax-7TgaBMLsQnMHpYHP/controller',
'http://witness-demo:5647/oobi/BF2rZTW79z4IXocYRQnjjsOuvFUQv-ptCf8Yltd7PfsM/controller',
],
});
break;
}
});
});
10 changes: 9 additions & 1 deletion src/keri/app/clienting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Tier } from '../core/salter';
import { Identifier } from './aiding';
import { Contacts, Challenges } from './contacting';
import { Agent, Controller } from './controller';
import { Oobis, Operations, KeyEvents, KeyStates } from './coring';
import { Oobis, Operations, KeyEvents, KeyStates, Config } from './coring';
import { Credentials, Ipex, Registries, Schemas } from './credentialing';
import { Delegations } from './delegating';
import { Escrows } from './escrowing';
Expand Down Expand Up @@ -478,4 +478,12 @@ export class SignifyClient {
delegations(): Delegations {
return new Delegations(this);
}

/**
* Get agent config resource
* @returns {Config}
*/
config(): Config {
return new Config(this);
}
}
23 changes: 23 additions & 0 deletions src/keri/app/coring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ export interface OperationsDeps {
): Promise<Response>;
}

export interface AgentConfig {
iurls?: string[];
}

/**
* Operations
* @remarks
Expand Down Expand Up @@ -278,3 +282,22 @@ export class KeyStates {
return await res.json();
}
}

export class Config {
public client: SignifyClient;

/**
* Config
* @param {SignifyClient} client
*/
constructor(client: SignifyClient) {
this.client = client;
}

async get(): Promise<AgentConfig> {
const path = `/config`;
const method = 'GET';
const res = await this.client.fetch(path, method, null);
return await res.json();
}
}
17 changes: 17 additions & 0 deletions test/app/coring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,23 @@ describe('Coring', () => {
'EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao'
);
});

it('Agent configuration', async () => {
await libsodium.ready;
const bran = '0123456789abcdefghijk';

const client = new SignifyClient(url, bran, Tier.low, boot_url);

await client.boot();
await client.connect();

const config = client.config();

await config.get();
const lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length - 1]!;
assert.equal(lastCall[0]!, url + '/config');
assert.equal(lastCall[1]!.method, 'GET');
});
});

describe('Operations', () => {
Expand Down

0 comments on commit e8a4047

Please sign in to comment.