@@ -50,14 +50,20 @@ func DefaultIMS() *IMSConfig {
5050 HostName : "localhost" ,
5151 HostPort : 3306 ,
5252 Database : "ims" ,
53+ // Some arbitrary value. We'll get errors from MariaDB if the server
54+ // hits the DB with too many parallel requests.
55+ MaxOpenConns : 20 ,
5356 },
54- InProcess : DBStoreMaria {
57+ Fake : DBStoreMaria {
5558 HostName : "localhost" ,
5659 // HostPort can be left as 0 for automatic port selection on startup
5760 HostPort : 0 ,
5861 Database : "ims-db" ,
5962 Username : "ims-db-user" ,
6063 Password : rand .Text (),
64+ // This needs to be 1 for the fake DB because of
65+ // https://github.com/dolthub/go-mysql-server/issues/1306
66+ MaxOpenConns : 1 ,
6167 },
6268 },
6369 Directory : Directory {
@@ -78,17 +84,37 @@ func DefaultIMS() *IMSConfig {
7884// Validate should be called after an IMSConfig has been fully configured.
7985func (c * IMSConfig ) Validate () error {
8086 var errs []error
87+
88+ // IMS database
8189 errs = append (errs , c .Store .Type .Validate ())
82- if c .Store .Type == DBStoreTypeNoOp {
90+ if c .Store .Type != DBStoreTypeMaria {
8391 c .Store .MariaDB = DBStoreMaria {}
8492 }
93+ if c .Store .Type != DBStoreTypeFake {
94+ c .Store .Fake = DBStoreMaria {}
95+ }
96+
97+ // User directory
8598 errs = append (errs , c .Directory .Directory .Validate ())
8699 if c .Directory .Directory != DirectoryTypeTestUsers {
87100 c .Directory .TestUsers = nil
88101 }
89102 if c .Directory .Directory != DirectoryTypeClubhouseDB {
90103 c .Directory .ClubhouseDB = ClubhouseDB {}
91104 }
105+
106+ // Deployment
107+ errs = append (errs , c .Core .Deployment .Validate ())
108+ if c .Core .Deployment != DeploymentTypeDev {
109+ if c .Directory .Directory != DirectoryTypeClubhouseDB {
110+ errs = append (errs , errors .New ("non-dev environments must use a ClubhouseDB directory" ))
111+ }
112+ if c .Store .Type != DBStoreTypeMaria {
113+ errs = append (errs , errors .New ("non-dev environments must use a MariaDB datastore" ))
114+ }
115+ }
116+
117+ // Attachments store
92118 errs = append (errs , c .AttachmentsStore .Type .Validate ())
93119 if c .AttachmentsStore .Type == AttachmentsStoreLocal {
94120 if c .AttachmentsStore .Local .Dir == nil {
@@ -106,9 +132,8 @@ func (c *IMSConfig) Validate() error {
106132 }
107133 c .AttachmentsStore .Local = LocalAttachments {}
108134 }
109- if c .Core .Deployment != "dev" && c .Directory .Directory == DirectoryTypeTestUsers {
110- errs = append (errs , errors .New ("do not use TestUsers outside dev! A ClubhouseDB must be provided" ))
111- }
135+
136+ // Assorted other validations
112137 if c .Core .AccessTokenLifetime > c .Core .RefreshTokenLifetime {
113138 errs = append (errs , errors .New ("access token lifetime should not be greater than refresh token lifetime" ))
114139 }
@@ -137,6 +162,7 @@ type DeploymentType string
137162
138163type DBStoreType string
139164
165+ // All these consts should have lowercase values to allow case-insensitive matching.
140166const (
141167 DirectoryTypeClubhouseDB DirectoryType = "clubhousedb"
142168 DirectoryTypeTestUsers DirectoryType = "testusers"
@@ -148,12 +174,12 @@ const (
148174 DeploymentTypeProduction DeploymentType = "production"
149175 DBStoreTypeMaria DBStoreType = "mariadb"
150176 DBStoreTypeNoOp DBStoreType = "noop"
151- DBStoreTypeInProcess DBStoreType = "inprocess "
177+ DBStoreTypeFake DBStoreType = "fake "
152178)
153179
154180func (d DBStoreType ) Validate () error {
155181 switch d {
156- case DBStoreTypeMaria , DBStoreTypeNoOp , DBStoreTypeInProcess :
182+ case DBStoreTypeMaria , DBStoreTypeNoOp , DBStoreTypeFake :
157183 return nil
158184 default :
159185 return fmt .Errorf ("unknown DB store type %v" , d )
@@ -195,7 +221,7 @@ type ConfigCore struct {
195221 Admins []string
196222 MasterKey string `redact:"true"`
197223 JWTSecret string `redact:"true"`
198- Deployment string
224+ Deployment DeploymentType
199225
200226 // CacheControlShort is the duration we set in various responses' Cache-Control headers
201227 // for resources that aren't expected to change often, but still do change (e.g. the list of
@@ -216,17 +242,18 @@ type ConfigCore struct {
216242}
217243
218244type DBStore struct {
219- Type DBStoreType
220- MariaDB DBStoreMaria
221- InProcess DBStoreMaria
245+ Type DBStoreType
246+ MariaDB DBStoreMaria
247+ Fake DBStoreMaria
222248}
223249
224250type DBStoreMaria struct {
225- HostName string
226- HostPort int32
227- Database string
228- Username string
229- Password string `redact:"true"`
251+ HostName string
252+ HostPort int32
253+ Database string
254+ Username string
255+ Password string `redact:"true"`
256+ MaxOpenConns int32
230257}
231258
232259type TestUser struct {
0 commit comments