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-02-13 11:27:33 -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-02-13 11:27:33 -06:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices/postgres"
|
|
|
|
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices/sqlite3"
|
2017-05-25 07:33:50 -05:00
|
|
|
"github.com/matrix-org/gomatrixserverlib"
|
2017-05-23 11:43:05 -05:00
|
|
|
)
|
|
|
|
|
2020-02-13 11:27:33 -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)
|
|
|
|
CreateDevice(ctx context.Context, localpart string, deviceID *string, accessToken string, displayName *string) (dev *authtypes.Device, returnErr error)
|
|
|
|
UpdateDevice(ctx context.Context, localpart, deviceID string, displayName *string) error
|
|
|
|
RemoveDevice(ctx context.Context, deviceID, localpart string) error
|
|
|
|
RemoveDevices(ctx context.Context, localpart string, devices []string) error
|
|
|
|
RemoveAllDevices(ctx context.Context, localpart string) error
|
2017-05-25 07:33:50 -05:00
|
|
|
}
|
|
|
|
|
2020-02-13 11:27:33 -06:00
|
|
|
func NewDatabase(dataSourceName string, serverName gomatrixserverlib.ServerName) (Database, error) {
|
|
|
|
uri, err := url.Parse(dataSourceName)
|
2018-06-01 06:16:19 -05:00
|
|
|
if err != nil {
|
2020-02-13 11:27:33 -06:00
|
|
|
return postgres.NewDatabase(dataSourceName, serverName)
|
|
|
|
}
|
|
|
|
switch uri.Scheme {
|
|
|
|
case "postgres":
|
|
|
|
return postgres.NewDatabase(dataSourceName, serverName)
|
|
|
|
case "file":
|
|
|
|
return sqlite3.NewDatabase(dataSourceName, serverName)
|
|
|
|
default:
|
|
|
|
return postgres.NewDatabase(dataSourceName, serverName)
|
2018-06-01 06:16:19 -05:00
|
|
|
}
|
2017-10-15 05:29:47 -05:00
|
|
|
}
|