From 7c8225dd85e13e8a026abc563f8a44a3fb54f0fb Mon Sep 17 00:00:00 2001 From: "Giau. Tran Minh" Date: Tue, 28 Oct 2025 13:02:01 +0700 Subject: [PATCH 1/2] mysql/awsmysql: allow inject HTTP client --- mysql/awsmysql/awsmysql.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mysql/awsmysql/awsmysql.go b/mysql/awsmysql/awsmysql.go index 619ee8757..939f26c8f 100644 --- a/mysql/awsmysql/awsmysql.go +++ b/mysql/awsmysql/awsmysql.go @@ -32,6 +32,7 @@ import ( "database/sql" "database/sql/driver" "fmt" + "net/http" "net/url" "sync/atomic" @@ -50,7 +51,7 @@ import ( // Set is a Wire provider set that provides a *sql.DB given // *Params and an HTTP client. var Set = wire.NewSet( - wire.Struct(new(URLOpener), "CertSource"), + wire.Struct(new(URLOpener), "CertSource", "HTTPClient"), rds.CertFetcherSet, ) @@ -66,6 +67,9 @@ var Set = wire.NewSet( // - aws_profile: the AWS shared config profile to use // - aws_role_arn: the ARN of the role to assume type URLOpener struct { + // HTTPClient is the HTTP client used to fetch RDS certificates. + // and IAM authentication tokens. + HTTPClient *http.Client // CertSource specifies how the opener will obtain the RDS Certificate // Authority. If nil, it will use the default *rds.CertFetcher. CertSource rds.CertPoolProvider @@ -85,7 +89,7 @@ func init() { func (uo *URLOpener) OpenMySQLURL(ctx context.Context, u *url.URL) (*sql.DB, error) { source := uo.CertSource if source == nil { - source = new(rds.CertFetcher) + source = &rds.CertFetcher{Client: uo.HTTPClient} } if u.Host == "" { return nil, fmt.Errorf("open OpenMySQLURL: empty endpoint") @@ -100,6 +104,7 @@ func (uo *URLOpener) OpenMySQLURL(ctx context.Context, u *url.URL) (*sql.DB, err ) q.Del("aws_profile") cfg, err := config.LoadDefaultConfig(ctx, + config.WithHTTPClient(uo.HTTPClient), // Ignored if nil. config.WithSharedConfigProfile(profile)) // Ignored if empty. if err != nil { return nil, fmt.Errorf("open OpenMySQLURL: load AWS config: %v", err) From 3f6c4fe4e9775c7e4e92156915b7b97da5fa27b9 Mon Sep 17 00:00:00 2001 From: "Giau. Tran Minh" <12751435+giautm@users.noreply.github.com> Date: Tue, 28 Oct 2025 13:07:08 +0700 Subject: [PATCH 2/2] Apply suggestion from @giautm --- mysql/awsmysql/awsmysql.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql/awsmysql/awsmysql.go b/mysql/awsmysql/awsmysql.go index 939f26c8f..fa08050e9 100644 --- a/mysql/awsmysql/awsmysql.go +++ b/mysql/awsmysql/awsmysql.go @@ -67,7 +67,7 @@ var Set = wire.NewSet( // - aws_profile: the AWS shared config profile to use // - aws_role_arn: the ARN of the role to assume type URLOpener struct { - // HTTPClient is the HTTP client used to fetch RDS certificates. + // HTTPClient is the HTTP client used to fetch RDS certificates, // and IAM authentication tokens. HTTPClient *http.Client // CertSource specifies how the opener will obtain the RDS Certificate