2023-04-10 15:36:59 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2018-08-24 22:33:04 +00:00
|
|
|
import Watchable from './watchable';
|
2022-03-08 17:28:36 +00:00
|
|
|
import classic from 'ember-classic-decorator';
|
2018-08-24 22:33:04 +00:00
|
|
|
|
2022-03-08 17:28:36 +00:00
|
|
|
@classic
|
2020-06-11 21:23:00 +00:00
|
|
|
export default class DeploymentAdapter extends Watchable {
|
2021-02-10 14:38:37 +00:00
|
|
|
fail(deployment) {
|
|
|
|
const id = deployment.get('id');
|
|
|
|
const url = urlForAction(this.urlForFindRecord(id, 'deployment'), '/fail');
|
|
|
|
return this.ajax(url, 'POST', {
|
|
|
|
data: {
|
|
|
|
DeploymentId: id,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-08-24 22:33:04 +00:00
|
|
|
promote(deployment) {
|
|
|
|
const id = deployment.get('id');
|
2021-12-28 16:08:12 +00:00
|
|
|
const url = urlForAction(
|
|
|
|
this.urlForFindRecord(id, 'deployment'),
|
|
|
|
'/promote'
|
|
|
|
);
|
2018-08-24 22:33:04 +00:00
|
|
|
return this.ajax(url, 'POST', {
|
|
|
|
data: {
|
|
|
|
DeploymentId: id,
|
|
|
|
All: true,
|
|
|
|
},
|
|
|
|
});
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-24 22:33:04 +00:00
|
|
|
|
|
|
|
// The deployment action API endpoints all end with the ID
|
|
|
|
// /deployment/:action/:deployment_id instead of /deployment/:deployment_id/:action
|
|
|
|
function urlForAction(url, extension = '') {
|
|
|
|
const [path, params] = url.split('?');
|
|
|
|
const pathParts = path.split('/');
|
|
|
|
const idPart = pathParts.pop();
|
|
|
|
let newUrl = `${pathParts.join('/')}${extension}/${idPart}`;
|
|
|
|
|
|
|
|
if (params) {
|
|
|
|
newUrl += `?${params}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return newUrl;
|
|
|
|
}
|