diff --git a/public/app/features/dashboard/upload.ts b/public/app/features/dashboard/upload.ts
index 5ef329fc76e..19274811a33 100644
--- a/public/app/features/dashboard/upload.ts
+++ b/public/app/features/dashboard/upload.ts
@@ -1,4 +1,5 @@
import coreModule from 'app/core/core_module';
+import appEvents from 'app/core/app_events';
const template = `
@@ -26,7 +27,7 @@ function uploadDashboardDirective(timer, alertSrv, $location) {
dash = JSON.parse(e.target.result);
} catch (err) {
console.log(err);
- scope.appEvent('alert-error', ['Import failed', 'JSON -> JS Serialization failed: ' + err.message]);
+ appEvents.emit('alert-error', ['Import failed', 'JSON -> JS Serialization failed: ' + err.message]);
return;
}
diff --git a/public/app/plugins/datasource/stackdriver/config_ctrl.ts b/public/app/plugins/datasource/stackdriver/config_ctrl.ts
index 405d91833cd..95f10ec1986 100644
--- a/public/app/plugins/datasource/stackdriver/config_ctrl.ts
+++ b/public/app/plugins/datasource/stackdriver/config_ctrl.ts
@@ -2,10 +2,67 @@ export class StackdriverConfigCtrl {
static templateUrl = 'public/app/plugins/datasource/stackdriver/partials/config.html';
datasourceSrv: any;
current: any;
+ jsonText: string;
+ validationErrors: string[] = [];
+ inputDataValid: boolean;
/** @ngInject */
constructor($scope, datasourceSrv) {
this.datasourceSrv = datasourceSrv;
this.current.jsonData = this.current.jsonData || {};
+ this.current.secureJsonData = this.current.secureJsonData || {};
+ }
+
+ save(jwt) {
+ this.current.secureJsonData.privateKey = jwt.private_key;
+ this.current.jsonData.tokenUri = jwt.token_uri;
+ this.current.jsonData.clientEmail = jwt.client_email;
+ }
+
+ validateJwt(jwt) {
+ this.resetValidationMessages();
+ if (!jwt.private_key || jwt.private_key.length === 0) {
+ this.validationErrors.push('Private key field missing in JWT file.');
+ }
+
+ if (!jwt.token_uri || jwt.token_uri.length === 0) {
+ this.validationErrors.push('Token URI field missing in JWT file.');
+ }
+
+ if (!jwt.client_email || jwt.client_email.length === 0) {
+ this.validationErrors.push('Client Email field missing in JWT file.');
+ }
+
+ if (this.validationErrors.length === 0) {
+ this.inputDataValid = true;
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ onUpload(json) {
+ this.jsonText = '';
+ if (this.validateJwt(json)) {
+ this.save(json);
+ }
+ }
+
+ onPasteJwt(e) {
+ try {
+ const json = JSON.parse(e.originalEvent.clipboardData.getData('text/plain') || this.jsonText);
+ if (this.validateJwt(json)) {
+ this.save(json);
+ }
+ } catch (error) {
+ this.resetValidationMessages();
+ this.validationErrors.push(`Invalid json: ${error.message}`);
+ }
+ }
+
+ resetValidationMessages() {
+ this.validationErrors = [];
+ this.inputDataValid = false;
+ this.jsonText = '';
}
}
diff --git a/public/app/plugins/datasource/stackdriver/partials/config.html b/public/app/plugins/datasource/stackdriver/partials/config.html
index c0af41fb891..c7933a4e3e1 100644
--- a/public/app/plugins/datasource/stackdriver/partials/config.html
+++ b/public/app/plugins/datasource/stackdriver/partials/config.html
@@ -1,6 +1,26 @@
-