Refactor internal API calls to use centralized HTTP client for applying API Auth in common#2251
Merged
cb-github-robot merged 1 commit intocloud-barista:mainfrom Jan 2, 2026
Merged
Conversation
Signed-off-by: Seokho Son <shsongist@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR centralizes HTTP client creation and authentication for internal API calls to improve maintainability and consistency across CB-Tumblebug. The refactoring introduces clientManager.NewHttpClient() to apply Basic Auth uniformly to all internal subsystem communications (CB-Spider and Terrarium).
Key Changes:
- Introduced global API credentials (
model.APIUsername,model.APIPassword) initialized from environment variables - Created centralized HTTP client functions (
NewHttpClient(),NewHttpClientBasic()) in the client manager - Applied Basic Auth to CB-Spider API calls, consistent with Terrarium API calls
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/main.go | Initializes global API credentials from environment variables |
| src/core/model/common.go | Adds global variables and constants for API username/password |
| src/core/common/client/client.go | Implements NewHttpClient() with Basic Auth and NewHttpClientBasic() for non-authenticated clients |
| src/core/common/config.go | Adds config initialization and update logic for API credentials |
| src/interface/rest/server/middlewares/checkReadiness.go | Updates to use centralized HTTP client |
| src/interface/rest/server/middlewares/authmw/authmw.go | Uses NewHttpClientBasic() for IAM manager calls |
| src/core/resource/*.go | Refactors 10+ resource files to use centralized HTTP client and ExecuteHttpRequest() |
| src/core/infra/*.go | Refactors 5 infra files to use centralized HTTP client |
| src/core/common/utility.go | Partially refactored - uses NewHttpClient() but retains old request pattern in one location |
| src/core/common/label/label.go | Updates label operations to use centralized HTTP client |
| docker-compose.yaml | Enables TB_API_USERNAME/PASSWORD for both Tumblebug and Spider services |
Comments suppressed due to low confidence (1)
src/core/common/utility.go:1189
- The refactoring is incomplete here. While the client has been updated to use
clientManager.NewHttpClient(), the function still uses the old resty request pattern withclient.R()instead of usingclientManager.ExecuteHttpRequest(). This is inconsistent with the refactoring pattern used throughout the rest of the codebase. Consider refactoring this function to useExecuteHttpRequest()for consistency with other API calls in the codebase.
client := clientManager.NewHttpClient()
resp, err := client.R().
SetResult(&model.RetrievedRegionList{}).
//SetError(&SimpleMsg{}).
Get(url)
if err != nil {
log.Error().Err(err).Msg("")
content := model.RetrievedRegionList{}
err := fmt.Errorf("an error occurred while requesting to CB-Spider")
return content, err
}
switch {
case resp.StatusCode() >= 400 || resp.StatusCode() < 200:
err := fmt.Errorf(string(resp.Body()))
log.Error().Err(err).Msg("")
content := model.RetrievedRegionList{}
return content, err
}
temp, _ := resp.Result().(*model.RetrievedRegionList)
return *temp, nil
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
Author
|
/approve |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Refactor internal API calls to use centralized HTTP client
Summary
Refactored all internal API call patterns to use common functions
clientManager.NewHttpClient()andclientManager.ExecuteHttpRequest()for better maintainability and consistency.Changes
clientManager.NewHttpClient()instead of directly callingresty.New()os.Getenv()calls for credentials by using global variables (model.APIUsername,model.APIPassword)Assumptions
Benefits