Skip to content

Commit c042e70

Browse files
⬆️ mongo: Added New to re-support custom mongo configuration and hashers.
1 parent 56a353f commit c042e70

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
9+
### Added
10+
- mongo: Added New to re-support custom mongo configuration and hashers.
11+
812
### Changed
913
- mongo: Changed `MongoStore` to `Store` to be more idiomatic.
1014
- mongo: Changed `ConnectToMongo` to `Connect` to be more idiomatic.

mongo/mongo.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,23 +136,24 @@ func Connect(cfg *Config) (*mgo.Database, error) {
136136
return session.DB(cfg.DatabaseName), nil
137137
}
138138

139-
// NewDefaultStore returns a Store configured with the default mongo configuration and default Hasher.
140-
func NewDefaultStore() (*Store, error) {
139+
// New allows for custom mongo configuration and custom hashers.
140+
func New(cfg *Config, hashee fosite.Hasher) (*Store, error) {
141141
log := logger.WithFields(logrus.Fields{
142142
"package": "mongo",
143-
"method": "NewDefaultStore",
143+
"method": "NewFromConfig",
144144
})
145145

146-
cfg := DefaultConfig()
147146
database, err := Connect(cfg)
148147
if err != nil {
149148
log.WithError(err).Error("Unable to connect to mongo! Are you sure mongo is running on localhost?")
150149
return nil, err
151150
}
152151

153-
// Initialize the default fosite Hasher.
154-
hasher := &fosite.BCrypt{
155-
WorkFactor: 10,
152+
if hashee == nil {
153+
// Initialize default fosite Hasher.
154+
hashee = &fosite.BCrypt{
155+
WorkFactor: 10,
156+
}
156157
}
157158

158159
// Build up the mongo endpoints
@@ -161,11 +162,11 @@ func NewDefaultStore() (*Store, error) {
161162
}
162163
mongoClients := &ClientManager{
163164
DB: database,
164-
Hasher: hasher,
165+
Hasher: hashee,
165166
}
166167
mongoUsers := &UserManager{
167168
DB: database,
168-
Hasher: hasher,
169+
Hasher: hashee,
169170
}
170171
mongoRequests := &RequestManager{
171172
DB: database,
@@ -198,7 +199,7 @@ func NewDefaultStore() (*Store, error) {
198199

199200
return &Store{
200201
DB: database,
201-
Hasher: hasher,
202+
Hasher: hashee,
202203
Storer: storage.Storer{
203204
Cache: mongoCache,
204205
Clients: mongoClients,
@@ -207,3 +208,10 @@ func NewDefaultStore() (*Store, error) {
207208
},
208209
}, nil
209210
}
211+
212+
// NewDefaultStore returns a Store configured with the default mongo
213+
// configuration and default Hasher.
214+
func NewDefaultStore() (*Store, error) {
215+
cfg := DefaultConfig()
216+
return New(cfg, nil)
217+
}

0 commit comments

Comments
 (0)