types.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package datasources
  2. import "github.com/grafana/grafana/pkg/models"
  3. import "github.com/grafana/grafana/pkg/components/simplejson"
  4. type DatasourcesAsConfig struct {
  5. PurgeOtherDatasources bool `json:"purge_other_datasources" yaml:"purge_other_datasources"`
  6. Datasources []DataSourceFromConfig `json:"datasources" yaml:"datasources"`
  7. }
  8. type DataSourceFromConfig struct {
  9. OrgId int64 `json:"org_id" yaml:"org_id"`
  10. Version int `json:"version" yaml:"version"`
  11. Name string `json:"name" yaml:"name"`
  12. Type string `json:"type" yaml:"type"`
  13. Access string `json:"access" yaml:"access"`
  14. Url string `json:"url" yaml:"url"`
  15. Password string `json:"password" yaml:"password"`
  16. User string `json:"user" yaml:"user"`
  17. Database string `json:"database" yaml:"database"`
  18. BasicAuth bool `json:"basic_auth" yaml:"basic_auth"`
  19. BasicAuthUser string `json:"basic_auth_user" yaml:"basic_auth_user"`
  20. BasicAuthPassword string `json:"basic_auth_password" yaml:"basic_auth_password"`
  21. WithCredentials bool `json:"with_credentials" yaml:"with_credentials"`
  22. IsDefault bool `json:"is_default" yaml:"is_default"`
  23. JsonData string `json:"json_data" yaml:"json_data"`
  24. SecureJsonData map[string]string `json:"secure_json_data" yaml:"secure_json_data"`
  25. }
  26. func createInsertCommand(ds DataSourceFromConfig) *models.AddDataSourceCommand {
  27. jsonData, err := simplejson.NewJson([]byte(ds.JsonData))
  28. if err != nil {
  29. jsonData = simplejson.New()
  30. }
  31. return &models.AddDataSourceCommand{
  32. OrgId: ds.OrgId,
  33. Name: ds.Name,
  34. Type: ds.Type,
  35. Access: models.DsAccess(ds.Access),
  36. Url: ds.Url,
  37. Password: ds.Password,
  38. User: ds.User,
  39. Database: ds.Database,
  40. BasicAuth: ds.BasicAuth,
  41. BasicAuthUser: ds.BasicAuthUser,
  42. BasicAuthPassword: ds.BasicAuthPassword,
  43. WithCredentials: ds.WithCredentials,
  44. IsDefault: ds.IsDefault,
  45. JsonData: jsonData,
  46. SecureJsonData: ds.SecureJsonData,
  47. }
  48. }
  49. func createUpdateCommand(ds DataSourceFromConfig, id int64) *models.UpdateDataSourceCommand {
  50. jsonData, err := simplejson.NewJson([]byte(ds.JsonData))
  51. if err != nil {
  52. jsonData = simplejson.New()
  53. }
  54. return &models.UpdateDataSourceCommand{
  55. Id: id,
  56. OrgId: ds.OrgId,
  57. Name: ds.Name,
  58. Type: ds.Type,
  59. Access: models.DsAccess(ds.Access),
  60. Url: ds.Url,
  61. Password: ds.Password,
  62. User: ds.User,
  63. Database: ds.Database,
  64. BasicAuth: ds.BasicAuth,
  65. BasicAuthUser: ds.BasicAuthUser,
  66. BasicAuthPassword: ds.BasicAuthPassword,
  67. WithCredentials: ds.WithCredentials,
  68. IsDefault: ds.IsDefault,
  69. JsonData: jsonData,
  70. SecureJsonData: ds.SecureJsonData,
  71. }
  72. }