diff --git a/dashboard/src/components/BackupProviderForm.vue b/dashboard/src/components/BackupProviderForm.vue
index 7c07b38da..972c11d04 100644
--- a/dashboard/src/components/BackupProviderForm.vue
+++ b/dashboard/src/components/BackupProviderForm.vue
@@ -284,7 +284,7 @@ onMounted(async () => {
-
+
{{ gcsFileParseError }}
diff --git a/dashboard/src/components/DomainProviderForm.vue b/dashboard/src/components/DomainProviderForm.vue
index c98ebf40e..47dc98630 100644
--- a/dashboard/src/components/DomainProviderForm.vue
+++ b/dashboard/src/components/DomainProviderForm.vue
@@ -4,7 +4,8 @@ import { useI18n } from 'vue-i18n';
const i18n = useI18n();
const t = i18n.t;
-import { TextInput, FormGroup, Checkbox, SingleSelect } from 'pankow';
+import { ref } from 'vue';
+import { TextInput, InputGroup, Button, FormGroup, Checkbox, SingleSelect } from 'pankow';
import { ENDPOINTS_OVH } from '../constants.js';
import DomainsModel from '../models/DomainsModel.js';
@@ -88,18 +89,37 @@ function onProviderChange(p) {
resetFields(p);
}
+const gcdnsFileParseError = ref('');
function onGcdnsFileInputChange(event) {
- const reader = new FileReader();
- reader.onload = function (result) {
- if (!result.target || !result.target.result) return console.error('Unable to read local file');
- const serviceAccount = JSON.parse(result.target.result);
- dnsConfig.value.projectId = serviceAccount.project_id;
- dnsConfig.value.credentials = {
- client_email: serviceAccount.client_email,
- private_key: serviceAccount.private_key,
- };
+ gcdnsFileParseError.value = '';
+
+ const fr = new FileReader();
+
+ fr.onload = () => {
+ // validate input file
+ try {
+ const keyJson = JSON.parse(fr.result);
+ if (!keyJson.project_id) throw new Error('project_id field missing in JSON key file');
+ if (!keyJson.client_email) throw new Error('client_email field missing in JSON key file');
+ if (!keyJson.private_key) throw new Error('private_key field missing in JSON key file');
+
+ dnsConfig.value.projectId = keyJson.project_id;
+ dnsConfig.value.credentials = {
+ client_email: keyJson.client_email,
+ private_key: keyJson.private_key,
+ };
+ } catch (e) {
+ if (e.name === 'SyntaxError') gcdnsFileParseError.value = 'Invalid JSON';
+ else gcdnsFileParseError.value = e.message;
+
+ dnsConfig.value.projectId = '';
+ dnsConfig.value.credentials = {
+ client_email: '',
+ private_key: '',
+ };
+ }
};
- reader.readAsText(event.target.files[0]);
+ fr.readAsText(event.target.files[0]);
}
@@ -123,14 +143,13 @@ function onGcdnsFileInputChange(event) {
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+ {{ gcdnsFileParseError }}