mirror of
https://github.com/hoernschen/dendrite.git
synced 2024-12-27 23:48:27 +00:00
Rename packages under /auth (#114)
Previously, all database stuff was under the helpfully named package 'storage'. However, this convention is used throughout all of dendrite, which will clash the moment we want to add auth to all the CS API endpoints. To prevent the package name clash, add sub-directories which represent what is being stored so the final usage ends up being: ``` func doThing(db *storage.SyncServerDatabase, authDB *accounts.Database) { // ... } ```
This commit is contained in:
parent
0325459e7f
commit
d63a1ddc7c
6 changed files with 60 additions and 12 deletions
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package storage
|
package accounts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package storage
|
package accounts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
@ -23,14 +23,14 @@ import (
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AccountDatabase represents an account database
|
// Database represents an account database
|
||||||
type AccountDatabase struct {
|
type Database struct {
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
accounts accountsStatements
|
accounts accountsStatements
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAccountDatabase creates a new accounts database
|
// NewDatabase creates a new accounts database
|
||||||
func NewAccountDatabase(dataSourceName string, serverName gomatrixserverlib.ServerName) (*AccountDatabase, error) {
|
func NewDatabase(dataSourceName string, serverName gomatrixserverlib.ServerName) (*Database, error) {
|
||||||
var db *sql.DB
|
var db *sql.DB
|
||||||
var err error
|
var err error
|
||||||
if db, err = sql.Open("postgres", dataSourceName); err != nil {
|
if db, err = sql.Open("postgres", dataSourceName); err != nil {
|
||||||
|
@ -40,12 +40,12 @@ func NewAccountDatabase(dataSourceName string, serverName gomatrixserverlib.Serv
|
||||||
if err = a.prepare(db, serverName); err != nil {
|
if err = a.prepare(db, serverName); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &AccountDatabase{db, a}, nil
|
return &Database{db, a}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAccountByPassword returns the account associated with the given localpart and password.
|
// GetAccountByPassword returns the account associated with the given localpart and password.
|
||||||
// Returns sql.ErrNoRows if no account exists which matches the given credentials.
|
// Returns sql.ErrNoRows if no account exists which matches the given credentials.
|
||||||
func (d *AccountDatabase) GetAccountByPassword(localpart, plaintextPassword string) (*types.Account, error) {
|
func (d *Database) GetAccountByPassword(localpart, plaintextPassword string) (*types.Account, error) {
|
||||||
hash, err := d.accounts.selectPasswordHash(localpart)
|
hash, err := d.accounts.selectPasswordHash(localpart)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -58,7 +58,7 @@ func (d *AccountDatabase) GetAccountByPassword(localpart, plaintextPassword stri
|
||||||
|
|
||||||
// CreateAccount makes a new account with the given login name and password. If no password is supplied,
|
// CreateAccount makes a new account with the given login name and password. If no password is supplied,
|
||||||
// the account will be a passwordless account.
|
// the account will be a passwordless account.
|
||||||
func (d *AccountDatabase) CreateAccount(localpart, plaintextPassword string) (*types.Account, error) {
|
func (d *Database) CreateAccount(localpart, plaintextPassword string) (*types.Account, error) {
|
||||||
hash, err := hashPassword(plaintextPassword)
|
hash, err := hashPassword(plaintextPassword)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
|
@ -0,0 +1,25 @@
|
||||||
|
// Copyright 2017 Vector Creations Ltd
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package devices
|
||||||
|
|
||||||
|
// Database represents a device database.
|
||||||
|
type Database struct {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewDatabase creates a new device database
|
||||||
|
func NewDatabase() *Database {
|
||||||
|
return &Database{}
|
||||||
|
}
|
|
@ -24,6 +24,6 @@ type Account struct {
|
||||||
Localpart string
|
Localpart string
|
||||||
ServerName gomatrixserverlib.ServerName
|
ServerName gomatrixserverlib.ServerName
|
||||||
// TODO: Other flags like IsAdmin, IsGuest
|
// TODO: Other flags like IsAdmin, IsGuest
|
||||||
// TODO: Device IDs
|
// TODO: Devices
|
||||||
// TODO: Associations (e.g. with application services)
|
// TODO: Associations (e.g. with application services)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
// Copyright 2017 Vector Creations Ltd
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package types
|
||||||
|
|
||||||
|
// Device represents a client's device (mobile, web, etc)
|
||||||
|
type Device struct {
|
||||||
|
ID string
|
||||||
|
UserID string
|
||||||
|
AccessToken string
|
||||||
|
// TODO: display name, last used timestamp, keys, etc
|
||||||
|
}
|
|
@ -19,7 +19,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth/storage"
|
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
|
||||||
"github.com/matrix-org/dendrite/clientapi/config"
|
"github.com/matrix-org/dendrite/clientapi/config"
|
||||||
"github.com/matrix-org/dendrite/clientapi/producers"
|
"github.com/matrix-org/dendrite/clientapi/producers"
|
||||||
"github.com/matrix-org/dendrite/clientapi/routing"
|
"github.com/matrix-org/dendrite/clientapi/routing"
|
||||||
|
@ -81,7 +81,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
queryAPI := api.NewRoomserverQueryAPIHTTP(cfg.RoomserverURL, nil)
|
queryAPI := api.NewRoomserverQueryAPIHTTP(cfg.RoomserverURL, nil)
|
||||||
accountDB, err := storage.NewAccountDatabase(accountDataSource, serverName)
|
accountDB, err := accounts.NewDatabase(accountDataSource, serverName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panicf("Failed to setup account database(%s): %s", accountDataSource, err.Error())
|
log.Panicf("Failed to setup account database(%s): %s", accountDataSource, err.Error())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue