Skip to content

Commit 033929c

Browse files
authored
Merge pull request #162 from ovh/flags
fix: safe wrappers for MarkFlagsMutuallyExclusive to prevent WASM panics
2 parents cc6e2d6 + da1db9c commit 033929c

21 files changed

+99
-64
lines changed

.goreleaser.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ builds:
1818
binary: ovhcloud
1919
env:
2020
- CGO_ENABLED=0
21+
flags:
22+
- -trimpath
2123
ldflags:
2224
- -s -w -extldflags -static -X github.com/ovh/ovhcloud-cli/internal/version.Version={{.Tag}}
2325
goos:
@@ -30,6 +32,8 @@ builds:
3032
binary: ovhcloud
3133
env:
3234
- CGO_ENABLED=0
35+
flags:
36+
- -trimpath
3337
ldflags:
3438
- -s -w -extldflags -static -X github.com/ovh/ovhcloud-cli/internal/version.Version={{.Tag}}
3539
goos:
@@ -79,4 +83,4 @@ homebrew_casks:
7983
directory: Casks
8084
caveats: "See https://github.com/ovh/ovhcloud-cli for usage."
8185
homepage: "https://github.com/ovh/ovhcloud-cli"
82-
description: "OVHcloud CLI - Command line interface for OVHcloud."
86+
description: "OVHcloud CLI - Command line interface for OVHcloud."

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ BUILD_CMD = CGO_ENABLED=0 go build
99
all: build
1010

1111
build:
12-
${BUILD_CMD} -ldflags "${LD_FLAGS}" -o ovhcloud ./cmd/ovhcloud
12+
${BUILD_CMD} -trimpath -ldflags "${LD_FLAGS}" -o ovhcloud ./cmd/ovhcloud
1313

1414
wasm:
15-
GOOS=js GOARCH=wasm ${BUILD_CMD} -ldflags "${LD_FLAGS}" -o ovhcloud.wasm ./cmd/ovhcloud
15+
GOOS=js GOARCH=wasm ${BUILD_CMD} -trimpath -ldflags "${LD_FLAGS}" -o ovhcloud.wasm ./cmd/ovhcloud
1616

1717
test:
1818
go test -v ./...

internal/cmd/account.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func init() {
8080
oauth2CreateCmd.Flags().StringVar(&account.Oauth2ClientSpec.Name, "name", "", "Name of the OAuth2 client")
8181
addParameterFileFlags(oauth2CreateCmd, false, assets.MeOpenapiSchema, "/me/api/oauth2/client", "post", account.Oauth2ClientCreateSample, nil)
8282
addInteractiveEditorFlag(oauth2CreateCmd)
83-
oauth2CreateCmd.MarkFlagsMutuallyExclusive("from-file", "editor")
83+
markFlagsMutuallyExclusive(oauth2CreateCmd, "from-file", "editor")
8484

8585
oauth2ClientCmd.AddCommand(oauth2CreateCmd)
8686

internal/cmd/baremetal.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ Please note that all parameters are not compatible with all OSes.
148148
reinstallBaremetalCmd.Flags().StringVar(&baremetal.Customizations.PostInstallationScriptExtension, "post-installation-script-extension", "", "Post-installation script extension (cmd, ps1)")
149149
reinstallBaremetalCmd.Flags().StringVar(&baremetal.Customizations.SshKey, "ssh-key", "", "SSH public key")
150150
reinstallBaremetalCmd.Flags().BoolVar(&flags.WaitForTask, "wait", false, "Wait for reinstall to be done before exiting")
151-
reinstallBaremetalCmd.MarkFlagsMutuallyExclusive("from-file", "editor")
151+
markFlagsMutuallyExclusive(reinstallBaremetalCmd, "from-file", "editor")
152152
baremetalCmd.AddCommand(reinstallBaremetalCmd)
153153

154154
// List boots and their options
@@ -180,8 +180,8 @@ Please note that all parameters are not compatible with all OSes.
180180
baremetalBootSetScriptCmd.Flags().StringVar(&baremetal.EditBaremetalParams.BootScript, "script", "", "Boot script to set on the baremetal")
181181
addInteractiveEditorFlag(baremetalBootSetScriptCmd)
182182
addParameterFileFlags(baremetalBootSetScriptCmd, true, nil, "", "", "", nil)
183-
baremetalBootSetScriptCmd.MarkFlagsOneRequired("script", "from-file", "editor")
184-
baremetalBootSetScriptCmd.MarkFlagsMutuallyExclusive("script", "from-file", "editor")
183+
markFlagsOneRequired(baremetalBootSetScriptCmd, "script", "from-file", "editor")
184+
markFlagsMutuallyExclusive(baremetalBootSetScriptCmd, "script", "from-file", "editor")
185185
baremetalBootCmd.AddCommand(baremetalBootSetScriptCmd)
186186

187187
baremetalListInterventionsCmd := &cobra.Command{

internal/cmd/cloud_alerting.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func initCloudAlertingCommand(cloudCmd *cobra.Command) {
4747
alertingCreateCmd.Flags().StringVar(&cloud.AlertingConfigSpec.Service, "service", "", "Service of the alert. Allowed: ai_endpoint, all, block_storage, data_platform, instances, instances_gpu, instances_without_gpu, objet_storage, rancher, snapshot")
4848
addParameterFileFlags(alertingCreateCmd, false, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/alerting", "post", cloud.AlertingConfigCreateExample, nil)
4949
addInteractiveEditorFlag(alertingCreateCmd)
50-
alertingCreateCmd.MarkFlagsMutuallyExclusive("from-file", "editor")
50+
markFlagsMutuallyExclusive(alertingCreateCmd, "from-file", "editor")
5151
alertingCmd.AddCommand(alertingCreateCmd)
5252

5353
// Edit alerting configuration

internal/cmd/cloud_container_registry.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func initContainerRegistryCommand(cloudCmd *cobra.Command) {
5252
createCmd.Flags().StringVar(&cloud.CloudContainerRegistrySpec.Region, "region", "", "Region for the container registry (e.g., DE, GRA, BHS)")
5353
addParameterFileFlags(createCmd, false, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/containerRegistry", "post", cloud.CloudContainerRegistryCreateSample, nil)
5454
addInteractiveEditorFlag(createCmd)
55-
createCmd.MarkFlagsMutuallyExclusive("from-file", "editor")
55+
markFlagsMutuallyExclusive(createCmd, "from-file", "editor")
5656
registryCmd.AddCommand(createCmd)
5757

5858
registryCmd.AddCommand(&cobra.Command{
@@ -102,7 +102,7 @@ func initContainerRegistryUsersCommand(registryCmd *cobra.Command) {
102102
createCmd.Flags().StringVar(&cloud.CloudContainerRegistryUserSpec.Login, "login", "", "User login")
103103
addParameterFileFlags(createCmd, false, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/containerRegistry/{registryId}/users", "post", cloud.CloudContainerRegistryUserCreateSample, nil)
104104
addInteractiveEditorFlag(createCmd)
105-
createCmd.MarkFlagsMutuallyExclusive("from-file", "editor")
105+
markFlagsMutuallyExclusive(createCmd, "from-file", "editor")
106106
usersCmd.AddCommand(createCmd)
107107

108108
usersCmd.AddCommand(&cobra.Command{
@@ -137,7 +137,7 @@ func initContainerRegistryIAMCommand(registryCmd *cobra.Command) {
137137
enableCmd.Flags().BoolVar(&cloud.CloudContainerRegistryIamSpec.DeleteUsers, "delete-users", false, "Delete existing container registry users when enabling IAM")
138138
addParameterFileFlags(enableCmd, false, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/containerRegistry/{registryId}/iam", "post", cloud.CloudContainerRegistryIamEnableSample, nil)
139139
addInteractiveEditorFlag(enableCmd)
140-
enableCmd.MarkFlagsMutuallyExclusive("from-file", "editor")
140+
markFlagsMutuallyExclusive(enableCmd, "from-file", "editor")
141141
iamCmd.AddCommand(enableCmd)
142142

143143
iamCmd.AddCommand(&cobra.Command{
@@ -276,7 +276,7 @@ func initContainerRegistryOIDCCommand(registryCmd *cobra.Command) {
276276
createCmd.Flags().BoolVar(&cloud.CloudContainerRegistryOidcCreateSpec.Provider.VerifyCert, "verify-cert", false, "Verify the provider TLS certificate")
277277
addParameterFileFlags(createCmd, false, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/containerRegistry/{registryID}/openIdConnect", "post", cloud.CloudContainerRegistryOidcCreateSample, nil)
278278
addInteractiveEditorFlag(createCmd)
279-
createCmd.MarkFlagsMutuallyExclusive("from-file", "editor")
279+
markFlagsMutuallyExclusive(createCmd, "from-file", "editor")
280280
oidcCmd.AddCommand(createCmd)
281281

282282
editCmd := &cobra.Command{

internal/cmd/cloud_database.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ There are two ways to define the creation parameters:
119119
databaseCreateCmd.Flags().IntVar(&cloud.DatabaseSpec.Disk.Size, "disk-size", 0, "Disk size (GB)")
120120
databaseCreateCmd.Flags().StringVar(&cloud.DatabaseSpec.ForkFrom.BackupID, "fork-from.backup-id", "", "Backup ID (not compatible with fork-from.point-in-time)")
121121
databaseCreateCmd.Flags().StringVar(&cloud.DatabaseSpec.ForkFrom.PointInTime, "fork-from.point-in-time", "", "Point in time to restore from (not compatible with fork-from.backup-id)")
122-
databaseCreateCmd.MarkFlagsMutuallyExclusive("fork-from.backup-id", "fork-from.point-in-time")
122+
markFlagsMutuallyExclusive(databaseCreateCmd, "fork-from.backup-id", "fork-from.point-in-time")
123123
databaseCreateCmd.Flags().StringVar(&cloud.DatabaseSpec.ForkFrom.ServiceID, "fork-from.service-id", "", "Service ID that owns the backups")
124124
databaseCreateCmd.Flags().StringVar(&cloud.DatabaseSpec.MaintenanceTime, "maintenance-time", "", "Time on which maintenances can start every day")
125125
databaseCreateCmd.Flags().StringVar(&cloud.DatabaseSpec.Plan, "plan", "", "Database plan (you can get the list of available plans using 'ovhcloud cloud reference database list-plans')")
@@ -137,9 +137,9 @@ There are two ways to define the creation parameters:
137137

138138
// Nodes list definition
139139
databaseCreateCmd.Flags().StringSliceVar(&cloud.DatabaseSpec.CLINodesList, "nodes-list", nil, "List of nodes (format: flavor1:region1,flavor2:region2...)")
140-
databaseCreateCmd.MarkFlagsMutuallyExclusive("nodes-pattern.flavor", "nodes-list")
141-
databaseCreateCmd.MarkFlagsMutuallyExclusive("nodes-pattern.number", "nodes-list")
142-
databaseCreateCmd.MarkFlagsMutuallyExclusive("nodes-pattern.region", "nodes-list")
140+
markFlagsMutuallyExclusive(databaseCreateCmd, "nodes-pattern.flavor", "nodes-list")
141+
markFlagsMutuallyExclusive(databaseCreateCmd, "nodes-pattern.number", "nodes-list")
142+
markFlagsMutuallyExclusive(databaseCreateCmd, "nodes-pattern.region", "nodes-list")
143143

144144
// Common flags for other mean to define parameters
145145
addInteractiveEditorFlag(databaseCreateCmd)

internal/cmd/cloud_instance.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,19 @@ There are three ways to define the creation parameters:
7777
// Boot options
7878
instanceCreateCmd.Flags().StringVar(&cloud.InstanceCreationParameters.BootFrom.ImageID, "boot-from.image", "", "Image ID to boot from (you can use 'ovhcloud cloud reference list-images' to get the image ID or 'ovhcloud cloud instance snapshot ls' to get the snapshots)")
7979
instanceCreateCmd.Flags().StringVar(&cloud.InstanceCreationParameters.BootFrom.VolumeID, "boot-from.volume", "", "Volume ID to boot from")
80-
instanceCreateCmd.MarkFlagsMutuallyExclusive("boot-from.image", "boot-from.volume")
80+
markFlagsMutuallyExclusive(instanceCreateCmd, "boot-from.image", "boot-from.volume")
8181

8282
// Private Network - Floating IP
8383
instanceCreateCmd.Flags().StringVar(&cloud.InstanceCreationParameters.Network.Private.FloatingIp.ID, "network.private.floating-ip.id", "", "ID of an existing floating IP")
8484
instanceCreateCmd.Flags().StringVar(&cloud.InstanceCreationParameters.Network.Private.FloatingIpCreate.Description, "network.private.floating-ip.create.description", "", "Description for the floating IP to create")
85-
instanceCreateCmd.MarkFlagsMutuallyExclusive("network.private.floating-ip.id", "network.private.floating-ip.create.description")
85+
markFlagsMutuallyExclusive(instanceCreateCmd, "network.private.floating-ip.id", "network.private.floating-ip.create.description")
8686

8787
// Private Network - Gateway
8888
instanceCreateCmd.Flags().StringVar(&cloud.InstanceCreationParameters.Network.Private.Gateway.ID, "network.private.gateway.id", "", "ID of the existing gateway to attach to the private network")
8989
instanceCreateCmd.Flags().StringVar(&cloud.InstanceCreationParameters.Network.Private.GatewayCreate.Model, "network.private.gateway.create.model", "", "Model for the gateway to create (s, m, l)")
9090
instanceCreateCmd.Flags().StringVar(&cloud.InstanceCreationParameters.Network.Private.GatewayCreate.Name, "network.private.gateway.create.name", "", "Name for the gateway to create")
91-
instanceCreateCmd.MarkFlagsMutuallyExclusive("network.private.gateway.id", "network.private.gateway.create.model")
92-
instanceCreateCmd.MarkFlagsMutuallyExclusive("network.private.gateway.id", "network.private.gateway.create.name")
91+
markFlagsMutuallyExclusive(instanceCreateCmd, "network.private.gateway.id", "network.private.gateway.create.model")
92+
markFlagsMutuallyExclusive(instanceCreateCmd, "network.private.gateway.id", "network.private.gateway.create.name")
9393

9494
// Private network - IP
9595
instanceCreateCmd.Flags().StringVar(&cloud.InstanceCreationParameters.Network.Private.IP, "network.private.ip", "", "Instance IP in the private network")
@@ -104,12 +104,12 @@ There are three ways to define the creation parameters:
104104
instanceCreateCmd.Flags().BoolVar(&cloud.InstanceCreationParameters.Network.Private.NetworkCreate.Subnet.EnableDhcp, "network.private.create.subnet-enable-dhcp", false, "Enable DHCP for the subnet to create")
105105
instanceCreateCmd.Flags().IntVar(&cloud.InstanceCreationParameters.Network.Private.NetworkCreate.Subnet.IPVersion, "network.private.create.subnet-ip-version", 0, "IP version for the subnet to create")
106106
instanceCreateCmd.Flags().IntVar(&cloud.InstanceCreationParameters.Network.Private.NetworkCreate.VlanID, "network.private.create.vlan-id", 0, "VLAN ID for the private network to create")
107-
instanceCreateCmd.MarkFlagsMutuallyExclusive("network.private.id", "network.private.create.name")
107+
markFlagsMutuallyExclusive(instanceCreateCmd, "network.private.id", "network.private.create.name")
108108

109109
// Network - Public
110110
instanceCreateCmd.Flags().BoolVar(&cloud.InstanceCreationParameters.Network.Public, "network.public", false, "Set the new instance as public")
111-
instanceCreateCmd.MarkFlagsMutuallyExclusive("network.private.id", "network.public")
112-
instanceCreateCmd.MarkFlagsMutuallyExclusive("network.private.create.name", "network.public")
111+
markFlagsMutuallyExclusive(instanceCreateCmd, "network.private.id", "network.public")
112+
markFlagsMutuallyExclusive(instanceCreateCmd, "network.private.create.name", "network.public")
113113

114114
// Autobackup
115115
instanceCreateCmd.Flags().StringVar(&cloud.InstanceCreationParameters.Autobackup.Cron, "backup-cron", "", "Autobackup Unix Cron pattern (eg: '0 0 * * *')")
@@ -121,8 +121,8 @@ There are three ways to define the creation parameters:
121121
// SSH Key Creation
122122
instanceCreateCmd.Flags().StringVar(&cloud.InstanceCreationParameters.SshKeyCreate.Name, "ssh-key.create.name", "", "Name for the SSH key to create")
123123
instanceCreateCmd.Flags().StringVar(&cloud.InstanceCreationParameters.SshKeyCreate.PublicKey, "ssh-key.create.public-key", "", "Public key for the SSH key to create")
124-
instanceCreateCmd.MarkFlagsMutuallyExclusive("ssh-key.name", "ssh-key.create.name")
125-
instanceCreateCmd.MarkFlagsMutuallyExclusive("ssh-key.name", "ssh-key.create.public-key")
124+
markFlagsMutuallyExclusive(instanceCreateCmd, "ssh-key.name", "ssh-key.create.name")
125+
markFlagsMutuallyExclusive(instanceCreateCmd, "ssh-key.name", "ssh-key.create.public-key")
126126

127127
// User Data
128128
instanceCreateCmd.Flags().StringVar(&cloud.InstanceCreationParameters.UserData, "user-data", "", "Configuration information or scripts to use upon launch")
@@ -135,7 +135,7 @@ There are three ways to define the creation parameters:
135135
instanceCreateCmd.Flags().BoolVar(&cloud.InstanceImageViaInteractiveSelector, "image-selector", false, "Use the interactive image selector")
136136
instanceCreateCmd.Flags().BoolVar(&cloud.InstanceFlavorViaInteractiveSelector, "flavor-selector", false, "Use the interactive flavor selector")
137137
}
138-
instanceCreateCmd.MarkFlagsMutuallyExclusive("from-file", "editor")
138+
markFlagsMutuallyExclusive(instanceCreateCmd, "from-file", "editor")
139139

140140
return instanceCreateCmd
141141
}
@@ -284,8 +284,8 @@ There are three ways to define the installation parameters:
284284
reinstallCmd.Flags().BoolVar(&flags.WaitForTask, "wait", false, "Wait for reinstall to be done before exiting")
285285
if !(runtime.GOARCH == "wasm" && runtime.GOOS == "js") {
286286
reinstallCmd.Flags().BoolVar(&cloud.InstanceImageViaInteractiveSelector, "image-selector", false, "Use the interactive image selector to define installation parameters")
287-
reinstallCmd.MarkFlagsMutuallyExclusive("from-file", "editor", "image-selector")
288287
}
288+
markFlagsMutuallyExclusive(reinstallCmd, "from-file", "editor", "image-selector")
289289
instanceCmd.AddCommand(reinstallCmd)
290290

291291
instanceCmd.AddCommand(&cobra.Command{

internal/cmd/cloud_kube.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func initKubeCommand(cloudCmd *cobra.Command) {
110110
}
111111
ipRestrictionsEditCmd.Flags().StringSliceVar(&cloud.KubeIPRestrictions, "ips", nil, "List of IPs to restrict access to the Kubernetes cluster")
112112
addInteractiveEditorFlag(ipRestrictionsEditCmd)
113-
ipRestrictionsEditCmd.MarkFlagsMutuallyExclusive("ips", "editor")
113+
markFlagsMutuallyExclusive(ipRestrictionsEditCmd, "ips", "editor")
114114
ipRestrictionsCmd.AddCommand(ipRestrictionsEditCmd)
115115

116116
kubeConfigCmd := &cobra.Command{
@@ -365,7 +365,7 @@ There are three ways to define the creation parameters:
365365
// Common flags for other means to define parameters
366366
addParameterFileFlags(kubeCreateCmd, false, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/kube", "post", cloud.CloudKubeCreationExample, nil)
367367
addInteractiveEditorFlag(kubeCreateCmd)
368-
kubeCreateCmd.MarkFlagsMutuallyExclusive("from-file", "editor")
368+
markFlagsMutuallyExclusive(kubeCreateCmd, "from-file", "editor")
369369

370370
return kubeCreateCmd
371371
}
@@ -450,7 +450,7 @@ There are three ways to define the reset parameters:
450450
// Common flags for other means to define parameters
451451
addParameterFileFlags(kubeResetCmd, false, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/kube/reset", "post", cloud.CloudKubeResetExample, nil)
452452
addInteractiveEditorFlag(kubeResetCmd)
453-
kubeResetCmd.MarkFlagsMutuallyExclusive("from-file", "editor")
453+
markFlagsMutuallyExclusive(kubeResetCmd, "from-file", "editor")
454454

455455
return kubeResetCmd
456456
}
@@ -567,8 +567,8 @@ There are three ways to define the creation parameters:
567567
addInteractiveEditorFlag(nodepoolCreateCmd)
568568
if !(runtime.GOARCH == "wasm" && runtime.GOOS == "js") {
569569
nodepoolCreateCmd.Flags().BoolVar(&cloud.InstanceFlavorViaInteractiveSelector, "flavor-selector", false, "Use the interactive flavor selector")
570-
nodepoolCreateCmd.MarkFlagsMutuallyExclusive("from-file", "editor")
571570
}
571+
markFlagsMutuallyExclusive(nodepoolCreateCmd, "from-file", "editor")
572572

573573
return nodepoolCreateCmd
574574
}
@@ -632,7 +632,7 @@ There are three ways to define the parameters:
632632
// Common flags for other means to define parameters
633633
addParameterFileFlags(createCmd, false, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/kube/{kubeId}/openIdConnect", "post", cloud.CloudKubeOIDCCreationExample, nil)
634634
addInteractiveEditorFlag(createCmd)
635-
createCmd.MarkFlagsMutuallyExclusive("from-file", "editor")
635+
markFlagsMutuallyExclusive(createCmd, "from-file", "editor")
636636

637637
return createCmd
638638
}

0 commit comments

Comments
 (0)