endpoint for status of the user - #162
Conversation
| {Name: "/sign-multiple-transactions", Open: true}, | ||
| {Name: "/set-security-mode", Open: true}, | ||
| {Name: "/unset-security-mode", Open: true}, | ||
| {Name: "/security-status", Open: true}, |
There was a problem hiding this comment.
as this can be extended in the future, perhaps we rename it to something more generic like user-status
| logUserStatusRequest(userIp, userAgent, &request, debugErr) | ||
| }() | ||
|
|
||
| err := json.NewDecoder(c.Request.Body).Decode(&request) |
There was a problem hiding this comment.
I don't think request body and UserStatusRequest is needed here.. perhaps it can be something similar to node's /address/:address endpoint instead (/guardian/user-status/erd1....)
| { Name = "/sign-multiple-transactions", Open = true, Auth = false, MaxContentLength = 1500000 }, | ||
| { Name = "/set-security-mode", Open = true, Auth = false, MaxContentLength = 200 }, | ||
| { Name = "/unset-security-mode", Open = true, Auth = false, MaxContentLength = 200 }, | ||
| { Name = "/security-status", Open = true, Auth = false, MaxContentLength = 200 }, |
There was a problem hiding this comment.
MaxContentLength not needed, it does not apply for get requests
| // NoExpiryValue is the returned value for a persistent key expiry time | ||
| const NoExpiryValue = -1 | ||
|
|
||
| type Status int |
There was a problem hiding this comment.
missing comments on new fields
| UserAddr string `json:"user"` | ||
| } | ||
|
|
||
| // UserStatusResponse - is the JSON response for the user status interrogation |
There was a problem hiding this comment.
| // UserStatusResponse - is the JSON response for the user status interrogation | |
| // UserStatusResponse is the JSON response for the user status request |
| return resolver.verifyCodesReturningGuardian(userAddress, txs[0].GuardianAddr, userIp, code, secondCode) | ||
| } | ||
|
|
||
| func (resolver *serviceResolver) verifyUserReturningSecurityStatus(userAddr string) (core.Status, error) { |
There was a problem hiding this comment.
| func (resolver *serviceResolver) verifyUserReturningSecurityStatus(userAddr string) (core.Status, error) { | |
| func (resolver *serviceResolver) getUserStatus(userAddr string) (core.Status, error) { |
no verification done here
| func (resolver *serviceResolver) verifyUserReturningSecurityStatus(userAddr string) (core.Status, error) { | ||
| userAddress, err := sdkData.NewAddressFromBech32String(userAddr) | ||
| if err != nil { | ||
| return 0, err |
There was a problem hiding this comment.
| return 0, err | |
| return core.NotSet, err |
| addressBytes := userAddress.AddressBytes() | ||
| resolver.userCritSection.RLock(string(addressBytes)) | ||
| _, err = resolver.getUserInfo(addressBytes) | ||
| resolver.userCritSection.RUnlock(string(addressBytes)) | ||
| if err != nil { | ||
| return -1, err | ||
| } |
There was a problem hiding this comment.
I think this can be removed 🤔
| if r.GetSecurityStatusCalled != nil { | ||
| return r.GetSecurityStatusCalled(key) | ||
| } | ||
| return -1 |
There was a problem hiding this comment.
| return -1 | |
| return core.NotSet |
|
|
||
| // GetSecurityStatus - | ||
| func (r *RateLimiterMock) GetSecurityStatus(key string) core.Status { | ||
| return 0 |
There was a problem hiding this comment.
| return 0 | |
| return core.NotSet |
| signMultipleTransactionsPath = "/sign-multiple-transactions" | ||
| setSecurityModeNoExpirePath = "/set-security-mode" | ||
| unsetSecurityModeNoExpirePath = "/unset-security-mode" | ||
| getSecurityStatus = "/security-status" |
There was a problem hiding this comment.
rename to getSecurityStatusPath?
| type Status int | ||
|
|
||
| const ( | ||
| NotSet Status = iota | ||
| ManualSet | ||
| AutomaticallySet |
There was a problem hiding this comment.
are these changes needed? did you run go mod tidy?
| return totp.rateLimiter.UnsetSecurityModeNoExpire(key) | ||
| } | ||
|
|
||
| // GetSecurityStatus - returns the status of the security mode |
There was a problem hiding this comment.
| // GetSecurityStatus - returns the status of the security mode | |
| // GetSecurityStatus returns the status of the security mode |
?
| _, err = resolver.getUserInfo(addressBytes) | ||
| resolver.userCritSection.RUnlock(string(addressBytes)) | ||
| if err != nil { | ||
| return -1, err |
There was a problem hiding this comment.
set it as a error value, not needed it anymore
There was a problem hiding this comment.
no, all those lines are removed now.
|
|
||
| // swagger:route GET /security-status Guardian getSecurityStatus | ||
| // Returns the security status. | ||
| // swagger:route GET /user-status Guardian getSecurityStatus |
There was a problem hiding this comment.
| // swagger:route GET /user-status Guardian getSecurityStatus | |
| // swagger:route GET /user-status Guardian getUserStatus |
| // swagger:route GET /security-status Guardian getSecurityStatus | ||
| // Returns the security status. | ||
| // swagger:route GET /user-status Guardian getSecurityStatus | ||
| // Returns the security status of the user. |
There was a problem hiding this comment.
| // Returns the security status of the user. | |
| // Returns the status of the user. |
|
|
||
| facade := mockFacade.GuardianFacadeStub{ | ||
| GetSecurityStatusCalled: func(request requests.UserStatusRequest) (*requests.UserStatusResponse, error) { | ||
| GetSecurityStatusCalled: func(userAddress string) (*requests.UserStatusResponse, error) { |
There was a problem hiding this comment.
rename this as well to GetUserStatusCalled
| if trials < maxFailures && expTime != core.NoExpiryValue { | ||
| trials, err := strconv.ParseInt(dbVal, 10, 64) | ||
| if err != nil { | ||
| log.Debug("error when returning security status", "err", err) |
There was a problem hiding this comment.
| log.Debug("error when returning security status", "err", err) | |
| log.Debug("error when converting security status", "err", err) |
| // GetSecurityStatus gets the user's security status | ||
| func (resolver *serviceResolver) GetSecurityStatus(request requests.UserStatusRequest) (*requests.UserStatusResponse, error) { | ||
| status, err := resolver.verifyUserReturningSecurityStatus(request.UserAddr) | ||
| // GetUserStatus gets the user's security status |
There was a problem hiding this comment.
| // GetUserStatus gets the user's security status | |
| // GetUserStatus gets the user's status |
| SetSecurityModeNoExpireCalled func(userIp string, request requests.SecurityModeNoExpire) (*requests.OTPCodeVerifyData, error) | ||
| UnsetSecurityModeNoExpireCalled func(userIp string, request requests.SecurityModeNoExpire) (*requests.OTPCodeVerifyData, error) | ||
| GetSecurityStatusCalled func(request requests.UserStatusRequest) (*requests.UserStatusResponse, error) | ||
| GetSecurityStatusCalled func(userAddress string) (*requests.UserStatusResponse, error) |
There was a problem hiding this comment.
| GetSecurityStatusCalled func(userAddress string) (*requests.UserStatusResponse, error) | |
| GetUserStatusCalled func(userAddress string) (*requests.UserStatusResponse, error) |
There was a problem hiding this comment.
i think we need to also generate swagger files based on these changes
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
remove these empty lines?
| } | ||
| }, | ||
| "userStatusResponse": { | ||
| "description": "The status of the operation", |
There was a problem hiding this comment.
status of which operation?
this should be the address/user status on the TCS
| const NoExpiryValue = -1 | ||
|
|
||
| // Status represents the status of the security mode | ||
| type Status int |
There was a problem hiding this comment.
I think this is too generic, especially when used for the security mode
maybe EnhancedSecurityModeStatus
|
|
||
| // UserStatusResponse is the JSON response for the user status interrogation | ||
| type UserStatusResponse struct { | ||
| SecurityStatus int `json:"status"` |
There was a problem hiding this comment.
Maybe rename to SecurityModeStatus? or EnhancedSecurityModeStatus?
SecurityStatus = NotSet doesn't sound good, as the account has protection via regular 2FA
| _, err = resolver.getUserInfo(addressBytes) | ||
| resolver.userCritSection.RUnlock(string(addressBytes)) | ||
| if err != nil { | ||
| return -1, err |
The base branch was changed.
No description provided.