Skip to content

Commit e4302bf

Browse files
fix: Rename --hetzner-disable-public-4/6 to --hetzner-disable-public-ipv4/6 (fixes #102, thanks @simonostendorf")
2 parents f4da5fb + 1d8da51 commit e4302bf

File tree

3 files changed

+135
-15
lines changed

3 files changed

+135
-15
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ You can find sources and pre-compiled binaries [here](https://github.com/JonasPr
1515

1616
```bash
1717
# Download the binary (this example downloads the binary for linux amd64)
18-
$ wget https://github.com/JonasProgrammer/docker-machine-driver-hetzner/releases/download/3.12.1/docker-machine-driver-hetzner_3.12.1_linux_amd64.tar.gz
19-
$ tar -xvf docker-machine-driver-hetzner_3.12.1_linux_amd64.tar.gz
18+
$ wget https://github.com/JonasProgrammer/docker-machine-driver-hetzner/releases/download/3.12.2/docker-machine-driver-hetzner_3.12.2_linux_amd64.tar.gz
19+
$ tar -xvf docker-machine-driver-hetzner_3.12.2_linux_amd64.tar.gz
2020

2121
# Make it executable and copy the binary in a directory accessible with your $PATH
2222
$ chmod +x docker-machine-driver-hetzner
@@ -148,8 +148,8 @@ was used during creation.
148148
| `--hetzner-firewalls` | `HETZNER_FIREWALLS` | |
149149
| `--hetzner-volumes` | `HETZNER_VOLUMES` | |
150150
| `--hetzner-use-private-network` | `HETZNER_USE_PRIVATE_NETWORK` | false |
151-
| `--hetzner-disable-public-4` | `HETZNER_DISABLE_PUBLIC_4` | false |
152-
| `--hetzner-disable-public-6` | `HETZNER_DISABLE_PUBLIC_6` | false |
151+
| `--hetzner-disable-public-ipv4` | `HETZNER_DISABLE_PUBLIC_IPV4` | false |
152+
| `--hetzner-disable-public-ipv6` | `HETZNER_DISABLE_PUBLIC_IPV6` | false |
153153
| `--hetzner-disable-public` | `HETZNER_DISABLE_PUBLIC` | false |
154154
| `--hetzner-server-label` | (inoperative) | `[]` |
155155
| `--hetzner-key-label` | (inoperative) | `[]` |
@@ -177,7 +177,7 @@ Hetzner assigns them at the given time, so users should take care what retention
177177

178178
When disabling all public IPs, `--hetzner-use-private-network` must be given.
179179
`--hetzner-disable-public` will take care of that, and behaves as if
180-
`--hetzner-disable-public-4 --hetzner-disable-public-6 --hetzner-use-private-network`
180+
`--hetzner-disable-public-ipv4 --hetzner-disable-public-ipv6 --hetzner-use-private-network`
181181
were given.
182182
Using `--hetzner-use-private-network` implicitly or explicitly requires at least one `--hetzner-network`
183183
to be given.
@@ -237,7 +237,9 @@ $ docker-machine create --driver hetzner
237237
### 4.0.0
238238

239239
* `--hetzner-user-data-from-file` will be fully deprecated and its flag description will only read 'DEPRECATED, legacy'; current fallback behaviour will be retained. `--hetzner-flag-user-data-file` should be used instead.
240+
* `--hetzner-disable-public-4`/`--hetzner-disable-public-6` will be fully deprecated and its flag description will only read 'DEPRECATED, legacy'; current fallback behaviour will be retained. `--hetzner-disable-public-ipv4`/`--hetzner-disable-public-ipv6` should be used instead.
240241

241242
### 5.0.0
242243

243244
* `--hetzner-user-data-from-file` will be removed entirely, including its fallback behavior
245+
* `--hetzner-disable-public-4`/`--hetzner-disable-public-6` ill be removed entirely, including their fallback behavior

driver.go

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ const (
7878
flagVolumes = "hetzner-volumes"
7979
flagNetworks = "hetzner-networks"
8080
flagUsePrivateNetwork = "hetzner-use-private-network"
81-
flagDisablePublic4 = "hetzner-disable-public-4"
82-
flagDisablePublic6 = "hetzner-disable-public-6"
81+
flagDisablePublic4 = "hetzner-disable-public-ipv4"
82+
flagDisablePublic6 = "hetzner-disable-public-ipv6"
8383
flagPrimary4 = "hetzner-primary-ipv4"
8484
flagPrimary6 = "hetzner-primary-ipv6"
8585
flagDisablePublic = "hetzner-disable-public"
@@ -106,6 +106,8 @@ const (
106106
defaultWaitOnError = 0
107107

108108
legacyFlagUserDataFromFile = "hetzner-user-data-from-file"
109+
legacyFlagDisablePublic4 = "hetzner-disable-public-4"
110+
legacyFlagDisablePublic6 = "hetzner-disable-public-6"
109111
)
110112

111113
// NewDriver initializes a new driver instance; see [drivers.Driver.NewDriver]
@@ -201,15 +203,25 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
201203
Usage: "Use private network",
202204
},
203205
mcnflag.BoolFlag{
204-
EnvVar: "HETZNER_DISABLE_PUBLIC_4",
206+
EnvVar: "HETZNER_DISABLE_PUBLIC_IPV4",
205207
Name: flagDisablePublic4,
206208
Usage: "Disable public ipv4",
207209
},
208210
mcnflag.BoolFlag{
209-
EnvVar: "HETZNER_DISABLE_PUBLIC_6",
211+
EnvVar: "HETZNER_DISABLE_PUBLIC_4",
212+
Name: legacyFlagDisablePublic4,
213+
Usage: "DEPRECATED, use --hetzner-disable-public-ipv4; disable public ipv4",
214+
},
215+
mcnflag.BoolFlag{
216+
EnvVar: "HETZNER_DISABLE_PUBLIC_IPV6",
210217
Name: flagDisablePublic6,
211218
Usage: "Disable public ipv6",
212219
},
220+
mcnflag.BoolFlag{
221+
EnvVar: "HETZNER_DISABLE_PUBLIC_6",
222+
Name: legacyFlagDisablePublic6,
223+
Usage: "DEPRECATED, use --hetzner-disable-public-ipv6; disable public ipv6",
224+
},
213225
mcnflag.BoolFlag{
214226
EnvVar: "HETZNER_DISABLE_PUBLIC",
215227
Name: flagDisablePublic,
@@ -306,8 +318,8 @@ func (d *Driver) setConfigFromFlagsImpl(opts drivers.DriverOptions) error {
306318
d.Networks = opts.StringSlice(flagNetworks)
307319
disablePublic := opts.Bool(flagDisablePublic)
308320
d.UsePrivateNetwork = opts.Bool(flagUsePrivateNetwork) || disablePublic
309-
d.DisablePublic4 = opts.Bool(flagDisablePublic4) || disablePublic
310-
d.DisablePublic6 = opts.Bool(flagDisablePublic6) || disablePublic
321+
d.DisablePublic4 = d.deprecatedBooleanFlag(opts, flagDisablePublic4, legacyFlagDisablePublic4) || disablePublic
322+
d.DisablePublic6 = d.deprecatedBooleanFlag(opts, flagDisablePublic6, legacyFlagDisablePublic6) || disablePublic
311323
d.PrimaryIPv4 = opts.String(flagPrimary4)
312324
d.PrimaryIPv6 = opts.String(flagPrimary6)
313325
d.Firewalls = opts.StringSlice(flagFirewalls)
@@ -361,6 +373,14 @@ func (d *Driver) setConfigFromFlagsImpl(opts drivers.DriverOptions) error {
361373
return nil
362374
}
363375

376+
func (d *Driver) deprecatedBooleanFlag(opts drivers.DriverOptions, flag, deprecatedFlag string) bool {
377+
if opts.Bool(deprecatedFlag) {
378+
log.Warnf("--%v is deprecated, use --%v instead", deprecatedFlag, flag)
379+
return true
380+
}
381+
return opts.Bool(flag)
382+
}
383+
364384
func (d *Driver) setUserDataFlags(opts drivers.DriverOptions) error {
365385
userData := opts.String(flagUserData)
366386
userDataFile := opts.String(flagUserDataFile)

driver_test.go

Lines changed: 102 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ func TestUserData(t *testing.T) {
4646
d = NewDriver()
4747
err = d.setConfigFromFlagsImpl(&commandstest.FakeFlagger{
4848
Data: map[string]interface{}{
49-
flagAPIToken: "foo",
5049
legacyFlagUserDataFromFile: true,
5150
flagUserDataFile: file,
5251
},
@@ -56,7 +55,6 @@ func TestUserData(t *testing.T) {
5655
// inline user data
5756
d = NewDriver()
5857
err = d.setConfigFromFlagsImpl(makeFlags(map[string]interface{}{
59-
flagAPIToken: "foo",
6058
flagUserData: inlineContents,
6159
}))
6260
if err != nil {
@@ -74,7 +72,6 @@ func TestUserData(t *testing.T) {
7472
// file user data
7573
d = NewDriver()
7674
err = d.setConfigFromFlagsImpl(makeFlags(map[string]interface{}{
77-
flagAPIToken: "foo",
7875
flagUserDataFile: file,
7976
}))
8077
if err != nil {
@@ -92,7 +89,6 @@ func TestUserData(t *testing.T) {
9289
// legacy file user data
9390
d = NewDriver()
9491
err = d.setConfigFromFlagsImpl(makeFlags(map[string]interface{}{
95-
flagAPIToken: "foo",
9692
flagUserData: file,
9793
legacyFlagUserDataFromFile: true,
9894
}))
@@ -109,6 +105,108 @@ func TestUserData(t *testing.T) {
109105
}
110106
}
111107

108+
func TestDisablePublic(t *testing.T) {
109+
d := NewDriver()
110+
err := d.setConfigFromFlagsImpl(makeFlags(map[string]interface{}{
111+
flagDisablePublic: true,
112+
}))
113+
if err != nil {
114+
t.Fatalf("unexpected error, %v", err)
115+
}
116+
117+
if !d.DisablePublic4 {
118+
t.Error("expected public ipv4 to be disabled")
119+
}
120+
if !d.DisablePublic6 {
121+
t.Error("expected public ipv6 to be disabled")
122+
}
123+
if !d.UsePrivateNetwork {
124+
t.Error("expected private network to be enabled")
125+
}
126+
}
127+
128+
func TestDisablePublic46(t *testing.T) {
129+
d := NewDriver()
130+
err := d.setConfigFromFlagsImpl(makeFlags(map[string]interface{}{
131+
flagDisablePublic4: true,
132+
}))
133+
if err != nil {
134+
t.Fatalf("unexpected error, %v", err)
135+
}
136+
137+
if !d.DisablePublic4 {
138+
t.Error("expected public ipv4 to be disabled")
139+
}
140+
if d.DisablePublic6 {
141+
t.Error("public ipv6 disabled unexpectedly")
142+
}
143+
if d.UsePrivateNetwork {
144+
t.Error("network enabled unexpectedly")
145+
}
146+
147+
// 6
148+
d = NewDriver()
149+
err = d.setConfigFromFlagsImpl(makeFlags(map[string]interface{}{
150+
flagDisablePublic6: true,
151+
}))
152+
if err != nil {
153+
t.Fatalf("unexpected error, %v", err)
154+
}
155+
156+
if d.DisablePublic4 {
157+
t.Error("public ipv4 disabled unexpectedly")
158+
}
159+
if !d.DisablePublic6 {
160+
t.Error("expected public ipv6 to be disabled")
161+
}
162+
if d.UsePrivateNetwork {
163+
t.Error("network enabled unexpectedly")
164+
}
165+
}
166+
167+
func TestDisablePublic46Legacy(t *testing.T) {
168+
d := NewDriver()
169+
err := d.setConfigFromFlagsImpl(makeFlags(map[string]interface{}{
170+
legacyFlagDisablePublic4: true,
171+
// any truthy flag should take precedence
172+
flagDisablePublic4: false,
173+
}))
174+
if err != nil {
175+
t.Fatalf("unexpected error, %v", err)
176+
}
177+
178+
if !d.DisablePublic4 {
179+
t.Error("expected public ipv4 to be disabled")
180+
}
181+
if d.DisablePublic6 {
182+
t.Error("public ipv6 disabled unexpectedly")
183+
}
184+
if d.UsePrivateNetwork {
185+
t.Error("network enabled unexpectedly")
186+
}
187+
188+
// 6
189+
d = NewDriver()
190+
err = d.setConfigFromFlagsImpl(makeFlags(map[string]interface{}{
191+
legacyFlagDisablePublic6: true,
192+
// any truthy flag should take precedence
193+
flagDisablePublic6: false,
194+
}))
195+
if err != nil {
196+
t.Fatalf("unexpected error, %v", err)
197+
}
198+
199+
if d.DisablePublic4 {
200+
t.Error("public ipv4 disabled unexpectedly")
201+
}
202+
if !d.DisablePublic6 {
203+
t.Error("expected public ipv6 to be disabled")
204+
}
205+
if d.UsePrivateNetwork {
206+
t.Error("network enabled unexpectedly")
207+
}
208+
}
209+
112210
func assertMutualExclusion(t *testing.T, err error, flag1, flag2 string) {
113211
if err == nil {
114212
t.Errorf("expected mutually exclusive flags to fail, but no error was thrown: %v %v", flag1, flag2)

0 commit comments

Comments
 (0)