44 "context"
55 "errors"
66 "fmt"
7+ "github.com/netbirdio/netbird/shared/auth"
78 "math/rand"
89 "net"
910 "net/netip"
@@ -1046,7 +1047,7 @@ func (am *DefaultAccountManager) removeUserFromCache(ctx context.Context, accoun
10461047}
10471048
10481049// 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 ,
1050+ func (am * DefaultAccountManager ) updateAccountDomainAttributesIfNotUpToDate (ctx context.Context , accountID string , userAuth auth .UserAuth ,
10501051 primaryDomain bool ,
10511052) error {
10521053 if userAuth .Domain == "" {
@@ -1095,7 +1096,7 @@ func (am *DefaultAccountManager) handleExistingUserAccount(
10951096 ctx context.Context ,
10961097 userAccountID string ,
10971098 domainAccountID string ,
1098- userAuth nbcontext .UserAuth ,
1099+ userAuth auth .UserAuth ,
10991100) error {
11001101 primaryDomain := domainAccountID == "" || userAccountID == domainAccountID
11011102 err := am .updateAccountDomainAttributesIfNotUpToDate (ctx , userAccountID , userAuth , primaryDomain )
@@ -1114,7 +1115,7 @@ func (am *DefaultAccountManager) handleExistingUserAccount(
11141115
11151116// addNewPrivateAccount validates if there is an existing primary account for the domain, if so it adds the new user to that account,
11161117// 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 ) {
1118+ func (am * DefaultAccountManager ) addNewPrivateAccount (ctx context.Context , domainAccountID string , userAuth auth .UserAuth ) (string , error ) {
11181119 if userAuth .UserId == "" {
11191120 return "" , fmt .Errorf ("user ID is empty" )
11201121 }
@@ -1145,7 +1146,7 @@ func (am *DefaultAccountManager) addNewPrivateAccount(ctx context.Context, domai
11451146 return newAccount .Id , nil
11461147}
11471148
1148- func (am * DefaultAccountManager ) addNewUserToDomainAccount (ctx context.Context , domainAccountID string , userAuth nbcontext .UserAuth ) (string , error ) {
1149+ func (am * DefaultAccountManager ) addNewUserToDomainAccount (ctx context.Context , domainAccountID string , userAuth auth .UserAuth ) (string , error ) {
11491150 newUser := types .NewRegularUser (userAuth .UserId )
11501151 newUser .AccountID = domainAccountID
11511152
@@ -1309,7 +1310,7 @@ func (am *DefaultAccountManager) UpdateAccountOnboarding(ctx context.Context, ac
13091310 return newOnboarding , nil
13101311}
13111312
1312- func (am * DefaultAccountManager ) GetAccountIDFromUserAuth (ctx context.Context , userAuth nbcontext .UserAuth ) (string , string , error ) {
1313+ func (am * DefaultAccountManager ) GetAccountIDFromUserAuth (ctx context.Context , userAuth auth .UserAuth ) (string , string , error ) {
13131314 if userAuth .UserId == "" {
13141315 return "" , "" , errors .New (emptyUserID )
13151316 }
@@ -1353,7 +1354,7 @@ func (am *DefaultAccountManager) GetAccountIDFromUserAuth(ctx context.Context, u
13531354// syncJWTGroups processes the JWT groups for a user, updates the account based on the groups,
13541355// and propagates changes to peers if group propagation is enabled.
13551356// requires userAuth to have been ValidateAndParseToken and EnsureUserAccessByJWTGroups by the AuthManager
1356- func (am * DefaultAccountManager ) SyncUserJWTGroups (ctx context.Context , userAuth nbcontext .UserAuth ) error {
1357+ func (am * DefaultAccountManager ) SyncUserJWTGroups (ctx context.Context , userAuth auth .UserAuth ) error {
13571358 if userAuth .IsChild || userAuth .IsPAT {
13581359 return nil
13591360 }
@@ -1511,7 +1512,7 @@ func (am *DefaultAccountManager) SyncUserJWTGroups(ctx context.Context, userAuth
15111512// Existing user + Existing account + Existing domain reclassified Domain as private -> Nothing changes (index domain)
15121513//
15131514// UserAuth IsChild -> checks that account exists
1514- func (am * DefaultAccountManager ) getAccountIDWithAuthorizationClaims (ctx context.Context , userAuth nbcontext .UserAuth ) (string , error ) {
1515+ func (am * DefaultAccountManager ) getAccountIDWithAuthorizationClaims (ctx context.Context , userAuth auth .UserAuth ) (string , error ) {
15151516 log .WithContext (ctx ).Tracef ("getting account with authorization claims. User ID: \" %s\" , Account ID: \" %s\" , Domain: \" %s\" , Domain Category: \" %s\" " ,
15161517 userAuth .UserId , userAuth .AccountId , userAuth .Domain , userAuth .DomainCategory )
15171518
@@ -1590,7 +1591,7 @@ func (am *DefaultAccountManager) getPrivateDomainWithGlobalLock(ctx context.Cont
15901591 return domainAccountID , cancel , nil
15911592}
15921593
1593- func (am * DefaultAccountManager ) handlePrivateAccountWithIDFromClaim (ctx context.Context , userAuth nbcontext .UserAuth ) (string , error ) {
1594+ func (am * DefaultAccountManager ) handlePrivateAccountWithIDFromClaim (ctx context.Context , userAuth auth .UserAuth ) (string , error ) {
15941595 userAccountID , err := am .Store .GetAccountIDByUserID (ctx , store .LockingStrengthNone , userAuth .UserId )
15951596 if err != nil {
15961597 log .WithContext (ctx ).Errorf ("error getting account ID by user ID: %v" , err )
@@ -1638,7 +1639,7 @@ func handleNotFound(err error) error {
16381639 return nil
16391640}
16401641
1641- func domainIsUpToDate (domain string , domainCategory string , userAuth nbcontext .UserAuth ) bool {
1642+ func domainIsUpToDate (domain string , domainCategory string , userAuth auth .UserAuth ) bool {
16421643 return domainCategory == types .PrivateCategory || userAuth .DomainCategory != types .PrivateCategory || domain != userAuth .Domain
16431644}
16441645
0 commit comments