-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from Sphereon-Opensource/develop
First release for testing
- Loading branch information
Showing
19 changed files
with
486 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,137 @@ | ||
import { program } from 'commander' | ||
import { GxEntityType } from './types' | ||
import { printTable } from 'console-table-printer' | ||
import { getAgent } from '@sphereon/gx-agent' | ||
import { EcosystemConfig, getAgent, normalizeEcosystemConfigurationObject } from '@sphereon/gx-agent' | ||
import { VerifiableCredential } from '@veramo/core' | ||
import { | ||
addEcosystemConfigObject, | ||
assertValidEcosystemConfigObject, | ||
deleteEcosystemConfigObject, | ||
getAgentConfigPath, | ||
getEcosystemConfigObject, | ||
getEcosystemConfigObjects, | ||
} from '@sphereon/gx-agent/dist/utils/config-utils' | ||
import fs from 'fs' | ||
|
||
const ecosystem = program.command('ecosystem').description('gx-participant ecosystem') | ||
const ecosystem = program.command('ecosystem').description('Ecosystem specific commands') | ||
|
||
ecosystem | ||
.command('add') | ||
.description('Adds a new Gaia-x ecosystem to the client') | ||
.requiredOption('-n, --name <string>', 'ecosystem name') | ||
.requiredOption('-url, --ecosystem-url <string>', 'gaia-x ecosystem server address') | ||
.action(async (cmd) => { | ||
const agent = await getAgent() | ||
const id = await agent.dataStoreSaveMessage({ | ||
//todo: create an entity here instead of using message | ||
message: { | ||
id: cmd.name, | ||
type: GxEntityType.ecosystem, | ||
createdAt: new Date().toUTCString(), | ||
data: { | ||
name: cmd.name, | ||
'ecosystem-url': cmd.ecosystemUrl, | ||
.alias('update') | ||
.description('Adds or updates a Gaia-x ecosystem to the client') | ||
.argument( | ||
'<name>', | ||
'ecosystem name. Please ensure to use use quotes in case the name contains spaces. We suggest to use a shorthand/abbreviation for the name, and to use the description for the fullname' | ||
) | ||
.argument('<url>', 'gaia-x ecosystem server address') | ||
.option('-d, --description <string>', 'Description') | ||
.action(async (name, url, cmd) => { | ||
//just to verify the agent loads | ||
await getAgent() | ||
|
||
const configPath = getAgentConfigPath() | ||
const existingConfig = getEcosystemConfigObject(configPath, name) | ||
const ecosystemConfig: EcosystemConfig = { | ||
name, | ||
url, | ||
description: cmd.description, | ||
} | ||
assertValidEcosystemConfigObject(ecosystemConfig) | ||
addEcosystemConfigObject(configPath, ecosystemConfig) | ||
//just to verify the agent loads | ||
await getAgent() | ||
|
||
if (existingConfig) { | ||
console.log(`Existing ecosystem ${name} has been updated in your agent configuration: ${getAgentConfigPath()}`) | ||
printTable([ | ||
{ | ||
version: 'previous', | ||
name: existingConfig.name, | ||
url: existingConfig.url, | ||
description: existingConfig.description, | ||
}, | ||
}, | ||
}) | ||
printTable([{ id }]) | ||
{ version: 'new', name, url, description: cmd.description }, | ||
]) | ||
} else { | ||
console.log(`New ecosystem ${name} has been added to your agent configuration: ${getAgentConfigPath()}`) | ||
printTable([{ name, url, description: cmd.description }]) | ||
} | ||
}) | ||
|
||
ecosystem | ||
.command('list') | ||
.description('Lists all Gaia-x ecosystems known to the agent (that are in the configuration)') | ||
.action(async (cmd) => { | ||
const configPath = getAgentConfigPath() | ||
const ecosystems = getEcosystemConfigObjects(configPath) | ||
|
||
if (!ecosystems || ecosystems.length === 0) { | ||
console.log('No ecosystems currently configured. You can create one using the "gx-agent ecosystem add" command') | ||
} else { | ||
printTable(ecosystems) | ||
} | ||
}) | ||
|
||
ecosystem | ||
.command('delete') | ||
.description('Deletes a Gaia-x ecosystem from the agent configuration') | ||
.argument('<name>', 'ecosystem name') | ||
.action(async (name) => { | ||
//just to verify the agent loads | ||
await getAgent() | ||
|
||
const configPath = getAgentConfigPath() | ||
const existing = getEcosystemConfigObject(configPath, name) | ||
if (!existing) { | ||
console.log(`No ecosystem with name "${name}" was found in the agent config: ${configPath}`) | ||
} else { | ||
deleteEcosystemConfigObject(configPath, name) | ||
|
||
//just to verify the agent loads | ||
await getAgent() | ||
|
||
printTable([{ ...existing }]) | ||
console.log(`Ecosystem ${name} has been deleted from your agent configuration: ${getAgentConfigPath()}`) | ||
} | ||
}) | ||
|
||
ecosystem | ||
.command('submit') | ||
.description('Onboards the participant to the new ecosystem') | ||
.option('-sid, --sd-id <string>', 'id of your self-description') | ||
.option('-cid, --compliance-id <string>', '') | ||
// .option('-eurl, --ecosystem-url <string>', 'URL of gx-compliance server') | ||
.option('-e, --ecosystem <string>', 'alias of your ecosystem') | ||
.action(async (cmd) => { | ||
.argument('<name>', 'The ecosystem name (has to be available in your configuration)') | ||
.option('-sid, --sd-id <string>', 'ID of your self-description verifiable credential') | ||
.option('-sf, --sd-file <string>', 'File containing your self-description verifiable credential') | ||
.option('-cid, --compliance-id <string>', 'ID of your compliance credential') | ||
.option('-cf, --compliance-file <string>', 'File containing your compliance credential') | ||
.action(async (name, cmd) => { | ||
const agent = await getAgent() | ||
if (!cmd.sdId && !cmd.sdFile) { | ||
throw Error('Verifiable Credential ID or file for self-description need to be selected. Please check parameters') | ||
} | ||
if (!cmd.complianceId && !cmd.complianceFile) { | ||
throw Error('Verifiable Credential ID or file for self-description need to be selected. Please check parameters') | ||
} | ||
try { | ||
const agent = await getAgent() | ||
const selfDescriptionId = cmd.sdId | ||
const complianceId = cmd.complianceId | ||
|
||
//fixme: Does not take ecosystem into account at all | ||
const selfDescription = await agent.onboardParticipantWithCredentialIds({ | ||
selfDescriptionId, | ||
complianceId, | ||
const selfDescriptionVC = cmd.sdFile | ||
? (JSON.parse(fs.readFileSync(cmd.sdFile, 'utf-8')) as VerifiableCredential) | ||
: await agent.dataStoreGetVerifiableCredential({ hash: cmd.sdId }) | ||
const complianceVC = cmd.complianceFile | ||
? (JSON.parse(fs.readFileSync(cmd.complianceFile, 'utf-8')) as VerifiableCredential) | ||
: await agent.dataStoreGetVerifiableCredential({ hash: cmd.complianceId }) | ||
|
||
const agentPath = getAgentConfigPath() | ||
const ecosystemConfig: EcosystemConfig | undefined = getEcosystemConfigObject(agentPath, name) | ||
if (!ecosystemConfig) { | ||
console.error(`Couldn't find the ecosystem: ${name}`) | ||
return | ||
} | ||
const selfDescription = await agent.onboardParticipantOnEcosystem({ | ||
ecosystemUrl: normalizeEcosystemConfigurationObject(ecosystemConfig).url, | ||
selfDescriptionVC, | ||
complianceVC, | ||
}) | ||
console.log(JSON.stringify(selfDescription, null, 2)) | ||
printTable([{ ...selfDescription }]) | ||
} catch (e: unknown) { | ||
console.error(e) | ||
} catch (e: any) { | ||
console.error(e.message) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.