Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI Secrets sync: Add purge query param to delete endpoint #24497

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions ui/app/adapters/sync/destination.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@ export default class SyncDestinationAdapter extends ApplicationAdapter {

urlForDeleteRecord(id, modelName, snapshot) {
const { name, type } = snapshot.attributes();
// the modelName may be sync/destination or a child depending if it was initiated from the list or details view
// since the id for sync/destinations is type/name it will actually generate the correct url but the slash will be encoded
// if we normalize to use the child model name for url generation instead things will be consistent
const normalizedModelName =
modelName === 'sync/destination' ? `${pluralize(modelName)}/${type}` : modelName;
return `${super.urlForDeleteRecord(name, normalizedModelName, snapshot)}`;
// the only delete option in the UI is to purge which unsyncs all secrets prior to deleting
return `${this.buildURL('sync/destinations')}/${type}/${name}?purge=true`;
}

query(store, { modelName }) {
Expand Down
10 changes: 6 additions & 4 deletions ui/tests/unit/adapters/sync/destinations-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,11 @@ module('Unit | Adapter | sync | destination', function (hooks) {
});

test('it should make request to correct endpoint for deleteRecord with base model', async function (assert) {
assert.expect(1);
assert.expect(2);

this.server.delete('/sys/sync/destinations/aws-sm/us-west-1', () => {
this.server.delete('/sys/sync/destinations/aws-sm/us-west-1', (schema, req) => {
assert.ok(true, 'DELETE request made to correct endpoint');
assert.propEqual(req.queryParams, { purge: 'true' }, 'Purge query param is passed in request');
return {};
});

Expand All @@ -144,12 +145,13 @@ module('Unit | Adapter | sync | destination', function (hooks) {
});

test('it should make request to correct endpoint for deleteRecord', async function (assert) {
assert.expect(1);
assert.expect(2);

const destination = this.server.create('sync-destination', 'aws-sm');

this.server.delete(`/sys/sync/destinations/${destination.type}/${destination.name}`, () => {
this.server.delete(`/sys/sync/destinations/${destination.type}/${destination.name}`, (schema, req) => {
assert.ok(true, 'DELETE request made to correct endpoint');
assert.propEqual(req.queryParams, { purge: 'true' }, 'Purge query param is passed in request');
return {};
});

Expand Down