mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Get datasource secure json fields from secrets
This commit is contained in:
parent
612a18ad0f
commit
9c16deb33f
@ -97,7 +97,7 @@ func (hs *HTTPServer) GetDataSourceById(c *models.ReqContext) response.Response
|
|||||||
return response.Error(404, "Data source not found", err)
|
return response.Error(404, "Data source not found", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
dto := convertModelToDtos(filtered[0])
|
dto := hs.convertModelToDtos(c.Req.Context(), filtered[0])
|
||||||
|
|
||||||
// Add accesscontrol metadata
|
// Add accesscontrol metadata
|
||||||
dto.AccessControl = hs.getAccessControlMetadata(c, c.OrgId, datasources.ScopePrefix, dto.UID)
|
dto.AccessControl = hs.getAccessControlMetadata(c, c.OrgId, datasources.ScopePrefix, dto.UID)
|
||||||
@ -156,7 +156,7 @@ func (hs *HTTPServer) GetDataSourceByUID(c *models.ReqContext) response.Response
|
|||||||
return response.Error(404, "Data source not found", err)
|
return response.Error(404, "Data source not found", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
dto := convertModelToDtos(filtered[0])
|
dto := hs.convertModelToDtos(c.Req.Context(), filtered[0])
|
||||||
|
|
||||||
// Add accesscontrol metadata
|
// Add accesscontrol metadata
|
||||||
dto.AccessControl = hs.getAccessControlMetadata(c, c.OrgId, datasources.ScopePrefix, dto.UID)
|
dto.AccessControl = hs.getAccessControlMetadata(c, c.OrgId, datasources.ScopePrefix, dto.UID)
|
||||||
@ -265,7 +265,7 @@ func (hs *HTTPServer) AddDataSource(c *models.ReqContext) response.Response {
|
|||||||
return response.Error(500, "Failed to add datasource", err)
|
return response.Error(500, "Failed to add datasource", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ds := convertModelToDtos(cmd.Result)
|
ds := hs.convertModelToDtos(c.Req.Context(), cmd.Result)
|
||||||
return response.JSON(http.StatusOK, util.DynMap{
|
return response.JSON(http.StatusOK, util.DynMap{
|
||||||
"message": "Datasource added",
|
"message": "Datasource added",
|
||||||
"id": cmd.Result.Id,
|
"id": cmd.Result.Id,
|
||||||
@ -327,7 +327,7 @@ func (hs *HTTPServer) UpdateDataSource(c *models.ReqContext) response.Response {
|
|||||||
return response.Error(500, "Failed to query datasource", err)
|
return response.Error(500, "Failed to query datasource", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
datasourceDTO := convertModelToDtos(query.Result)
|
datasourceDTO := hs.convertModelToDtos(c.Req.Context(), query.Result)
|
||||||
|
|
||||||
hs.Live.HandleDatasourceUpdate(c.OrgId, datasourceDTO.UID)
|
hs.Live.HandleDatasourceUpdate(c.OrgId, datasourceDTO.UID)
|
||||||
|
|
||||||
@ -408,7 +408,7 @@ func (hs *HTTPServer) GetDataSourceByName(c *models.ReqContext) response.Respons
|
|||||||
return response.Error(404, "Data source not found", err)
|
return response.Error(404, "Data source not found", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
dto := convertModelToDtos(filtered[0])
|
dto := hs.convertModelToDtos(c.Req.Context(), filtered[0])
|
||||||
return response.JSON(http.StatusOK, &dto)
|
return response.JSON(http.StatusOK, &dto)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -457,7 +457,7 @@ func (hs *HTTPServer) CallDatasourceResource(c *models.ReqContext) {
|
|||||||
hs.callPluginResource(c, plugin.ID, ds.Uid)
|
hs.callPluginResource(c, plugin.ID, ds.Uid)
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertModelToDtos(ds *models.DataSource) dtos.DataSource {
|
func (hs *HTTPServer) convertModelToDtos(ctx context.Context, ds *models.DataSource) dtos.DataSource {
|
||||||
dto := dtos.DataSource{
|
dto := dtos.DataSource{
|
||||||
Id: ds.Id,
|
Id: ds.Id,
|
||||||
UID: ds.Uid,
|
UID: ds.Uid,
|
||||||
@ -480,9 +480,12 @@ func convertModelToDtos(ds *models.DataSource) dtos.DataSource {
|
|||||||
ReadOnly: ds.ReadOnly,
|
ReadOnly: ds.ReadOnly,
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range ds.SecureJsonData {
|
secrets, err := hs.DataSourcesService.DecryptedValues(ctx, ds)
|
||||||
if len(v) > 0 {
|
if err == nil {
|
||||||
dto.SecureJsonFields[k] = true
|
for k, v := range secrets {
|
||||||
|
if len(v) > 0 {
|
||||||
|
dto.SecureJsonFields[k] = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user