You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
4.3 KiB

  1. package database
  2. import (
  3. "github.com/matrix-org/go-neb/api"
  4. "github.com/matrix-org/go-neb/types"
  5. )
  6. // Storer is the interface which needs to be conformed to in order to persist Go-NEB data
  7. type Storer interface {
  8. StoreMatrixClientConfig(config api.ClientConfig) (oldConfig api.ClientConfig, err error)
  9. LoadMatrixClientConfigs() (configs []api.ClientConfig, err error)
  10. LoadMatrixClientConfig(userID string) (config api.ClientConfig, err error)
  11. UpdateNextBatch(userID, nextBatch string) (err error)
  12. LoadNextBatch(userID string) (nextBatch string, err error)
  13. LoadService(serviceID string) (service types.Service, err error)
  14. DeleteService(serviceID string) (err error)
  15. LoadServicesForUser(serviceUserID string) (services []types.Service, err error)
  16. LoadServicesByType(serviceType string) (services []types.Service, err error)
  17. StoreService(service types.Service) (oldService types.Service, err error)
  18. LoadAuthRealm(realmID string) (realm types.AuthRealm, err error)
  19. LoadAuthRealmsByType(realmType string) (realms []types.AuthRealm, err error)
  20. StoreAuthRealm(realm types.AuthRealm) (old types.AuthRealm, err error)
  21. StoreAuthSession(session types.AuthSession) (old types.AuthSession, err error)
  22. LoadAuthSessionByUser(realmID, userID string) (session types.AuthSession, err error)
  23. LoadAuthSessionByID(realmID, sessionID string) (session types.AuthSession, err error)
  24. RemoveAuthSession(realmID, userID string) error
  25. LoadBotOptions(userID, roomID string) (opts types.BotOptions, err error)
  26. StoreBotOptions(opts types.BotOptions) (oldOpts types.BotOptions, err error)
  27. InsertFromConfig(cfg *api.ConfigFile) error
  28. }
  29. // NopStorage nops every store API call. This is intended to be embedded into derived structs
  30. // in tests
  31. type NopStorage struct{}
  32. // StoreMatrixClientConfig NOP
  33. func (s *NopStorage) StoreMatrixClientConfig(config api.ClientConfig) (oldConfig api.ClientConfig, err error) {
  34. return api.ClientConfig{}, nil
  35. }
  36. // LoadMatrixClientConfigs NOP
  37. func (s *NopStorage) LoadMatrixClientConfigs() (configs []api.ClientConfig, err error) {
  38. return
  39. }
  40. // LoadMatrixClientConfig NOP
  41. func (s *NopStorage) LoadMatrixClientConfig(userID string) (config api.ClientConfig, err error) {
  42. return
  43. }
  44. // UpdateNextBatch NOP
  45. func (s *NopStorage) UpdateNextBatch(userID, nextBatch string) (err error) {
  46. return
  47. }
  48. // LoadNextBatch NOP
  49. func (s *NopStorage) LoadNextBatch(userID string) (nextBatch string, err error) {
  50. return
  51. }
  52. // LoadService NOP
  53. func (s *NopStorage) LoadService(serviceID string) (service types.Service, err error) {
  54. return
  55. }
  56. // DeleteService NOP
  57. func (s *NopStorage) DeleteService(serviceID string) (err error) {
  58. return
  59. }
  60. // LoadServicesForUser NOP
  61. func (s *NopStorage) LoadServicesForUser(serviceUserID string) (services []types.Service, err error) {
  62. return
  63. }
  64. // LoadServicesByType NOP
  65. func (s *NopStorage) LoadServicesByType(serviceType string) (services []types.Service, err error) {
  66. return
  67. }
  68. // StoreService NOP
  69. func (s *NopStorage) StoreService(service types.Service) (oldService types.Service, err error) {
  70. return
  71. }
  72. // LoadAuthRealm NOP
  73. func (s *NopStorage) LoadAuthRealm(realmID string) (realm types.AuthRealm, err error) {
  74. return
  75. }
  76. // LoadAuthRealmsByType NOP
  77. func (s *NopStorage) LoadAuthRealmsByType(realmType string) (realms []types.AuthRealm, err error) {
  78. return
  79. }
  80. // StoreAuthRealm NOP
  81. func (s *NopStorage) StoreAuthRealm(realm types.AuthRealm) (old types.AuthRealm, err error) {
  82. return
  83. }
  84. // StoreAuthSession NOP
  85. func (s *NopStorage) StoreAuthSession(session types.AuthSession) (old types.AuthSession, err error) {
  86. return
  87. }
  88. // LoadAuthSessionByUser NOP
  89. func (s *NopStorage) LoadAuthSessionByUser(realmID, userID string) (session types.AuthSession, err error) {
  90. return
  91. }
  92. // LoadAuthSessionByID NOP
  93. func (s *NopStorage) LoadAuthSessionByID(realmID, sessionID string) (session types.AuthSession, err error) {
  94. return
  95. }
  96. // RemoveAuthSession NOP
  97. func (s *NopStorage) RemoveAuthSession(realmID, userID string) error {
  98. return nil
  99. }
  100. // LoadBotOptions NOP
  101. func (s *NopStorage) LoadBotOptions(userID, roomID string) (opts types.BotOptions, err error) {
  102. return
  103. }
  104. // StoreBotOptions NOP
  105. func (s *NopStorage) StoreBotOptions(opts types.BotOptions) (oldOpts types.BotOptions, err error) {
  106. return
  107. }
  108. // InsertFromConfig NOP
  109. func (s *NopStorage) InsertFromConfig(cfg *api.ConfigFile) error {
  110. return nil
  111. }