Skip to content

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
seokho-son:main
Jan 2, 2026
Merged

Refactor internal API calls to use centralized HTTP client for applying API Auth in common#2251
cb-github-robot merged 1 commit intocloud-barista:mainfrom
seokho-son:main

Conversation

@seokho-son
Copy link
Copy Markdown
Member

Refactor internal API calls to use centralized HTTP client

Summary

Refactored all internal API call patterns to use common functions clientManager.NewHttpClient() and clientManager.ExecuteHttpRequest() for better maintainability and consistency.

Changes

  • Centralized HTTP client creation: All internal API calls now use clientManager.NewHttpClient() instead of directly calling resty.New()
  • Unified Basic Auth handling: Removed repeated os.Getenv() calls for credentials by using global variables (model.APIUsername, model.APIPassword)
  • Applied Basic Auth to CB-Spider API calls: Spider API calls now use Basic Auth by default, consistent with Terrarium API calls
  • Reduced code duplication: Eliminated redundant client initialization patterns across multiple files

Assumptions

  • Internal subsystems (CB-Spider, Terrarium) use Basic Auth with the same credentials as CB-Tumblebug API
  • These subsystems are initiated/managed by Tumblebug within a trusted network (Docker network)

Benefits

  • Reduced maintenance overhead by centralizing HTTP client configuration
  • Improved consistency across all internal API calls
  • Easier to update authentication logic in one place
  • Suppressed unnecessary security warnings for internal HTTP communication

Signed-off-by: Seokho Son <shsongist@gmail.com>
Copilot AI review requested due to automatic review settings January 2, 2026 18:58
@seokho-son seokho-son requested a review from yunkon-kim as a code owner January 2, 2026 18:58
@github-actions github-actions bot added the src label Jan 2, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 with client.R() instead of using clientManager.ExecuteHttpRequest(). This is inconsistent with the refactoring pattern used throughout the rest of the codebase. Consider refactoring this function to use ExecuteHttpRequest() 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.

@seokho-son
Copy link
Copy Markdown
Member Author

/approve

@github-actions github-actions bot added the approved This PR is approved and will be merged soon. label Jan 2, 2026
@cb-github-robot cb-github-robot merged commit 78e9672 into cloud-barista:main Jan 2, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved This PR is approved and will be merged soon. src

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants