MCPcopy Create free account
hub / github.com/PasarGuard/node / SyncUser

Method SyncUser

backend/xray/user.go:120–156  ·  view source on GitHub ↗
(ctx context.Context, user *common.User)

Source from the content-addressed store, hash-verified

118}
119
120func (x *Xray) SyncUser(ctx context.Context, user *common.User) error {
121 proxySetting, err := setupUserAccount(user)
122 if err != nil {
123 return err
124 }
125
126 handler := x.handler
127 inbounds := x.config.InboundConfigs
128
129 var errMessage string
130
131 userInbounds := user.GetInbounds()
132
133 for _, inbound := range inbounds {
134 if inbound.exclude {
135 continue
136 }
137
138 _ = handler.RemoveInboundUser(ctx, inbound.Tag, user.Email)
139 account, isActive := isActiveInbound(inbound, userInbounds, proxySetting)
140 if isActive {
141 inbound.updateUser(account)
142 err = handler.AddInboundUser(ctx, inbound.Tag, accountForAPI(inbound, account))
143 if err != nil {
144 log.Println(err)
145 errMessage += "\n" + err.Error()
146 }
147 } else {
148 inbound.removeUser(user.GetEmail())
149 }
150 }
151
152 if errMessage != "" {
153 return errors.New("failed to add user:" + errMessage)
154 }
155 return nil
156}
157
158func (x *Xray) SyncUsers(ctx context.Context, users []*common.User) error {
159 x.config.syncUsers(users)

Callers

nothing calls this directly

Calls 10

setupUserAccountFunction · 0.85
isActiveInboundFunction · 0.85
accountForAPIFunction · 0.85
GetInboundsMethod · 0.80
RemoveInboundUserMethod · 0.80
updateUserMethod · 0.80
AddInboundUserMethod · 0.80
ErrorMethod · 0.80
removeUserMethod · 0.80
GetEmailMethod · 0.65

Tested by

no test coverage detected