Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor metadb fixes for dynamo and bolt #2884

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ var (
ErrMissingAuthHeader = errors.New("required authorization header is missing")
ErrUserAPIKeyNotFound = errors.New("user info for given API key hash not found")
ErrUserSessionNotFound = errors.New("user session for given ID not found")
ErrInvalidMetaDBVersion = errors.New("unrecognized version meta")
ErrBucketDoesNotExist = errors.New("bucket does not exist")
ErrOpenIDProviderDoesNotExist = errors.New("openid provider does not exist in given config")
ErrHashKeyNotCreated = errors.New("cookiestore generated random hash key is nil, aborting")
Expand Down
2 changes: 1 addition & 1 deletion pkg/meta/boltdb/boltdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,7 @@ func (bdw *BoltDB) PatchDB() error {
}

if version.GetVersionIndex(DBVersion) == -1 {
return fmt.Errorf("DB has broken format, no version found %w", err)
return fmt.Errorf("%w: %s could not identify patches", zerr.ErrInvalidMetaDBVersion, DBVersion)
}

for patchIndex, patch := range bdw.Patches {
Expand Down
20 changes: 13 additions & 7 deletions pkg/meta/dynamodb/dynamodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -1730,23 +1730,29 @@ func (dwr DynamoDB) GetUserAPIKeys(ctx context.Context) ([]mTypes.APIKeyDetails,
return nil, fmt.Errorf("failed to get userData for identity %s %w", userid, err)
}

changed := false

for hashedKey, apiKeyDetails := range userData.APIKeys {
// if expiresAt is not nil value
if !apiKeyDetails.ExpirationDate.Equal(time.Time{}) && time.Now().After(apiKeyDetails.ExpirationDate) {
apiKeyDetails.IsExpired = true

changed = true
}

userData.APIKeys[hashedKey] = apiKeyDetails

err = dwr.SetUserData(ctx, userData)
if err != nil {
return nil, err
}

apiKeys = append(apiKeys, apiKeyDetails)
}

return apiKeys, nil
if !changed {
// return early, no need to make a call to update key expiry in the DB
return apiKeys, nil
}

err = dwr.SetUserData(ctx, userData)

return apiKeys, err
}

func (dwr DynamoDB) AddUserAPIKey(ctx context.Context, hashedKey string, apiKeyDetails *mTypes.APIKeyDetails) error {
Expand Down Expand Up @@ -2049,7 +2055,7 @@ func (dwr *DynamoDB) PatchDB() error {
}

if version.GetVersionIndex(DBVersion) == -1 {
return fmt.Errorf("DB has broken format, no version found %w", err)
return fmt.Errorf("%w: %s could not identify patches", zerr.ErrInvalidMetaDBVersion, DBVersion)
}

for patchIndex, patch := range dwr.Patches {
Expand Down
Loading