Merge pull request #14024 from bergquist/cp_v5.3.x
Cherry picks for v5.3.4
This commit is contained in:
@@ -344,6 +344,7 @@ header_property = username
|
|||||||
auto_sign_up = true
|
auto_sign_up = true
|
||||||
ldap_sync_ttl = 60
|
ldap_sync_ttl = 60
|
||||||
whitelist =
|
whitelist =
|
||||||
|
headers =
|
||||||
|
|
||||||
#################################### Auth LDAP ###########################
|
#################################### Auth LDAP ###########################
|
||||||
[auth.ldap]
|
[auth.ldap]
|
||||||
|
|||||||
@@ -294,6 +294,7 @@ log_queries =
|
|||||||
;auto_sign_up = true
|
;auto_sign_up = true
|
||||||
;ldap_sync_ttl = 60
|
;ldap_sync_ttl = 60
|
||||||
;whitelist = 192.168.1.1, 192.168.2.1
|
;whitelist = 192.168.1.1, 192.168.2.1
|
||||||
|
;headers = Email:X-User-Email, Name:X-User-Name
|
||||||
|
|
||||||
#################################### Basic Auth ##########################
|
#################################### Basic Auth ##########################
|
||||||
[auth.basic]
|
[auth.basic]
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
"company": "Grafana Labs"
|
"company": "Grafana Labs"
|
||||||
},
|
},
|
||||||
"name": "grafana",
|
"name": "grafana",
|
||||||
"version": "5.3.3",
|
"version": "5.3.4",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "http://github.com/grafana/grafana.git"
|
"url": "http://github.com/grafana/grafana.git"
|
||||||
|
|||||||
@@ -195,6 +195,10 @@ func (proxy *DataSourceProxy) getDirector() func(req *http.Request) {
|
|||||||
req.Header.Del("X-Forwarded-Proto")
|
req.Header.Del("X-Forwarded-Proto")
|
||||||
req.Header.Set("User-Agent", fmt.Sprintf("Grafana/%s", setting.BuildVersion))
|
req.Header.Set("User-Agent", fmt.Sprintf("Grafana/%s", setting.BuildVersion))
|
||||||
|
|
||||||
|
// Clear Origin and Referer to avoir CORS issues
|
||||||
|
req.Header.Del("Origin")
|
||||||
|
req.Header.Del("Referer")
|
||||||
|
|
||||||
// set X-Forwarded-For header
|
// set X-Forwarded-For header
|
||||||
if req.RemoteAddr != "" {
|
if req.RemoteAddr != "" {
|
||||||
remoteAddr, _, err := net.SplitHostPort(req.RemoteAddr)
|
remoteAddr, _, err := net.SplitHostPort(req.RemoteAddr)
|
||||||
|
|||||||
@@ -362,6 +362,32 @@ func TestDSRouteRule(t *testing.T) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Convey("When proxying a custom datasource", func() {
|
||||||
|
plugin := &plugins.DataSourcePlugin{}
|
||||||
|
ds := &m.DataSource{
|
||||||
|
Type: "custom-datasource",
|
||||||
|
Url: "http://host/root/",
|
||||||
|
}
|
||||||
|
ctx := &m.ReqContext{}
|
||||||
|
proxy := NewDataSourceProxy(ds, plugin, ctx, "/path/to/folder/")
|
||||||
|
req, err := http.NewRequest(http.MethodGet, "http://grafana.com/sub", nil)
|
||||||
|
req.Header.Add("Origin", "grafana.com")
|
||||||
|
req.Header.Add("Referer", "grafana.com")
|
||||||
|
req.Header.Add("X-Canary", "stillthere")
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
proxy.getDirector()(req)
|
||||||
|
|
||||||
|
Convey("Should keep user request (including trailing slash)", func() {
|
||||||
|
So(req.URL.String(), ShouldEqual, "http://host/root/path/to/folder/")
|
||||||
|
})
|
||||||
|
|
||||||
|
Convey("Origin and Referer headers should be dropped", func() {
|
||||||
|
So(req.Header.Get("Origin"), ShouldEqual, "")
|
||||||
|
So(req.Header.Get("Referer"), ShouldEqual, "")
|
||||||
|
So(req.Header.Get("X-Canary"), ShouldEqual, "stillthere")
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,11 +15,19 @@
|
|||||||
You can share dashboards on <a class="external-link" href="https://grafana.com">Grafana.com</a>
|
You can share dashboards on <a class="external-link" href="https://grafana.com">Grafana.com</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<gf-form-switch
|
||||||
|
class="gf-form"
|
||||||
|
label="Export for sharing externally"
|
||||||
|
label-class="width-16"
|
||||||
|
checked="ctrl.shareExternally"
|
||||||
|
tooltip="Useful for sharing dashboard publicly on grafana.com. Will templatize data source names. Can then only be used with the specific dashboard import API.">
|
||||||
|
</gf-form-switch>
|
||||||
|
|
||||||
<div class="gf-form-button-row">
|
<div class="gf-form-button-row">
|
||||||
<button type="button" class="btn gf-form-btn width-10 btn-success" ng-click="ctrl.save()">
|
<button type="button" class="btn gf-form-btn width-10 btn-success" ng-click="ctrl.saveDashboardAsFile()">
|
||||||
<i class="fa fa-save"></i> Save to file
|
<i class="fa fa-save"></i> Save to file
|
||||||
</button>
|
</button>
|
||||||
<button type="button" class="btn gf-form-btn width-10 btn-secondary" ng-click="ctrl.saveJson()">
|
<button type="button" class="btn gf-form-btn width-10 btn-secondary" ng-click="ctrl.viewJson()">
|
||||||
<i class="fa fa-file-text-o"></i> View JSON
|
<i class="fa fa-file-text-o"></i> View JSON
|
||||||
</button>
|
</button>
|
||||||
<a class="btn btn-link" ng-click="ctrl.dismiss()">Cancel</a>
|
<a class="btn btn-link" ng-click="ctrl.dismiss()">Cancel</a>
|
||||||
|
|||||||
@@ -8,27 +8,47 @@ export class DashExportCtrl {
|
|||||||
dash: any;
|
dash: any;
|
||||||
exporter: DashboardExporter;
|
exporter: DashboardExporter;
|
||||||
dismiss: () => void;
|
dismiss: () => void;
|
||||||
|
shareExternally: boolean;
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
constructor(private dashboardSrv, datasourceSrv, private $scope, private $rootScope) {
|
constructor(private dashboardSrv, datasourceSrv, private $scope, private $rootScope) {
|
||||||
this.exporter = new DashboardExporter(datasourceSrv);
|
this.exporter = new DashboardExporter(datasourceSrv);
|
||||||
|
|
||||||
this.exporter.makeExportable(this.dashboardSrv.getCurrent()).then(dash => {
|
this.dash = this.dashboardSrv.getCurrent();
|
||||||
this.$scope.$apply(() => {
|
|
||||||
this.dash = dash;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
save() {
|
saveDashboardAsFile() {
|
||||||
const blob = new Blob([angular.toJson(this.dash, true)], {
|
if (this.shareExternally) {
|
||||||
|
this.exporter.makeExportable(this.dash).then((dashboardJson: any) => {
|
||||||
|
this.$scope.$apply(() => {
|
||||||
|
this.openSaveAsDialog(dashboardJson);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.openSaveAsDialog(this.dash.getSaveModelClone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
viewJson() {
|
||||||
|
if (this.shareExternally) {
|
||||||
|
this.exporter.makeExportable(this.dash).then((dashboardJson: any) => {
|
||||||
|
this.$scope.$apply(() => {
|
||||||
|
this.openJsonModal(dashboardJson);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.openJsonModal(this.dash.getSaveModelClone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private openSaveAsDialog(dash: any) {
|
||||||
|
const blob = new Blob([angular.toJson(dash, true)], {
|
||||||
type: 'application/json;charset=utf-8',
|
type: 'application/json;charset=utf-8',
|
||||||
});
|
});
|
||||||
saveAs(blob, this.dash.title + '-' + new Date().getTime() + '.json');
|
saveAs(blob, dash.title + '-' + new Date().getTime() + '.json');
|
||||||
}
|
}
|
||||||
|
|
||||||
saveJson() {
|
private openJsonModal(clone: any) {
|
||||||
const clone = this.dash;
|
|
||||||
const editScope = this.$rootScope.$new();
|
const editScope = this.$rootScope.$new();
|
||||||
editScope.object = clone;
|
editScope.object = clone;
|
||||||
editScope.enableCopy = true;
|
editScope.enableCopy = true;
|
||||||
|
|||||||
@@ -29,19 +29,36 @@ export class DashboardExporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const templateizeDatasourceUsage = obj => {
|
const templateizeDatasourceUsage = obj => {
|
||||||
|
let datasource = obj.datasource;
|
||||||
|
let datasourceVariable = null;
|
||||||
|
|
||||||
// ignore data source properties that contain a variable
|
// ignore data source properties that contain a variable
|
||||||
if (obj.datasource && obj.datasource.indexOf('$') === 0) {
|
if (datasource && datasource.indexOf('$') === 0) {
|
||||||
if (variableLookup[obj.datasource.substring(1)]) {
|
datasourceVariable = variableLookup[datasource.substring(1)];
|
||||||
return;
|
if (datasourceVariable && datasourceVariable.current) {
|
||||||
|
datasource = datasourceVariable.current.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
promises.push(
|
promises.push(
|
||||||
this.datasourceSrv.get(obj.datasource).then(ds => {
|
this.datasourceSrv.get(datasource).then(ds => {
|
||||||
if (ds.meta.builtIn) {
|
if (ds.meta.builtIn) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add data source type to require list
|
||||||
|
requires['datasource' + ds.meta.id] = {
|
||||||
|
type: 'datasource',
|
||||||
|
id: ds.meta.id,
|
||||||
|
name: ds.meta.name,
|
||||||
|
version: ds.meta.info.version || '1.0.0',
|
||||||
|
};
|
||||||
|
|
||||||
|
// if used via variable we can skip templatizing usage
|
||||||
|
if (datasourceVariable) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const refName = 'DS_' + ds.name.replace(' ', '_').toUpperCase();
|
const refName = 'DS_' + ds.name.replace(' ', '_').toUpperCase();
|
||||||
datasources[refName] = {
|
datasources[refName] = {
|
||||||
name: refName,
|
name: refName,
|
||||||
@@ -51,14 +68,8 @@ export class DashboardExporter {
|
|||||||
pluginId: ds.meta.id,
|
pluginId: ds.meta.id,
|
||||||
pluginName: ds.meta.name,
|
pluginName: ds.meta.name,
|
||||||
};
|
};
|
||||||
obj.datasource = '${' + refName + '}';
|
|
||||||
|
|
||||||
requires['datasource' + ds.meta.id] = {
|
obj.datasource = '${' + refName + '}';
|
||||||
type: 'datasource',
|
|
||||||
id: ds.meta.id,
|
|
||||||
name: ds.meta.name,
|
|
||||||
version: ds.meta.info.version || '1.0.0',
|
|
||||||
};
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ describe('given dashboard with repeated panels', () => {
|
|||||||
{
|
{
|
||||||
name: 'ds',
|
name: 'ds',
|
||||||
type: 'datasource',
|
type: 'datasource',
|
||||||
query: 'testdb',
|
query: 'other2',
|
||||||
current: { value: 'prod', text: 'prod' },
|
current: { value: 'other2', text: 'other2' },
|
||||||
options: [],
|
options: [],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -205,6 +205,11 @@ describe('given dashboard with repeated panels', () => {
|
|||||||
expect(variable.options[0].text).toBe('${VAR_PREFIX}');
|
expect(variable.options[0].text).toBe('${VAR_PREFIX}');
|
||||||
expect(variable.options[0].value).toBe('${VAR_PREFIX}');
|
expect(variable.options[0].value).toBe('${VAR_PREFIX}');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should add datasources only use via datasource variable to requires', () => {
|
||||||
|
const require = _.find(exported.__requires, { name: 'OtherDB_2' });
|
||||||
|
expect(require.id).toBe('other2');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Stub responses
|
// Stub responses
|
||||||
@@ -219,6 +224,11 @@ stubs['other'] = {
|
|||||||
meta: { id: 'other', info: { version: '1.2.1' }, name: 'OtherDB' },
|
meta: { id: 'other', info: { version: '1.2.1' }, name: 'OtherDB' },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
stubs['other2'] = {
|
||||||
|
name: 'other2',
|
||||||
|
meta: { id: 'other2', info: { version: '1.2.1' }, name: 'OtherDB_2' },
|
||||||
|
};
|
||||||
|
|
||||||
stubs['-- Mixed --'] = {
|
stubs['-- Mixed --'] = {
|
||||||
name: 'mixed',
|
name: 'mixed',
|
||||||
meta: {
|
meta: {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export class TemplateSrv {
|
|||||||
const existsOrEmpty = value => value || value === '';
|
const existsOrEmpty = value => value || value === '';
|
||||||
|
|
||||||
this.index = this.variables.reduce((acc, currentValue) => {
|
this.index = this.variables.reduce((acc, currentValue) => {
|
||||||
if (currentValue.current && !currentValue.current.isNone && existsOrEmpty(currentValue.current.value)) {
|
if (currentValue.current && (currentValue.current.isNone || existsOrEmpty(currentValue.current.value))) {
|
||||||
acc[currentValue.name] = currentValue;
|
acc[currentValue.name] = currentValue;
|
||||||
}
|
}
|
||||||
return acc;
|
return acc;
|
||||||
|
|||||||
Reference in New Issue
Block a user