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

Add new route to promote staging state in module config #259

Merged
merged 1 commit into from
Aug 13, 2021
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
1 change: 1 addition & 0 deletions app/v1/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ function exposeRoutes () {
app.get('/module', auth.validateAuth, moduleConfig.get);
app.post('/module', auth.validateAuth, moduleConfig.post);
app.post('/module/promote', auth.validateAuth, moduleConfig.promote);
app.post('/module/promoteNoId', auth.validateAuth, moduleConfig.promoteNoId);
app.get('/about', auth.validateAuth, about.getInfo);
app.post('/security/certificate', certificates.createCertificate);
app.post('/security/private', certificates.createPrivateKey);
Expand Down
29 changes: 29 additions & 0 deletions app/v1/module-config/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,34 @@ function post(isProduction, req, res, next) {
}
}

function promoteNoId (req, res, next) {
if (res.parcel.message) {
return res.parcel.deliver();
}

// retrieve the staging config
const flow = helper.getModuleConfigFlow('status', false);

flow(function(err, data) {
if (err) {
app.locals.log.error(err);
return res.parcel
.setStatus(500)
.setMessage('Internal server error')
.deliver();
}
if (!certController.openSSLEnabled) { // cert gen not enabled
data.forEach(obj => {
delete obj.certificate;
delete obj.private_key
})
}
// modify the body and pass the express parameters along as if we are posting to production
req.body = data[0];
post(true, req, res, next);
});
}

function checkAndUpdateCertificate (cb) {
if (!certController.openSSLEnabled) {
if (cb) {
Expand Down Expand Up @@ -183,5 +211,6 @@ module.exports = {
get: get,
post: post.bind(null, false),
promote: post.bind(null, true),
promoteNoId: promoteNoId,
checkAndUpdateCertificate: checkAndUpdateCertificate
};
8 changes: 4 additions & 4 deletions src/components/ModuleConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
name="chooseEnvironment" />

<div class="pull-right">
<b-btn v-if="environment == 'STAGING' && canPromote" v-b-modal.promoteModal class="btn btn-style-green btn-sm align-middle">Promote changes to production</b-btn>
<b-btn v-if="environment == 'STAGING' && canPromote" v-b-modal.promoteModal class="btn btn-style-green btn-sm align-middle">Promote staging to production</b-btn>
</div>

<h4>Module Config<a class="fa fa-question-circle color-primary doc-link" v-b-tooltip.hover title="Click here for more info about this page" href="https://smartdevicelink.com/en/guides/sdl-server/user-interface/module-config/" target="_blank"></a></h4>
Expand Down Expand Up @@ -243,9 +243,9 @@
</div>

<!-- PROMOTE GROUP MODAL -->
<b-modal ref="promoteModal" title="Promote Module Config to Production" hide-footer id="promoteModal" tabindex="-1" role="dialog" aria-labelledby="modalLabel" aria-hidden="true">
<b-modal ref="promoteModal" title="Promote Staging Module Config to Production" hide-footer id="promoteModal" tabindex="-1" role="dialog" aria-labelledby="modalLabel" aria-hidden="true">
<small class="form-text text-muted">
This will promote the module config to production, immediately updating the production policy table. Are you sure you want to do this?
This will promote the saved module config state on STAGING to production, immediately updating the production policy table. Are you sure you want to do this?
</small>
<vue-ladda
type="button"
Expand Down Expand Up @@ -382,7 +382,7 @@ export default {
this.handleModalClick("promote_button_loading", "promoteModal", "promoteConfig");
},
"promoteConfig": function (cb) {
this.httpRequest("post", "module/promote", { "body": this.module_config }, cb);
this.httpRequest("post", "module/promoteNoId", { "body": {} }, cb);
},
"addRetryUpdateElement": function () {
var newVal = this.module_config.seconds_between_retries.length ? this.module_config.seconds_between_retries[this.module_config.seconds_between_retries.length - 1]*5 : 1;
Expand Down