Skip to content

Commit

Permalink
Added list-assets command to CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
macterra committed Jan 3, 2025
1 parent 031a75f commit bf5589a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
10 changes: 10 additions & 0 deletions packages/keymaster/src/keymaster-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,16 @@ export async function createAsset(data, options = {}) {
}
}

export async function listAssets() {
try {
const response = await axios.get(`${URL}/api/v1/assets`);
return response.data.assets;
}
catch (error) {
throwError(error);
}
}

export async function resolveAsset(name) {
try {
const response = await axios.get(`${URL}/api/v1/assets/${name}`);
Expand Down
13 changes: 13 additions & 0 deletions scripts/keychain-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,19 @@ program
}
});

program
.command('list-assets')
.description('List assets owned by current ID')
.action(async () => {
try {
const assets = await keymaster.listAssets();
console.log(JSON.stringify(assets, null, 4));
}
catch (error) {
console.error(error.message || error);
}
});

program
.command('create-poll-template')
.description('Generate a poll template')
Expand Down
11 changes: 10 additions & 1 deletion services/keymaster/server/src/keymaster-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ v1router.post('/schemas/:id/template/', async (req, res) => {
}
});

v1router.post('/assets/', async (req, res) => {
v1router.post('/assets', async (req, res) => {
try {
const { data, options } = req.body;
const did = await keymaster.createAsset(data, options);
Expand All @@ -583,6 +583,15 @@ v1router.post('/assets/', async (req, res) => {
}
});

v1router.get('/assets', async (req, res) => {
try {
const assets = await keymaster.listAssets();
res.json({ assets });
} catch (error) {
res.status(500).send({ error: error.toString() });
}
});

v1router.get('/assets/:id', async (req, res) => {
try {
const asset = await keymaster.resolveAsset(req.params.id);
Expand Down

0 comments on commit bf5589a

Please sign in to comment.