@@ -17,6 +17,8 @@ import (
1717 "sync/atomic"
1818 "time"
1919
20+ "github.com/netbirdio/netbird/shared/auth"
21+
2022 cacheStore "github.com/eko/gocache/lib/v4/store"
2123 "github.com/eko/gocache/store/redis/v4"
2224 "github.com/rs/xid"
@@ -1046,7 +1048,7 @@ func (am *DefaultAccountManager) removeUserFromCache(ctx context.Context, accoun
10461048}
10471049
10481050// updateAccountDomainAttributesIfNotUpToDate updates the account domain attributes if they are not up to date and then, saves the account changes
1049- func (am * DefaultAccountManager ) updateAccountDomainAttributesIfNotUpToDate (ctx context.Context , accountID string , userAuth nbcontext .UserAuth ,
1051+ func (am * DefaultAccountManager ) updateAccountDomainAttributesIfNotUpToDate (ctx context.Context , accountID string , userAuth auth .UserAuth ,
10501052 primaryDomain bool ,
10511053) error {
10521054 if userAuth .Domain == "" {
@@ -1095,7 +1097,7 @@ func (am *DefaultAccountManager) handleExistingUserAccount(
10951097 ctx context.Context ,
10961098 userAccountID string ,
10971099 domainAccountID string ,
1098- userAuth nbcontext .UserAuth ,
1100+ userAuth auth .UserAuth ,
10991101) error {
11001102 primaryDomain := domainAccountID == "" || userAccountID == domainAccountID
11011103 err := am .updateAccountDomainAttributesIfNotUpToDate (ctx , userAccountID , userAuth , primaryDomain )
@@ -1114,7 +1116,7 @@ func (am *DefaultAccountManager) handleExistingUserAccount(
11141116
11151117// addNewPrivateAccount validates if there is an existing primary account for the domain, if so it adds the new user to that account,
11161118// otherwise it will create a new account and make it primary account for the domain.
1117- func (am * DefaultAccountManager ) addNewPrivateAccount (ctx context.Context , domainAccountID string , userAuth nbcontext .UserAuth ) (string , error ) {
1119+ func (am * DefaultAccountManager ) addNewPrivateAccount (ctx context.Context , domainAccountID string , userAuth auth .UserAuth ) (string , error ) {
11181120 if userAuth .UserId == "" {
11191121 return "" , fmt .Errorf ("user ID is empty" )
11201122 }
@@ -1145,7 +1147,7 @@ func (am *DefaultAccountManager) addNewPrivateAccount(ctx context.Context, domai
11451147 return newAccount .Id , nil
11461148}
11471149
1148- func (am * DefaultAccountManager ) addNewUserToDomainAccount (ctx context.Context , domainAccountID string , userAuth nbcontext .UserAuth ) (string , error ) {
1150+ func (am * DefaultAccountManager ) addNewUserToDomainAccount (ctx context.Context , domainAccountID string , userAuth auth .UserAuth ) (string , error ) {
11491151 newUser := types .NewRegularUser (userAuth .UserId )
11501152 newUser .AccountID = domainAccountID
11511153
@@ -1309,7 +1311,7 @@ func (am *DefaultAccountManager) UpdateAccountOnboarding(ctx context.Context, ac
13091311 return newOnboarding , nil
13101312}
13111313
1312- func (am * DefaultAccountManager ) GetAccountIDFromUserAuth (ctx context.Context , userAuth nbcontext .UserAuth ) (string , string , error ) {
1314+ func (am * DefaultAccountManager ) GetAccountIDFromUserAuth (ctx context.Context , userAuth auth .UserAuth ) (string , string , error ) {
13131315 if userAuth .UserId == "" {
13141316 return "" , "" , errors .New (emptyUserID )
13151317 }
@@ -1353,7 +1355,7 @@ func (am *DefaultAccountManager) GetAccountIDFromUserAuth(ctx context.Context, u
13531355// syncJWTGroups processes the JWT groups for a user, updates the account based on the groups,
13541356// and propagates changes to peers if group propagation is enabled.
13551357// requires userAuth to have been ValidateAndParseToken and EnsureUserAccessByJWTGroups by the AuthManager
1356- func (am * DefaultAccountManager ) SyncUserJWTGroups (ctx context.Context , userAuth nbcontext .UserAuth ) error {
1358+ func (am * DefaultAccountManager ) SyncUserJWTGroups (ctx context.Context , userAuth auth .UserAuth ) error {
13571359 if userAuth .IsChild || userAuth .IsPAT {
13581360 return nil
13591361 }
@@ -1511,7 +1513,7 @@ func (am *DefaultAccountManager) SyncUserJWTGroups(ctx context.Context, userAuth
15111513// Existing user + Existing account + Existing domain reclassified Domain as private -> Nothing changes (index domain)
15121514//
15131515// UserAuth IsChild -> checks that account exists
1514- func (am * DefaultAccountManager ) getAccountIDWithAuthorizationClaims (ctx context.Context , userAuth nbcontext .UserAuth ) (string , error ) {
1516+ func (am * DefaultAccountManager ) getAccountIDWithAuthorizationClaims (ctx context.Context , userAuth auth .UserAuth ) (string , error ) {
15151517 log .WithContext (ctx ).Tracef ("getting account with authorization claims. User ID: \" %s\" , Account ID: \" %s\" , Domain: \" %s\" , Domain Category: \" %s\" " ,
15161518 userAuth .UserId , userAuth .AccountId , userAuth .Domain , userAuth .DomainCategory )
15171519
@@ -1590,7 +1592,7 @@ func (am *DefaultAccountManager) getPrivateDomainWithGlobalLock(ctx context.Cont
15901592 return domainAccountID , cancel , nil
15911593}
15921594
1593- func (am * DefaultAccountManager ) handlePrivateAccountWithIDFromClaim (ctx context.Context , userAuth nbcontext .UserAuth ) (string , error ) {
1595+ func (am * DefaultAccountManager ) handlePrivateAccountWithIDFromClaim (ctx context.Context , userAuth auth .UserAuth ) (string , error ) {
15941596 userAccountID , err := am .Store .GetAccountIDByUserID (ctx , store .LockingStrengthNone , userAuth .UserId )
15951597 if err != nil {
15961598 log .WithContext (ctx ).Errorf ("error getting account ID by user ID: %v" , err )
@@ -1638,7 +1640,7 @@ func handleNotFound(err error) error {
16381640 return nil
16391641}
16401642
1641- func domainIsUpToDate (domain string , domainCategory string , userAuth nbcontext .UserAuth ) bool {
1643+ func domainIsUpToDate (domain string , domainCategory string , userAuth auth .UserAuth ) bool {
16421644 return domainCategory == types .PrivateCategory || userAuth .DomainCategory != types .PrivateCategory || domain != userAuth .Domain
16431645}
16441646
0 commit comments