diff --git a/internal/cmd/all/list.go b/internal/cmd/all/list.go index cb3919fc..1ec1a5df 100644 --- a/internal/cmd/all/list.go +++ b/internal/cmd/all/list.go @@ -161,7 +161,7 @@ Listed resources are: for i, lc := range cmds { cols := lc.DefaultColumns - table := lc.OutputTable(s) + table := lc.OutputTable(s.Client()) table.WriteHeader(cols) if len(resources[i]) == 0 { diff --git a/internal/cmd/base/cmd.go b/internal/cmd/base/cmd.go index 434976ee..079680d3 100644 --- a/internal/cmd/base/cmd.go +++ b/internal/cmd/base/cmd.go @@ -16,7 +16,7 @@ type Cmd struct { // CobraCommand creates a command that can be registered with cobra. func (gc *Cmd) CobraCommand(s state.State) *cobra.Command { - cmd := gc.BaseCobraCommand(s) + cmd := gc.BaseCobraCommand(s.Client()) if cmd.Args == nil { cmd.Args = cobra.NoArgs diff --git a/internal/cmd/base/create.go b/internal/cmd/base/create.go index a863a761..496a0dd0 100644 --- a/internal/cmd/base/create.go +++ b/internal/cmd/base/create.go @@ -22,7 +22,7 @@ type CreateCmd struct { // CobraCommand creates a command that can be registered with cobra. func (cc *CreateCmd) CobraCommand(s state.State) *cobra.Command { - cmd := cc.BaseCobraCommand(s) + cmd := cc.BaseCobraCommand(s.Client()) output.AddFlag(cmd, output.OptionJSON(), output.OptionYAML()) diff --git a/internal/cmd/base/delete.go b/internal/cmd/base/delete.go index bf4ee117..a1ef8342 100644 --- a/internal/cmd/base/delete.go +++ b/internal/cmd/base/delete.go @@ -30,7 +30,7 @@ func (dc *DeleteCmd) CobraCommand(s state.State) *cobra.Command { Use: fmt.Sprintf("delete [FLAGS] %s", strings.ToUpper(dc.ResourceNameSingular)), Short: dc.ShortDescription, Args: cobra.ExactArgs(1), - ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(dc.NameSuggestions(s))), + ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(dc.NameSuggestions(s.Client()))), TraverseChildren: true, DisableFlagsInUseLine: true, PreRunE: util.ChainRunE(s.EnsureToken), diff --git a/internal/cmd/base/describe.go b/internal/cmd/base/describe.go index fe6cd527..5d50faf1 100644 --- a/internal/cmd/base/describe.go +++ b/internal/cmd/base/describe.go @@ -35,7 +35,7 @@ func (dc *DescribeCmd) CobraCommand(s state.State) *cobra.Command { Use: fmt.Sprintf("describe [FLAGS] %s", strings.ToUpper(dc.ResourceNameSingular)), Short: dc.ShortDescription, Args: cobra.ExactArgs(1), - ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(dc.NameSuggestions(s))), + ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(dc.NameSuggestions(s.Client()))), TraverseChildren: true, DisableFlagsInUseLine: true, PreRunE: util.ChainRunE(s.EnsureToken), diff --git a/internal/cmd/base/labels.go b/internal/cmd/base/labels.go index 88e31497..d5472770 100644 --- a/internal/cmd/base/labels.go +++ b/internal/cmd/base/labels.go @@ -30,7 +30,7 @@ func (lc *LabelCmds) AddCobraCommand(s state.State) *cobra.Command { Use: fmt.Sprintf("add-label [FLAGS] %s LABEL", strings.ToUpper(lc.ResourceNameSingular)), Short: lc.ShortDescriptionAdd, Args: cobra.ExactArgs(2), - ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(lc.NameSuggestions(s))), + ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(lc.NameSuggestions(s.Client()))), TraverseChildren: true, DisableFlagsInUseLine: true, PreRunE: util.ChainRunE(validateAddLabel, s.EnsureToken), @@ -88,12 +88,12 @@ func (lc *LabelCmds) RemoveCobraCommand(s state.State) *cobra.Command { Short: lc.ShortDescriptionRemove, Args: cobra.RangeArgs(1, 2), ValidArgsFunction: cmpl.SuggestArgs( - cmpl.SuggestCandidatesF(lc.NameSuggestions(s)), + cmpl.SuggestCandidatesF(lc.NameSuggestions(s.Client())), cmpl.SuggestCandidatesCtx(func(_ *cobra.Command, args []string) []string { if len(args) != 1 { return nil } - return lc.LabelKeySuggestions(s)(args[0]) + return lc.LabelKeySuggestions(s.Client())(args[0]) }), ), TraverseChildren: true, diff --git a/internal/cmd/base/list.go b/internal/cmd/base/list.go index 2f2d2230..a15dcff0 100644 --- a/internal/cmd/base/list.go +++ b/internal/cmd/base/list.go @@ -26,7 +26,7 @@ type ListCmd struct { // CobraCommand creates a command that can be registered with cobra. func (lc *ListCmd) CobraCommand(s state.State) *cobra.Command { - outputColumns := lc.OutputTable(s).Columns() + outputColumns := lc.OutputTable(s.Client()).Columns() cmd := &cobra.Command{ Use: "list [FlAGS]", @@ -81,7 +81,7 @@ func (lc *ListCmd) Run(s state.State, cmd *cobra.Command) error { cols = outOpts["columns"] } - table := lc.OutputTable(s) + table := lc.OutputTable(s.Client()) if !outOpts.IsSet("noheader") { table.WriteHeader(cols) } diff --git a/internal/cmd/base/set_rdns.go b/internal/cmd/base/set_rdns.go index d4857df2..d363ad7a 100644 --- a/internal/cmd/base/set_rdns.go +++ b/internal/cmd/base/set_rdns.go @@ -31,7 +31,7 @@ func (rc *SetRdnsCmd) CobraCommand(s state.State) *cobra.Command { Use: fmt.Sprintf("set-rdns [FLAGS] %s", strings.ToUpper(rc.ResourceNameSingular)), Short: rc.ShortDescription, Args: cobra.ExactArgs(1), - ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(rc.NameSuggestions(s))), + ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(rc.NameSuggestions(s.Client()))), TraverseChildren: true, DisableFlagsInUseLine: true, PreRunE: util.ChainRunE(s.EnsureToken), @@ -69,7 +69,7 @@ func (rc *SetRdnsCmd) Run(s state.State, cmd *cobra.Command, args []string) erro ip = rc.GetDefaultIP(resource) } hostname, _ := cmd.Flags().GetString("hostname") - action, _, err := s.RDNS().ChangeDNSPtr(s, resource.(hcloud.RDNSSupporter), ip, hcloud.String(hostname)) + action, _, err := s.Client().RDNS().ChangeDNSPtr(s, resource.(hcloud.RDNSSupporter), ip, hcloud.String(hostname)) if err != nil { return err } diff --git a/internal/cmd/base/update.go b/internal/cmd/base/update.go index a2907953..9ddf0c30 100644 --- a/internal/cmd/base/update.go +++ b/internal/cmd/base/update.go @@ -31,7 +31,7 @@ func (uc *UpdateCmd) CobraCommand(s state.State) *cobra.Command { Use: fmt.Sprintf("update [FLAGS] %s", strings.ToUpper(uc.ResourceNameSingular)), Short: uc.ShortDescription, Args: cobra.ExactArgs(1), - ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(uc.NameSuggestions(s))), + ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(uc.NameSuggestions(s.Client()))), TraverseChildren: true, DisableFlagsInUseLine: true, PreRunE: util.ChainRunE(s.EnsureToken), diff --git a/internal/cmd/certificate/create.go b/internal/cmd/certificate/create.go index 173af176..43c5e1db 100644 --- a/internal/cmd/certificate/create.go +++ b/internal/cmd/certificate/create.go @@ -95,7 +95,7 @@ func createUploaded(s state.State, cmd *cobra.Command) (*hcloud.Certificate, err Certificate: string(certPEM), PrivateKey: string(keyPEM), } - cert, _, err = s.Certificate().Create(s, createOpts) + cert, _, err = s.Client().Certificate().Create(s, createOpts) if err != nil { return nil, err } @@ -126,7 +126,7 @@ func createManaged(s state.State, cmd *cobra.Command) (*hcloud.Certificate, erro Type: hcloud.CertificateTypeManaged, DomainNames: domains, } - res, _, err = s.Certificate().CreateCertificate(s, createOpts) + res, _, err = s.Client().Certificate().CreateCertificate(s, createOpts) if err != nil { return nil, err } diff --git a/internal/cmd/certificate/delete.go b/internal/cmd/certificate/delete.go index 9298f1a8..66f51813 100644 --- a/internal/cmd/certificate/delete.go +++ b/internal/cmd/certificate/delete.go @@ -14,11 +14,11 @@ var DeleteCmd = base.DeleteCmd{ ShortDescription: "Delete a certificate", NameSuggestions: func(c hcapi2.Client) func() []string { return c.Firewall().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) { - return s.Certificate().Get(s, idOrName) + return s.Client().Certificate().Get(s, idOrName) }, Delete: func(s state.State, cmd *cobra.Command, resource interface{}) error { certificate := resource.(*hcloud.Certificate) - if _, err := s.Certificate().Delete(s, certificate); err != nil { + if _, err := s.Client().Certificate().Delete(s, certificate); err != nil { return err } return nil diff --git a/internal/cmd/certificate/describe.go b/internal/cmd/certificate/describe.go index 75cfedc8..6573cbc2 100644 --- a/internal/cmd/certificate/describe.go +++ b/internal/cmd/certificate/describe.go @@ -18,7 +18,7 @@ var DescribeCmd = base.DescribeCmd{ JSONKeyGetByName: "certificates", NameSuggestions: func(c hcapi2.Client) func() []string { return c.Certificate().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, interface{}, error) { - cert, _, err := s.Certificate().Get(s, idOrName) + cert, _, err := s.Client().Certificate().Get(s, idOrName) if err != nil { return nil, nil, err } @@ -66,7 +66,7 @@ var DescribeCmd = base.DescribeCmd{ cmd.Printf(" - ID: %d\n", ub.ID) continue } - cmd.Printf(" - Name: %s\n", s.LoadBalancer().LoadBalancerName(ub.ID)) + cmd.Printf(" - Name: %s\n", s.Client().LoadBalancer().LoadBalancerName(ub.ID)) } } return nil diff --git a/internal/cmd/certificate/labels.go b/internal/cmd/certificate/labels.go index 6080b00d..60d1305d 100644 --- a/internal/cmd/certificate/labels.go +++ b/internal/cmd/certificate/labels.go @@ -16,7 +16,7 @@ var LabelCmds = base.LabelCmds{ NameSuggestions: func(c hcapi2.Client) func() []string { return c.Certificate().Names }, LabelKeySuggestions: func(c hcapi2.Client) func(idOrName string) []string { return c.Certificate().LabelKeys }, FetchLabels: func(s state.State, idOrName string) (map[string]string, int64, error) { - certificate, _, err := s.Certificate().Get(s, idOrName) + certificate, _, err := s.Client().Certificate().Get(s, idOrName) if err != nil { return nil, 0, err } @@ -29,7 +29,7 @@ var LabelCmds = base.LabelCmds{ opts := hcloud.CertificateUpdateOpts{ Labels: labels, } - _, _, err := s.Certificate().Update(s, &hcloud.Certificate{ID: id}, opts) + _, _, err := s.Client().Certificate().Update(s, &hcloud.Certificate{ID: id}, opts) return err }, } diff --git a/internal/cmd/certificate/list.go b/internal/cmd/certificate/list.go index d45c29a2..9acc0a19 100644 --- a/internal/cmd/certificate/list.go +++ b/internal/cmd/certificate/list.go @@ -25,7 +25,7 @@ var ListCmd = base.ListCmd{ if len(sorts) > 0 { opts.Sort = sorts } - certificates, err := s.Certificate().AllWithOpts(s, opts) + certificates, err := s.Client().Certificate().AllWithOpts(s, opts) var resources []interface{} for _, n := range certificates { diff --git a/internal/cmd/certificate/update.go b/internal/cmd/certificate/update.go index 55985934..5d347d04 100644 --- a/internal/cmd/certificate/update.go +++ b/internal/cmd/certificate/update.go @@ -15,7 +15,7 @@ var UpdateCmd = base.UpdateCmd{ ShortDescription: "Update a certificate", NameSuggestions: func(c hcapi2.Client) func() []string { return c.Firewall().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) { - return s.Certificate().Get(s, idOrName) + return s.Client().Certificate().Get(s, idOrName) }, DefineFlags: func(cmd *cobra.Command) { cmd.Flags().String("name", "", "Certificate Name") @@ -25,7 +25,7 @@ var UpdateCmd = base.UpdateCmd{ updOpts := hcloud.CertificateUpdateOpts{ Name: flags["name"].String(), } - _, _, err := s.Certificate().Update(s, certificate, updOpts) + _, _, err := s.Client().Certificate().Update(s, certificate, updOpts) if err != nil { return err } diff --git a/internal/cmd/context/create.go b/internal/cmd/context/create.go index 4a33762f..92b6db5c 100644 --- a/internal/cmd/context/create.go +++ b/internal/cmd/context/create.go @@ -85,7 +85,7 @@ func runCreate(s state.State, cmd *cobra.Command, args []string) error { cfg.Contexts = append(cfg.Contexts, context) cfg.ActiveContext = context - if err := s.WriteConfig(); err != nil { + if err := cfg.Write(); err != nil { return err } diff --git a/internal/cmd/context/delete.go b/internal/cmd/context/delete.go index 0c5f5467..89eca4be 100644 --- a/internal/cmd/context/delete.go +++ b/internal/cmd/context/delete.go @@ -35,5 +35,5 @@ func runDelete(s state.State, _ *cobra.Command, args []string) error { cfg.ActiveContext = nil } cfg.RemoveContext(context) - return s.WriteConfig() + return cfg.Write() } diff --git a/internal/cmd/context/use.go b/internal/cmd/context/use.go index e82c4f06..f5d89f1d 100644 --- a/internal/cmd/context/use.go +++ b/internal/cmd/context/use.go @@ -34,5 +34,5 @@ func runUse(s state.State, _ *cobra.Command, args []string) error { return fmt.Errorf("context not found: %v", name) } cfg.ActiveContext = context - return s.WriteConfig() + return cfg.Write() } diff --git a/internal/cmd/datacenter/describe.go b/internal/cmd/datacenter/describe.go index 7d73f88c..132dec36 100644 --- a/internal/cmd/datacenter/describe.go +++ b/internal/cmd/datacenter/describe.go @@ -16,7 +16,7 @@ var DescribeCmd = base.DescribeCmd{ JSONKeyGetByName: "datacenters", NameSuggestions: func(c hcapi2.Client) func() []string { return c.Datacenter().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, interface{}, error) { - dc, _, err := s.Datacenter().Get(s, idOrName) + dc, _, err := s.Client().Datacenter().Get(s, idOrName) if err != nil { return nil, nil, err } @@ -40,8 +40,8 @@ var DescribeCmd = base.DescribeCmd{ printServerTypes := func(list []*hcloud.ServerType) { for _, t := range list { cmd.Printf(" - ID:\t\t %d\n", t.ID) - cmd.Printf(" Name:\t %s\n", s.ServerType().ServerTypeName(t.ID)) - cmd.Printf(" Description: %s\n", s.ServerType().ServerTypeDescription(t.ID)) + cmd.Printf(" Name:\t %s\n", s.Client().ServerType().ServerTypeName(t.ID)) + cmd.Printf(" Description: %s\n", s.Client().ServerType().ServerTypeDescription(t.ID)) } } diff --git a/internal/cmd/datacenter/list.go b/internal/cmd/datacenter/list.go index b74cece3..0894c0d0 100644 --- a/internal/cmd/datacenter/list.go +++ b/internal/cmd/datacenter/list.go @@ -21,7 +21,7 @@ var ListCmd = base.ListCmd{ if len(sorts) > 0 { opts.Sort = sorts } - datacenters, err := s.Datacenter().AllWithOpts(s, opts) + datacenters, err := s.Client().Datacenter().AllWithOpts(s, opts) var resources []interface{} for _, n := range datacenters { resources = append(resources, n) diff --git a/internal/cmd/firewall/add_rule.go b/internal/cmd/firewall/add_rule.go index b220e1f9..736dd0e9 100644 --- a/internal/cmd/firewall/add_rule.go +++ b/internal/cmd/firewall/add_rule.go @@ -49,7 +49,7 @@ var AddRuleCmd = base.Cmd{ description, _ := cmd.Flags().GetString("description") idOrName := args[0] - firewall, _, err := s.Firewall().Get(s, idOrName) + firewall, _, err := s.Client().Firewall().Get(s, idOrName) if err != nil { return err } @@ -106,7 +106,7 @@ var AddRuleCmd = base.Cmd{ rules := append(firewall.Rules, rule) - actions, _, err := s.Firewall().SetRules(s, firewall, + actions, _, err := s.Client().Firewall().SetRules(s, firewall, hcloud.FirewallSetRulesOpts{Rules: rules}, ) if err != nil { diff --git a/internal/cmd/firewall/apply_to_resource.go b/internal/cmd/firewall/apply_to_resource.go index f501ad11..156d03bc 100644 --- a/internal/cmd/firewall/apply_to_resource.go +++ b/internal/cmd/firewall/apply_to_resource.go @@ -53,7 +53,7 @@ var ApplyToResourceCmd = base.Cmd{ serverIdOrName, _ := cmd.Flags().GetString("server") labelSelector, _ := cmd.Flags().GetString("label-selector") idOrName := args[0] - firewall, _, err := s.Firewall().Get(s, idOrName) + firewall, _, err := s.Client().Firewall().Get(s, idOrName) if err != nil { return err } @@ -64,7 +64,7 @@ var ApplyToResourceCmd = base.Cmd{ switch opts.Type { case hcloud.FirewallResourceTypeServer: - server, _, err := s.Server().Get(s, serverIdOrName) + server, _, err := s.Client().Server().Get(s, serverIdOrName) if err != nil { return err } @@ -78,7 +78,7 @@ var ApplyToResourceCmd = base.Cmd{ return fmt.Errorf("unknown type %s", opts.Type) } - actions, _, err := s.Firewall().ApplyResources(s, firewall, []hcloud.FirewallResource{opts}) + actions, _, err := s.Client().Firewall().ApplyResources(s, firewall, []hcloud.FirewallResource{opts}) if err != nil { return err } diff --git a/internal/cmd/firewall/create.go b/internal/cmd/firewall/create.go index d8d024d4..2feb9df5 100644 --- a/internal/cmd/firewall/create.go +++ b/internal/cmd/firewall/create.go @@ -78,7 +78,7 @@ var CreateCmd = base.CreateCmd{ } } - result, _, err := s.Firewall().Create(s, opts) + result, _, err := s.Client().Firewall().Create(s, opts) if err != nil { return nil, nil, err } diff --git a/internal/cmd/firewall/delete.go b/internal/cmd/firewall/delete.go index ca4b0b49..eafce2ba 100644 --- a/internal/cmd/firewall/delete.go +++ b/internal/cmd/firewall/delete.go @@ -14,11 +14,11 @@ var DeleteCmd = base.DeleteCmd{ ShortDescription: "Delete a firewall", NameSuggestions: func(c hcapi2.Client) func() []string { return c.Firewall().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) { - return s.Firewall().Get(s, idOrName) + return s.Client().Firewall().Get(s, idOrName) }, Delete: func(s state.State, cmd *cobra.Command, resource interface{}) error { firewall := resource.(*hcloud.Firewall) - if _, err := s.Firewall().Delete(s, firewall); err != nil { + if _, err := s.Client().Firewall().Delete(s, firewall); err != nil { return err } return nil diff --git a/internal/cmd/firewall/delete_rule.go b/internal/cmd/firewall/delete_rule.go index 804e16e7..59e5d66a 100644 --- a/internal/cmd/firewall/delete_rule.go +++ b/internal/cmd/firewall/delete_rule.go @@ -50,7 +50,7 @@ var DeleteRuleCmd = base.Cmd{ description, _ := cmd.Flags().GetString("description") idOrName := args[0] - firewall, _, err := s.Firewall().Get(s, idOrName) + firewall, _, err := s.Client().Firewall().Get(s, idOrName) if err != nil { return err } @@ -114,7 +114,7 @@ var DeleteRuleCmd = base.Cmd{ if len(rules) == len(firewall.Rules) { return fmt.Errorf("the specified rule was not found in the ruleset of Firewall %d", firewall.ID) } - actions, _, err := s.Firewall().SetRules(s, firewall, + actions, _, err := s.Client().Firewall().SetRules(s, firewall, hcloud.FirewallSetRulesOpts{Rules: rules}, ) if err != nil { diff --git a/internal/cmd/firewall/describe.go b/internal/cmd/firewall/describe.go index b2567541..bdcf3ab9 100644 --- a/internal/cmd/firewall/describe.go +++ b/internal/cmd/firewall/describe.go @@ -20,7 +20,7 @@ var DescribeCmd = base.DescribeCmd{ JSONKeyGetByName: "firewalls", NameSuggestions: func(c hcapi2.Client) func() []string { return c.Firewall().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, interface{}, error) { - fw, _, err := s.Firewall().Get(s, idOrName) + fw, _, err := s.Client().Firewall().Get(s, idOrName) if err != nil { return nil, nil, err } @@ -80,7 +80,7 @@ var DescribeCmd = base.DescribeCmd{ switch resource.Type { case hcloud.FirewallResourceTypeServer: cmd.Printf(" Server ID:\t\t%d\n", resource.Server.ID) - cmd.Printf(" Server Name:\t%s\n", s.Server().ServerName(resource.Server.ID)) + cmd.Printf(" Server Name:\t%s\n", s.Client().Server().ServerName(resource.Server.ID)) case hcloud.FirewallResourceTypeLabelSelector: cmd.Printf(" Label Selector:\t%s\n", resource.LabelSelector.Selector) } diff --git a/internal/cmd/firewall/labels.go b/internal/cmd/firewall/labels.go index 46902535..4c1f9883 100644 --- a/internal/cmd/firewall/labels.go +++ b/internal/cmd/firewall/labels.go @@ -16,7 +16,7 @@ var LabelCmds = base.LabelCmds{ NameSuggestions: func(c hcapi2.Client) func() []string { return c.Firewall().Names }, LabelKeySuggestions: func(c hcapi2.Client) func(idOrName string) []string { return c.Firewall().LabelKeys }, FetchLabels: func(s state.State, idOrName string) (map[string]string, int64, error) { - firewall, _, err := s.Firewall().Get(s, idOrName) + firewall, _, err := s.Client().Firewall().Get(s, idOrName) if err != nil { return nil, 0, err } @@ -29,7 +29,7 @@ var LabelCmds = base.LabelCmds{ opts := hcloud.FirewallUpdateOpts{ Labels: labels, } - _, _, err := s.Firewall().Update(s, &hcloud.Firewall{ID: id}, opts) + _, _, err := s.Client().Firewall().Update(s, &hcloud.Firewall{ID: id}, opts) return err }, } diff --git a/internal/cmd/firewall/list.go b/internal/cmd/firewall/list.go index 919c65ec..a983840e 100644 --- a/internal/cmd/firewall/list.go +++ b/internal/cmd/firewall/list.go @@ -23,7 +23,7 @@ var ListCmd = base.ListCmd{ if len(sorts) > 0 { opts.Sort = sorts } - firewalls, err := s.Firewall().AllWithOpts(s, opts) + firewalls, err := s.Client().Firewall().AllWithOpts(s, opts) var resources []interface{} for _, n := range firewalls { diff --git a/internal/cmd/firewall/remove_from_resource.go b/internal/cmd/firewall/remove_from_resource.go index c4211acf..c2ab8e98 100644 --- a/internal/cmd/firewall/remove_from_resource.go +++ b/internal/cmd/firewall/remove_from_resource.go @@ -53,7 +53,7 @@ var RemoveFromResourceCmd = base.Cmd{ labelSelector, _ := cmd.Flags().GetString("label-selector") idOrName := args[0] - firewall, _, err := s.Firewall().Get(s, idOrName) + firewall, _, err := s.Client().Firewall().Get(s, idOrName) if err != nil { return err } @@ -64,7 +64,7 @@ var RemoveFromResourceCmd = base.Cmd{ switch opts.Type { case hcloud.FirewallResourceTypeServer: - server, _, err := s.Server().Get(s, serverIdOrName) + server, _, err := s.Client().Server().Get(s, serverIdOrName) if err != nil { return err } @@ -77,7 +77,7 @@ var RemoveFromResourceCmd = base.Cmd{ default: return fmt.Errorf("unknown type %s", opts.Type) } - actions, _, err := s.Firewall().RemoveResources(s, firewall, []hcloud.FirewallResource{opts}) + actions, _, err := s.Client().Firewall().RemoveResources(s, firewall, []hcloud.FirewallResource{opts}) if err != nil { return err } diff --git a/internal/cmd/firewall/replace_rules.go b/internal/cmd/firewall/replace_rules.go index 3ea90aca..4e6eaa7a 100644 --- a/internal/cmd/firewall/replace_rules.go +++ b/internal/cmd/firewall/replace_rules.go @@ -33,7 +33,7 @@ var ReplaceRulesCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - firewall, _, err := s.Firewall().Get(s, idOrName) + firewall, _, err := s.Client().Firewall().Get(s, idOrName) if err != nil { return err } @@ -90,7 +90,7 @@ var ReplaceRulesCmd = base.Cmd{ opts.Rules = append(opts.Rules, r) } - actions, _, err := s.Firewall().SetRules(s, firewall, opts) + actions, _, err := s.Client().Firewall().SetRules(s, firewall, opts) if err != nil { return err } diff --git a/internal/cmd/firewall/update.go b/internal/cmd/firewall/update.go index 8767b80e..18cf7fbc 100644 --- a/internal/cmd/firewall/update.go +++ b/internal/cmd/firewall/update.go @@ -15,7 +15,7 @@ var UpdateCmd = base.UpdateCmd{ ShortDescription: "Update a firewall", NameSuggestions: func(c hcapi2.Client) func() []string { return c.Firewall().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) { - return s.Firewall().Get(s, idOrName) + return s.Client().Firewall().Get(s, idOrName) }, DefineFlags: func(cmd *cobra.Command) { cmd.Flags().String("name", "", "Firewall name") @@ -25,7 +25,7 @@ var UpdateCmd = base.UpdateCmd{ updOpts := hcloud.FirewallUpdateOpts{ Name: flags["name"].String(), } - _, _, err := s.Firewall().Update(s, firewall, updOpts) + _, _, err := s.Client().Firewall().Update(s, firewall, updOpts) if err != nil { return err } diff --git a/internal/cmd/floatingip/assign.go b/internal/cmd/floatingip/assign.go index f0b6b2c2..40865898 100644 --- a/internal/cmd/floatingip/assign.go +++ b/internal/cmd/floatingip/assign.go @@ -27,7 +27,7 @@ var AssignCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - floatingIP, _, err := s.FloatingIP().Get(s, idOrName) + floatingIP, _, err := s.Client().FloatingIP().Get(s, idOrName) if err != nil { return err } @@ -36,7 +36,7 @@ var AssignCmd = base.Cmd{ } serverIDOrName := args[1] - server, _, err := s.Server().Get(s, serverIDOrName) + server, _, err := s.Client().Server().Get(s, serverIDOrName) if err != nil { return err } @@ -44,7 +44,7 @@ var AssignCmd = base.Cmd{ return fmt.Errorf("server not found: %s", serverIDOrName) } - action, _, err := s.FloatingIP().Assign(s, floatingIP, server) + action, _, err := s.Client().FloatingIP().Assign(s, floatingIP, server) if err != nil { return err } diff --git a/internal/cmd/floatingip/create.go b/internal/cmd/floatingip/create.go index dadd3ecd..33765b73 100644 --- a/internal/cmd/floatingip/create.go +++ b/internal/cmd/floatingip/create.go @@ -79,7 +79,7 @@ var CreateCmd = base.CreateCmd{ createOpts.HomeLocation = &hcloud.Location{Name: homeLocation} } if serverNameOrID != "" { - server, _, err := s.Server().Get(s, serverNameOrID) + server, _, err := s.Client().Server().Get(s, serverNameOrID) if err != nil { return nil, nil, err } @@ -89,7 +89,7 @@ var CreateCmd = base.CreateCmd{ createOpts.Server = server } - result, _, err := s.FloatingIP().Create(s, createOpts) + result, _, err := s.Client().FloatingIP().Create(s, createOpts) if err != nil { return nil, nil, err } diff --git a/internal/cmd/floatingip/delete.go b/internal/cmd/floatingip/delete.go index 66139746..010b603f 100644 --- a/internal/cmd/floatingip/delete.go +++ b/internal/cmd/floatingip/delete.go @@ -14,11 +14,11 @@ var DeleteCmd = base.DeleteCmd{ ShortDescription: "Delete a Floating IP", NameSuggestions: func(c hcapi2.Client) func() []string { return c.FloatingIP().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) { - return s.FloatingIP().Get(s, idOrName) + return s.Client().FloatingIP().Get(s, idOrName) }, Delete: func(s state.State, cmd *cobra.Command, resource interface{}) error { floatingIP := resource.(*hcloud.FloatingIP) - if _, err := s.FloatingIP().Delete(s, floatingIP); err != nil { + if _, err := s.Client().FloatingIP().Delete(s, floatingIP); err != nil { return err } return nil diff --git a/internal/cmd/floatingip/describe.go b/internal/cmd/floatingip/describe.go index 8111abfa..0bfae839 100644 --- a/internal/cmd/floatingip/describe.go +++ b/internal/cmd/floatingip/describe.go @@ -18,7 +18,7 @@ var DescribeCmd = base.DescribeCmd{ JSONKeyGetByName: "floating_ips", NameSuggestions: func(c hcapi2.Client) func() []string { return c.FloatingIP().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, interface{}, error) { - ip, _, err := s.FloatingIP().Get(s, idOrName) + ip, _, err := s.Client().FloatingIP().Get(s, idOrName) if err != nil { return nil, nil, err } @@ -42,7 +42,7 @@ var DescribeCmd = base.DescribeCmd{ if floatingIP.Server != nil { cmd.Printf("Server:\n") cmd.Printf(" ID:\t%d\n", floatingIP.Server.ID) - cmd.Printf(" Name:\t%s\n", s.Server().ServerName(floatingIP.Server.ID)) + cmd.Printf(" Name:\t%s\n", s.Client().Server().ServerName(floatingIP.Server.ID)) } else { cmd.Print("Server:\n Not assigned\n") } diff --git a/internal/cmd/floatingip/disable_protection.go b/internal/cmd/floatingip/disable_protection.go index 5274f0cb..3c7cb60f 100644 --- a/internal/cmd/floatingip/disable_protection.go +++ b/internal/cmd/floatingip/disable_protection.go @@ -27,7 +27,7 @@ var DisableProtectionCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - floatingIP, _, err := s.FloatingIP().Get(s, idOrName) + floatingIP, _, err := s.Client().FloatingIP().Get(s, idOrName) if err != nil { return err } diff --git a/internal/cmd/floatingip/enable_protection.go b/internal/cmd/floatingip/enable_protection.go index 484ccc60..e236c2ca 100644 --- a/internal/cmd/floatingip/enable_protection.go +++ b/internal/cmd/floatingip/enable_protection.go @@ -40,7 +40,7 @@ func changeProtection(s state.State, cmd *cobra.Command, return nil } - action, _, err := s.FloatingIP().ChangeProtection(s, floatingIP, opts) + action, _, err := s.Client().FloatingIP().ChangeProtection(s, floatingIP, opts) if err != nil { return err } @@ -74,7 +74,7 @@ var EnableProtectionCmd = base.Cmd{ Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - floatingIP, _, err := s.FloatingIP().Get(s, idOrName) + floatingIP, _, err := s.Client().FloatingIP().Get(s, idOrName) if err != nil { return err } diff --git a/internal/cmd/floatingip/labels.go b/internal/cmd/floatingip/labels.go index 6526ab68..a63a7598 100644 --- a/internal/cmd/floatingip/labels.go +++ b/internal/cmd/floatingip/labels.go @@ -16,7 +16,7 @@ var LabelCmds = base.LabelCmds{ NameSuggestions: func(c hcapi2.Client) func() []string { return c.FloatingIP().Names }, LabelKeySuggestions: func(c hcapi2.Client) func(idOrName string) []string { return c.FloatingIP().LabelKeys }, FetchLabels: func(s state.State, idOrName string) (map[string]string, int64, error) { - floatingIP, _, err := s.FloatingIP().Get(s, idOrName) + floatingIP, _, err := s.Client().FloatingIP().Get(s, idOrName) if err != nil { return nil, 0, err } @@ -29,7 +29,7 @@ var LabelCmds = base.LabelCmds{ opts := hcloud.FloatingIPUpdateOpts{ Labels: labels, } - _, _, err := s.FloatingIP().Update(s, &hcloud.FloatingIP{ID: id}, opts) + _, _, err := s.Client().FloatingIP().Update(s, &hcloud.FloatingIP{ID: id}, opts) return err }, } diff --git a/internal/cmd/floatingip/list.go b/internal/cmd/floatingip/list.go index 9ec312c5..c2710642 100644 --- a/internal/cmd/floatingip/list.go +++ b/internal/cmd/floatingip/list.go @@ -26,7 +26,7 @@ var ListCmd = base.ListCmd{ if len(sorts) > 0 { opts.Sort = sorts } - floatingIPs, err := s.FloatingIP().AllWithOpts(s, opts) + floatingIPs, err := s.Client().FloatingIP().AllWithOpts(s, opts) var resources []interface{} for _, n := range floatingIPs { diff --git a/internal/cmd/floatingip/set_rdns.go b/internal/cmd/floatingip/set_rdns.go index d910621d..b1d387a8 100644 --- a/internal/cmd/floatingip/set_rdns.go +++ b/internal/cmd/floatingip/set_rdns.go @@ -16,7 +16,7 @@ var SetRDNSCmd = base.SetRdnsCmd{ ShortDescription: "Change reverse DNS of a Floating IP", NameSuggestions: func(c hcapi2.Client) func() []string { return c.FloatingIP().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) { - return s.FloatingIP().Get(s, idOrName) + return s.Client().FloatingIP().Get(s, idOrName) }, GetDefaultIP: func(resource interface{}) net.IP { floatingIP := resource.(*hcloud.FloatingIP) diff --git a/internal/cmd/floatingip/unassign.go b/internal/cmd/floatingip/unassign.go index a3972dd5..d59837f8 100644 --- a/internal/cmd/floatingip/unassign.go +++ b/internal/cmd/floatingip/unassign.go @@ -24,7 +24,7 @@ var UnassignCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - floatingIP, _, err := s.FloatingIP().Get(s, idOrName) + floatingIP, _, err := s.Client().FloatingIP().Get(s, idOrName) if err != nil { return err } @@ -32,7 +32,7 @@ var UnassignCmd = base.Cmd{ return fmt.Errorf("Floating IP not found: %v", idOrName) } - action, _, err := s.FloatingIP().Unassign(s, floatingIP) + action, _, err := s.Client().FloatingIP().Unassign(s, floatingIP) if err != nil { return err } diff --git a/internal/cmd/floatingip/update.go b/internal/cmd/floatingip/update.go index 56a0b2f9..4a0175a2 100644 --- a/internal/cmd/floatingip/update.go +++ b/internal/cmd/floatingip/update.go @@ -15,7 +15,7 @@ var UpdateCmd = base.UpdateCmd{ ShortDescription: "Update a Floating IP", NameSuggestions: func(c hcapi2.Client) func() []string { return c.FloatingIP().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) { - return s.FloatingIP().Get(s, idOrName) + return s.Client().FloatingIP().Get(s, idOrName) }, DefineFlags: func(cmd *cobra.Command) { cmd.Flags().String("name", "", "Floating IP name") @@ -27,7 +27,7 @@ var UpdateCmd = base.UpdateCmd{ Name: flags["name"].String(), Description: flags["description"].String(), } - _, _, err := s.FloatingIP().Update(s, floatingIP, updOpts) + _, _, err := s.Client().FloatingIP().Update(s, floatingIP, updOpts) if err != nil { return err } diff --git a/internal/cmd/image/delete.go b/internal/cmd/image/delete.go index 55f79ab9..1f7f8cd9 100644 --- a/internal/cmd/image/delete.go +++ b/internal/cmd/image/delete.go @@ -14,11 +14,11 @@ var DeleteCmd = base.DeleteCmd{ ShortDescription: "Delete an image", NameSuggestions: func(c hcapi2.Client) func() []string { return c.Image().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) { - return s.Image().Get(s, idOrName) + return s.Client().Image().Get(s, idOrName) }, Delete: func(s state.State, cmd *cobra.Command, resource interface{}) error { image := resource.(*hcloud.Image) - if _, err := s.Image().Delete(s, image); err != nil { + if _, err := s.Client().Image().Delete(s, image); err != nil { return err } return nil diff --git a/internal/cmd/image/describe.go b/internal/cmd/image/describe.go index a2142b6b..327e22fa 100644 --- a/internal/cmd/image/describe.go +++ b/internal/cmd/image/describe.go @@ -34,7 +34,7 @@ var DescribeCmd = base.DescribeCmd{ if !cmd.Flags().Changed("architecture") { _, _ = fmt.Fprintln(os.Stderr, "INFO: This command only returns x86 images by default. Explicitly set the --architecture=x86|arm flag to hide this message.") } - img, _, err := s.Image().GetForArchitecture(s, idOrName, hcloud.Architecture(arch)) + img, _, err := s.Client().Image().GetForArchitecture(s, idOrName, hcloud.Architecture(arch)) if err != nil { return nil, nil, err } diff --git a/internal/cmd/image/enable_protection.go b/internal/cmd/image/enable_protection.go index 0d5f9a67..3bac739e 100644 --- a/internal/cmd/image/enable_protection.go +++ b/internal/cmd/image/enable_protection.go @@ -42,7 +42,7 @@ func changeProtection(s state.State, cmd *cobra.Command, return nil } - action, _, err := s.Image().ChangeProtection(s, image, opts) + action, _, err := s.Client().Image().ChangeProtection(s, image, opts) if err != nil { return err } diff --git a/internal/cmd/image/labels.go b/internal/cmd/image/labels.go index 851c0da4..e1ae3849 100644 --- a/internal/cmd/image/labels.go +++ b/internal/cmd/image/labels.go @@ -16,7 +16,7 @@ var LabelCmds = base.LabelCmds{ NameSuggestions: func(c hcapi2.Client) func() []string { return c.Image().Names }, LabelKeySuggestions: func(c hcapi2.Client) func(idOrName string) []string { return c.Image().LabelKeys }, FetchLabels: func(s state.State, idOrName string) (map[string]string, int64, error) { - image, _, err := s.Image().Get(s, idOrName) + image, _, err := s.Client().Image().Get(s, idOrName) if err != nil { return nil, 0, err } @@ -29,7 +29,7 @@ var LabelCmds = base.LabelCmds{ opts := hcloud.ImageUpdateOpts{ Labels: labels, } - _, _, err := s.Image().Update(s, &hcloud.Image{ID: id}, opts) + _, _, err := s.Client().Image().Update(s, &hcloud.Image{ID: id}, opts) return err }, } diff --git a/internal/cmd/image/list.go b/internal/cmd/image/list.go index 7ef3dccc..67178cd5 100644 --- a/internal/cmd/image/list.go +++ b/internal/cmd/image/list.go @@ -60,7 +60,7 @@ var ListCmd = base.ListCmd{ opts.Sort = sorts } - images, err := s.Image().AllWithOpts(s, opts) + images, err := s.Client().Image().AllWithOpts(s, opts) var resources []interface{} for _, n := range images { diff --git a/internal/cmd/image/update.go b/internal/cmd/image/update.go index 1292802f..75e2562f 100644 --- a/internal/cmd/image/update.go +++ b/internal/cmd/image/update.go @@ -16,7 +16,7 @@ var UpdateCmd = base.UpdateCmd{ ShortDescription: "Update an image", NameSuggestions: func(c hcapi2.Client) func() []string { return c.Image().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) { - return s.Image().Get(s, idOrName) + return s.Client().Image().Get(s, idOrName) }, DefineFlags: func(cmd *cobra.Command) { cmd.Flags().String("description", "", "Image description") @@ -29,7 +29,7 @@ var UpdateCmd = base.UpdateCmd{ Description: hcloud.String(flags["description"].String()), Type: hcloud.ImageType(flags["type"].String()), } - _, _, err := s.Image().Update(s, image, updOpts) + _, _, err := s.Client().Image().Update(s, image, updOpts) if err != nil { return err } diff --git a/internal/cmd/iso/describe.go b/internal/cmd/iso/describe.go index 6b5c5c60..f14b3d84 100644 --- a/internal/cmd/iso/describe.go +++ b/internal/cmd/iso/describe.go @@ -18,7 +18,7 @@ var DescribeCmd = base.DescribeCmd{ JSONKeyGetByName: "isos", NameSuggestions: func(c hcapi2.Client) func() []string { return c.Location().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, interface{}, error) { - iso, _, err := s.ISO().Get(s, idOrName) + iso, _, err := s.Client().ISO().Get(s, idOrName) if err != nil { return nil, nil, err } diff --git a/internal/cmd/iso/list.go b/internal/cmd/iso/list.go index 056da67f..2eebd966 100644 --- a/internal/cmd/iso/list.go +++ b/internal/cmd/iso/list.go @@ -65,7 +65,7 @@ var ListCmd = base.ListCmd{ opts.Sort = sorts } - isos, err := s.ISO().AllWithOpts(s, opts) + isos, err := s.Client().ISO().AllWithOpts(s, opts) var resources []interface{} for _, iso := range isos { diff --git a/internal/cmd/loadbalancer/add_service.go b/internal/cmd/loadbalancer/add_service.go index 772b85be..125e9904 100644 --- a/internal/cmd/loadbalancer/add_service.go +++ b/internal/cmd/loadbalancer/add_service.go @@ -82,7 +82,7 @@ var AddServiceCmd = base.Cmd{ httpCookieLifetime, _ := cmd.Flags().GetDuration("http-cookie-lifetime") httpRedirect, _ := cmd.Flags().GetBool("http-redirect-http") - loadBalancer, _, err := s.LoadBalancer().Get(s, idOrName) + loadBalancer, _, err := s.Client().LoadBalancer().Get(s, idOrName) if err != nil { return err } @@ -117,7 +117,7 @@ var AddServiceCmd = base.Cmd{ opts.HTTP.Certificates = append(opts.HTTP.Certificates, &hcloud.Certificate{ID: certificateID}) } } - action, _, err := s.LoadBalancer().AddService(s, loadBalancer, opts) + action, _, err := s.Client().LoadBalancer().AddService(s, loadBalancer, opts) if err != nil { return err } diff --git a/internal/cmd/loadbalancer/add_target.go b/internal/cmd/loadbalancer/add_target.go index cf0aed66..781668c5 100644 --- a/internal/cmd/loadbalancer/add_target.go +++ b/internal/cmd/loadbalancer/add_target.go @@ -50,7 +50,7 @@ var AddTargetCmd = base.Cmd{ if !util.ExactlyOneSet(serverIDOrName, labelSelector, ipAddr) { return fmt.Errorf("--server, --label-selector, and --ip are mutually exclusive") } - if loadBalancer, _, err = s.LoadBalancer().Get(s, idOrName); err != nil { + if loadBalancer, _, err = s.Client().LoadBalancer().Get(s, idOrName); err != nil { return err } if loadBalancer == nil { @@ -59,14 +59,14 @@ var AddTargetCmd = base.Cmd{ switch { case serverIDOrName != "": - server, _, err := s.Server().Get(s, serverIDOrName) + server, _, err := s.Client().Server().Get(s, serverIDOrName) if err != nil { return err } if server == nil { return fmt.Errorf("server not found: %s", serverIDOrName) } - action, _, err = s.LoadBalancer().AddServerTarget(s, loadBalancer, hcloud.LoadBalancerAddServerTargetOpts{ + action, _, err = s.Client().LoadBalancer().AddServerTarget(s, loadBalancer, hcloud.LoadBalancerAddServerTargetOpts{ Server: server, UsePrivateIP: hcloud.Bool(usePrivateIP), }) @@ -74,7 +74,7 @@ var AddTargetCmd = base.Cmd{ return err } case labelSelector != "": - action, _, err = s.LoadBalancer().AddLabelSelectorTarget(s, loadBalancer, hcloud.LoadBalancerAddLabelSelectorTargetOpts{ + action, _, err = s.Client().LoadBalancer().AddLabelSelectorTarget(s, loadBalancer, hcloud.LoadBalancerAddLabelSelectorTargetOpts{ Selector: labelSelector, UsePrivateIP: hcloud.Bool(usePrivateIP), }) @@ -86,7 +86,7 @@ var AddTargetCmd = base.Cmd{ if ip == nil { return fmt.Errorf("invalid ip provided") } - action, _, err = s.LoadBalancer().AddIPTarget(s, loadBalancer, hcloud.LoadBalancerAddIPTargetOpts{ + action, _, err = s.Client().LoadBalancer().AddIPTarget(s, loadBalancer, hcloud.LoadBalancerAddIPTargetOpts{ IP: ip, }) if err != nil { diff --git a/internal/cmd/loadbalancer/attach_to_network.go b/internal/cmd/loadbalancer/attach_to_network.go index c400defc..63432446 100644 --- a/internal/cmd/loadbalancer/attach_to_network.go +++ b/internal/cmd/loadbalancer/attach_to_network.go @@ -33,7 +33,7 @@ var AttachToNetworkCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - loadBalancer, _, err := s.LoadBalancer().Get(s, idOrName) + loadBalancer, _, err := s.Client().LoadBalancer().Get(s, idOrName) if err != nil { return err } @@ -42,7 +42,7 @@ var AttachToNetworkCmd = base.Cmd{ } networkIDOrName, _ := cmd.Flags().GetString("network") - network, _, err := s.Network().Get(s, networkIDOrName) + network, _, err := s.Client().Network().Get(s, networkIDOrName) if err != nil { return err } @@ -56,7 +56,7 @@ var AttachToNetworkCmd = base.Cmd{ Network: network, IP: ip, } - action, _, err := s.LoadBalancer().AttachToNetwork(s, loadBalancer, opts) + action, _, err := s.Client().LoadBalancer().AttachToNetwork(s, loadBalancer, opts) if err != nil { return err diff --git a/internal/cmd/loadbalancer/change_algorithm.go b/internal/cmd/loadbalancer/change_algorithm.go index 89223024..75507729 100644 --- a/internal/cmd/loadbalancer/change_algorithm.go +++ b/internal/cmd/loadbalancer/change_algorithm.go @@ -35,7 +35,7 @@ var ChangeAlgorithmCmd = base.Cmd{ Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] algorithm, _ := cmd.Flags().GetString("algorithm-type") - loadBalancer, _, err := s.LoadBalancer().Get(s, idOrName) + loadBalancer, _, err := s.Client().LoadBalancer().Get(s, idOrName) if err != nil { return err } @@ -43,7 +43,7 @@ var ChangeAlgorithmCmd = base.Cmd{ return fmt.Errorf("Load Balancer not found: %s", idOrName) } - action, _, err := s.LoadBalancer().ChangeAlgorithm(s, loadBalancer, hcloud.LoadBalancerChangeAlgorithmOpts{Type: hcloud.LoadBalancerAlgorithmType(algorithm)}) + action, _, err := s.Client().LoadBalancer().ChangeAlgorithm(s, loadBalancer, hcloud.LoadBalancerChangeAlgorithmOpts{Type: hcloud.LoadBalancerAlgorithmType(algorithm)}) if err != nil { return err } diff --git a/internal/cmd/loadbalancer/change_type.go b/internal/cmd/loadbalancer/change_type.go index b32b8fa9..0a589ce5 100644 --- a/internal/cmd/loadbalancer/change_type.go +++ b/internal/cmd/loadbalancer/change_type.go @@ -28,7 +28,7 @@ var ChangeTypeCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - loadBalancer, _, err := s.LoadBalancer().Get(s, idOrName) + loadBalancer, _, err := s.Client().LoadBalancer().Get(s, idOrName) if err != nil { return err } @@ -37,7 +37,7 @@ var ChangeTypeCmd = base.Cmd{ } loadBalancerTypeIDOrName := args[1] - loadBalancerType, _, err := s.LoadBalancerType().Get(s, loadBalancerTypeIDOrName) + loadBalancerType, _, err := s.Client().LoadBalancerType().Get(s, loadBalancerTypeIDOrName) if err != nil { return err } @@ -48,7 +48,7 @@ var ChangeTypeCmd = base.Cmd{ opts := hcloud.LoadBalancerChangeTypeOpts{ LoadBalancerType: loadBalancerType, } - action, _, err := s.LoadBalancer().ChangeType(s, loadBalancer, opts) + action, _, err := s.Client().LoadBalancer().ChangeType(s, loadBalancer, opts) if err != nil { return err } diff --git a/internal/cmd/loadbalancer/create.go b/internal/cmd/loadbalancer/create.go index 924f981a..59d338b6 100644 --- a/internal/cmd/loadbalancer/create.go +++ b/internal/cmd/loadbalancer/create.go @@ -76,7 +76,7 @@ var CreateCmd = base.CreateCmd{ if location != "" { createOpts.Location = &hcloud.Location{Name: location} } - result, _, err := s.LoadBalancer().Create(s, createOpts) + result, _, err := s.Client().LoadBalancer().Create(s, createOpts) if err != nil { return nil, nil, err } @@ -84,7 +84,7 @@ var CreateCmd = base.CreateCmd{ if err := s.ActionProgress(cmd, s, result.Action); err != nil { return nil, nil, err } - loadBalancer, _, err := s.LoadBalancer().GetByID(s, result.LoadBalancer.ID) + loadBalancer, _, err := s.Client().LoadBalancer().GetByID(s, result.LoadBalancer.ID) if err != nil { return nil, nil, err } diff --git a/internal/cmd/loadbalancer/delete.go b/internal/cmd/loadbalancer/delete.go index 6f665739..de5a1816 100644 --- a/internal/cmd/loadbalancer/delete.go +++ b/internal/cmd/loadbalancer/delete.go @@ -14,11 +14,11 @@ var DeleteCmd = base.DeleteCmd{ ShortDescription: "Delete a Load Balancer", NameSuggestions: func(c hcapi2.Client) func() []string { return c.LoadBalancer().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) { - return s.LoadBalancer().Get(s, idOrName) + return s.Client().LoadBalancer().Get(s, idOrName) }, Delete: func(s state.State, cmd *cobra.Command, resource interface{}) error { loadBalancer := resource.(*hcloud.LoadBalancer) - if _, err := s.LoadBalancer().Delete(s, loadBalancer); err != nil { + if _, err := s.Client().LoadBalancer().Delete(s, loadBalancer); err != nil { return err } return nil diff --git a/internal/cmd/loadbalancer/delete_service.go b/internal/cmd/loadbalancer/delete_service.go index 5cd15965..4300c33e 100644 --- a/internal/cmd/loadbalancer/delete_service.go +++ b/internal/cmd/loadbalancer/delete_service.go @@ -29,14 +29,14 @@ var DeleteServiceCmd = base.Cmd{ Run: func(s state.State, cmd *cobra.Command, args []string) error { listenPort, _ := cmd.Flags().GetInt("listen-port") idOrName := args[0] - loadBalancer, _, err := s.LoadBalancer().Get(s, idOrName) + loadBalancer, _, err := s.Client().LoadBalancer().Get(s, idOrName) if err != nil { return err } if loadBalancer == nil { return fmt.Errorf("Load Balancer not found: %s", idOrName) } - _, _, err = s.LoadBalancer().DeleteService(s, loadBalancer, listenPort) + _, _, err = s.Client().LoadBalancer().DeleteService(s, loadBalancer, listenPort) if err != nil { return err } diff --git a/internal/cmd/loadbalancer/describe.go b/internal/cmd/loadbalancer/describe.go index ecd30312..92041e6a 100644 --- a/internal/cmd/loadbalancer/describe.go +++ b/internal/cmd/loadbalancer/describe.go @@ -19,7 +19,7 @@ var DescribeCmd = base.DescribeCmd{ JSONKeyGetByName: "load_balancers", NameSuggestions: func(c hcapi2.Client) func() []string { return c.LoadBalancer().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, interface{}, error) { - lb, _, err := s.LoadBalancer().Get(s, idOrName) + lb, _, err := s.Client().LoadBalancer().Get(s, idOrName) if err != nil { return nil, nil, err } @@ -45,7 +45,7 @@ var DescribeCmd = base.DescribeCmd{ if len(loadBalancer.PrivateNet) > 0 { for _, n := range loadBalancer.PrivateNet { cmd.Printf(" - ID:\t\t\t%d\n", n.Network.ID) - cmd.Printf(" Name:\t\t%s\n", s.Network().Name(n.Network.ID)) + cmd.Printf(" Name:\t\t%s\n", s.Client().Network().Name(n.Network.ID)) cmd.Printf(" IP:\t\t\t%s\n", n.IP.String()) } } else { @@ -110,7 +110,7 @@ var DescribeCmd = base.DescribeCmd{ case hcloud.LoadBalancerTargetTypeServer: cmd.Printf(" Server:\n") cmd.Printf(" ID:\t\t\t%d\n", target.Server.Server.ID) - cmd.Printf(" Name:\t\t\t%s\n", s.Server().ServerName(target.Server.Server.ID)) + cmd.Printf(" Name:\t\t\t%s\n", s.Client().Server().ServerName(target.Server.Server.ID)) cmd.Printf(" Use Private IP:\t\t%s\n", util.YesNo(target.UsePrivateIP)) cmd.Printf(" Status:\n") for _, healthStatus := range target.HealthStatus { diff --git a/internal/cmd/loadbalancer/detach_from_network.go b/internal/cmd/loadbalancer/detach_from_network.go index 1249c12e..18d405ab 100644 --- a/internal/cmd/loadbalancer/detach_from_network.go +++ b/internal/cmd/loadbalancer/detach_from_network.go @@ -29,7 +29,7 @@ var DetachFromNetworkCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - loadBalancer, _, err := s.LoadBalancer().Get(s, idOrName) + loadBalancer, _, err := s.Client().LoadBalancer().Get(s, idOrName) if err != nil { return err } @@ -37,7 +37,7 @@ var DetachFromNetworkCmd = base.Cmd{ return fmt.Errorf("Load Balancer not found: %s", idOrName) } networkIDOrName, _ := cmd.Flags().GetString("network") - network, _, err := s.Network().Get(s, networkIDOrName) + network, _, err := s.Client().Network().Get(s, networkIDOrName) if err != nil { return err } @@ -48,7 +48,7 @@ var DetachFromNetworkCmd = base.Cmd{ opts := hcloud.LoadBalancerDetachFromNetworkOpts{ Network: network, } - action, _, err := s.LoadBalancer().DetachFromNetwork(s, loadBalancer, opts) + action, _, err := s.Client().LoadBalancer().DetachFromNetwork(s, loadBalancer, opts) if err != nil { return err } diff --git a/internal/cmd/loadbalancer/disable_protection.go b/internal/cmd/loadbalancer/disable_protection.go index 5de5c68a..c22c17d7 100644 --- a/internal/cmd/loadbalancer/disable_protection.go +++ b/internal/cmd/loadbalancer/disable_protection.go @@ -27,7 +27,7 @@ var DisableProtectionCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - loadBalancer, _, err := s.LoadBalancer().Get(s, idOrName) + loadBalancer, _, err := s.Client().LoadBalancer().Get(s, idOrName) if err != nil { return err } diff --git a/internal/cmd/loadbalancer/disable_public_interface.go b/internal/cmd/loadbalancer/disable_public_interface.go index ff4d87de..ac69db54 100644 --- a/internal/cmd/loadbalancer/disable_public_interface.go +++ b/internal/cmd/loadbalancer/disable_public_interface.go @@ -24,7 +24,7 @@ var DisablePublicInterfaceCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - loadBalancer, _, err := s.LoadBalancer().Get(s, idOrName) + loadBalancer, _, err := s.Client().LoadBalancer().Get(s, idOrName) if err != nil { return err } @@ -32,7 +32,7 @@ var DisablePublicInterfaceCmd = base.Cmd{ return fmt.Errorf("Load Balancer not found: %s", idOrName) } - action, _, err := s.LoadBalancer().DisablePublicInterface(s, loadBalancer) + action, _, err := s.Client().LoadBalancer().DisablePublicInterface(s, loadBalancer) if err != nil { return err } diff --git a/internal/cmd/loadbalancer/enable_protection.go b/internal/cmd/loadbalancer/enable_protection.go index a436315c..470e504e 100644 --- a/internal/cmd/loadbalancer/enable_protection.go +++ b/internal/cmd/loadbalancer/enable_protection.go @@ -40,7 +40,7 @@ func changeProtection(s state.State, cmd *cobra.Command, return nil } - action, _, err := s.LoadBalancer().ChangeProtection(s, loadBalancer, opts) + action, _, err := s.Client().LoadBalancer().ChangeProtection(s, loadBalancer, opts) if err != nil { return err } @@ -73,7 +73,7 @@ var EnableProtectionCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - loadBalancer, _, err := s.LoadBalancer().Get(s, idOrName) + loadBalancer, _, err := s.Client().LoadBalancer().Get(s, idOrName) if err != nil { return err } diff --git a/internal/cmd/loadbalancer/enable_public_interface.go b/internal/cmd/loadbalancer/enable_public_interface.go index 580051ed..dc09f6a8 100644 --- a/internal/cmd/loadbalancer/enable_public_interface.go +++ b/internal/cmd/loadbalancer/enable_public_interface.go @@ -24,7 +24,7 @@ var EnablePublicInterfaceCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - loadBalancer, _, err := s.LoadBalancer().Get(s, idOrName) + loadBalancer, _, err := s.Client().LoadBalancer().Get(s, idOrName) if err != nil { return err } @@ -32,7 +32,7 @@ var EnablePublicInterfaceCmd = base.Cmd{ return fmt.Errorf("Load Balancer not found: %s", idOrName) } - action, _, err := s.LoadBalancer().EnablePublicInterface(s, loadBalancer) + action, _, err := s.Client().LoadBalancer().EnablePublicInterface(s, loadBalancer) if err != nil { return err } diff --git a/internal/cmd/loadbalancer/labels.go b/internal/cmd/loadbalancer/labels.go index 10b6e9ca..c7c19d74 100644 --- a/internal/cmd/loadbalancer/labels.go +++ b/internal/cmd/loadbalancer/labels.go @@ -16,7 +16,7 @@ var LabelCmds = base.LabelCmds{ NameSuggestions: func(c hcapi2.Client) func() []string { return c.LoadBalancer().Names }, LabelKeySuggestions: func(c hcapi2.Client) func(idOrName string) []string { return c.LoadBalancer().LabelKeys }, FetchLabels: func(s state.State, idOrName string) (map[string]string, int64, error) { - loadBalancer, _, err := s.LoadBalancer().Get(s, idOrName) + loadBalancer, _, err := s.Client().LoadBalancer().Get(s, idOrName) if err != nil { return nil, 0, err } @@ -29,7 +29,7 @@ var LabelCmds = base.LabelCmds{ opts := hcloud.LoadBalancerUpdateOpts{ Labels: labels, } - _, _, err := s.LoadBalancer().Update(s, &hcloud.LoadBalancer{ID: id}, opts) + _, _, err := s.Client().LoadBalancer().Update(s, &hcloud.LoadBalancer{ID: id}, opts) return err }, } diff --git a/internal/cmd/loadbalancer/list.go b/internal/cmd/loadbalancer/list.go index 058f2a4e..226d8a6d 100644 --- a/internal/cmd/loadbalancer/list.go +++ b/internal/cmd/loadbalancer/list.go @@ -24,7 +24,7 @@ var ListCmd = base.ListCmd{ if len(sorts) > 0 { opts.Sort = sorts } - loadBalancers, err := s.LoadBalancer().AllWithOpts(s, opts) + loadBalancers, err := s.Client().LoadBalancer().AllWithOpts(s, opts) var resources []interface{} for _, r := range loadBalancers { diff --git a/internal/cmd/loadbalancer/metrics.go b/internal/cmd/loadbalancer/metrics.go index f6986d02..4ca0c378 100644 --- a/internal/cmd/loadbalancer/metrics.go +++ b/internal/cmd/loadbalancer/metrics.go @@ -52,7 +52,7 @@ var MetricsCmd = base.Cmd{ outputFlags := output.FlagsForCommand(cmd) idOrName := args[0] - LoadBalancer, _, err := s.LoadBalancer().Get(s, idOrName) + LoadBalancer, _, err := s.Client().LoadBalancer().Get(s, idOrName) if err != nil { return err } @@ -88,7 +88,7 @@ var MetricsCmd = base.Cmd{ } } - m, resp, err := s.LoadBalancer().GetMetrics(s, LoadBalancer, hcloud.LoadBalancerGetMetricsOpts{ + m, resp, err := s.Client().LoadBalancer().GetMetrics(s, LoadBalancer, hcloud.LoadBalancerGetMetricsOpts{ Types: metricTypes, Start: startTime, End: endTime, diff --git a/internal/cmd/loadbalancer/remove_target.go b/internal/cmd/loadbalancer/remove_target.go index 34a4dcdb..4c13d83f 100644 --- a/internal/cmd/loadbalancer/remove_target.go +++ b/internal/cmd/loadbalancer/remove_target.go @@ -47,7 +47,7 @@ var RemoveTargetCmd = base.Cmd{ idOrName := args[0] - loadBalancer, _, err = s.LoadBalancer().Get(s, idOrName) + loadBalancer, _, err = s.Client().LoadBalancer().Get(s, idOrName) if err != nil { return err } @@ -60,19 +60,19 @@ var RemoveTargetCmd = base.Cmd{ } switch { case serverIDOrName != "": - server, _, err := s.Server().Get(s, serverIDOrName) + server, _, err := s.Client().Server().Get(s, serverIDOrName) if err != nil { return err } if server == nil { return fmt.Errorf("server not found: %s", serverIDOrName) } - action, _, err = s.LoadBalancer().RemoveServerTarget(s, loadBalancer, server) + action, _, err = s.Client().LoadBalancer().RemoveServerTarget(s, loadBalancer, server) if err != nil { return err } case labelSelector != "": - action, _, err = s.LoadBalancer().RemoveLabelSelectorTarget(s, loadBalancer, labelSelector) + action, _, err = s.Client().LoadBalancer().RemoveLabelSelectorTarget(s, loadBalancer, labelSelector) if err != nil { return err } @@ -81,7 +81,7 @@ var RemoveTargetCmd = base.Cmd{ if ip == nil { return fmt.Errorf("invalid ip provided") } - if action, _, err = s.LoadBalancer().RemoveIPTarget(s, loadBalancer, ip); err != nil { + if action, _, err = s.Client().LoadBalancer().RemoveIPTarget(s, loadBalancer, ip); err != nil { return err } default: diff --git a/internal/cmd/loadbalancer/set_rdns.go b/internal/cmd/loadbalancer/set_rdns.go index 69ab5ff7..5ba4947d 100644 --- a/internal/cmd/loadbalancer/set_rdns.go +++ b/internal/cmd/loadbalancer/set_rdns.go @@ -16,7 +16,7 @@ var SetRDNSCmd = base.SetRdnsCmd{ ShortDescription: "Change reverse DNS of a Load Balancer", NameSuggestions: func(c hcapi2.Client) func() []string { return c.LoadBalancer().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) { - return s.LoadBalancer().Get(s, idOrName) + return s.Client().LoadBalancer().Get(s, idOrName) }, GetDefaultIP: func(resource interface{}) net.IP { loadBalancer := resource.(*hcloud.LoadBalancer) diff --git a/internal/cmd/loadbalancer/update.go b/internal/cmd/loadbalancer/update.go index 9ce08e03..4a7a2372 100644 --- a/internal/cmd/loadbalancer/update.go +++ b/internal/cmd/loadbalancer/update.go @@ -15,7 +15,7 @@ var UpdateCmd = base.UpdateCmd{ ShortDescription: "Update a Load Balancer", NameSuggestions: func(c hcapi2.Client) func() []string { return c.LoadBalancer().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) { - return s.LoadBalancer().Get(s, idOrName) + return s.Client().LoadBalancer().Get(s, idOrName) }, DefineFlags: func(cmd *cobra.Command) { cmd.Flags().String("name", "", "LoadBalancer name") @@ -25,7 +25,7 @@ var UpdateCmd = base.UpdateCmd{ updOpts := hcloud.LoadBalancerUpdateOpts{ Name: flags["name"].String(), } - _, _, err := s.LoadBalancer().Update(s, floatingIP, updOpts) + _, _, err := s.Client().LoadBalancer().Update(s, floatingIP, updOpts) if err != nil { return err } diff --git a/internal/cmd/loadbalancer/update_service.go b/internal/cmd/loadbalancer/update_service.go index b5b622fd..6b3a57d6 100644 --- a/internal/cmd/loadbalancer/update_service.go +++ b/internal/cmd/loadbalancer/update_service.go @@ -56,7 +56,7 @@ var UpdateServiceCmd = base.Cmd{ idOrName := args[0] listenPort, _ := cmd.Flags().GetInt("listen-port") - loadBalancer, _, err := s.LoadBalancer().Get(s, idOrName) + loadBalancer, _, err := s.Client().LoadBalancer().Get(s, idOrName) if err != nil { return err } @@ -159,7 +159,7 @@ var UpdateServiceCmd = base.Cmd{ } } - action, _, err := s.LoadBalancer().UpdateService(s, loadBalancer, listenPort, opts) + action, _, err := s.Client().LoadBalancer().UpdateService(s, loadBalancer, listenPort, opts) if err != nil { return err } diff --git a/internal/cmd/loadbalancertype/describe.go b/internal/cmd/loadbalancertype/describe.go index 1123d8cf..3c32fc8f 100644 --- a/internal/cmd/loadbalancertype/describe.go +++ b/internal/cmd/loadbalancertype/describe.go @@ -16,7 +16,7 @@ var DescribeCmd = base.DescribeCmd{ JSONKeyGetByName: "load_balancer_types", NameSuggestions: func(c hcapi2.Client) func() []string { return c.LoadBalancerType().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, interface{}, error) { - lbt, _, err := s.LoadBalancerType().Get(s, idOrName) + lbt, _, err := s.Client().LoadBalancerType().Get(s, idOrName) if err != nil { return nil, nil, err } diff --git a/internal/cmd/loadbalancertype/list.go b/internal/cmd/loadbalancertype/list.go index a6ccc6b7..20fff54a 100644 --- a/internal/cmd/loadbalancertype/list.go +++ b/internal/cmd/loadbalancertype/list.go @@ -22,7 +22,7 @@ var ListCmd = base.ListCmd{ if len(sorts) > 0 { opts.Sort = sorts } - loadBalancerTypes, err := s.LoadBalancerType().AllWithOpts(s, opts) + loadBalancerTypes, err := s.Client().LoadBalancerType().AllWithOpts(s, opts) var resources []interface{} for _, r := range loadBalancerTypes { diff --git a/internal/cmd/location/describe.go b/internal/cmd/location/describe.go index 643620f2..f6ede55d 100644 --- a/internal/cmd/location/describe.go +++ b/internal/cmd/location/describe.go @@ -17,7 +17,7 @@ var DescribeCmd = base.DescribeCmd{ JSONKeyGetByName: "locations", NameSuggestions: func(c hcapi2.Client) func() []string { return c.Location().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, interface{}, error) { - l, _, err := s.Location().Get(s, idOrName) + l, _, err := s.Client().Location().Get(s, idOrName) if err != nil { return nil, nil, err } diff --git a/internal/cmd/location/list.go b/internal/cmd/location/list.go index 4f34c695..25f2b14f 100644 --- a/internal/cmd/location/list.go +++ b/internal/cmd/location/list.go @@ -21,7 +21,7 @@ var ListCmd = base.ListCmd{ if len(sorts) > 0 { opts.Sort = sorts } - locations, err := s.Location().AllWithOpts(s, opts) + locations, err := s.Client().Location().AllWithOpts(s, opts) var resources []interface{} for _, n := range locations { diff --git a/internal/cmd/network/add_route.go b/internal/cmd/network/add_route.go index cc2bf236..599a9f41 100644 --- a/internal/cmd/network/add_route.go +++ b/internal/cmd/network/add_route.go @@ -37,7 +37,7 @@ var AddRouteCmd = base.Cmd{ destination, _ := cmd.Flags().GetIPNet("destination") idOrName := args[0] - network, _, err := s.Network().Get(s, idOrName) + network, _, err := s.Client().Network().Get(s, idOrName) if err != nil { return err } @@ -51,7 +51,7 @@ var AddRouteCmd = base.Cmd{ Destination: &destination, }, } - action, _, err := s.Network().AddRoute(s, network, opts) + action, _, err := s.Client().Network().AddRoute(s, network, opts) if err != nil { return err } diff --git a/internal/cmd/network/add_subnet.go b/internal/cmd/network/add_subnet.go index dc057ead..0ebab456 100644 --- a/internal/cmd/network/add_subnet.go +++ b/internal/cmd/network/add_subnet.go @@ -44,7 +44,7 @@ var AddSubnetCmd = base.Cmd{ vSwitchID, _ := cmd.Flags().GetInt64("vswitch-id") idOrName := args[0] - network, _, err := s.Network().Get(s, idOrName) + network, _, err := s.Client().Network().Get(s, idOrName) if err != nil { return err } @@ -66,7 +66,7 @@ var AddSubnetCmd = base.Cmd{ opts := hcloud.NetworkAddSubnetOpts{ Subnet: subnet, } - action, _, err := s.Network().AddSubnet(s, network, opts) + action, _, err := s.Client().Network().AddSubnet(s, network, opts) if err != nil { return err } diff --git a/internal/cmd/network/change_ip_range.go b/internal/cmd/network/change_ip_range.go index 3db9ac7d..186cf2a1 100644 --- a/internal/cmd/network/change_ip_range.go +++ b/internal/cmd/network/change_ip_range.go @@ -31,7 +31,7 @@ var ChangeIPRangeCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - network, _, err := s.Network().Get(s, idOrName) + network, _, err := s.Client().Network().Get(s, idOrName) if err != nil { return err } @@ -44,7 +44,7 @@ var ChangeIPRangeCmd = base.Cmd{ IPRange: &ipRange, } - action, _, err := s.Network().ChangeIPRange(s, network, opts) + action, _, err := s.Client().Network().ChangeIPRange(s, network, opts) if err != nil { return err } diff --git a/internal/cmd/network/create.go b/internal/cmd/network/create.go index 40f825d8..b99ae525 100644 --- a/internal/cmd/network/create.go +++ b/internal/cmd/network/create.go @@ -54,7 +54,7 @@ var CreateCmd = base.CreateCmd{ ExposeRoutesToVSwitch: exposeRoutesToVSwitch, } - network, _, err := s.Network().Create(s, createOpts) + network, _, err := s.Client().Network().Create(s, createOpts) if err != nil { return nil, nil, err } diff --git a/internal/cmd/network/delete.go b/internal/cmd/network/delete.go index e565219d..1507ab1b 100644 --- a/internal/cmd/network/delete.go +++ b/internal/cmd/network/delete.go @@ -14,11 +14,11 @@ var DeleteCmd = base.DeleteCmd{ ShortDescription: "Delete a network", NameSuggestions: func(c hcapi2.Client) func() []string { return c.Network().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) { - return s.Network().Get(s, idOrName) + return s.Client().Network().Get(s, idOrName) }, Delete: func(s state.State, cmd *cobra.Command, resource interface{}) error { network := resource.(*hcloud.Network) - if _, err := s.Network().Delete(s, network); err != nil { + if _, err := s.Client().Network().Delete(s, network); err != nil { return err } return nil diff --git a/internal/cmd/network/describe.go b/internal/cmd/network/describe.go index 0e075ec1..56115de5 100644 --- a/internal/cmd/network/describe.go +++ b/internal/cmd/network/describe.go @@ -19,7 +19,7 @@ var DescribeCmd = base.DescribeCmd{ JSONKeyGetByName: "networks", NameSuggestions: func(c hcapi2.Client) func() []string { return c.Network().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, interface{}, error) { - n, _, err := s.Network().Get(s, idOrName) + n, _, err := s.Client().Network().Get(s, idOrName) if err != nil { return nil, nil, err } diff --git a/internal/cmd/network/disable_protection.go b/internal/cmd/network/disable_protection.go index ffe3f2ae..7ad0ef26 100644 --- a/internal/cmd/network/disable_protection.go +++ b/internal/cmd/network/disable_protection.go @@ -27,7 +27,7 @@ var DisableProtectionCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - network, _, err := s.Network().Get(s, idOrName) + network, _, err := s.Client().Network().Get(s, idOrName) if err != nil { return err } diff --git a/internal/cmd/network/enable_protection.go b/internal/cmd/network/enable_protection.go index 67c4b53e..ec5d3640 100644 --- a/internal/cmd/network/enable_protection.go +++ b/internal/cmd/network/enable_protection.go @@ -40,7 +40,7 @@ func changeProtection(s state.State, cmd *cobra.Command, return nil } - action, _, err := s.Network().ChangeProtection(s, network, opts) + action, _, err := s.Client().Network().ChangeProtection(s, network, opts) if err != nil { return err } @@ -73,7 +73,7 @@ var EnableProtectionCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - network, _, err := s.Network().Get(s, idOrName) + network, _, err := s.Client().Network().Get(s, idOrName) if err != nil { return err } diff --git a/internal/cmd/network/expose-routes-to-vswitch.go b/internal/cmd/network/expose-routes-to-vswitch.go index e9635322..413ec357 100644 --- a/internal/cmd/network/expose-routes-to-vswitch.go +++ b/internal/cmd/network/expose-routes-to-vswitch.go @@ -30,7 +30,7 @@ var ExposeRoutesToVSwitchCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - network, _, err := s.Network().Get(s, idOrName) + network, _, err := s.Client().Network().Get(s, idOrName) if err != nil { return err } @@ -43,7 +43,7 @@ var ExposeRoutesToVSwitchCmd = base.Cmd{ ExposeRoutesToVSwitch: hcloud.Ptr(!disable), } - _, _, err = s.Network().Update(s, network, opts) + _, _, err = s.Client().Network().Update(s, network, opts) if err != nil { return err } diff --git a/internal/cmd/network/labels.go b/internal/cmd/network/labels.go index f7f7d493..415d70ae 100644 --- a/internal/cmd/network/labels.go +++ b/internal/cmd/network/labels.go @@ -16,7 +16,7 @@ var LabelCmds = base.LabelCmds{ NameSuggestions: func(c hcapi2.Client) func() []string { return c.Network().Names }, LabelKeySuggestions: func(c hcapi2.Client) func(idOrName string) []string { return c.Network().LabelKeys }, FetchLabels: func(s state.State, idOrName string) (map[string]string, int64, error) { - network, _, err := s.Network().Get(s, idOrName) + network, _, err := s.Client().Network().Get(s, idOrName) if err != nil { return nil, 0, err } @@ -29,7 +29,7 @@ var LabelCmds = base.LabelCmds{ opts := hcloud.NetworkUpdateOpts{ Labels: labels, } - _, _, err := s.Network().Update(s, &hcloud.Network{ID: id}, opts) + _, _, err := s.Client().Network().Update(s, &hcloud.Network{ID: id}, opts) return err }, } diff --git a/internal/cmd/network/list.go b/internal/cmd/network/list.go index ee01ea6d..2d9c5449 100644 --- a/internal/cmd/network/list.go +++ b/internal/cmd/network/list.go @@ -26,7 +26,7 @@ var ListCmd = base.ListCmd{ if len(sorts) > 0 { opts.Sort = sorts } - networks, err := s.Network().AllWithOpts(s, opts) + networks, err := s.Client().Network().AllWithOpts(s, opts) var resources []interface{} for _, n := range networks { diff --git a/internal/cmd/network/remove_route.go b/internal/cmd/network/remove_route.go index 282bd38b..7c17d2e5 100644 --- a/internal/cmd/network/remove_route.go +++ b/internal/cmd/network/remove_route.go @@ -36,7 +36,7 @@ var RemoveRouteCmd = base.Cmd{ gateway, _ := cmd.Flags().GetIP("gateway") destination, _ := cmd.Flags().GetIPNet("destination") idOrName := args[0] - network, _, err := s.Network().Get(s, idOrName) + network, _, err := s.Client().Network().Get(s, idOrName) if err != nil { return err } @@ -50,7 +50,7 @@ var RemoveRouteCmd = base.Cmd{ Destination: &destination, }, } - action, _, err := s.Network().DeleteRoute(s, network, opts) + action, _, err := s.Client().Network().DeleteRoute(s, network, opts) if err != nil { return err } diff --git a/internal/cmd/network/remove_subnet.go b/internal/cmd/network/remove_subnet.go index 2110716a..b081e89a 100644 --- a/internal/cmd/network/remove_subnet.go +++ b/internal/cmd/network/remove_subnet.go @@ -30,7 +30,7 @@ var RemoveSubnetCmd = base.Cmd{ Run: func(s state.State, cmd *cobra.Command, args []string) error { ipRange, _ := cmd.Flags().GetIPNet("ip-range") idOrName := args[0] - network, _, err := s.Network().Get(s, idOrName) + network, _, err := s.Client().Network().Get(s, idOrName) if err != nil { return err } @@ -43,7 +43,7 @@ var RemoveSubnetCmd = base.Cmd{ IPRange: &ipRange, }, } - action, _, err := s.Network().DeleteSubnet(s, network, opts) + action, _, err := s.Client().Network().DeleteSubnet(s, network, opts) if err != nil { return err } diff --git a/internal/cmd/network/update.go b/internal/cmd/network/update.go index 01533110..8cebafe7 100644 --- a/internal/cmd/network/update.go +++ b/internal/cmd/network/update.go @@ -15,7 +15,7 @@ var UpdateCmd = base.UpdateCmd{ ShortDescription: "Update a Network.\n\nTo enable or disable exposing routes to the vSwitch connection you can use the subcommand \"hcloud network expose-routes-to-vswitch\".", NameSuggestions: func(c hcapi2.Client) func() []string { return c.Network().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) { - return s.Network().Get(s, idOrName) + return s.Client().Network().Get(s, idOrName) }, DefineFlags: func(cmd *cobra.Command) { cmd.Flags().String("name", "", "Network name") @@ -25,7 +25,7 @@ var UpdateCmd = base.UpdateCmd{ updOpts := hcloud.NetworkUpdateOpts{ Name: flags["name"].String(), } - _, _, err := s.Network().Update(s, floatingIP, updOpts) + _, _, err := s.Client().Network().Update(s, floatingIP, updOpts) if err != nil { return err } diff --git a/internal/cmd/placementgroup/create.go b/internal/cmd/placementgroup/create.go index 3af6e5ce..dea1e2f2 100644 --- a/internal/cmd/placementgroup/create.go +++ b/internal/cmd/placementgroup/create.go @@ -36,7 +36,7 @@ var CreateCmd = base.CreateCmd{ Type: hcloud.PlacementGroupType(placementGroupType), } - result, _, err := s.PlacementGroup().Create(s, opts) + result, _, err := s.Client().PlacementGroup().Create(s, opts) if err != nil { return nil, nil, err } diff --git a/internal/cmd/placementgroup/delete.go b/internal/cmd/placementgroup/delete.go index 77734369..13b52512 100644 --- a/internal/cmd/placementgroup/delete.go +++ b/internal/cmd/placementgroup/delete.go @@ -14,11 +14,11 @@ var DeleteCmd = base.DeleteCmd{ ShortDescription: "Delete a placement group", NameSuggestions: func(c hcapi2.Client) func() []string { return c.PlacementGroup().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) { - return s.PlacementGroup().Get(s, idOrName) + return s.Client().PlacementGroup().Get(s, idOrName) }, Delete: func(s state.State, cmd *cobra.Command, resource interface{}) error { placementGroup := resource.(*hcloud.PlacementGroup) - if _, err := s.PlacementGroup().Delete(s, placementGroup); err != nil { + if _, err := s.Client().PlacementGroup().Delete(s, placementGroup); err != nil { return err } return nil diff --git a/internal/cmd/placementgroup/describe.go b/internal/cmd/placementgroup/describe.go index e4b6239a..81abf85c 100644 --- a/internal/cmd/placementgroup/describe.go +++ b/internal/cmd/placementgroup/describe.go @@ -18,7 +18,7 @@ var DescribeCmd = base.DescribeCmd{ JSONKeyGetByName: "placement_groups", NameSuggestions: func(c hcapi2.Client) func() []string { return c.PlacementGroup().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, interface{}, error) { - pg, _, err := s.PlacementGroup().Get(s, idOrName) + pg, _, err := s.Client().PlacementGroup().Get(s, idOrName) if err != nil { return nil, nil, err } @@ -43,7 +43,7 @@ var DescribeCmd = base.DescribeCmd{ cmd.Print("Servers:\n") for _, serverID := range placementGroup.Servers { cmd.Printf(" - Server ID:\t\t%d\n", serverID) - cmd.Printf(" Server Name:\t%s\n", s.Server().ServerName(serverID)) + cmd.Printf(" Server Name:\t%s\n", s.Client().Server().ServerName(serverID)) } cmd.Printf("Type:\t\t%s\n", placementGroup.Type) diff --git a/internal/cmd/placementgroup/labels.go b/internal/cmd/placementgroup/labels.go index 919f2eda..fc6dfe2a 100644 --- a/internal/cmd/placementgroup/labels.go +++ b/internal/cmd/placementgroup/labels.go @@ -16,7 +16,7 @@ var LabelCmds = base.LabelCmds{ NameSuggestions: func(c hcapi2.Client) func() []string { return c.PlacementGroup().Names }, LabelKeySuggestions: func(c hcapi2.Client) func(idOrName string) []string { return c.PlacementGroup().LabelKeys }, FetchLabels: func(s state.State, idOrName string) (map[string]string, int64, error) { - placementGroup, _, err := s.PlacementGroup().Get(s, idOrName) + placementGroup, _, err := s.Client().PlacementGroup().Get(s, idOrName) if err != nil { return nil, 0, err } @@ -29,7 +29,7 @@ var LabelCmds = base.LabelCmds{ opts := hcloud.PlacementGroupUpdateOpts{ Labels: labels, } - _, _, err := s.PlacementGroup().Update(s, &hcloud.PlacementGroup{ID: id}, opts) + _, _, err := s.Client().PlacementGroup().Update(s, &hcloud.PlacementGroup{ID: id}, opts) return err }, } diff --git a/internal/cmd/placementgroup/list.go b/internal/cmd/placementgroup/list.go index f2114cc8..487b620b 100644 --- a/internal/cmd/placementgroup/list.go +++ b/internal/cmd/placementgroup/list.go @@ -25,7 +25,7 @@ var ListCmd = base.ListCmd{ if len(sorts) > 0 { opts.Sort = sorts } - placementGroups, err := s.PlacementGroup().AllWithOpts(s, opts) + placementGroups, err := s.Client().PlacementGroup().AllWithOpts(s, opts) var resources []interface{} for _, n := range placementGroups { diff --git a/internal/cmd/placementgroup/update.go b/internal/cmd/placementgroup/update.go index 515b02b6..fae341d3 100644 --- a/internal/cmd/placementgroup/update.go +++ b/internal/cmd/placementgroup/update.go @@ -15,7 +15,7 @@ var UpdateCmd = base.UpdateCmd{ ShortDescription: "Update a placement group", NameSuggestions: func(c hcapi2.Client) func() []string { return c.PlacementGroup().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) { - return s.PlacementGroup().Get(s, idOrName) + return s.Client().PlacementGroup().Get(s, idOrName) }, DefineFlags: func(cmd *cobra.Command) { cmd.Flags().String("name", "", "Placement group name") @@ -25,7 +25,7 @@ var UpdateCmd = base.UpdateCmd{ updOpts := hcloud.PlacementGroupUpdateOpts{ Name: flags["name"].String(), } - _, _, err := s.PlacementGroup().Update(s, placementGroup, updOpts) + _, _, err := s.Client().PlacementGroup().Update(s, placementGroup, updOpts) if err != nil { return err } diff --git a/internal/cmd/primaryip/assign.go b/internal/cmd/primaryip/assign.go index 6169af33..35e674f8 100644 --- a/internal/cmd/primaryip/assign.go +++ b/internal/cmd/primaryip/assign.go @@ -31,7 +31,7 @@ var AssignCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - primaryIP, _, err := s.PrimaryIP().Get(s, idOrName) + primaryIP, _, err := s.Client().PrimaryIP().Get(s, idOrName) if err != nil { return err } @@ -41,7 +41,7 @@ var AssignCmd = base.Cmd{ serverIDOrName, _ := cmd.Flags().GetString("server") - server, _, err := s.Server().Get(s, serverIDOrName) + server, _, err := s.Client().Server().Get(s, serverIDOrName) if err != nil { return err } @@ -54,7 +54,7 @@ var AssignCmd = base.Cmd{ AssigneeID: server.ID, } - action, _, err := s.PrimaryIP().Assign(s, opts) + action, _, err := s.Client().PrimaryIP().Assign(s, opts) if err != nil { return err } diff --git a/internal/cmd/primaryip/changedns.go b/internal/cmd/primaryip/changedns.go index af2a38f7..c7ab9af1 100644 --- a/internal/cmd/primaryip/changedns.go +++ b/internal/cmd/primaryip/changedns.go @@ -32,7 +32,7 @@ var ChangeDNSCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - primaryIP, _, err := s.PrimaryIP().Get(s, idOrName) + primaryIP, _, err := s.Client().PrimaryIP().Get(s, idOrName) if err != nil { return err } @@ -48,7 +48,7 @@ var ChangeDNSCmd = base.Cmd{ IP: ip, } - action, _, err := s.PrimaryIP().ChangeDNSPtr(s, opts) + action, _, err := s.Client().PrimaryIP().ChangeDNSPtr(s, opts) if err != nil { return err } diff --git a/internal/cmd/primaryip/create.go b/internal/cmd/primaryip/create.go index 35f68953..4813173b 100644 --- a/internal/cmd/primaryip/create.go +++ b/internal/cmd/primaryip/create.go @@ -61,7 +61,7 @@ var CreateCmd = base.CreateCmd{ createOpts.AssigneeID = &assigneeID } - result, _, err := s.PrimaryIP().Create(s, createOpts) + result, _, err := s.Client().PrimaryIP().Create(s, createOpts) if err != nil { return nil, nil, err } diff --git a/internal/cmd/primaryip/delete.go b/internal/cmd/primaryip/delete.go index e8102745..87caf3c8 100644 --- a/internal/cmd/primaryip/delete.go +++ b/internal/cmd/primaryip/delete.go @@ -14,11 +14,11 @@ var DeleteCmd = base.DeleteCmd{ ShortDescription: "Delete a Primary IP", NameSuggestions: func(c hcapi2.Client) func() []string { return c.PrimaryIP().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) { - return s.PrimaryIP().Get(s, idOrName) + return s.Client().PrimaryIP().Get(s, idOrName) }, Delete: func(s state.State, cmd *cobra.Command, resource interface{}) error { primaryIP := resource.(*hcloud.PrimaryIP) - if _, err := s.PrimaryIP().Delete(s, primaryIP); err != nil { + if _, err := s.Client().PrimaryIP().Delete(s, primaryIP); err != nil { return err } return nil diff --git a/internal/cmd/primaryip/describe.go b/internal/cmd/primaryip/describe.go index fd689178..2c8008ea 100644 --- a/internal/cmd/primaryip/describe.go +++ b/internal/cmd/primaryip/describe.go @@ -18,7 +18,7 @@ var DescribeCmd = base.DescribeCmd{ JSONKeyGetByName: "primary_ips", NameSuggestions: func(c hcapi2.Client) func() []string { return c.PrimaryIP().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, interface{}, error) { - ip, _, err := s.PrimaryIP().Get(s, idOrName) + ip, _, err := s.Client().PrimaryIP().Get(s, idOrName) if err != nil { return nil, nil, err } diff --git a/internal/cmd/primaryip/disable_protection.go b/internal/cmd/primaryip/disable_protection.go index de8678fb..272ae885 100644 --- a/internal/cmd/primaryip/disable_protection.go +++ b/internal/cmd/primaryip/disable_protection.go @@ -28,7 +28,7 @@ var DisableProtectionCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - primaryIP, _, err := s.PrimaryIP().Get(s, idOrName) + primaryIP, _, err := s.Client().PrimaryIP().Get(s, idOrName) if err != nil { return err } diff --git a/internal/cmd/primaryip/enable_protection.go b/internal/cmd/primaryip/enable_protection.go index 592a9c51..4e146feb 100644 --- a/internal/cmd/primaryip/enable_protection.go +++ b/internal/cmd/primaryip/enable_protection.go @@ -38,7 +38,7 @@ func changeProtection(s state.State, cmd *cobra.Command, opts.ID = primaryIp.ID - action, _, err := s.PrimaryIP().ChangeProtection(s, opts) + action, _, err := s.Client().PrimaryIP().ChangeProtection(s, opts) if err != nil { return err } @@ -72,7 +72,7 @@ var EnableProtectionCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - primaryIP, _, err := s.PrimaryIP().Get(s, idOrName) + primaryIP, _, err := s.Client().PrimaryIP().Get(s, idOrName) if err != nil { return err } diff --git a/internal/cmd/primaryip/labels.go b/internal/cmd/primaryip/labels.go index fb8adaec..5a84f92d 100644 --- a/internal/cmd/primaryip/labels.go +++ b/internal/cmd/primaryip/labels.go @@ -16,7 +16,7 @@ var LabelCmds = base.LabelCmds{ NameSuggestions: func(c hcapi2.Client) func() []string { return c.PrimaryIP().Names }, LabelKeySuggestions: func(c hcapi2.Client) func(idOrName string) []string { return c.PrimaryIP().LabelKeys }, FetchLabels: func(s state.State, idOrName string) (map[string]string, int64, error) { - primaryIP, _, err := s.PrimaryIP().Get(s, idOrName) + primaryIP, _, err := s.Client().PrimaryIP().Get(s, idOrName) if err != nil { return nil, 0, err } @@ -29,7 +29,7 @@ var LabelCmds = base.LabelCmds{ opts := hcloud.PrimaryIPUpdateOpts{ Labels: &labels, } - _, _, err := s.PrimaryIP().Update(s, &hcloud.PrimaryIP{ID: id}, opts) + _, _, err := s.Client().PrimaryIP().Update(s, &hcloud.PrimaryIP{ID: id}, opts) return err }, } diff --git a/internal/cmd/primaryip/list.go b/internal/cmd/primaryip/list.go index 55427791..5996d042 100644 --- a/internal/cmd/primaryip/list.go +++ b/internal/cmd/primaryip/list.go @@ -26,7 +26,7 @@ var ListCmd = base.ListCmd{ if len(sorts) > 0 { opts.Sort = sorts } - primaryips, err := s.PrimaryIP().AllWithOpts(s, opts) + primaryips, err := s.Client().PrimaryIP().AllWithOpts(s, opts) var resources []interface{} for _, n := range primaryips { diff --git a/internal/cmd/primaryip/unassign.go b/internal/cmd/primaryip/unassign.go index d0a88281..95d3a0ff 100644 --- a/internal/cmd/primaryip/unassign.go +++ b/internal/cmd/primaryip/unassign.go @@ -27,7 +27,7 @@ var UnAssignCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - primaryIP, _, err := s.PrimaryIP().Get(s, idOrName) + primaryIP, _, err := s.Client().PrimaryIP().Get(s, idOrName) if err != nil { return err } @@ -35,7 +35,7 @@ var UnAssignCmd = base.Cmd{ return fmt.Errorf("Primary IP not found: %v", idOrName) } - action, _, err := s.PrimaryIP().Unassign(s, primaryIP.ID) + action, _, err := s.Client().PrimaryIP().Unassign(s, primaryIP.ID) if err != nil { return err } diff --git a/internal/cmd/primaryip/update.go b/internal/cmd/primaryip/update.go index 94220a46..5cb81bd7 100644 --- a/internal/cmd/primaryip/update.go +++ b/internal/cmd/primaryip/update.go @@ -15,7 +15,7 @@ var updateCmd = base.UpdateCmd{ ShortDescription: "Update a Primary IP", NameSuggestions: func(c hcapi2.Client) func() []string { return c.PrimaryIP().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) { - return s.PrimaryIP().Get(s, idOrName) + return s.Client().PrimaryIP().Get(s, idOrName) }, DefineFlags: func(cmd *cobra.Command) { cmd.Flags().String("name", "", "Primary IP name") @@ -32,7 +32,7 @@ var updateCmd = base.UpdateCmd{ updOpts.AutoDelete = hcloud.Ptr(autoDelete) } - _, _, err := s.PrimaryIP().Update(s, primaryIP, updOpts) + _, _, err := s.Client().PrimaryIP().Update(s, primaryIP, updOpts) if err != nil { return err } diff --git a/internal/cmd/server/add_to_placement_group.go b/internal/cmd/server/add_to_placement_group.go index 81637865..fbd54303 100644 --- a/internal/cmd/server/add_to_placement_group.go +++ b/internal/cmd/server/add_to_placement_group.go @@ -28,7 +28,7 @@ var AddToPlacementGroupCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - server, _, err := s.Server().Get(s, idOrName) + server, _, err := s.Client().Server().Get(s, idOrName) if err != nil { return err } @@ -37,7 +37,7 @@ var AddToPlacementGroupCmd = base.Cmd{ } placementGroupIDOrName, _ := cmd.Flags().GetString("placement-group") - placementGroup, _, err := s.PlacementGroup().Get(s, placementGroupIDOrName) + placementGroup, _, err := s.Client().PlacementGroup().Get(s, placementGroupIDOrName) if err != nil { return err } @@ -45,7 +45,7 @@ var AddToPlacementGroupCmd = base.Cmd{ return fmt.Errorf("placement group not found %s", placementGroupIDOrName) } - action, _, err := s.Server().AddToPlacementGroup(s, server, placementGroup) + action, _, err := s.Client().Server().AddToPlacementGroup(s, server, placementGroup) if err != nil { return err } diff --git a/internal/cmd/server/attach_iso.go b/internal/cmd/server/attach_iso.go index 7dec788a..624cac5c 100644 --- a/internal/cmd/server/attach_iso.go +++ b/internal/cmd/server/attach_iso.go @@ -28,7 +28,7 @@ var AttachISOCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - server, _, err := s.Server().Get(s, idOrName) + server, _, err := s.Client().Server().Get(s, idOrName) if err != nil { return err } @@ -37,7 +37,7 @@ var AttachISOCmd = base.Cmd{ } isoIDOrName := args[1] - iso, _, err := s.ISO().Get(s, isoIDOrName) + iso, _, err := s.Client().ISO().Get(s, isoIDOrName) if err != nil { return err } @@ -51,7 +51,7 @@ var AttachISOCmd = base.Cmd{ return errors.New("failed to attach iso: iso has a different architecture than the server") } - action, _, err := s.Server().AttachISO(s, server, iso) + action, _, err := s.Client().Server().AttachISO(s, server, iso) if err != nil { return err } diff --git a/internal/cmd/server/attach_to_network.go b/internal/cmd/server/attach_to_network.go index 2c377cc8..15ec347d 100644 --- a/internal/cmd/server/attach_to_network.go +++ b/internal/cmd/server/attach_to_network.go @@ -35,7 +35,7 @@ var AttachToNetworkCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - server, _, err := s.Server().Get(s, idOrName) + server, _, err := s.Client().Server().Get(s, idOrName) if err != nil { return err } @@ -44,7 +44,7 @@ var AttachToNetworkCmd = base.Cmd{ } networkIDOrName, _ := cmd.Flags().GetString("network") - network, _, err := s.Network().Get(s, networkIDOrName) + network, _, err := s.Client().Network().Get(s, networkIDOrName) if err != nil { return err } @@ -62,7 +62,7 @@ var AttachToNetworkCmd = base.Cmd{ for _, aliasIP := range aliasIPs { opts.AliasIPs = append(opts.AliasIPs, aliasIP) } - action, _, err := s.Server().AttachToNetwork(s, server, opts) + action, _, err := s.Client().Server().AttachToNetwork(s, server, opts) if err != nil { return err diff --git a/internal/cmd/server/change_alias_ips.go b/internal/cmd/server/change_alias_ips.go index 6caa9410..75565e0a 100644 --- a/internal/cmd/server/change_alias_ips.go +++ b/internal/cmd/server/change_alias_ips.go @@ -36,7 +36,7 @@ var ChangeAliasIPsCmd = base.Cmd{ Run: func(s state.State, cmd *cobra.Command, args []string) error { clear, _ := cmd.Flags().GetBool("clear") idOrName := args[0] - server, _, err := s.Server().Get(s, idOrName) + server, _, err := s.Client().Server().Get(s, idOrName) if err != nil { return err } @@ -45,7 +45,7 @@ var ChangeAliasIPsCmd = base.Cmd{ } networkIDOrName, _ := cmd.Flags().GetString("network") - network, _, err := s.Network().Get(s, networkIDOrName) + network, _, err := s.Client().Network().Get(s, networkIDOrName) if err != nil { return err } @@ -65,7 +65,7 @@ var ChangeAliasIPsCmd = base.Cmd{ opts.AliasIPs = append(opts.AliasIPs, net.ParseIP(aliasIP)) } } - action, _, err := s.Server().ChangeAliasIPs(s, server, opts) + action, _, err := s.Client().Server().ChangeAliasIPs(s, server, opts) if err != nil { return err diff --git a/internal/cmd/server/change_type.go b/internal/cmd/server/change_type.go index af95fc8b..ebe6c52d 100644 --- a/internal/cmd/server/change_type.go +++ b/internal/cmd/server/change_type.go @@ -31,7 +31,7 @@ var ChangeTypeCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - server, _, err := s.Server().Get(s, idOrName) + server, _, err := s.Client().Server().Get(s, idOrName) if err != nil { return err } @@ -40,7 +40,7 @@ var ChangeTypeCmd = base.Cmd{ } serverTypeIDOrName := args[1] - serverType, _, err := s.ServerType().Get(s, serverTypeIDOrName) + serverType, _, err := s.Client().ServerType().Get(s, serverTypeIDOrName) if err != nil { return err } @@ -57,7 +57,7 @@ var ChangeTypeCmd = base.Cmd{ ServerType: serverType, UpgradeDisk: !keepDisk, } - action, _, err := s.Server().ChangeType(s, server, opts) + action, _, err := s.Client().Server().ChangeType(s, server, opts) if err != nil { return err } diff --git a/internal/cmd/server/create.go b/internal/cmd/server/create.go index bfa8724a..3573314d 100644 --- a/internal/cmd/server/create.go +++ b/internal/cmd/server/create.go @@ -102,7 +102,7 @@ var CreateCmd = base.CreateCmd{ return nil, nil, err } - result, _, err := s.Server().Create(s, createOpts) + result, _, err := s.Client().Server().Create(s, createOpts) if err != nil { return nil, nil, err } @@ -114,7 +114,7 @@ var CreateCmd = base.CreateCmd{ return nil, nil, err } - server, _, err := s.Server().GetByID(s, result.Server.ID) + server, _, err := s.Client().Server().GetByID(s, result.Server.ID) if err != nil { return nil, nil, err } @@ -127,7 +127,7 @@ var CreateCmd = base.CreateCmd{ enableBackup, _ := cmd.Flags().GetBool("enable-backup") if enableBackup { - action, _, err := s.Server().EnableBackup(s, server, "") + action, _, err := s.Client().Server().EnableBackup(s, server, "") if err != nil { return nil, nil, err } @@ -157,7 +157,7 @@ var CreateCmd = base.CreateCmd{ if len(server.PrivateNet) > 0 { var networks []string for _, network := range server.PrivateNet { - networks = append(networks, fmt.Sprintf("- %s (%s)", network.IP.String(), s.Network().Name(network.Network.ID))) + networks = append(networks, fmt.Sprintf("- %s (%s)", network.IP.String(), s.Client().Network().Name(network.Network.ID))) } cmd.Printf("Private Networks:\n\t%s\n", strings.Join(networks, "\n")) } @@ -261,7 +261,7 @@ func createOptsFromFlags( primaryIPv6IDorName, _ := flags.GetString("primary-ipv6") protection, _ := flags.GetStringSlice("enable-protection") - serverType, _, err := s.ServerType().Get(s, serverTypeName) + serverType, _, err := s.Client().ServerType().Get(s, serverTypeName) if err != nil { return } @@ -275,7 +275,7 @@ func createOptsFromFlags( } // Select correct image based on server type architecture - image, _, err := s.Image().GetForArchitecture(s, imageIDorName, serverType.Architecture) + image, _, err := s.Client().Image().GetForArchitecture(s, imageIDorName, serverType.Architecture) if err != nil { return } @@ -315,7 +315,7 @@ func createOptsFromFlags( } if primaryIPv4IDorName != "" { var primaryIPv4 *hcloud.PrimaryIP - primaryIPv4, _, err = s.PrimaryIP().Get(s, primaryIPv4IDorName) + primaryIPv4, _, err = s.Client().PrimaryIP().Get(s, primaryIPv4IDorName) if err != nil { return } @@ -327,7 +327,7 @@ func createOptsFromFlags( } if primaryIPv6IDorName != "" { var primaryIPv6 *hcloud.PrimaryIP - primaryIPv6, _, err = s.PrimaryIP().Get(s, primaryIPv6IDorName) + primaryIPv6, _, err = s.Client().PrimaryIP().Get(s, primaryIPv6IDorName) if err != nil { return } @@ -358,7 +358,7 @@ func createOptsFromFlags( for _, sshKeyIDOrName := range sshKeys { var sshKey *hcloud.SSHKey - sshKey, _, err = s.SSHKey().Get(s, sshKeyIDOrName) + sshKey, _, err = s.Client().SSHKey().Get(s, sshKeyIDOrName) if err != nil { return } @@ -378,7 +378,7 @@ func createOptsFromFlags( } for _, volumeIDOrName := range volumes { var volume *hcloud.Volume - volume, _, err = s.Volume().Get(s, volumeIDOrName) + volume, _, err = s.Client().Volume().Get(s, volumeIDOrName) if err != nil { return } @@ -391,7 +391,7 @@ func createOptsFromFlags( } for _, networkIDOrName := range networks { var network *hcloud.Network - network, _, err = s.Network().Get(s, networkIDOrName) + network, _, err = s.Client().Network().Get(s, networkIDOrName) if err != nil { return } @@ -404,7 +404,7 @@ func createOptsFromFlags( } for _, firewallIDOrName := range firewalls { var firewall *hcloud.Firewall - firewall, _, err = s.Firewall().Get(s, firewallIDOrName) + firewall, _, err = s.Client().Firewall().Get(s, firewallIDOrName) if err != nil { return } @@ -424,7 +424,7 @@ func createOptsFromFlags( } if placementGroupIDorName != "" { var placementGroup *hcloud.PlacementGroup - placementGroup, _, err = s.PlacementGroup().Get(s, placementGroupIDorName) + placementGroup, _, err = s.Client().PlacementGroup().Get(s, placementGroupIDorName) if err != nil { return } @@ -459,7 +459,7 @@ func getSSHKeyForFingerprint( err = fmt.Errorf("lookup SSH key by fingerprint: %v", err) return } - sshKey, _, err = s.SSHKey().GetByFingerprint(s, ssh.FingerprintLegacyMD5(publicKey)) + sshKey, _, err = s.Client().SSHKey().GetByFingerprint(s, ssh.FingerprintLegacyMD5(publicKey)) if err != nil { err = fmt.Errorf("lookup SSH key by fingerprint: %v", err) return diff --git a/internal/cmd/server/create_image.go b/internal/cmd/server/create_image.go index ac4f5489..cf4f8402 100644 --- a/internal/cmd/server/create_image.go +++ b/internal/cmd/server/create_image.go @@ -31,7 +31,7 @@ var CreateImageCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - server, _, err := s.Server().Get(s, idOrName) + server, _, err := s.Client().Server().Get(s, idOrName) if err != nil { return err } @@ -55,7 +55,7 @@ var CreateImageCmd = base.Cmd{ Description: hcloud.Ptr(description), Labels: labels, } - result, _, err := s.Server().CreateImage(s, server, opts) + result, _, err := s.Client().Server().CreateImage(s, server, opts) if err != nil { return err } diff --git a/internal/cmd/server/delete.go b/internal/cmd/server/delete.go index 38d9c463..cb19f5e6 100644 --- a/internal/cmd/server/delete.go +++ b/internal/cmd/server/delete.go @@ -14,11 +14,11 @@ var DeleteCmd = base.DeleteCmd{ ShortDescription: "Delete a server", NameSuggestions: func(c hcapi2.Client) func() []string { return c.Server().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) { - return s.Server().Get(s, idOrName) + return s.Client().Server().Get(s, idOrName) }, Delete: func(s state.State, cmd *cobra.Command, resource interface{}) error { server := resource.(*hcloud.Server) - result, _, err := s.Server().DeleteWithResult(s, server) + result, _, err := s.Client().Server().DeleteWithResult(s, server) if err != nil { return err } diff --git a/internal/cmd/server/describe.go b/internal/cmd/server/describe.go index 9ebd3cbe..ec385bad 100644 --- a/internal/cmd/server/describe.go +++ b/internal/cmd/server/describe.go @@ -20,7 +20,7 @@ var DescribeCmd = base.DescribeCmd{ JSONKeyGetByName: "servers", NameSuggestions: func(c hcapi2.Client) func() []string { return c.Server().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, interface{}, error) { - srv, _, err := s.Server().Get(s, idOrName) + srv, _, err := s.Client().Server().Get(s, idOrName) if err != nil { return nil, nil, err } @@ -67,7 +67,7 @@ var DescribeCmd = base.DescribeCmd{ cmd.Printf(" Floating IPs:\n") if len(server.PublicNet.FloatingIPs) > 0 { for _, f := range server.PublicNet.FloatingIPs { - floatingIP, _, err := s.FloatingIP().GetByID(s, f.ID) + floatingIP, _, err := s.Client().FloatingIP().GetByID(s, f.ID) if err != nil { return fmt.Errorf("error fetching Floating IP: %v", err) } @@ -82,7 +82,7 @@ var DescribeCmd = base.DescribeCmd{ cmd.Printf("Private Net:\n") if len(server.PrivateNet) > 0 { for _, n := range server.PrivateNet { - network, _, err := s.Network().GetByID(s, n.Network.ID) + network, _, err := s.Client().Network().GetByID(s, n.Network.ID) if err != nil { return fmt.Errorf("error fetching network: %v", err) } @@ -106,7 +106,7 @@ var DescribeCmd = base.DescribeCmd{ cmd.Printf("Volumes:\n") if len(server.Volumes) > 0 { for _, v := range server.Volumes { - volume, _, err := s.Volume().GetByID(s, v.ID) + volume, _, err := s.Client().Volume().GetByID(s, v.ID) if err != nil { return fmt.Errorf("error fetching Volume: %v", err) } diff --git a/internal/cmd/server/detach_from_network.go b/internal/cmd/server/detach_from_network.go index a98f9ac8..8d24e570 100644 --- a/internal/cmd/server/detach_from_network.go +++ b/internal/cmd/server/detach_from_network.go @@ -30,7 +30,7 @@ var DetachFromNetworkCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - server, _, err := s.Server().Get(s, idOrName) + server, _, err := s.Client().Server().Get(s, idOrName) if err != nil { return err } @@ -38,7 +38,7 @@ var DetachFromNetworkCmd = base.Cmd{ return fmt.Errorf("server not found: %s", idOrName) } networkIDOrName, _ := cmd.Flags().GetString("network") - network, _, err := s.Network().Get(s, networkIDOrName) + network, _, err := s.Client().Network().Get(s, networkIDOrName) if err != nil { return err } @@ -49,7 +49,7 @@ var DetachFromNetworkCmd = base.Cmd{ opts := hcloud.ServerDetachFromNetworkOpts{ Network: network, } - action, _, err := s.Server().DetachFromNetwork(s, server, opts) + action, _, err := s.Client().Server().DetachFromNetwork(s, server, opts) if err != nil { return err } diff --git a/internal/cmd/server/detach_iso.go b/internal/cmd/server/detach_iso.go index 85e2125d..ae780cb7 100644 --- a/internal/cmd/server/detach_iso.go +++ b/internal/cmd/server/detach_iso.go @@ -24,7 +24,7 @@ var DetachISOCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - server, _, err := s.Server().Get(s, idOrName) + server, _, err := s.Client().Server().Get(s, idOrName) if err != nil { return err } @@ -32,7 +32,7 @@ var DetachISOCmd = base.Cmd{ return fmt.Errorf("server not found: %s", idOrName) } - action, _, err := s.Server().DetachISO(s, server) + action, _, err := s.Client().Server().DetachISO(s, server) if err != nil { return err } diff --git a/internal/cmd/server/disable_backup.go b/internal/cmd/server/disable_backup.go index 9abc9dde..416436c4 100644 --- a/internal/cmd/server/disable_backup.go +++ b/internal/cmd/server/disable_backup.go @@ -24,7 +24,7 @@ var DisableBackupCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - server, _, err := s.Server().Get(s, idOrName) + server, _, err := s.Client().Server().Get(s, idOrName) if err != nil { return err } @@ -32,7 +32,7 @@ var DisableBackupCmd = base.Cmd{ return fmt.Errorf("server not found: %s", idOrName) } - action, _, err := s.Server().DisableBackup(s, server) + action, _, err := s.Client().Server().DisableBackup(s, server) if err != nil { return err } diff --git a/internal/cmd/server/disable_protection.go b/internal/cmd/server/disable_protection.go index c239fe2f..bbf8d633 100644 --- a/internal/cmd/server/disable_protection.go +++ b/internal/cmd/server/disable_protection.go @@ -27,7 +27,7 @@ var DisableProtectionCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - server, _, err := s.Server().Get(s, idOrName) + server, _, err := s.Client().Server().Get(s, idOrName) if err != nil { return err } diff --git a/internal/cmd/server/disable_rescue.go b/internal/cmd/server/disable_rescue.go index 95adafb3..826a9d73 100644 --- a/internal/cmd/server/disable_rescue.go +++ b/internal/cmd/server/disable_rescue.go @@ -24,7 +24,7 @@ var DisableRescueCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - server, _, err := s.Server().Get(s, idOrName) + server, _, err := s.Client().Server().Get(s, idOrName) if err != nil { return err } @@ -32,7 +32,7 @@ var DisableRescueCmd = base.Cmd{ return fmt.Errorf("server not found: %s", idOrName) } - action, _, err := s.Server().DisableRescue(s, server) + action, _, err := s.Client().Server().DisableRescue(s, server) if err != nil { return err } diff --git a/internal/cmd/server/enable_backup.go b/internal/cmd/server/enable_backup.go index 5c9549b4..9dd96720 100644 --- a/internal/cmd/server/enable_backup.go +++ b/internal/cmd/server/enable_backup.go @@ -28,7 +28,7 @@ var EnableBackupCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - server, _, err := s.Server().Get(s, idOrName) + server, _, err := s.Client().Server().Get(s, idOrName) if err != nil { return err } @@ -41,7 +41,7 @@ var EnableBackupCmd = base.Cmd{ cmd.Print("[WARN] The ability to specify a backup window when enabling backups has been removed. Ignoring flag.\n") } - action, _, err := s.Server().EnableBackup(s, server, "") + action, _, err := s.Client().Server().EnableBackup(s, server, "") if err != nil { return err } diff --git a/internal/cmd/server/enable_protection.go b/internal/cmd/server/enable_protection.go index 3e23bdc2..fbd4474a 100644 --- a/internal/cmd/server/enable_protection.go +++ b/internal/cmd/server/enable_protection.go @@ -42,7 +42,7 @@ func changeProtection(s state.State, cmd *cobra.Command, return nil } - action, _, err := s.Server().ChangeProtection(s, server, opts) + action, _, err := s.Client().Server().ChangeProtection(s, server, opts) if err != nil { return err } @@ -75,7 +75,7 @@ var EnableProtectionCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - server, _, err := s.Server().Get(s, idOrName) + server, _, err := s.Client().Server().Get(s, idOrName) if err != nil { return err } diff --git a/internal/cmd/server/enable_rescue.go b/internal/cmd/server/enable_rescue.go index af8e9e36..d75cfaf7 100644 --- a/internal/cmd/server/enable_rescue.go +++ b/internal/cmd/server/enable_rescue.go @@ -31,7 +31,7 @@ var EnableRescueCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - server, _, err := s.Server().Get(s, idOrName) + server, _, err := s.Client().Server().Get(s, idOrName) if err != nil { return err } @@ -47,7 +47,7 @@ var EnableRescueCmd = base.Cmd{ sshKeys, _ := cmd.Flags().GetStringSlice("ssh-key") for _, sshKeyIDOrName := range sshKeys { - sshKey, _, err := s.SSHKey().Get(s, sshKeyIDOrName) + sshKey, _, err := s.Client().SSHKey().Get(s, sshKeyIDOrName) if err != nil { return err } @@ -57,7 +57,7 @@ var EnableRescueCmd = base.Cmd{ opts.SSHKeys = append(opts.SSHKeys, sshKey) } - result, _, err := s.Server().EnableRescue(s, server, opts) + result, _, err := s.Client().Server().EnableRescue(s, server, opts) if err != nil { return err } diff --git a/internal/cmd/server/ip.go b/internal/cmd/server/ip.go index ca36b088..36654969 100644 --- a/internal/cmd/server/ip.go +++ b/internal/cmd/server/ip.go @@ -27,7 +27,7 @@ var IPCmd = base.Cmd{ Run: func(s state.State, cmd *cobra.Command, args []string) error { ipv6, err := cmd.Flags().GetBool("ipv6") idOrName := args[0] - server, _, err := s.Server().Get(s, idOrName) + server, _, err := s.Client().Server().Get(s, idOrName) if err != nil { return err } diff --git a/internal/cmd/server/labels.go b/internal/cmd/server/labels.go index 42c43ce2..ecb5ede0 100644 --- a/internal/cmd/server/labels.go +++ b/internal/cmd/server/labels.go @@ -16,7 +16,7 @@ var LabelCmds = base.LabelCmds{ NameSuggestions: func(c hcapi2.Client) func() []string { return c.Server().Names }, LabelKeySuggestions: func(c hcapi2.Client) func(idOrName string) []string { return c.Server().LabelKeys }, FetchLabels: func(s state.State, idOrName string) (map[string]string, int64, error) { - server, _, err := s.Server().Get(s, idOrName) + server, _, err := s.Client().Server().Get(s, idOrName) if err != nil { return nil, 0, err } @@ -29,7 +29,7 @@ var LabelCmds = base.LabelCmds{ opts := hcloud.ServerUpdateOpts{ Labels: labels, } - _, _, err := s.Server().Update(s, &hcloud.Server{ID: id}, opts) + _, _, err := s.Client().Server().Update(s, &hcloud.Server{ID: id}, opts) return err }, } diff --git a/internal/cmd/server/list.go b/internal/cmd/server/list.go index ada09fbd..4ae20539 100644 --- a/internal/cmd/server/list.go +++ b/internal/cmd/server/list.go @@ -60,7 +60,7 @@ var ListCmd = base.ListCmd{ } } } - servers, err := s.Server().AllWithOpts(s, opts) + servers, err := s.Client().Server().AllWithOpts(s, opts) var resources []interface{} for _, r := range servers { diff --git a/internal/cmd/server/metrics.go b/internal/cmd/server/metrics.go index 164eed69..240f647b 100644 --- a/internal/cmd/server/metrics.go +++ b/internal/cmd/server/metrics.go @@ -51,7 +51,7 @@ var MetricsCmd = base.Cmd{ outputFlags := output.FlagsForCommand(cmd) idOrName := args[0] - server, _, err := s.Server().Get(s, idOrName) + server, _, err := s.Client().Server().Get(s, idOrName) if err != nil { return err } @@ -87,7 +87,7 @@ var MetricsCmd = base.Cmd{ } } - m, resp, err := s.Server().GetMetrics(s, server, hcloud.ServerGetMetricsOpts{ + m, resp, err := s.Client().Server().GetMetrics(s, server, hcloud.ServerGetMetricsOpts{ Types: metricTypes, Start: startTime, End: endTime, diff --git a/internal/cmd/server/poweroff.go b/internal/cmd/server/poweroff.go index ddc75f6b..706889c1 100644 --- a/internal/cmd/server/poweroff.go +++ b/internal/cmd/server/poweroff.go @@ -24,7 +24,7 @@ var PoweroffCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - server, _, err := s.Server().Get(s, idOrName) + server, _, err := s.Client().Server().Get(s, idOrName) if err != nil { return err } @@ -32,7 +32,7 @@ var PoweroffCmd = base.Cmd{ return fmt.Errorf("server not found: %s", idOrName) } - action, _, err := s.Server().Poweroff(s, server) + action, _, err := s.Client().Server().Poweroff(s, server) if err != nil { return err } diff --git a/internal/cmd/server/poweron.go b/internal/cmd/server/poweron.go index 876b97fd..f3626893 100644 --- a/internal/cmd/server/poweron.go +++ b/internal/cmd/server/poweron.go @@ -24,7 +24,7 @@ var PoweronCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - server, _, err := s.Server().Get(s, idOrName) + server, _, err := s.Client().Server().Get(s, idOrName) if err != nil { return err } @@ -32,7 +32,7 @@ var PoweronCmd = base.Cmd{ return fmt.Errorf("server not found: %s", idOrName) } - action, _, err := s.Server().Poweron(s, server) + action, _, err := s.Client().Server().Poweron(s, server) if err != nil { return err } diff --git a/internal/cmd/server/reboot.go b/internal/cmd/server/reboot.go index 94add797..864fc843 100644 --- a/internal/cmd/server/reboot.go +++ b/internal/cmd/server/reboot.go @@ -24,7 +24,7 @@ var RebootCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - server, _, err := s.Server().Get(s, idOrName) + server, _, err := s.Client().Server().Get(s, idOrName) if err != nil { return err } @@ -32,7 +32,7 @@ var RebootCmd = base.Cmd{ return fmt.Errorf("server not found: %s", idOrName) } - action, _, err := s.Server().Reboot(s, server) + action, _, err := s.Client().Server().Reboot(s, server) if err != nil { return err } diff --git a/internal/cmd/server/rebuild.go b/internal/cmd/server/rebuild.go index 54b7bf60..d0da69b1 100644 --- a/internal/cmd/server/rebuild.go +++ b/internal/cmd/server/rebuild.go @@ -33,7 +33,7 @@ var RebuildCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { serverIDOrName := args[0] - server, _, err := s.Server().Get(s, serverIDOrName) + server, _, err := s.Client().Server().Get(s, serverIDOrName) if err != nil { return err } @@ -43,7 +43,7 @@ var RebuildCmd = base.Cmd{ imageIDOrName, _ := cmd.Flags().GetString("image") // Select correct image based on server type architecture - image, _, err := s.Image().GetForArchitecture(s, imageIDOrName, server.ServerType.Architecture) + image, _, err := s.Client().Image().GetForArchitecture(s, imageIDOrName, server.ServerType.Architecture) if err != nil { return err } @@ -64,7 +64,7 @@ var RebuildCmd = base.Cmd{ opts := hcloud.ServerRebuildOpts{ Image: image, } - result, _, err := s.Server().RebuildWithResult(s, server, opts) + result, _, err := s.Client().Server().RebuildWithResult(s, server, opts) if err != nil { return err } diff --git a/internal/cmd/server/remove_from_placement_group.go b/internal/cmd/server/remove_from_placement_group.go index ee4f4138..38f175c1 100644 --- a/internal/cmd/server/remove_from_placement_group.go +++ b/internal/cmd/server/remove_from_placement_group.go @@ -25,7 +25,7 @@ var RemoveFromPlacementGroupCmd = base.Cmd{ Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - server, _, err := s.Server().Get(s, idOrName) + server, _, err := s.Client().Server().Get(s, idOrName) if err != nil { return err } @@ -33,7 +33,7 @@ var RemoveFromPlacementGroupCmd = base.Cmd{ return fmt.Errorf("server not found: %s", idOrName) } - action, _, err := s.Server().RemoveFromPlacementGroup(s, server) + action, _, err := s.Client().Server().RemoveFromPlacementGroup(s, server) if err != nil { return err } diff --git a/internal/cmd/server/request_console.go b/internal/cmd/server/request_console.go index 9b8310e4..26fdb41f 100644 --- a/internal/cmd/server/request_console.go +++ b/internal/cmd/server/request_console.go @@ -29,7 +29,7 @@ var RequestConsoleCmd = base.Cmd{ Run: func(s state.State, cmd *cobra.Command, args []string) error { outOpts := output.FlagsForCommand(cmd) idOrName := args[0] - server, _, err := s.Server().Get(s, idOrName) + server, _, err := s.Client().Server().Get(s, idOrName) if err != nil { return err } @@ -37,7 +37,7 @@ var RequestConsoleCmd = base.Cmd{ return fmt.Errorf("server not found: %s", idOrName) } - result, _, err := s.Server().RequestConsole(s, server) + result, _, err := s.Client().Server().RequestConsole(s, server) if err != nil { return err } diff --git a/internal/cmd/server/reset.go b/internal/cmd/server/reset.go index 6e77d5e3..f8760fec 100644 --- a/internal/cmd/server/reset.go +++ b/internal/cmd/server/reset.go @@ -24,7 +24,7 @@ var ResetCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - server, _, err := s.Server().Get(s, idOrName) + server, _, err := s.Client().Server().Get(s, idOrName) if err != nil { return err } @@ -32,7 +32,7 @@ var ResetCmd = base.Cmd{ return fmt.Errorf("server not found: %s", idOrName) } - action, _, err := s.Server().Reset(s, server) + action, _, err := s.Client().Server().Reset(s, server) if err != nil { return err } diff --git a/internal/cmd/server/reset_password.go b/internal/cmd/server/reset_password.go index ea7a8db9..ec45e337 100644 --- a/internal/cmd/server/reset_password.go +++ b/internal/cmd/server/reset_password.go @@ -24,7 +24,7 @@ var ResetPasswordCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - server, _, err := s.Server().Get(s, idOrName) + server, _, err := s.Client().Server().Get(s, idOrName) if err != nil { return err } @@ -32,7 +32,7 @@ var ResetPasswordCmd = base.Cmd{ return fmt.Errorf("server not found: %s", idOrName) } - result, _, err := s.Server().ResetPassword(s, server) + result, _, err := s.Client().Server().ResetPassword(s, server) if err != nil { return err } diff --git a/internal/cmd/server/set_rdns.go b/internal/cmd/server/set_rdns.go index 45b1ab5f..6ca0e777 100644 --- a/internal/cmd/server/set_rdns.go +++ b/internal/cmd/server/set_rdns.go @@ -16,7 +16,7 @@ var SetRDNSCmd = base.SetRdnsCmd{ ShortDescription: "Change reverse DNS of a Server", NameSuggestions: func(c hcapi2.Client) func() []string { return c.Server().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) { - return s.Server().Get(s, idOrName) + return s.Client().Server().Get(s, idOrName) }, GetDefaultIP: func(resource interface{}) net.IP { server := resource.(*hcloud.Server) diff --git a/internal/cmd/server/shutdown.go b/internal/cmd/server/shutdown.go index b7e11670..67a81c5a 100644 --- a/internal/cmd/server/shutdown.go +++ b/internal/cmd/server/shutdown.go @@ -43,7 +43,7 @@ var ShutdownCmd = base.Cmd{ timeout, _ := cmd.Flags().GetDuration("wait-timeout") idOrName := args[0] - server, _, err := s.Server().Get(s, idOrName) + server, _, err := s.Client().Server().Get(s, idOrName) if err != nil { return err } @@ -51,7 +51,7 @@ var ShutdownCmd = base.Cmd{ return fmt.Errorf("server not found: %s", idOrName) } - action, _, err := s.Server().Shutdown(s, server) + action, _, err := s.Client().Server().Shutdown(s, server) if err != nil { return err } @@ -82,7 +82,7 @@ var ShutdownCmd = base.Cmd{ errCh <- errors.New("failed to shut down server") return } - server, _, err = s.Server().GetByID(s, server.ID) + server, _, err = s.Client().Server().GetByID(s, server.ID) if err != nil { errCh <- err return diff --git a/internal/cmd/server/ssh.go b/internal/cmd/server/ssh.go index 62afab48..ee3ce6da 100644 --- a/internal/cmd/server/ssh.go +++ b/internal/cmd/server/ssh.go @@ -33,7 +33,7 @@ var SSHCmd = base.Cmd{ }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] - server, _, err := s.Server().Get(s, idOrName) + server, _, err := s.Client().Server().Get(s, idOrName) if err != nil { return err } diff --git a/internal/cmd/server/update.go b/internal/cmd/server/update.go index d3802c72..d89ee2fb 100644 --- a/internal/cmd/server/update.go +++ b/internal/cmd/server/update.go @@ -15,7 +15,7 @@ var UpdateCmd = base.UpdateCmd{ ShortDescription: "Update a Server", NameSuggestions: func(c hcapi2.Client) func() []string { return c.Server().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) { - return s.Server().Get(s, idOrName) + return s.Client().Server().Get(s, idOrName) }, DefineFlags: func(cmd *cobra.Command) { cmd.Flags().String("name", "", "Server name") @@ -25,7 +25,7 @@ var UpdateCmd = base.UpdateCmd{ updOpts := hcloud.ServerUpdateOpts{ Name: flags["name"].String(), } - _, _, err := s.Server().Update(s, floatingIP, updOpts) + _, _, err := s.Client().Server().Update(s, floatingIP, updOpts) if err != nil { return err } diff --git a/internal/cmd/servertype/describe.go b/internal/cmd/servertype/describe.go index 436b4551..b95a35dd 100644 --- a/internal/cmd/servertype/describe.go +++ b/internal/cmd/servertype/describe.go @@ -17,7 +17,7 @@ var DescribeCmd = base.DescribeCmd{ JSONKeyGetByName: "server_types", NameSuggestions: func(c hcapi2.Client) func() []string { return c.ServerType().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, interface{}, error) { - st, _, err := s.ServerType().Get(s, idOrName) + st, _, err := s.Client().ServerType().Get(s, idOrName) if err != nil { return nil, nil, err } diff --git a/internal/cmd/servertype/list.go b/internal/cmd/servertype/list.go index 79508301..d2ef199e 100644 --- a/internal/cmd/servertype/list.go +++ b/internal/cmd/servertype/list.go @@ -25,7 +25,7 @@ var ListCmd = base.ListCmd{ if len(sorts) > 0 { opts.Sort = sorts } - servers, err := s.ServerType().AllWithOpts(s, opts) + servers, err := s.Client().ServerType().AllWithOpts(s, opts) var resources []interface{} for _, r := range servers { diff --git a/internal/cmd/sshkey/create.go b/internal/cmd/sshkey/create.go index 34f616c6..ad85d310 100644 --- a/internal/cmd/sshkey/create.go +++ b/internal/cmd/sshkey/create.go @@ -57,7 +57,7 @@ var CreateCmd = base.CreateCmd{ PublicKey: publicKey, Labels: labels, } - sshKey, _, err := s.SSHKey().Create(s, opts) + sshKey, _, err := s.Client().SSHKey().Create(s, opts) if err != nil { return nil, nil, err } diff --git a/internal/cmd/sshkey/delete.go b/internal/cmd/sshkey/delete.go index 367ccd48..902be564 100644 --- a/internal/cmd/sshkey/delete.go +++ b/internal/cmd/sshkey/delete.go @@ -14,11 +14,11 @@ var DeleteCmd = base.DeleteCmd{ ShortDescription: "Delete a SSH Key", NameSuggestions: func(c hcapi2.Client) func() []string { return c.SSHKey().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) { - return s.SSHKey().Get(s, idOrName) + return s.Client().SSHKey().Get(s, idOrName) }, Delete: func(s state.State, cmd *cobra.Command, resource interface{}) error { sshKey := resource.(*hcloud.SSHKey) - if _, err := s.SSHKey().Delete(s, sshKey); err != nil { + if _, err := s.Client().SSHKey().Delete(s, sshKey); err != nil { return err } return nil diff --git a/internal/cmd/sshkey/describe.go b/internal/cmd/sshkey/describe.go index b29b241f..6b9d8e88 100644 --- a/internal/cmd/sshkey/describe.go +++ b/internal/cmd/sshkey/describe.go @@ -20,7 +20,7 @@ var DescribeCmd = base.DescribeCmd{ JSONKeyGetByName: "ssh_keys", NameSuggestions: func(c hcapi2.Client) func() []string { return c.SSHKey().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, interface{}, error) { - key, _, err := s.SSHKey().Get(s, idOrName) + key, _, err := s.Client().SSHKey().Get(s, idOrName) if err != nil { return nil, nil, err } diff --git a/internal/cmd/sshkey/labels.go b/internal/cmd/sshkey/labels.go index 52e86eab..3bfaf396 100644 --- a/internal/cmd/sshkey/labels.go +++ b/internal/cmd/sshkey/labels.go @@ -16,7 +16,7 @@ var LabelCmds = base.LabelCmds{ NameSuggestions: func(c hcapi2.Client) func() []string { return c.SSHKey().Names }, LabelKeySuggestions: func(c hcapi2.Client) func(idOrName string) []string { return c.SSHKey().LabelKeys }, FetchLabels: func(s state.State, idOrName string) (map[string]string, int64, error) { - sshKey, _, err := s.SSHKey().Get(s, idOrName) + sshKey, _, err := s.Client().SSHKey().Get(s, idOrName) if err != nil { return nil, 0, err } @@ -29,7 +29,7 @@ var LabelCmds = base.LabelCmds{ opts := hcloud.SSHKeyUpdateOpts{ Labels: labels, } - _, _, err := s.SSHKey().Update(s, &hcloud.SSHKey{ID: id}, opts) + _, _, err := s.Client().SSHKey().Update(s, &hcloud.SSHKey{ID: id}, opts) return err }, } diff --git a/internal/cmd/sshkey/list.go b/internal/cmd/sshkey/list.go index 67bf7aab..996d4030 100644 --- a/internal/cmd/sshkey/list.go +++ b/internal/cmd/sshkey/list.go @@ -24,7 +24,7 @@ var ListCmd = base.ListCmd{ if len(sorts) > 0 { opts.Sort = sorts } - sshKeys, err := s.SSHKey().AllWithOpts(s, opts) + sshKeys, err := s.Client().SSHKey().AllWithOpts(s, opts) var resources []interface{} for _, n := range sshKeys { diff --git a/internal/cmd/sshkey/update.go b/internal/cmd/sshkey/update.go index a482dfc9..467c4f7b 100644 --- a/internal/cmd/sshkey/update.go +++ b/internal/cmd/sshkey/update.go @@ -15,7 +15,7 @@ var UpdateCmd = base.UpdateCmd{ ShortDescription: "Update a SSHKey", NameSuggestions: func(c hcapi2.Client) func() []string { return c.SSHKey().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) { - return s.SSHKey().Get(s, idOrName) + return s.Client().SSHKey().Get(s, idOrName) }, DefineFlags: func(cmd *cobra.Command) { cmd.Flags().String("name", "", "SSH Key name") @@ -25,7 +25,7 @@ var UpdateCmd = base.UpdateCmd{ updOpts := hcloud.SSHKeyUpdateOpts{ Name: flags["name"].String(), } - _, _, err := s.SSHKey().Update(s, floatingIP, updOpts) + _, _, err := s.Client().SSHKey().Update(s, floatingIP, updOpts) if err != nil { return err } diff --git a/internal/cmd/volume/attach.go b/internal/cmd/volume/attach.go index 2b9098dd..b3d589c0 100644 --- a/internal/cmd/volume/attach.go +++ b/internal/cmd/volume/attach.go @@ -30,7 +30,7 @@ var AttachCmd = base.Cmd{ return cmd }, Run: func(s state.State, cmd *cobra.Command, args []string) error { - volume, _, err := s.Volume().Get(s, args[0]) + volume, _, err := s.Client().Volume().Get(s, args[0]) if err != nil { return err } @@ -39,7 +39,7 @@ var AttachCmd = base.Cmd{ } serverIDOrName, _ := cmd.Flags().GetString("server") - server, _, err := s.Server().Get(s, serverIDOrName) + server, _, err := s.Client().Server().Get(s, serverIDOrName) if err != nil { return err } @@ -47,7 +47,7 @@ var AttachCmd = base.Cmd{ return fmt.Errorf("server not found: %s", serverIDOrName) } automount, _ := cmd.Flags().GetBool("automount") - action, _, err := s.Volume().AttachWithOpts(s, volume, hcloud.VolumeAttachOpts{ + action, _, err := s.Client().Volume().AttachWithOpts(s, volume, hcloud.VolumeAttachOpts{ Server: server, Automount: &automount, }) diff --git a/internal/cmd/volume/create.go b/internal/cmd/volume/create.go index 651866a5..5d72be6b 100644 --- a/internal/cmd/volume/create.go +++ b/internal/cmd/volume/create.go @@ -77,7 +77,7 @@ var CreateCmd = base.CreateCmd{ } } if serverIDOrName != "" { - server, _, err := s.Server().Get(s, serverIDOrName) + server, _, err := s.Client().Server().Get(s, serverIDOrName) if err != nil { return nil, nil, err } @@ -93,7 +93,7 @@ var CreateCmd = base.CreateCmd{ createOpts.Format = &format } - result, _, err := s.Volume().Create(s, createOpts) + result, _, err := s.Client().Volume().Create(s, createOpts) if err != nil { return nil, nil, err } diff --git a/internal/cmd/volume/delete.go b/internal/cmd/volume/delete.go index 0e8cf77d..9aa9b1c3 100644 --- a/internal/cmd/volume/delete.go +++ b/internal/cmd/volume/delete.go @@ -14,11 +14,11 @@ var DeleteCmd = base.DeleteCmd{ ShortDescription: "Delete a Volume", NameSuggestions: func(c hcapi2.Client) func() []string { return c.Volume().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) { - return s.Volume().Get(s, idOrName) + return s.Client().Volume().Get(s, idOrName) }, Delete: func(s state.State, cmd *cobra.Command, resource interface{}) error { volume := resource.(*hcloud.Volume) - if _, err := s.Volume().Delete(s, volume); err != nil { + if _, err := s.Client().Volume().Delete(s, volume); err != nil { return err } return nil diff --git a/internal/cmd/volume/describe.go b/internal/cmd/volume/describe.go index b4ccebc8..44c292d2 100644 --- a/internal/cmd/volume/describe.go +++ b/internal/cmd/volume/describe.go @@ -18,7 +18,7 @@ var DescribeCmd = base.DescribeCmd{ JSONKeyGetByName: "volumes", NameSuggestions: func(c hcapi2.Client) func() []string { return c.Volume().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, interface{}, error) { - v, _, err := s.Volume().Get(s, idOrName) + v, _, err := s.Client().Volume().Get(s, idOrName) if err != nil { return nil, nil, err } @@ -42,7 +42,7 @@ var DescribeCmd = base.DescribeCmd{ if volume.Server != nil { cmd.Printf("Server:\n") cmd.Printf(" ID:\t\t%d\n", volume.Server.ID) - cmd.Printf(" Name:\t\t%s\n", s.Server().ServerName(volume.Server.ID)) + cmd.Printf(" Name:\t\t%s\n", s.Client().Server().ServerName(volume.Server.ID)) } else { cmd.Print("Server:\n Not attached\n") } diff --git a/internal/cmd/volume/detach.go b/internal/cmd/volume/detach.go index 499c9de9..dff81363 100644 --- a/internal/cmd/volume/detach.go +++ b/internal/cmd/volume/detach.go @@ -23,7 +23,7 @@ var DetachCmd = base.Cmd{ } }, Run: func(s state.State, cmd *cobra.Command, args []string) error { - volume, _, err := s.Volume().Get(s, args[0]) + volume, _, err := s.Client().Volume().Get(s, args[0]) if err != nil { return err } @@ -31,7 +31,7 @@ var DetachCmd = base.Cmd{ return fmt.Errorf("volume not found: %s", args[0]) } - action, _, err := s.Volume().Detach(s, volume) + action, _, err := s.Client().Volume().Detach(s, volume) if err != nil { return err } diff --git a/internal/cmd/volume/disable_protection.go b/internal/cmd/volume/disable_protection.go index d60d0449..28ce5e68 100644 --- a/internal/cmd/volume/disable_protection.go +++ b/internal/cmd/volume/disable_protection.go @@ -26,7 +26,7 @@ var DisableProtectionCmd = base.Cmd{ } }, Run: func(s state.State, cmd *cobra.Command, args []string) error { - volume, _, err := s.Volume().Get(s, args[0]) + volume, _, err := s.Client().Volume().Get(s, args[0]) if err != nil { return err } diff --git a/internal/cmd/volume/enable_protection.go b/internal/cmd/volume/enable_protection.go index 207bb627..f0803114 100644 --- a/internal/cmd/volume/enable_protection.go +++ b/internal/cmd/volume/enable_protection.go @@ -40,7 +40,7 @@ func changeProtection(s state.State, cmd *cobra.Command, return nil } - action, _, err := s.Volume().ChangeProtection(s, volume, opts) + action, _, err := s.Client().Volume().ChangeProtection(s, volume, opts) if err != nil { return err } @@ -72,7 +72,7 @@ var EnableProtectionCmd = base.Cmd{ } }, Run: func(s state.State, cmd *cobra.Command, args []string) error { - volume, _, err := s.Volume().Get(s, args[0]) + volume, _, err := s.Client().Volume().Get(s, args[0]) if err != nil { return err } diff --git a/internal/cmd/volume/labels.go b/internal/cmd/volume/labels.go index 951823f6..57a8d972 100644 --- a/internal/cmd/volume/labels.go +++ b/internal/cmd/volume/labels.go @@ -16,7 +16,7 @@ var LabelCmds = base.LabelCmds{ NameSuggestions: func(c hcapi2.Client) func() []string { return c.Volume().Names }, LabelKeySuggestions: func(c hcapi2.Client) func(idOrName string) []string { return c.Volume().LabelKeys }, FetchLabels: func(s state.State, idOrName string) (map[string]string, int64, error) { - volume, _, err := s.Volume().Get(s, idOrName) + volume, _, err := s.Client().Volume().Get(s, idOrName) if err != nil { return nil, 0, err } @@ -29,7 +29,7 @@ var LabelCmds = base.LabelCmds{ opts := hcloud.VolumeUpdateOpts{ Labels: labels, } - _, _, err := s.Volume().Update(s, &hcloud.Volume{ID: id}, opts) + _, _, err := s.Client().Volume().Update(s, &hcloud.Volume{ID: id}, opts) return err }, } diff --git a/internal/cmd/volume/list.go b/internal/cmd/volume/list.go index 050c44da..ab5885e7 100644 --- a/internal/cmd/volume/list.go +++ b/internal/cmd/volume/list.go @@ -26,7 +26,7 @@ var ListCmd = base.ListCmd{ if len(sorts) > 0 { opts.Sort = sorts } - volumes, err := s.Volume().AllWithOpts(s, opts) + volumes, err := s.Client().Volume().AllWithOpts(s, opts) var resources []interface{} for _, n := range volumes { diff --git a/internal/cmd/volume/resize.go b/internal/cmd/volume/resize.go index 5760ac90..869d3fc1 100644 --- a/internal/cmd/volume/resize.go +++ b/internal/cmd/volume/resize.go @@ -26,7 +26,7 @@ var ResizeCmd = base.Cmd{ return cmd }, Run: func(s state.State, cmd *cobra.Command, args []string) error { - volume, _, err := s.Volume().Get(s, args[0]) + volume, _, err := s.Client().Volume().Get(s, args[0]) if err != nil { return err } @@ -35,7 +35,7 @@ var ResizeCmd = base.Cmd{ } size, _ := cmd.Flags().GetInt("size") - action, _, err := s.Volume().Resize(s, volume, size) + action, _, err := s.Client().Volume().Resize(s, volume, size) if err != nil { return err } diff --git a/internal/cmd/volume/update.go b/internal/cmd/volume/update.go index 663fcc08..8b39917e 100644 --- a/internal/cmd/volume/update.go +++ b/internal/cmd/volume/update.go @@ -15,7 +15,7 @@ var UpdateCmd = base.UpdateCmd{ ShortDescription: "Update a Volume", NameSuggestions: func(c hcapi2.Client) func() []string { return c.Volume().Names }, Fetch: func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) { - return s.Volume().Get(s, idOrName) + return s.Client().Volume().Get(s, idOrName) }, DefineFlags: func(cmd *cobra.Command) { cmd.Flags().String("name", "", "Volume name") @@ -25,7 +25,7 @@ var UpdateCmd = base.UpdateCmd{ updOpts := hcloud.VolumeUpdateOpts{ Name: flags["name"].String(), } - _, _, err := s.Volume().Update(s, floatingIP, updOpts) + _, _, err := s.Client().Volume().Update(s, floatingIP, updOpts) if err != nil { return err } diff --git a/internal/state/config.go b/internal/state/config.go index eabba389..6155e8d1 100644 --- a/internal/state/config.go +++ b/internal/state/config.go @@ -2,6 +2,8 @@ package state import ( "fmt" + "os" + "path/filepath" toml "github.com/pelletier/go-toml/v2" ) @@ -9,6 +11,7 @@ import ( var DefaultConfigPath string type Config struct { + Path string Endpoint string ActiveContext *ConfigContext Contexts []*ConfigContext @@ -19,6 +22,20 @@ type ConfigContext struct { Token string } +func (config *Config) Write() error { + data, err := MarshalConfig(config) + if err != nil { + return err + } + if err := os.MkdirAll(filepath.Dir(config.Path), 0777); err != nil { + return err + } + if err := os.WriteFile(config.Path, data, 0600); err != nil { + return err + } + return nil +} + func (config *Config) ContextNames() []string { if len(config.Contexts) == 0 { return nil diff --git a/internal/state/helpers.go b/internal/state/helpers.go index 4b41254b..4dcde3d5 100644 --- a/internal/state/helpers.go +++ b/internal/state/helpers.go @@ -60,7 +60,7 @@ func (c *state) ActionsProgresses(cmd *cobra.Command, ctx context.Context, actio } func (c *state) EnsureToken(_ *cobra.Command, _ []string) error { - if c.Token == "" { + if c.token == "" { return errors.New("no active context or token (see `hcloud context --help`)") } return nil diff --git a/internal/state/state.go b/internal/state/state.go index 650eb7cd..9ea01c9b 100644 --- a/internal/state/state.go +++ b/internal/state/state.go @@ -3,10 +3,8 @@ package state import ( "context" "fmt" - "io/ioutil" "log" "os" - "path/filepath" "time" "github.com/hetznercloud/cli/internal/hcapi2" @@ -15,110 +13,125 @@ import ( ) type State interface { + context.Context + TokenEnsurer ActionWaiter - context.Context - hcapi2.Client - WriteConfig() error + Client() hcapi2.Client Config() *Config } type state struct { context.Context - hcapi2.Client - - Token string - Endpoint string - ConfigPath string - Debug bool - DebugFilePath string - hcloudClient *hcloud.Client - config *Config + token string + endpoint string + debug bool + debugFilePath string + client hcapi2.Client + hcloudClient *hcloud.Client + config *Config } func New() (State, error) { - s := &state{ - Context: context.Background(), - config: &Config{}, - ConfigPath: DefaultConfigPath, + configPath := os.Getenv("HCLOUD_CONFIG") + if configPath == "" { + configPath = DefaultConfigPath } - if p := os.Getenv("HCLOUD_CONFIG"); p != "" { - s.ConfigPath = p + + cfg, err := readConfig(configPath) + if err != nil { + return nil, fmt.Errorf("unable to read config file %q: %s\n", configPath, err) } - if err := s.readConfig(); err != nil { - return nil, fmt.Errorf("unable to read config file %q: %s\n", s.ConfigPath, err) + + var ( + token string + endpoint string + ) + if cfg.ActiveContext != nil { + token = cfg.ActiveContext.Token + } + if cfg.Endpoint != "" { + endpoint = cfg.Endpoint + } + + s := &state{ + Context: context.Background(), + config: cfg, + token: token, + endpoint: endpoint, } + s.readEnv() s.hcloudClient = s.newClient() - s.Client = hcapi2.NewClient(s.hcloudClient) + s.client = hcapi2.NewClient(s.hcloudClient) return s, nil } +func (c *state) Client() hcapi2.Client { + return c.client +} + func (c *state) Config() *Config { return c.config } func (c *state) readEnv() { if s := os.Getenv("HCLOUD_TOKEN"); s != "" { - c.Token = s + c.token = s } if s := os.Getenv("HCLOUD_ENDPOINT"); s != "" { - c.Endpoint = s + c.endpoint = s } if s := os.Getenv("HCLOUD_DEBUG"); s != "" { - c.Debug = true + c.debug = true } if s := os.Getenv("HCLOUD_DEBUG_FILE"); s != "" { - c.DebugFilePath = s + c.debugFilePath = s } if s := os.Getenv("HCLOUD_CONTEXT"); s != "" && c.config != nil { if cfgCtx := c.config.ContextByName(s); cfgCtx != nil { c.config.ActiveContext = cfgCtx - c.Token = cfgCtx.Token + c.token = cfgCtx.Token } else { log.Printf("warning: context %q specified in HCLOUD_CONTEXT does not exist\n", s) } } } -func (c *state) readConfig() error { - _, err := os.Stat(c.ConfigPath) +func readConfig(path string) (*Config, error) { + _, err := os.Stat(path) if err != nil && !os.IsNotExist(err) { - return err + return nil, err } - data, err := os.ReadFile(c.ConfigPath) + data, err := os.ReadFile(path) if err != nil { - return err - } - if err = UnmarshalConfig(c.config, data); err != nil { - return err + return nil, err } - if c.config.ActiveContext != nil { - c.Token = c.config.ActiveContext.Token - } - if c.config.Endpoint != "" { - c.Endpoint = c.config.Endpoint + cfg := &Config{Path: path} + if err = UnmarshalConfig(cfg, data); err != nil { + return nil, err } - return nil + + return cfg, nil } func (c *state) newClient() *hcloud.Client { opts := []hcloud.ClientOption{ - hcloud.WithToken(c.Token), + hcloud.WithToken(c.token), hcloud.WithApplication("hcloud-cli", version.Version), } - if c.Endpoint != "" { - opts = append(opts, hcloud.WithEndpoint(c.Endpoint)) + if c.endpoint != "" { + opts = append(opts, hcloud.WithEndpoint(c.endpoint)) } - if c.Debug { - if c.DebugFilePath == "" { + if c.debug { + if c.debugFilePath == "" { opts = append(opts, hcloud.WithDebugWriter(os.Stderr)) } else { - writer, _ := os.Create(c.DebugFilePath) + writer, _ := os.Create(c.debugFilePath) opts = append(opts, hcloud.WithDebugWriter(writer)) } } @@ -130,21 +143,3 @@ func (c *state) newClient() *hcloud.Client { } return hcloud.NewClient(opts...) } - -func (c *state) WriteConfig() error { - if c.config == nil { - return nil - } - - data, err := MarshalConfig(c.config) - if err != nil { - return err - } - if err := os.MkdirAll(filepath.Dir(c.ConfigPath), 0777); err != nil { - return err - } - if err := ioutil.WriteFile(c.ConfigPath, data, 0600); err != nil { - return err - } - return nil -} diff --git a/internal/testutil/fixture.go b/internal/testutil/fixture.go index b504e026..f21b66e1 100644 --- a/internal/testutil/fixture.go +++ b/internal/testutil/fixture.go @@ -59,26 +59,31 @@ func (f *Fixture) Finish() { // fixtureState implements state.State for testing purposes. type fixtureState struct { + context.Context state.TokenEnsurer state.ActionWaiter - context.Context - hcapi2.Client + + client hcapi2.Client } -func (fixtureState) WriteConfig() error { +func (*fixtureState) WriteConfig() error { return errors.New("not implemented") } -func (fixtureState) Config() *state.Config { +func (s *fixtureState) Client() hcapi2.Client { + return s.client +} + +func (*fixtureState) Config() *state.Config { return nil } // State returns a state.State implementation for testing purposes. func (f *Fixture) State() state.State { - return fixtureState{ + return &fixtureState{ + Context: context.Background(), TokenEnsurer: f.TokenEnsurer, ActionWaiter: f.ActionWaiter, - Context: context.Background(), - Client: f.Client, + client: f.Client, } }