Skip to content

Commit ccd25ba

Browse files
committed
chore: Simplify logic in v1 command handler.
1 parent c0188c0 commit ccd25ba

3 files changed

Lines changed: 12 additions & 22 deletions

File tree

cmd/cloud_sql_proxy/cloud_sql_proxy.go

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,6 @@ type TranslationResult struct {
764764
V2Args []string
765765
LogDebugStdout bool
766766
Verbose bool
767-
Unsupported []string
768767
LegacySet bool
769768
V2Compat bool
770769
V2Mode bool
@@ -804,18 +803,14 @@ func main() {
804803
}
805804

806805
// Translation failed
807-
if tr.V2Compat && len(tr.Unsupported) > 0 {
808-
fmt.Fprintf(os.Stderr, "Error: -v2-compat flag is set, but the following flags are not supported in v2 compatibility mode: %s\n", strings.Join(tr.Unsupported, ", "))
806+
if tr.V2Compat {
807+
fmt.Fprintln(os.Stderr, "Error: -v2-compat flag is set, but translation to v2 failed.")
809808
os.Exit(1)
810809
}
811810

812811
fmt.Fprintln(os.Stderr, "This proxy is using Auth Proxy v1 legacy mode.")
813812
if tr.LegacySet {
814813
fmt.Fprintln(os.Stderr, "This proxy is using Auth Proxy v1 legacy mode because the -legacy-v1-proxy flag is set")
815-
} else if len(tr.Unsupported) > 0 {
816-
fmt.Fprintln(os.Stderr, "This proxy is using Auth Proxy v1 legacy mode because it is using")
817-
fmt.Fprintln(os.Stderr, "flags that are not supported in v2 compatibility mode:")
818-
fmt.Fprintln(os.Stderr, strings.Join(tr.Unsupported, ", "))
819814
}
820815

821816
code := runProxy()
@@ -901,17 +896,6 @@ func translateV2Args() TranslationResult {
901896
return tr
902897
}
903898

904-
// Check for unsupported flags being set
905-
fs.Visit(func(f *flag.Flag) {
906-
switch f.Name {
907-
case "check_region":
908-
tr.Unsupported = append(tr.Unsupported, "-"+f.Name)
909-
}
910-
})
911-
if len(tr.Unsupported) > 0 {
912-
return tr
913-
}
914-
915899
fs.Visit(func(f *flag.Flag) {
916900
switch f.Name {
917901
case "projects":
@@ -996,7 +980,6 @@ func translateV2Args() TranslationResult {
996980
hasPrivate = true
997981
default:
998982
// Unknown type, fallback to v1
999-
tr.Unsupported = append(tr.Unsupported, "-ip_address_types="+*ipAddressTypes)
1000983
return tr
1001984
}
1002985
}

cmd/cloud_sql_proxy/translation_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,11 @@ func TestTranslateV2Args(t *testing.T) {
124124
wantOk: true,
125125
},
126126
{
127-
name: "unsupported flag check_region",
128-
args: []string{"cloud_sql_proxy", "-check_region", "-instances=i1"},
129-
wantOk: false,
127+
name: "ignored flag check_region",
128+
args: []string{"cloud_sql_proxy", "-check_region", "-instances=i1"},
129+
wantArgs: []string{"--auto-ip", "i1"},
130+
wantVerbose: true,
131+
wantOk: true,
130132
},
131133
{
132134
name: "fuse mode",

translatev2/translatev2_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ func TestModeComparison(t *testing.T) {
132132
args: []string{"-projects=my-project"},
133133
v2Expected: true,
134134
},
135+
{
136+
name: "check_region flag stays in v2",
137+
args: []string{"-check_region", "-instances=p:r:i"},
138+
v2Expected: true,
139+
},
135140
}
136141

137142
for _, tt := range tests {

0 commit comments

Comments
 (0)