datasource.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package models
  2. import (
  3. "errors"
  4. "time"
  5. )
  6. const (
  7. DS_GRAPHITE = "graphite"
  8. DS_INFLUXDB = "influxdb"
  9. DS_INFLUXDB_08 = "influxdb_08"
  10. DS_ES = "elasticsearch"
  11. DS_OPENTSDB = "opentsdb"
  12. DS_CLOUDWATCH = "cloudwatch"
  13. DS_ACCESS_DIRECT = "direct"
  14. DS_ACCESS_PROXY = "proxy"
  15. )
  16. // Typed errors
  17. var (
  18. ErrDataSourceNotFound = errors.New("Data source not found")
  19. )
  20. type DsAccess string
  21. type DataSource struct {
  22. Id int64
  23. OrgId int64
  24. Version int
  25. Name string
  26. Type string
  27. Access DsAccess
  28. Url string
  29. Password string
  30. User string
  31. Database string
  32. BasicAuth bool
  33. BasicAuthUser string
  34. BasicAuthPassword string
  35. IsDefault bool
  36. JsonData map[string]interface{}
  37. Created time.Time
  38. Updated time.Time
  39. }
  40. // ----------------------
  41. // COMMANDS
  42. // Also acts as api DTO
  43. type AddDataSourceCommand struct {
  44. Name string `json:"name" binding:"Required"`
  45. Type string `json:"type" binding:"Required"`
  46. Access DsAccess `json:"access" binding:"Required"`
  47. Url string `json:"url"`
  48. Password string `json:"password"`
  49. Database string `json:"database"`
  50. User string `json:"user"`
  51. BasicAuth bool `json:"basicAuth"`
  52. BasicAuthUser string `json:"basicAuthUser"`
  53. BasicAuthPassword string `json:"basicAuthPassword"`
  54. IsDefault bool `json:"isDefault"`
  55. JsonData map[string]interface{} `json:"jsonData"`
  56. OrgId int64 `json:"-"`
  57. Result *DataSource
  58. }
  59. // Also acts as api DTO
  60. type UpdateDataSourceCommand struct {
  61. Name string `json:"name" binding:"Required"`
  62. Type string `json:"type" binding:"Required"`
  63. Access DsAccess `json:"access" binding:"Required"`
  64. Url string `json:"url"`
  65. Password string `json:"password"`
  66. User string `json:"user"`
  67. Database string `json:"database"`
  68. BasicAuth bool `json:"basicAuth"`
  69. BasicAuthUser string `json:"basicAuthUser"`
  70. BasicAuthPassword string `json:"basicAuthPassword"`
  71. IsDefault bool `json:"isDefault"`
  72. JsonData map[string]interface{} `json:"jsonData"`
  73. OrgId int64 `json:"-"`
  74. Id int64 `json:"-"`
  75. }
  76. type DeleteDataSourceCommand struct {
  77. Id int64
  78. OrgId int64
  79. }
  80. // ---------------------
  81. // QUERIES
  82. type GetDataSourcesQuery struct {
  83. OrgId int64
  84. Result []*DataSource
  85. }
  86. type GetDataSourceByIdQuery struct {
  87. Id int64
  88. OrgId int64
  89. Result DataSource
  90. }
  91. type GetDataSourceByNameQuery struct {
  92. Name string
  93. OrgId int64
  94. Result DataSource
  95. }
  96. // ---------------------
  97. // EVENTS
  98. type DataSourceCreatedEvent struct {
  99. }