@@ -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