2017-05-22 10:49:32 -05:00
|
|
|
package devices
|
|
|
|
|
2017-05-23 11:43:05 -05:00
|
|
|
import (
|
2017-09-18 09:51:26 -05:00
|
|
|
"context"
|
2020-01-27 06:10:51 -06:00
|
|
|
"net/url"
|
2017-05-25 07:33:50 -05:00
|
|
|
|
2017-05-23 11:43:05 -05:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
2020-01-27 06:31:05 -06:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices/postgres"
|
2020-01-27 06:34:45 -06:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices/sqlite3"
|
2020-01-27 06:31:05 -06:00
|
|
|
"github.com/matrix-org/gomatrixserverlib"
|
2017-05-23 11:43:05 -05:00
|
|
|
)
|
|
|
|
|
2020-01-27 06:10:51 -06:00
|
|
|
type Database interface {
|
|
|
|
GetDeviceByAccessToken(ctx context.Context, token string) (*authtypes.Device, error)
|
|
|
|
GetDeviceByID(ctx context.Context, localpart, deviceID string) (*authtypes.Device, error)
|
|
|
|
GetDevicesByLocalpart(ctx context.Context, localpart string) ([]authtypes.Device, error)
|
2020-01-27 06:31:05 -06:00
|
|
|
CreateDevice(ctx context.Context, localpart string, deviceID *string, accessToken string, displayName *string) (dev *authtypes.Device, returnErr error)
|
2020-01-27 06:10:51 -06:00
|
|
|
UpdateDevice(ctx context.Context, localpart, deviceID string, displayName *string) error
|
|
|
|
RemoveDevice(ctx context.Context, deviceID, localpart string) error
|
|
|
|
RemoveAllDevices(ctx context.Context, localpart string) error
|
2017-10-17 13:12:54 -05:00
|
|
|
}
|
|
|
|
|
2020-01-27 06:31:05 -06:00
|
|
|
func NewDatabase(dataSourceName string, serverName gomatrixserverlib.ServerName) (Database, error) {
|
2020-01-27 06:10:51 -06:00
|
|
|
uri, err := url.Parse(dataSourceName)
|
2018-06-01 06:16:19 -05:00
|
|
|
if err != nil {
|
2020-01-27 06:31:05 -06:00
|
|
|
return postgres.NewDatabase(dataSourceName, serverName)
|
2020-01-27 06:10:51 -06:00
|
|
|
}
|
|
|
|
switch uri.Scheme {
|
|
|
|
case "postgres":
|
2020-01-27 06:31:05 -06:00
|
|
|
return postgres.NewDatabase(dataSourceName, serverName)
|
2020-01-27 06:10:51 -06:00
|
|
|
case "file":
|
2020-01-27 06:34:45 -06:00
|
|
|
return sqlite3.NewDatabase(dataSourceName, serverName)
|
2020-01-27 06:10:51 -06:00
|
|
|
default:
|
2020-01-27 06:31:05 -06:00
|
|
|
return postgres.NewDatabase(dataSourceName, serverName)
|
2018-06-01 06:16:19 -05:00
|
|
|
}
|
2017-10-15 05:29:47 -05:00
|
|
|
}
|