Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,19 @@ function clean() {
## generate - Generates all required files, before building
function generate() {
get_protoc

pbFile="internal/mdx/metadata_exchange.pb.go"
# Delete the old MDX pb file
rm "$pbFile"

PATH="${SCRIPT_DIR}/.tools/protoc/bin:$PATH" "${SCRIPT_DIR}/.tools/protoc/bin/protoc" \
--proto_path=. \
--go_out=. \
--go_opt=default_api_level=API_OPAQUE \
internal/mdx/metadata_exchange.proto \
--go_opt=paths=source_relative

# Add the copyright header to the generated protobuf file
pbFile="internal/mdx/metadata_exchange.pb.go"
mv "${pbFile}" "${pbFile}.tmp"
cat > "${pbFile}" <<EOF
// Copyright 2025 Google LLC
Expand Down
2 changes: 1 addition & 1 deletion dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -835,5 +835,5 @@ func newMDXRequest(ci cloudsql.ConnectionInfo, cfg dialConfig, metadataExchangeD
return nil
}

return &mdx.MetadataExchangeRequest{ClientProtocolType: &cpt}
return mdx.MetadataExchangeRequest_builder{ClientProtocolType: &cpt}.Build()
}
6 changes: 3 additions & 3 deletions dialer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1752,7 +1752,7 @@ func TestNewMDXRequest(t *testing.T) {
cfg: dialConfig{
mdxClientProtocolType: cloudsql.ClientProtocolTCP,
},
want: &mdx.MetadataExchangeRequest{ClientProtocolType: &tcp},
want: mdx.MetadataExchangeRequest_builder{ClientProtocolType: &tcp}.Build(),
},
{
desc: "when client protocol is CLIENT_PROTOCOL_UDS",
Expand All @@ -1762,7 +1762,7 @@ func TestNewMDXRequest(t *testing.T) {
cfg: dialConfig{
mdxClientProtocolType: cloudsql.ClientProtocolUDS,
},
want: &mdx.MetadataExchangeRequest{ClientProtocolType: &uds},
want: mdx.MetadataExchangeRequest_builder{ClientProtocolType: &uds}.Build(),
},
{
desc: "when client protocol is CLIENT_PROTOCOL_TLS",
Expand All @@ -1772,7 +1772,7 @@ func TestNewMDXRequest(t *testing.T) {
cfg: dialConfig{
mdxClientProtocolType: cloudsql.ClientProtocolTLS,
},
want: &mdx.MetadataExchangeRequest{ClientProtocolType: &tlsRes},
want: mdx.MetadataExchangeRequest_builder{ClientProtocolType: &tlsRes}.Build(),
},
}

Expand Down
10 changes: 3 additions & 7 deletions internal/cloudsql/metadataexchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,23 +196,19 @@ func (c *MDXConn) readMDX() (*mdx.MetadataExchangeResponse, error) {

// IsResponseOk returns true if a response was received and ResponseStatusCode == OK.
func (c *MDXConn) IsResponseOk() bool {
return c.res.ResponseStatusCode != nil &&
*c.res.ResponseStatusCode == mdx.MetadataExchangeResponse_OK
return c.res.GetResponseStatusCode() == mdx.MetadataExchangeResponse_OK
}

// GetErrorMessage returns the ErrorMessage in the MDX Response.
func (c *MDXConn) GetErrorMessage() string {
if c.res.ErrorMessage != nil {
return *c.res.ErrorMessage
}
return ""
return c.res.GetErrorMessage()
}

// writeMDX writes the MDX response back to the socket.
func (c *MDXConn) writeMDX(req *mdx.MetadataExchangeRequest) error {
// ctx only used for debug logging
ctx := context.Background()
c.logger.Debugf(ctx, "[%v] Writing MDX request, protocol:%v...", c.cn, req.ClientProtocolType)
c.logger.Debugf(ctx, "[%v] Writing MDX request, protocol:%v...", c.cn, req.GetClientProtocolType())

buf := buffPool.get()
defer buffPool.put(buf)
Expand Down
16 changes: 9 additions & 7 deletions internal/cloudsql/metadataexchange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ func newFakeConn(bytesToRead []byte) *fakeConn {
}

func newMDXResponseBytes(data []byte) (*mdx.MetadataExchangeResponse, []byte) {
res := &mdx.MetadataExchangeResponse{
res := mdx.MetadataExchangeResponse_builder{
ResponseStatusCode: ptr(mdx.MetadataExchangeResponse_OK),
}
}.Build()
resBytes, err := proto.Marshal(res)
if err != nil {
panic(err)
Expand All @@ -82,7 +82,9 @@ func newMDXResponseBytes(data []byte) (*mdx.MetadataExchangeResponse, []byte) {
}

func newMDXRequestBytes(data []byte) (*mdx.MetadataExchangeRequest, []byte) {
req := &mdx.MetadataExchangeRequest{UserAgent: proto.String("hello")}
req := mdx.MetadataExchangeRequest_builder{
UserAgent: proto.String("hello"),
}.Build()
resBytes, err := proto.Marshal(req)
if err != nil {
panic(err)
Expand Down Expand Up @@ -195,9 +197,9 @@ func TestMDXConn_Request_Response_WriteRead(t *testing.T) {
if !mdxConn.HasMDXResponse() {
t.Fatalf("expected no MDX response, got response")
}
if *mdxConn.GetMDXResponse().ResponseStatusCode != *res.ResponseStatusCode {
if mdxConn.GetMDXResponse().GetResponseStatusCode() != res.GetResponseStatusCode() {
t.Fatalf("expected status code %v, got %v",
res.ResponseStatusCode, mdxConn.GetMDXResponse().ResponseStatusCode)
res.GetResponseStatusCode(), mdxConn.GetMDXResponse().GetResponseStatusCode())
}
}

Expand All @@ -216,9 +218,9 @@ func TestMDXConn_Request_Response_ReadWrite(t *testing.T) {
if !mdxConn.HasMDXResponse() {
t.Fatalf("expected no MDX response, got response")
}
if *mdxConn.GetMDXResponse().ResponseStatusCode != *res.ResponseStatusCode {
if mdxConn.GetMDXResponse().GetResponseStatusCode() != res.GetResponseStatusCode() {
t.Fatalf("expected status code %v, got %v",
res.ResponseStatusCode, mdxConn.GetMDXResponse().ResponseStatusCode)
res.GetResponseStatusCode(), mdxConn.GetMDXResponse().GetResponseStatusCode())
}
}

Expand Down
Loading
Loading