Skip to content

Commit

Permalink
Sync Associations ID Format (hashicorp#25740)
Browse files Browse the repository at this point in the history
* updates sync associations id format

* fixes tests

* fixes test
  • Loading branch information
zofskeez authored Mar 4, 2024
1 parent e3d8a4d commit 087efc9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
4 changes: 3 additions & 1 deletion ui/app/adapters/sync/association.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,15 @@ export default class SyncAssociationAdapter extends ApplicationAdapter {
);
const url = this.buildURL(modelName, null, snapshot);
const data = snapshot.serialize();
const serializer = store.serializerFor('sync/association');

return this.ajax(url, 'POST', { data }).then((resp) => {
const association = Object.values(resp.data.associated_secrets).find((association) => {
return association.mount === data.mount && association.secret_name === data.secret_name;
});
return {
...association,
id: `${data.mount}/${data.secret_name}`,
id: serializer.generateId(association),
destinationName: resp.data.store_name,
destinationType: resp.data.store_type,
};
Expand Down
10 changes: 9 additions & 1 deletion ui/app/serializers/sync/association.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,21 @@ export default class SyncAssociationSerializer extends ApplicationSerializer {
subKey: { serialize: false },
};

generateId(data) {
let id = `${data.mount}/${data.secret_name}`;
if (data.sub_key) {
id += `/${data.sub_key}`;
}
return id;
}

extractLazyPaginatedData(payload) {
if (payload) {
const { store_name, store_type, associated_secrets } = payload.data;
const secrets = [];
for (const key in associated_secrets) {
const data = associated_secrets[key];
data.id = `${data.mount}/${data.secret_name}`;
data.id = this.generateId(data);
const association = {
destinationName: store_name,
destinationType: store_type,
Expand Down
7 changes: 7 additions & 0 deletions ui/tests/acceptance/sync/secrets/destination-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,11 @@ module('Acceptance | sync | destination', function (hooks) {
'Does no redirect when navigating to destination route other than edit or sync'
);
});

test('it should render correct number of associations in list for sub keys', async function (assert) {
this.server.db.syncDestinations.update({ granularity: 'secret-key' });

await visit('vault/sync/secrets/destinations/vercel-project/destination-vercel/secrets');
assert.dom('[data-test-list-item]').exists({ count: 3 }, 'Sub key associations render in list');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ module('Integration | Component | sync | Secrets::Page::Destinations::Destinatio
const data = JSON.parse(req.requestBody);
const expected = { mount: 'my-kv', secret_name: 'my-secret' };
assert.deepEqual(data, expected, 'Sync request made with mount and secret name');
return { data: { associated_secrets: {} } };
return { data: { associated_secrets: { 'my-kv_12345': data } } };
});

assert.dom(submit).isDisabled('Submit button is disabled when mount is not selected');
Expand Down

0 comments on commit 087efc9

Please sign in to comment.