Skip to content

Commit c006fc1

Browse files
committed
allow enabling protection during create
1 parent cbb4b55 commit c006fc1

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

internal/cmd/storagebox/create.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,19 @@ var CreateCmd = base.CreateCmd[*hcloud.StorageBox]{
5757
password, _ := cmd.Flags().GetString("password")
5858
sshKeys, _ := cmd.Flags().GetStringArray("ssh-key")
5959
labels, _ := cmd.Flags().GetStringToString("label")
60+
protection, _ := cmd.Flags().GetStringSlice("enable-protection")
61+
62+
protectionOpts, err := getChangeProtectionOpts(true, protection)
63+
if err != nil {
64+
return nil, nil, err
65+
}
6066

6167
enableSamba, _ := cmd.Flags().GetBool("enable-samba")
6268
enableSSH, _ := cmd.Flags().GetBool("enable-ssh")
6369
enableWebDAV, _ := cmd.Flags().GetBool("enable-webdav")
6470
enableZFS, _ := cmd.Flags().GetBool("enable-zfs")
6571
reachableExternally, _ := cmd.Flags().GetBool("reachable-externally")
6672

67-
var err error
6873
for i, sshKey := range sshKeys {
6974
sshKeys[i], err = resolveSSHKey(s, sshKey)
7075
if err != nil {
@@ -105,7 +110,12 @@ var CreateCmd = base.CreateCmd[*hcloud.StorageBox]{
105110
return nil, nil, fmt.Errorf("Storage Box not found: %d", result.StorageBox.ID)
106111
}
107112

108-
// TODO change protection here once change-protection is implemented
113+
if len(protection) > 0 {
114+
// TODO this check can be removed once delete protection is made nullable
115+
if err := changeProtection(s, cmd, storageBox, true, protectionOpts); err != nil {
116+
return nil, nil, err
117+
}
118+
}
109119

110120
return storageBox, util.Wrap("storage_box", hcloud.SchemaFromStorageBox(result.StorageBox)), nil
111121
},

0 commit comments

Comments
 (0)