Skip to content

Commit e971765

Browse files
simplify storage (#12)
1 parent 1bcbc1d commit e971765

File tree

12 files changed

+367
-672
lines changed

12 files changed

+367
-672
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ import "github.com/faroedev/faroe"
3636

3737
func main() {
3838
server := faroe.NewServer(
39-
mainStorage,
40-
cache,
41-
rateLimitStorage,
39+
storage,
4240
userStore,
4341
logger,
4442
userPasswordHashAlgorithms,

actions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2239,7 +2239,7 @@ type actionSessionStruct struct {
22392239
expiresAtDefined bool
22402240
}
22412241

2242-
func (server *ServerStruct) createActionSession(session cachedSessionStruct) actionSessionStruct {
2242+
func (server *ServerStruct) createActionSession(session sessionStruct) actionSessionStruct {
22432243
actionSession := actionSessionStruct{
22442244
id: session.id,
22452245
userId: session.userId,

server.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import (
88

99
// Use [NewServer].
1010
type ServerStruct struct {
11-
mainStorage MainStorageInterface
12-
cache CacheInterface
11+
storage StorageInterface
1312

1413
userStore UserStoreInterface
1514

@@ -30,18 +29,14 @@ type ServerStruct struct {
3029

3130
// All interfaces must be defined and cannot be nil.
3231
//
33-
// Storage entry keys are not globally-scoped. Different entries in mainStorage, cache, and rateLimitStorage may share the same key.
34-
//
3532
// maxConcurrentPasswordHashingProcesses defines the maximum number of concurrent processes for user password and temporary password hashing.
3633
//
3734
// emailAddressChecker is used for checking email addresses for signup and new email addresses of user email address updates.
3835
// It is not used in for sign ins or user password resets.
3936
//
4037
// InactivityTimeout and ActivityCheckInterval should be a non-zero value in sessionConfig.
4138
func NewServer(
42-
mainStorage MainStorageInterface,
43-
cache CacheInterface,
44-
rateLimitStorage RateLimitStorageInterface,
39+
storage StorageInterface,
4540
userStore UserStoreInterface,
4641
errorLogger ActionErrorLoggerInterface,
4742
userPasswordHashAlgorithms []PasswordHashAlgorithmInterface,
@@ -52,14 +47,13 @@ func NewServer(
5247
emailSender EmailSenderInterface,
5348
sessionConfig SessionConfigStruct,
5449
) *ServerStruct {
55-
verifyUserPasswordRateLimit := newTokenBucketRateLimit(rateLimitStorage, rateLimitStorageKeyPrefixVerifyUserPasswordRateLimit, clock, 5, time.Minute)
56-
sendEmailRateLimit := newTokenBucketRateLimit(rateLimitStorage, rateLimitStorageKeyPrefixSendEmailRateLimit, clock, 5, 30*time.Minute)
57-
verifyEmailAddressVerificationCodeEmailAddressRateLimit := newTokenBucketRateLimit(rateLimitStorage, rateLimitStorageKeyPrefixVerifyEmailAddressVerificationCodeEmailAddressRateLimit, clock, 5, time.Minute)
58-
verifyUserPasswordResetTemporaryPasswordUserRateLimit := newTokenBucketRateLimit(rateLimitStorage, rateLimitStorageKeyPrefixVerifyUserPasswordResetTemporaryPasswordUserRateLimit, clock, 5, time.Minute)
50+
verifyUserPasswordRateLimit := newTokenBucketRateLimit(storage, storageKeyPrefixVerifyUserPasswordTokenBucket, clock, 5, time.Minute)
51+
sendEmailRateLimit := newTokenBucketRateLimit(storage, storageKeyPrefixSendEmailTokenBucket, clock, 5, 30*time.Minute)
52+
verifyEmailAddressVerificationCodeEmailAddressRateLimit := newTokenBucketRateLimit(storage, storageKeyPrefixVerifyEmailAddressVerificationCodeEmailAddressTokenBucket, clock, 5, time.Minute)
53+
verifyUserPasswordResetTemporaryPasswordUserRateLimit := newTokenBucketRateLimit(storage, storageKeyPrefixVerifyUserPasswordResetTemporaryPasswordUserTokenBucket, clock, 5, time.Minute)
5954

6055
action := &ServerStruct{
61-
mainStorage: mainStorage,
62-
cache: cache,
56+
storage: storage,
6357
userStore: userStore,
6458
errorLogger: errorLogger,
6559
userPasswordHashAlgorithms: userPasswordHashAlgorithms,

0 commit comments

Comments
 (0)