commit ac94bd923902a4ea403a2c9ea1a68b8cd2e94962
Author: Jan Pašek <janpasek97@gmail.com>
Date:   Tue Apr 20 15:15:29 2021 +0200

    Re #8583 - create_certificate.js uses await

diff --git a/static/js/create_certificate.js b/static/js/create_certificate.js
index de2462b..2b35e32 100644
--- a/static/js/create_certificate.js
+++ b/static/js/create_certificate.js
@@ -42,29 +42,28 @@ var createCertificateApp = new Vue({
     },
     // actions to be performed when the page is loaded
     // - initialize notBefore and notAfter with current date and current date + 1 month respectively
-    mounted() {
+    async mounted() {
         this.notBefore = new Date().toDateInputValue(); // init notBefore to current date
         var endDate = new Date(new Date().getTime() + (30 * 24 * 60 * 60 * 1000));
         this.notAfter = endDate.toDateInputValue(); // init notAfter to notBefore + 30 days
 
         // Initialize available CA select values
-        axios.get(API_URL + "certificates", {
-            params: {
-                filtering: {
-                    CA: true
-                }
-            }
-        })
-            .then(function (response) {
-                if (response.data["success"]) {
-                    createCertificateApp.authorities = response.data["data"];
-                } else {
-                    createCertificateApp.authorities = []
+        try {
+            const response = await axios.get(API_URL + "certificates", {
+                params: {
+                    filtering: {
+                        CA: true
+                    }
                 }
-            })
-            .catch(function (error) {
-                console.log(error);
             });
+            if (response.data["success"]) {
+                createCertificateApp.authorities = response.data["data"];
+            } else {
+                createCertificateApp.authorities = []
+            }
+        } catch (error) {
+            console.log(error);
+        }
     },
     methods: {
         showError: function (message) {
@@ -73,7 +72,7 @@ var createCertificateApp = new Vue({
             this.errorMessage = message;
         },
         // handle certificate creation request
-        onCreateCertificate: function () {
+        onCreateCertificate: async function () {
             // validate input data
             // - validate if subject CN is filled in
             if (!this.isSelfSigned && this.certificateData.CA == null) {
@@ -86,20 +85,18 @@ var createCertificateApp = new Vue({
                 return;
             }
             this.certificateData.validityDays = parseInt(this.certificateData.validityDays);
-            axios.post(API_URL + "certificates", this.certificateData)
-                .then(function (response) {
-                    // on success return to index page
-                    if (response.data["success"]) {
-                        window.location.href = "/static/index.html?success=Certificate+successfully+created";
-                    }
-                    // on error display server response message
-                    else {
-                        createCertificateApp.showError(response.data["data"]);
-                    }
-                })
-                .catch(function (error) {
-                    console.log(error);
-                });
+            try {
+                const response = await axios.post(API_URL + "certificates", this.certificateData);
+                if (response.data["success"]) {
+                    window.location.href = "/static/index.html?success=Certificate+successfully+created";
+                }
+                // on error display server response message
+                else {
+                    createCertificateApp.showError(response.data["data"]);
+                }
+            } catch (error) {
+                console.log(error);
+            }
         }
     },
     // data watches
@@ -123,7 +120,7 @@ var createCertificateApp = new Vue({
         'certificateData.subject.CN': function (val, oldVal) {
             if (val !== '') this.invalidCN = false;
         },
-        'certificateData.CA': function (val, oldVal) {
+        'certificateData.CA': async function (val, oldVal) {
             // self-signed certificate - all fields are empty
             if (val === "null" || val == null) {
                 createCertificateApp.selectedCAData = {
@@ -138,16 +135,15 @@ var createCertificateApp = new Vue({
             }
             // a CA is selected - get CA's details and display them
             else {
-                axios.get(API_URL + "certificates/" + val + "/details")
-                    .then(function (response) {
-                        if (response.data["success"]) {
-                            createCertificateApp.selectedCAData = response.data["data"]["subject"];
-                        } else
-                            console.log("Error occurred while fetching CA details");
-                    })
-                    .catch(function (error) {
-                        console.log(error);
-                    });
+                try {
+                    const response = await axios.get(API_URL + "certificates/" + val + "/details");
+                    if (response.data["success"])
+                        createCertificateApp.selectedCAData = response.data["data"]["subject"];
+                    else
+                        console.log("Error occurred while fetching CA details");
+                } catch (error) {
+                    console.log(error);
+                }
             }
         }
     }
