Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ChangeHomeDirectoryCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ Use: "change-home-directory --home-directory <home-directory> <storage-box> <subaccount>", Short: "Update access settings of the Storage Box Subaccount", ValidArgsFunction: cmpl.SuggestArgs( cmpl.SuggestCandidatesF(client.StorageBox().Names), SuggestSubaccounts(client), ), TraverseChildren: true, DisableFlagsInUseLine: true, } cmd.Flags().String("home-directory", "", "Home directory of the Subaccount. Will be created if it doesn't exist yet") _ = cmd.MarkFlagRequired("home-directory") return cmd }, Run: func(s state.State, cmd *cobra.Command, args []string) error { storageBoxIDOrName, subaccountIDOrName := args[0], args[1] homeDirectory, _ := cmd.Flags().GetString("home-directory") storageBox, _, err := s.Client().StorageBox().Get(s, storageBoxIDOrName) if err != nil { return err } if storageBox == nil { return fmt.Errorf("Storage Box not found: %s", storageBoxIDOrName) } subaccount, _, err := s.Client().StorageBox().GetSubaccount(s, storageBox, subaccountIDOrName) if err != nil { return err } if subaccount == nil { return fmt.Errorf("Storage Box Subaccount not found: %s", subaccountIDOrName) } action, _, err := s.Client().StorageBox().ChangeSubaccountHomeDirectory(s, subaccount, hcloud.StorageBoxSubaccountChangeHomeDirectoryOpts{ HomeDirectory: homeDirectory, }) if err != nil { return err } if err := s.WaitForActions(s, cmd, action); err != nil { return err } cmd.Printf("Home directory updated for Storage Box Subaccount %d\n", subaccount.ID) return nil }, Experimental: experimental.StorageBoxes, }
View Source
var CreateCmd = base.CreateCmd[*hcloud.StorageBoxSubaccount]{ BaseCobraCommand: func(c hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ Use: "create [options] --password <password> --home-directory <home-directory> <storage-box>", ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(c.StorageBox().Names)), Short: "Create a Storage Box Subaccount", TraverseChildren: true, DisableFlagsInUseLine: true, } cmd.Flags().String("password", "", "Password for the Subaccount (required)") _ = cmd.MarkFlagRequired("password") cmd.Flags().String("home-directory", "", "Home directory for the Subaccount (required)") _ = cmd.MarkFlagRequired("home-directory") cmd.Flags().String("description", "", "Description for the Subaccount") cmd.Flags().StringToString("label", nil, "User-defined labels ('key=value') (can be specified multiple times)") cmd.Flags().Bool("enable-samba", false, "Whether the Samba subsystem should be enabled (true, false)") cmd.Flags().Bool("enable-ssh", false, "Whether the SSH subsystem should be enabled (true, false)") cmd.Flags().Bool("enable-webdav", false, "Whether the WebDAV subsystem should be enabled (true, false)") cmd.Flags().Bool("reachable-externally", false, "Whether the Storage Box should be accessible from outside the Hetzner network (true, false)") cmd.Flags().Bool("readonly", false, "Whether the Subaccount should be read-only (true, false)") return cmd }, Run: func(s state.State, cmd *cobra.Command, args []string) (*hcloud.StorageBoxSubaccount, any, error) { storageBoxIDOrName := args[0] password, _ := cmd.Flags().GetString("password") homeDirectory, _ := cmd.Flags().GetString("home-directory") description, _ := cmd.Flags().GetString("description") labels, _ := cmd.Flags().GetStringToString("label") enableSamba, _ := cmd.Flags().GetBool("enable-samba") enableSSH, _ := cmd.Flags().GetBool("enable-ssh") enableWebDAV, _ := cmd.Flags().GetBool("enable-webdav") reachableExternally, _ := cmd.Flags().GetBool("reachable-externally") readonly, _ := cmd.Flags().GetBool("readonly") storageBox, _, err := s.Client().StorageBox().Get(s, storageBoxIDOrName) if err != nil { return nil, nil, err } if storageBox == nil { return nil, nil, fmt.Errorf("Storage Box not found: %s", storageBoxIDOrName) } var accessSettings hcloud.StorageBoxSubaccountCreateOptsAccessSettings if cmd.Flags().Changed("enable-samba") { accessSettings.SambaEnabled = &enableSamba } if cmd.Flags().Changed("enable-ssh") { accessSettings.SSHEnabled = &enableSSH } if cmd.Flags().Changed("enable-webdav") { accessSettings.WebDAVEnabled = &enableWebDAV } if cmd.Flags().Changed("reachable-externally") { accessSettings.ReachableExternally = &reachableExternally } if cmd.Flags().Changed("readonly") { accessSettings.Readonly = &readonly } opts := hcloud.StorageBoxSubaccountCreateOpts{ HomeDirectory: homeDirectory, Password: password, Description: description, AccessSettings: &accessSettings, Labels: labels, } result, _, err := s.Client().StorageBox().CreateSubaccount(s, storageBox, opts) if err != nil { return nil, nil, err } if err := s.WaitForActions(s, cmd, result.Action); err != nil { return nil, nil, err } subaccount, _, err := s.Client().StorageBox().GetSubaccountByID(s, storageBox, result.Subaccount.ID) if err != nil { return nil, nil, err } if subaccount == nil { return nil, nil, fmt.Errorf("Storage Box Subaccount not found: %d", result.Subaccount.ID) } cmd.Printf("Storage Box Subaccount %d created\n", subaccount.ID) return subaccount, util.Wrap("subaccount", hcloud.SchemaFromStorageBoxSubaccount(subaccount)), nil }, Experimental: experimental.StorageBoxes, }
View Source
var DeleteCmd = base.DeleteCmd{ ResourceNameSingular: "Storage Box Subaccount", ResourceNamePlural: "Storage Box Subaccounts", ShortDescription: "Delete a Storage Box Subaccount", PositionalArgumentOverride: []string{"storage-box", "subaccount"}, ValidArgsFunction: func(client hcapi2.Client) []cobra.CompletionFunc { return []cobra.CompletionFunc{ cmpl.SuggestCandidatesF(client.StorageBox().Names), SuggestSubaccounts(client), } }, FetchFunc: func(s state.State, _ *cobra.Command, args []string) (base.FetchFunc, error) { storageBox, _, err := s.Client().StorageBox().Get(s, args[0]) if err != nil { return nil, err } if storageBox == nil { return nil, fmt.Errorf("Storage Box not found: %s", args[0]) } return func(s state.State, _ *cobra.Command, idOrName string) (any, *hcloud.Response, error) { return s.Client().StorageBox().GetSubaccount(s, storageBox, idOrName) }, nil }, Delete: func(s state.State, _ *cobra.Command, resource any) (*hcloud.Action, error) { subaccount := resource.(*hcloud.StorageBoxSubaccount) result, _, err := s.Client().StorageBox().DeleteSubaccount(s, subaccount) return result.Action, err }, Experimental: experimental.StorageBoxes, }
View Source
var DescribeCmd = base.DescribeCmd[*hcloud.StorageBoxSubaccount]{ ResourceNameSingular: "Storage Box Subaccount", ShortDescription: "Describe a Storage Box Subaccount", PositionalArgumentOverride: []string{"storage-box", "subaccount"}, ValidArgsFunction: func(client hcapi2.Client) []cobra.CompletionFunc { return []cobra.CompletionFunc{ cmpl.SuggestCandidatesF(client.StorageBox().Names), SuggestSubaccounts(client), } }, FetchWithArgs: func(s state.State, _ *cobra.Command, args []string) (*hcloud.StorageBoxSubaccount, any, error) { storageBoxIDOrName, subaccountIDOrName := args[0], args[1] storageBox, _, err := s.Client().StorageBox().Get(s, storageBoxIDOrName) if err != nil { return nil, nil, err } if storageBox == nil { return nil, nil, fmt.Errorf("Storage Box not found: %s", storageBoxIDOrName) } subaccount, _, err := s.Client().StorageBox().GetSubaccount(s, storageBox, subaccountIDOrName) if err != nil { return nil, nil, err } return subaccount, hcloud.SchemaFromStorageBoxSubaccount(subaccount), nil }, PrintText: func(_ state.State, cmd *cobra.Command, subaccount *hcloud.StorageBoxSubaccount) error { cmd.Printf("ID:\t\t\t%d\n", subaccount.ID) cmd.Printf("Description:\t\t%s\n", util.NA(subaccount.Description)) cmd.Printf("Created:\t\t%s (%s)\n", util.Datetime(subaccount.Created), humanize.Time(subaccount.Created)) cmd.Printf("Username:\t\t%s\n", subaccount.Username) cmd.Printf("Home Directory:\t\t%s\n", subaccount.HomeDirectory) cmd.Printf("Server:\t\t\t%s\n", subaccount.Server) accessSettings := subaccount.AccessSettings cmd.Println("Access Settings:") cmd.Printf(" Reachable Externally:\t%t\n", accessSettings.ReachableExternally) cmd.Printf(" Samba Enabled:\t%t\n", accessSettings.SambaEnabled) cmd.Printf(" SSH Enabled:\t\t%t\n", accessSettings.SSHEnabled) cmd.Printf(" WebDAV Enabled:\t%t\n", accessSettings.WebDAVEnabled) cmd.Printf(" Readonly:\t\t%t\n", accessSettings.Readonly) cmd.Println("Labels:") if len(subaccount.Labels) == 0 { cmd.Println(" No labels") } else { for key, value := range util.IterateInOrder(subaccount.Labels) { cmd.Printf(" %s: %s\n", key, value) } } cmd.Println("Storage Box:") cmd.Printf(" ID:\t\t\t%d\n", subaccount.StorageBox.ID) return nil }, Experimental: experimental.StorageBoxes, }
View Source
var ListCmd = base.ListCmd[*hcloud.StorageBoxSubaccount, schema.StorageBoxSubaccount]{ ResourceNamePlural: "Storage Box Subaccounts", JSONKeyGetByName: "subaccounts", DefaultColumns: []string{"id", "username", "home_directory", "description", "server", "age"}, ValidArgsFunction: func(client hcapi2.Client) cobra.CompletionFunc { return cmpl.SuggestCandidatesF(client.StorageBox().Names) }, PositionalArgumentOverride: []string{"storage-box"}, SortOption: config.OptionSortStorageBoxSubaccount, FetchWithArgs: func(s state.State, _ *pflag.FlagSet, listOpts hcloud.ListOpts, sorts []string, args []string) ([]*hcloud.StorageBoxSubaccount, error) { storageBoxIDOrName := args[0] storageBox, _, err := s.Client().StorageBox().Get(s, storageBoxIDOrName) if err != nil { return nil, err } if storageBox == nil { return nil, fmt.Errorf("Storage Box not found: %s", storageBoxIDOrName) } opts := hcloud.StorageBoxSubaccountListOpts{LabelSelector: listOpts.LabelSelector} if len(sorts) > 0 { opts.Sort = sorts } return s.Client().StorageBox().AllSubaccountsWithOpts(s, storageBox, opts) }, OutputTable: func(t *output.Table, _ hcapi2.Client) { t. AddAllowedFields(hcloud.StorageBoxSubaccount{}). AddFieldFn("description", func(obj any) string { subaccount := obj.(*hcloud.StorageBoxSubaccount) return util.NA(subaccount.Description) }). AddFieldFn("labels", func(obj any) string { subaccount := obj.(*hcloud.StorageBoxSubaccount) return util.LabelsToString(subaccount.Labels) }). AddFieldFn("created", func(obj any) string { subaccount := obj.(*hcloud.StorageBoxSubaccount) return util.Datetime(subaccount.Created) }). AddFieldFn("age", func(obj any) string { subaccount := obj.(*hcloud.StorageBoxSubaccount) return util.Age(subaccount.Created, time.Now()) }) }, Schema: hcloud.SchemaFromStorageBoxSubaccount, Experimental: experimental.StorageBoxes, }
View Source
var ResetPasswordCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ Use: "reset-password --password <password> <storage-box> <subaccount>", Short: "Reset the password of a Storage Box Subaccount", ValidArgsFunction: cmpl.SuggestArgs( cmpl.SuggestCandidatesF(client.StorageBox().Names), SuggestSubaccounts(client), ), TraverseChildren: true, DisableFlagsInUseLine: true, } cmd.Flags().String("password", "", "New password for the Storage Box Subaccount") _ = cmd.MarkFlagRequired("password") return cmd }, Run: func(s state.State, cmd *cobra.Command, args []string) error { storageBoxIDOrName, subaccountIDOrName := args[0], args[1] password, _ := cmd.Flags().GetString("password") storageBox, _, err := s.Client().StorageBox().Get(s, storageBoxIDOrName) if err != nil { return err } if storageBox == nil { return fmt.Errorf("Storage Box not found: %s", storageBoxIDOrName) } subaccount, _, err := s.Client().StorageBox().GetSubaccount(s, storageBox, subaccountIDOrName) if err != nil { return err } if subaccount == nil { return fmt.Errorf("Storage Box Subaccount not found: %s", subaccountIDOrName) } opts := hcloud.StorageBoxSubaccountResetPasswordOpts{ Password: password, } action, _, err := s.Client().StorageBox().ResetSubaccountPassword(s, subaccount, opts) if err != nil { return err } if err := s.WaitForActions(s, cmd, action); err != nil { return err } cmd.Printf("Password of Storage Box Subaccount %d reset\n", subaccount.ID) return nil }, Experimental: experimental.StorageBoxes, }
View Source
var UpdateAccessSettingsCmd = base.Cmd{ BaseCobraCommand: func(client hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ Use: "update-access-settings [options] <storage-box> <subaccount>", Short: "Update access settings of the Storage Box Subaccount", ValidArgsFunction: cmpl.SuggestArgs( cmpl.SuggestCandidatesF(client.StorageBox().Names), SuggestSubaccounts(client), ), TraverseChildren: true, DisableFlagsInUseLine: true, } cmd.Flags().Bool("enable-samba", false, "Whether the Samba subsystem should be enabled (true, false)") cmd.Flags().Bool("enable-ssh", false, "Whether the SSH subsystem should be enabled (true, false)") cmd.Flags().Bool("enable-webdav", false, "Whether the WebDAV subsystem should be enabled (true, false)") cmd.Flags().Bool("reachable-externally", false, "Whether the Storage Box should be accessible from outside the Hetzner network (true, false)") cmd.Flags().Bool("readonly", false, "Whether the Subaccount should be read-only (true, false)") cmd.MarkFlagsOneRequired("enable-samba", "enable-ssh", "enable-webdav", "reachable-externally", "readonly") return cmd }, Run: func(s state.State, cmd *cobra.Command, args []string) error { storageBoxIDOrName, subaccountIDOrName := args[0], args[1] enableSamba, _ := cmd.Flags().GetBool("enable-samba") enableSSH, _ := cmd.Flags().GetBool("enable-ssh") enableWebDAV, _ := cmd.Flags().GetBool("enable-webdav") reachableExternally, _ := cmd.Flags().GetBool("reachable-externally") readonly, _ := cmd.Flags().GetBool("readonly") storageBox, _, err := s.Client().StorageBox().Get(s, storageBoxIDOrName) if err != nil { return err } if storageBox == nil { return fmt.Errorf("Storage Box not found: %s", storageBoxIDOrName) } subaccount, _, err := s.Client().StorageBox().GetSubaccount(s, storageBox, subaccountIDOrName) if err != nil { return err } if subaccount == nil { return fmt.Errorf("Storage Box Subaccount not found: %s", subaccountIDOrName) } var opts hcloud.StorageBoxSubaccountUpdateAccessSettingsOpts if cmd.Flags().Changed("enable-samba") { opts.SambaEnabled = &enableSamba } if cmd.Flags().Changed("enable-ssh") { opts.SSHEnabled = &enableSSH } if cmd.Flags().Changed("enable-webdav") { opts.WebDAVEnabled = &enableWebDAV } if cmd.Flags().Changed("reachable-externally") { opts.ReachableExternally = &reachableExternally } if cmd.Flags().Changed("readonly") { opts.Readonly = &readonly } action, _, err := s.Client().StorageBox().UpdateSubaccountAccessSettings(s, subaccount, opts) if err != nil { return err } if err := s.WaitForActions(s, cmd, action); err != nil { return err } cmd.Printf("Access settings updated for Storage Box Subaccount %d\n", subaccount.ID) return nil }, Experimental: experimental.StorageBoxes, }
View Source
var UpdateCmd = base.UpdateCmd{ ResourceNameSingular: "Storage Box Subaccount", ShortDescription: "Update a Storage Box Subaccount", NameSuggestions: func(c hcapi2.Client) func() []string { return c.StorageBox().Names }, ValidArgsFunction: func(client hcapi2.Client) []cobra.CompletionFunc { return []cobra.CompletionFunc{ cmpl.SuggestCandidatesF(client.StorageBox().Names), SuggestSubaccounts(client), } }, PositionalArgumentOverride: []string{"storage-box", "subaccount"}, FetchWithArgs: func(s state.State, _ *cobra.Command, args []string) (any, *hcloud.Response, error) { storageBoxIDOrName, subaccountIDOrName := args[0], args[1] storageBox, _, err := s.Client().StorageBox().Get(s, storageBoxIDOrName) if err != nil { return nil, nil, err } if storageBox == nil { return nil, nil, fmt.Errorf("Storage Box not found: %s", storageBoxIDOrName) } return s.Client().StorageBox().GetSubaccount(s, storageBox, subaccountIDOrName) }, DefineFlags: func(cmd *cobra.Command) { cmd.Flags().String("description", "", "Description of the Storage Box Snapshot") cmd.MarkFlagsOneRequired("description") }, Update: func(s state.State, cmd *cobra.Command, resource interface{}, _ map[string]pflag.Value) error { subaccount := resource.(*hcloud.StorageBoxSubaccount) var opts hcloud.StorageBoxSubaccountUpdateOpts if cmd.Flags().Changed("description") { description, _ := cmd.Flags().GetString("description") opts.Description = &description } _, _, err := s.Client().StorageBox().UpdateSubaccount(s, subaccount, opts) if err != nil { return err } return nil }, Experimental: experimental.StorageBoxes, }
Functions ¶
func SuggestSubaccounts ¶
func SuggestSubaccounts(client hcapi2.Client) cobra.CompletionFunc
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.