-
Notifications
You must be signed in to change notification settings - Fork 605
feat: implement authentication response logging #235
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
aee8e50
feat(auth): add response logging and centralize path constants
JackZhao10086 0f95cbe
refactor(auth): improve response logging and error handling
JackZhao10086 581d6e1
fix(auth): ensure log cleanup runs only once per process
JackZhao10086 e7bd87a
refactor(auth): simplify log writer and cleanup logic
JackZhao10086 207eef4
docs(auth): add comments to auth paths and logging functions
JackZhao10086 36d7589
style(auth): fix indentation in path constants
JackZhao10086 e22e3f3
docs(auth): add missing function comments across auth package
JackZhao10086 771be63
docs(tests): add descriptive comments to auth test functions
JackZhao10086 4d2d38a
test(auth): rename test case and cleanup unused params
JackZhao10086 ce0760a
fix(auth): handle file close error in auth response logging
JackZhao10086 bc55626
fix(auth): ensure log cleanup runs only once
JackZhao10086 5f4276c
refactor(auth): replace custom log writer with standard logger
JackZhao10086 32b6ede
feat(auth): add structured logging for keychain errors
JackZhao10086 ba689fd
fix(auth): remove goroutine from auth log cleanup to prevent race con…
JackZhao10086 d7651b8
fix(auth): remove goroutine from auth log cleanup to prevent race con…
JackZhao10086 4be0565
refactor(auth): move auth logging logic to keychain package
JackZhao10086 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package auth | ||
|
|
||
| import ( | ||
| "net/http" | ||
|
|
||
| "github.com/larksuite/cli/internal/keychain" | ||
| larkcore "github.com/larksuite/oapi-sdk-go/v3/core" | ||
| ) | ||
|
|
||
| // logHTTPResponse logs the HTTP response details for an authentication request. | ||
| // It extracts the request path, status code, and x-tt-logid from the given HTTP response. | ||
| func logHTTPResponse(resp *http.Response) { | ||
| if resp == nil { | ||
| return | ||
| } | ||
|
|
||
| path := "missing" | ||
| if resp.Request != nil && resp.Request.URL != nil { | ||
| path = resp.Request.URL.Path | ||
| } | ||
|
|
||
| keychain.LogAuthResponse(path, resp.StatusCode, resp.Header.Get("x-tt-logid")) | ||
| } | ||
|
|
||
| // logSDKResponse logs the SDK response details for an authentication request. | ||
| // It extracts the status code and x-tt-logid from the given API response object. | ||
| func logSDKResponse(path string, apiResp *larkcore.ApiResp) { | ||
| if path == "" { | ||
| path = "missing" | ||
| } | ||
|
|
||
| if apiResp == nil { | ||
| keychain.LogAuthResponse(path, 0, "") | ||
| return | ||
| } | ||
|
|
||
| keychain.LogAuthResponse(path, apiResp.StatusCode, apiResp.Header.Get("x-tt-logid")) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // Copyright (c) 2026 Lark Technologies Pte. Ltd. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package auth | ||
|
|
||
| // Common authentication paths used for logging and API calls. | ||
| const ( | ||
| // PathDeviceAuthorization is the endpoint for device authorization. | ||
| PathDeviceAuthorization = "/oauth/v1/device_authorization" | ||
| // PathAppRegistration is the endpoint for application registration. | ||
| PathAppRegistration = "/oauth/v1/app/registration" | ||
| // PathOAuthTokenV2 is the endpoint for requesting an OAuth token (v2). | ||
| PathOAuthTokenV2 = "/open-apis/authen/v2/oauth/token" | ||
| // PathUserInfoV1 is the endpoint for fetching user information. | ||
| PathUserInfoV1 = "/open-apis/authen/v1/user_info" | ||
| // PathApplicationInfoV6Prefix is the prefix endpoint for fetching application info. | ||
| PathApplicationInfoV6Prefix = "/open-apis/application/v6/applications/" | ||
| ) | ||
|
|
||
| // ApplicationInfoPath returns the full API path for querying an application's information. | ||
| func ApplicationInfoPath(appId string) string { | ||
| return PathApplicationInfoV6Prefix + appId | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.