From fe852a5bb0a3c21de6081aa37d989f3ba56289db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20K=C3=A4mmerling?= Date: Wed, 23 Jun 2021 10:55:11 +0200 Subject: [PATCH] Move certificate commands to new structure (#334) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lukas Kämmerling --- internal/cmd/base/labels.go | 6 + internal/cmd/certificate/add_label.go | 68 --- internal/cmd/certificate/certificate.go | 11 +- internal/cmd/certificate/delete.go | 50 +- internal/cmd/certificate/describe.go | 155 ++---- internal/cmd/certificate/labels.go | 35 ++ internal/cmd/certificate/list.go | 158 +++--- internal/cmd/certificate/remove_label.go | 86 --- internal/hcapi2/certificate.go | 52 ++ internal/hcapi2/client.go | 61 ++- internal/hcapi2/firewall.go | 4 +- internal/hcapi2/interface_gen.go | 2 + internal/hcapi2/loadbalancer.go | 91 ++++ internal/hcapi2/mock_gen.go | 2 + internal/hcapi2/zz_certificate_client_base.go | 23 + internal/hcapi2/zz_certificate_client_mock.go | 237 +++++++++ .../hcapi2/zz_loadbalancer_client_base.go | 39 ++ .../hcapi2/zz_loadbalancer_client_mock.go | 492 ++++++++++++++++++ 18 files changed, 1161 insertions(+), 411 deletions(-) delete mode 100644 internal/cmd/certificate/add_label.go create mode 100644 internal/cmd/certificate/labels.go delete mode 100644 internal/cmd/certificate/remove_label.go create mode 100644 internal/hcapi2/certificate.go create mode 100644 internal/hcapi2/loadbalancer.go create mode 100644 internal/hcapi2/zz_certificate_client_base.go create mode 100644 internal/hcapi2/zz_certificate_client_mock.go create mode 100644 internal/hcapi2/zz_loadbalancer_client_base.go create mode 100644 internal/hcapi2/zz_loadbalancer_client_mock.go diff --git a/internal/cmd/base/labels.go b/internal/cmd/base/labels.go index 1ce64a56..dc72feb3 100644 --- a/internal/cmd/base/labels.go +++ b/internal/cmd/base/labels.go @@ -53,11 +53,17 @@ func (lc *LabelCmds) RunAdd(ctx context.Context, client hcapi2.Client, cmd *cobr if err != nil { return err } + + if labels == nil { + labels = map[string]string{} + } + key, val := util.SplitLabelVars(args[1]) if _, ok := labels[key]; ok && !overwrite { return fmt.Errorf("label %s on %s %d already exists", key, lc.ResourceNameSingular, id) } + labels[key] = val if err := lc.SetLabels(ctx, client, id, labels); err != nil { diff --git a/internal/cmd/certificate/add_label.go b/internal/cmd/certificate/add_label.go deleted file mode 100644 index 66cc422a..00000000 --- a/internal/cmd/certificate/add_label.go +++ /dev/null @@ -1,68 +0,0 @@ -package certificate - -import ( - "fmt" - - "github.com/hetznercloud/cli/internal/cmd/cmpl" - "github.com/hetznercloud/cli/internal/cmd/util" - "github.com/hetznercloud/cli/internal/state" - "github.com/hetznercloud/hcloud-go/hcloud" - "github.com/spf13/cobra" -) - -func newAddLabelCommand(cli *state.State) *cobra.Command { - cmd := &cobra.Command{ - Use: "add-label [FLAGS] CERTIFICATE LABEL", - Short: "Add a label to a certificate", - Args: cobra.ExactArgs(2), - ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(cli.CertificateNames)), - TraverseChildren: true, - DisableFlagsInUseLine: true, - PreRunE: util.ChainRunE(validateAddLabel, cli.EnsureToken), - RunE: cli.Wrap(runAddLabel), - } - - cmd.Flags().BoolP("overwrite", "o", false, "Overwrite label if it exists already") - return cmd -} - -func validateAddLabel(cmd *cobra.Command, args []string) error { - label := util.SplitLabel(args[1]) - if len(label) != 2 { - return fmt.Errorf("invalid label: %s", args[1]) - } - return nil -} - -func runAddLabel(cli *state.State, cmd *cobra.Command, args []string) error { - overwrite, err := cmd.Flags().GetBool("overwrite") - if err != nil { - return err - } - idOrName := args[0] - cert, _, err := cli.Client().Certificate.Get(cli.Context, idOrName) - if err != nil { - return err - } - if cert == nil { - return fmt.Errorf("Certificate not found: %s", idOrName) - } - label := util.SplitLabel(args[1]) - if _, ok := cert.Labels[label[0]]; ok && !overwrite { - return fmt.Errorf("Label %s on certificate %d already exists", label[0], cert.ID) - } - if cert.Labels == nil { - cert.Labels = make(map[string]string) - } - labels := cert.Labels - labels[label[0]] = label[1] - opts := hcloud.CertificateUpdateOpts{ - Labels: labels, - } - _, _, err = cli.Client().Certificate.Update(cli.Context, cert, opts) - if err != nil { - return err - } - fmt.Printf("Label %s added to certificate %d\n", label[0], cert.ID) - return nil -} diff --git a/internal/cmd/certificate/certificate.go b/internal/cmd/certificate/certificate.go index 0aa720df..f8b6cf32 100644 --- a/internal/cmd/certificate/certificate.go +++ b/internal/cmd/certificate/certificate.go @@ -1,6 +1,7 @@ package certificate import ( + "github.com/hetznercloud/cli/internal/hcapi2" "github.com/hetznercloud/cli/internal/state" "github.com/spf13/cobra" ) @@ -14,13 +15,13 @@ func NewCommand(cli *state.State) *cobra.Command { DisableFlagsInUseLine: true, } cmd.AddCommand( - newListCommand(cli), + listCmd.CobraCommand(cli.Context, hcapi2.NewClient(cli.Client()), cli), newCreateCommand(cli), newUpdateCommand(cli), - newAddLabelCommand(cli), - newRemoveLabelCommand(cli), - newDeleteCommand(cli), - newDescribeCommand(cli), + labelCmds.AddCobraCommand(cli.Context, hcapi2.NewClient(cli.Client()), cli), + labelCmds.RemoveCobraCommand(cli.Context, hcapi2.NewClient(cli.Client()), cli), + deleteCmd.CobraCommand(cli.Context, hcapi2.NewClient(cli.Client()), cli), + describeCmd.CobraCommand(cli.Context, hcapi2.NewClient(cli.Client()), cli), ) return cmd diff --git a/internal/cmd/certificate/delete.go b/internal/cmd/certificate/delete.go index d832e2d0..af39b56c 100644 --- a/internal/cmd/certificate/delete.go +++ b/internal/cmd/certificate/delete.go @@ -1,39 +1,25 @@ package certificate import ( - "fmt" + "context" - "github.com/hetznercloud/cli/internal/cmd/cmpl" - "github.com/hetznercloud/cli/internal/state" - "github.com/spf13/cobra" + "github.com/hetznercloud/cli/internal/cmd/base" + "github.com/hetznercloud/cli/internal/hcapi2" + "github.com/hetznercloud/hcloud-go/hcloud" ) -func newDeleteCommand(cli *state.State) *cobra.Command { - return &cobra.Command{ - Use: "delete CERTIFICATE", - Short: "Delete a certificate", - Args: cobra.ExactArgs(1), - ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(cli.CertificateNames)), - TraverseChildren: true, - DisableFlagsInUseLine: true, - PreRunE: cli.EnsureToken, - RunE: cli.Wrap(runDelete), - } -} - -func runDelete(cli *state.State, cmd *cobra.Command, args []string) error { - idOrName := args[0] - cert, _, err := cli.Client().Certificate.Get(cli.Context, idOrName) - if err != nil { - return err - } - if cert == nil { - return fmt.Errorf("Certificate %s not found", idOrName) - } - _, err = cli.Client().Certificate.Delete(cli.Context, cert) - if err != nil { - return err - } - fmt.Printf("Certificate %d deleted\n", cert.ID) - return nil +var deleteCmd = base.DeleteCmd{ + ResourceNameSingular: "certificate", + ShortDescription: "Delete a certificate", + NameSuggestions: func(c hcapi2.Client) func() []string { return c.Firewall().Names }, + Fetch: func(ctx context.Context, client hcapi2.Client, idOrName string) (interface{}, *hcloud.Response, error) { + return client.Certificate().Get(ctx, idOrName) + }, + Delete: func(ctx context.Context, client hcapi2.Client, resource interface{}) error { + certificate := resource.(*hcloud.Certificate) + if _, err := client.Certificate().Delete(ctx, certificate); err != nil { + return err + } + return nil + }, } diff --git a/internal/cmd/certificate/describe.go b/internal/cmd/certificate/describe.go index 30015249..48ce79bd 100644 --- a/internal/cmd/certificate/describe.go +++ b/internal/cmd/certificate/describe.go @@ -1,112 +1,71 @@ package certificate import ( - "encoding/json" + "context" "fmt" - humanize "github.com/dustin/go-humanize" - "github.com/hetznercloud/cli/internal/cmd/cmpl" - "github.com/hetznercloud/cli/internal/cmd/output" + "github.com/hetznercloud/cli/internal/cmd/base" + "github.com/hetznercloud/cli/internal/hcapi2" + + "github.com/dustin/go-humanize" "github.com/hetznercloud/cli/internal/cmd/util" - "github.com/hetznercloud/cli/internal/state" "github.com/hetznercloud/hcloud-go/hcloud" - "github.com/spf13/cobra" ) -func newDescribeCommand(cli *state.State) *cobra.Command { - cmd := &cobra.Command{ - Use: "describe [FLAGS] CERTIFICATE", - Short: "Describe a certificate", - Args: cobra.ExactArgs(1), - ValidArgsFunction: cmpl.SuggestArgs(cmpl.SuggestCandidatesF(cli.CertificateNames)), - TraverseChildren: true, - DisableFlagsInUseLine: true, - PreRunE: cli.EnsureToken, - RunE: cli.Wrap(runDescribe), - } - output.AddFlag(cmd, output.OptionJSON(), output.OptionFormat()) - return cmd -} - -func runDescribe(cli *state.State, cmd *cobra.Command, args []string) error { - outputFlags := output.FlagsForCommand(cmd) - - idOrName := args[0] - cert, resp, err := cli.Client().Certificate.Get(cli.Context, idOrName) - if err != nil { - return err - } - if cert == nil { - return fmt.Errorf("certificate not found: %s", idOrName) - } - - switch { - case outputFlags.IsSet("json"): - return describeJSON(resp) - case outputFlags.IsSet("format"): - return util.DescribeFormat(cert, outputFlags["format"][0]) - default: - return describeText(cli, cert) - } -} - -func describeJSON(resp *hcloud.Response) error { - var data map[string]interface{} - if err := json.NewDecoder(resp.Body).Decode(&data); err != nil { - return err - } - if server, ok := data["certificate"]; ok { - return util.DescribeJSON(server) - } - if servers, ok := data["certificates"].([]interface{}); ok { - return util.DescribeJSON(servers[0]) - } - return util.DescribeJSON(data) -} - -func describeText(cli *state.State, cert *hcloud.Certificate) error { - fmt.Printf("ID:\t\t\t%d\n", cert.ID) - fmt.Printf("Name:\t\t\t%s\n", cert.Name) - fmt.Printf("Type:\t\t\t%s\n", cert.Type) - fmt.Printf("Fingerprint:\t\t%s\n", cert.Fingerprint) - fmt.Printf("Created:\t\t%s (%s)\n", util.Datetime(cert.Created), humanize.Time(cert.Created)) - fmt.Printf("Not valid before:\t%s (%s)\n", util.Datetime(cert.NotValidBefore), humanize.Time(cert.NotValidBefore)) - fmt.Printf("Not valid after:\t%s (%s)\n", util.Datetime(cert.NotValidAfter), humanize.Time(cert.NotValidAfter)) - if cert.Status != nil { - fmt.Printf("Status:\n") - fmt.Printf(" Issuance: %s\n", cert.Status.Issuance) - fmt.Printf(" Renewal: %s\n", cert.Status.Renewal) - if cert.Status.IsFailed() { - fmt.Printf(" Failure reason: %s\n", cert.Status.Error.Message) +var describeCmd = base.DescribeCmd{ + ResourceNameSingular: "certificate", + ShortDescription: "Describe an certificate", + JSONKeyGetByID: "certificate", + JSONKeyGetByName: "certificates", + NameSuggestions: func(c hcapi2.Client) func() []string { return c.Certificate().Names }, + Fetch: func(ctx context.Context, client hcapi2.Client, idOrName string) (interface{}, *hcloud.Response, error) { + return client.Certificate().Get(ctx, idOrName) + }, + PrintText: func(_ context.Context, client hcapi2.Client, resource interface{}) error { + cert := resource.(*hcloud.Certificate) + fmt.Printf("ID:\t\t\t%d\n", cert.ID) + fmt.Printf("Name:\t\t\t%s\n", cert.Name) + fmt.Printf("Type:\t\t\t%s\n", cert.Type) + fmt.Printf("Fingerprint:\t\t%s\n", cert.Fingerprint) + fmt.Printf("Created:\t\t%s (%s)\n", util.Datetime(cert.Created), humanize.Time(cert.Created)) + fmt.Printf("Not valid before:\t%s (%s)\n", util.Datetime(cert.NotValidBefore), humanize.Time(cert.NotValidBefore)) + fmt.Printf("Not valid after:\t%s (%s)\n", util.Datetime(cert.NotValidAfter), humanize.Time(cert.NotValidAfter)) + if cert.Status != nil { + fmt.Printf("Status:\n") + fmt.Printf(" Issuance: %s\n", cert.Status.Issuance) + fmt.Printf(" Renewal: %s\n", cert.Status.Renewal) + if cert.Status.IsFailed() { + fmt.Printf(" Failure reason: %s\n", cert.Status.Error.Message) + } + } + fmt.Printf("Domain names:\n") + for _, domainName := range cert.DomainNames { + fmt.Printf(" - %s\n", domainName) } - } - fmt.Printf("Domain names:\n") - for _, domainName := range cert.DomainNames { - fmt.Printf(" - %s\n", domainName) - } - fmt.Print("Labels:\n") - if len(cert.Labels) == 0 { - fmt.Print(" No labels\n") - } else { - for key, value := range cert.Labels { - fmt.Printf(" %s:\t%s\n", key, value) + fmt.Print("Labels:\n") + if len(cert.Labels) == 0 { + fmt.Print(" No labels\n") + } else { + for key, value := range cert.Labels { + fmt.Printf(" %s:\t%s\n", key, value) + } } - } - fmt.Println("Used By:") - if len(cert.UsedBy) == 0 { - fmt.Println(" Certificate unused") - } else { - for _, ub := range cert.UsedBy { - fmt.Printf(" - Type: %s", ub.Type) - // Currently certificates can be only attached to load balancers. - // If we ever get something that is not a load balancer fall back - // to printing the ID. - if ub.Type != hcloud.CertificateUsedByRefTypeLoadBalancer { - fmt.Printf(" - ID: %d", ub.ID) - continue + fmt.Println("Used By:") + if len(cert.UsedBy) == 0 { + fmt.Println(" Certificate unused") + } else { + for _, ub := range cert.UsedBy { + fmt.Printf(" - Type: %s", ub.Type) + // Currently certificates can be only attached to load balancers. + // If we ever get something that is not a load balancer fall back + // to printing the ID. + if ub.Type != hcloud.CertificateUsedByRefTypeLoadBalancer { + fmt.Printf(" - ID: %d", ub.ID) + continue + } + fmt.Printf(" - Name: %s", client.LoadBalancer().LoadBalancerName(ub.ID)) } - fmt.Printf(" - Name: %s", cli.LoadBalancerName(ub.ID)) } - } - return nil + return nil + }, } diff --git a/internal/cmd/certificate/labels.go b/internal/cmd/certificate/labels.go new file mode 100644 index 00000000..cc972366 --- /dev/null +++ b/internal/cmd/certificate/labels.go @@ -0,0 +1,35 @@ +package certificate + +import ( + "context" + "fmt" + + "github.com/hetznercloud/cli/internal/cmd/base" + "github.com/hetznercloud/cli/internal/hcapi2" + "github.com/hetznercloud/hcloud-go/hcloud" +) + +var labelCmds = base.LabelCmds{ + ResourceNameSingular: "certificate", + ShortDescriptionAdd: "Add a label to an certificate", + ShortDescriptionRemove: "Remove a label from an certificate", + 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(ctx context.Context, client hcapi2.Client, idOrName string) (map[string]string, int, error) { + certificate, _, err := client.Certificate().Get(ctx, idOrName) + if err != nil { + return nil, 0, err + } + if certificate == nil { + return nil, 0, fmt.Errorf("certificate not found: %s", idOrName) + } + return certificate.Labels, certificate.ID, nil + }, + SetLabels: func(ctx context.Context, client hcapi2.Client, id int, labels map[string]string) error { + opts := hcloud.CertificateUpdateOpts{ + Labels: labels, + } + _, _, err := client.Certificate().Update(ctx, &hcloud.Certificate{ID: id}, opts) + return err + }, +} diff --git a/internal/cmd/certificate/list.go b/internal/cmd/certificate/list.go index 7ca0f1a9..e9fac493 100644 --- a/internal/cmd/certificate/list.go +++ b/internal/cmd/certificate/list.go @@ -1,60 +1,77 @@ package certificate import ( + "context" "strings" + "github.com/hetznercloud/cli/internal/cmd/base" + "github.com/hetznercloud/cli/internal/hcapi2" + "github.com/hetznercloud/cli/internal/cmd/output" "github.com/hetznercloud/cli/internal/cmd/util" - "github.com/hetznercloud/cli/internal/state" "github.com/hetznercloud/hcloud-go/hcloud" "github.com/hetznercloud/hcloud-go/hcloud/schema" - "github.com/spf13/cobra" ) -var listTableOutput *output.Table - -func init() { - listTableOutput = describeTableOutput() -} - -func newListCommand(cli *state.State) *cobra.Command { - cmd := &cobra.Command{ - Use: "list [FLAGS]", - Short: "List Certificates", - Long: util.ListLongDescription( - "Displays a list of certificates", - listTableOutput.Columns(), - ), - TraverseChildren: true, - DisableFlagsInUseLine: true, - PreRunE: cli.EnsureToken, - RunE: cli.Wrap(runList), - } - output.AddFlag(cmd, output.OptionNoHeader(), output.OptionColumns(listTableOutput.Columns()), output.OptionJSON()) - return cmd -} - -func runList(cli *state.State, cmd *cobra.Command, args []string) error { - outOpts := output.FlagsForCommand(cmd) +var listCmd = base.ListCmd{ + ResourceNamePlural: "certificates", + DefaultColumns: []string{"id", "name", "type", "domain_names", "not_valid_after"}, - labelSelector, _ := cmd.Flags().GetString("selector") + Fetch: func(ctx context.Context, client hcapi2.Client, listOpts hcloud.ListOpts) ([]interface{}, error) { + certficates, err := client.Certificate().AllWithOpts(ctx, hcloud.CertificateListOpts{ListOpts: listOpts}) - opts := hcloud.CertificateListOpts{ - ListOpts: hcloud.ListOpts{ - LabelSelector: labelSelector, - PerPage: 50, - }, - } + var resources []interface{} + for _, n := range certficates { + resources = append(resources, n) + } + return resources, err + }, - certs, err := cli.Client().Certificate.AllWithOpts(cli.Context, opts) - if err != nil { - return err - } + OutputTable: func(_ hcapi2.Client) *output.Table { + return output.NewTable(). + AddAllowedFields(hcloud.Certificate{}). + RemoveAllowedField("certificate", "chain"). + AddFieldFn("labels", output.FieldFn(func(obj interface{}) string { + cert := obj.(*hcloud.Certificate) + return util.LabelsToString(cert.Labels) + })). + AddFieldFn("not_valid_before", func(obj interface{}) string { + cert := obj.(*hcloud.Certificate) + return util.Datetime(cert.NotValidBefore) + }). + AddFieldFn("not_valid_after", func(obj interface{}) string { + cert := obj.(*hcloud.Certificate) + return util.Datetime(cert.NotValidAfter) + }). + AddFieldFn("issuance_status", func(obj interface{}) string { + cert := obj.(*hcloud.Certificate) + if cert.Type != hcloud.CertificateTypeManaged { + return "n/a" + } + return string(cert.Status.Issuance) + }). + AddFieldFn("renewal_status", func(obj interface{}) string { + cert := obj.(*hcloud.Certificate) + if cert.Type != hcloud.CertificateTypeManaged || + cert.Status.Renewal == hcloud.CertificateStatusTypeUnavailable { + return "n/a" + } + return string(cert.Status.Renewal) + }). + AddFieldFn("domain_names", func(obj interface{}) string { + cert := obj.(*hcloud.Certificate) + return strings.Join(cert.DomainNames, ", ") + }). + AddFieldFn("created", output.FieldFn(func(obj interface{}) string { + cert := obj.(*hcloud.Certificate) + return util.Datetime(cert.Created) + })) + }, - if outOpts.IsSet("json") { + JSONSchema: func(resources []interface{}) interface{} { var certSchemas []schema.Certificate - - for _, cert := range certs { + for _, resource := range resources { + cert := resource.(*hcloud.Certificate) certSchema := schema.Certificate{ ID: cert.ID, Certificate: cert.Certificate, @@ -80,62 +97,5 @@ func runList(cli *state.State, cmd *cobra.Command, args []string) error { } return util.DescribeJSON(certSchemas) - } - - cols := []string{"id", "name", "type", "domain_names", "not_valid_after"} - if outOpts.IsSet("columns") { - cols = outOpts["columns"] - } - tw := describeTableOutput() - if err := tw.ValidateColumns(cols); err != nil { - return nil - } - if !outOpts.IsSet("noheader") { - tw.WriteHeader(cols) - } - for _, cert := range certs { - tw.Write(cols, cert) - } - return tw.Flush() -} - -func describeTableOutput() *output.Table { - return output.NewTable(). - AddAllowedFields(hcloud.Certificate{}). - RemoveAllowedField("certificate", "chain"). - AddFieldFn("labels", output.FieldFn(func(obj interface{}) string { - cert := obj.(*hcloud.Certificate) - return util.LabelsToString(cert.Labels) - })). - AddFieldFn("not_valid_before", func(obj interface{}) string { - cert := obj.(*hcloud.Certificate) - return util.Datetime(cert.NotValidBefore) - }). - AddFieldFn("not_valid_after", func(obj interface{}) string { - cert := obj.(*hcloud.Certificate) - return util.Datetime(cert.NotValidAfter) - }). - AddFieldFn("issuance_status", func(obj interface{}) string { - cert := obj.(*hcloud.Certificate) - if cert.Type != hcloud.CertificateTypeManaged { - return "n/a" - } - return string(cert.Status.Issuance) - }). - AddFieldFn("renewal_status", func(obj interface{}) string { - cert := obj.(*hcloud.Certificate) - if cert.Type != hcloud.CertificateTypeManaged || - cert.Status.Renewal == hcloud.CertificateStatusTypeUnavailable { - return "n/a" - } - return string(cert.Status.Renewal) - }). - AddFieldFn("domain_names", func(obj interface{}) string { - cert := obj.(*hcloud.Certificate) - return strings.Join(cert.DomainNames, ", ") - }). - AddFieldFn("created", output.FieldFn(func(obj interface{}) string { - cert := obj.(*hcloud.Certificate) - return util.Datetime(cert.Created) - })) + }, } diff --git a/internal/cmd/certificate/remove_label.go b/internal/cmd/certificate/remove_label.go deleted file mode 100644 index d9ce97f1..00000000 --- a/internal/cmd/certificate/remove_label.go +++ /dev/null @@ -1,86 +0,0 @@ -package certificate - -import ( - "errors" - "fmt" - - "github.com/hetznercloud/cli/internal/cmd/cmpl" - "github.com/hetznercloud/cli/internal/cmd/util" - "github.com/hetznercloud/cli/internal/state" - "github.com/hetznercloud/hcloud-go/hcloud" - "github.com/spf13/cobra" -) - -func newRemoveLabelCommand(cli *state.State) *cobra.Command { - cmd := &cobra.Command{ - Use: "remove-label [FLAGS] CERTIFICATE LABELKEY", - Short: "Remove a label from a certificate", - Args: cobra.RangeArgs(1, 2), - ValidArgsFunction: cmpl.SuggestArgs( - cmpl.SuggestCandidatesF(cli.CertificateNames), - cmpl.SuggestCandidatesCtx(func(_ *cobra.Command, args []string) []string { - if len(args) != 1 { - return nil - } - return cli.CertificateLabelKeys(args[0]) - }), - ), - TraverseChildren: true, - DisableFlagsInUseLine: true, - PreRunE: util.ChainRunE(validateRemoveLabel, cli.EnsureToken), - RunE: cli.Wrap(runRemoveLabel), - } - cmd.Flags().BoolP("all", "a", false, "Remove all labels") - return cmd -} - -func validateRemoveLabel(cmd *cobra.Command, args []string) error { - all, err := cmd.Flags().GetBool("all") - if err != nil { - return err - } - if all && len(args) != 1 { - return errors.New("must not specify a label key when using --all/-a") - } - if !all && len(args) != 2 { - return errors.New("must specify a label key when not using --all/-a") - } - return nil -} - -func runRemoveLabel(cli *state.State, cmd *cobra.Command, args []string) error { - // We ensured the all flag is a valid boolean in - // validateCertificateRemoveLabel. No need to handle the error again here. - all, _ := cmd.Flags().GetBool("all") - idOrName := args[0] - cert, _, err := cli.Client().Certificate.Get(cli.Context, idOrName) - if err != nil { - return err - } - if cert == nil { - return fmt.Errorf("Certificate not found: %s", idOrName) - } - if all { - cert.Labels = make(map[string]string) - } else { - label := args[1] - if _, ok := cert.Labels[label]; !ok { - return fmt.Errorf("Label %s on certificate %d does not exist", label, cert.ID) - } - delete(cert.Labels, label) - } - opts := hcloud.CertificateUpdateOpts{ - Labels: cert.Labels, - } - _, _, err = cli.Client().Certificate.Update(cli.Context, cert, opts) - if err != nil { - return err - } - - if all { - fmt.Printf("All labels removed from certificate %d\n", cert.ID) - } else { - fmt.Printf("Label %s removed from certificate %d\n", args[1], cert.ID) - } - return nil -} diff --git a/internal/hcapi2/certificate.go b/internal/hcapi2/certificate.go new file mode 100644 index 00000000..b8ece248 --- /dev/null +++ b/internal/hcapi2/certificate.go @@ -0,0 +1,52 @@ +package hcapi2 + +import ( + "context" + "strconv" +) + +// CertificateClient embeds the Hetzner Cloud Certificate client and provides some +// additional helper functions. +type CertificateClient interface { + CertificateClientBase + Names() []string + LabelKeys(string) []string +} + +func NewCertificateClient(client CertificateClientBase) CertificateClient { + return &certificateClient{ + CertificateClientBase: client, + } +} + +type certificateClient struct { + CertificateClientBase +} + +// Names obtains a list of available data centers. It returns nil if +// data center names could not be fetched. +func (c *certificateClient) Names() []string { + dcs, err := c.All(context.Background()) + if err != nil || len(dcs) == 0 { + return nil + } + names := make([]string, len(dcs)) + for i, dc := range dcs { + name := dc.Name + if name == "" { + name = strconv.Itoa(dc.ID) + } + names[i] = name + } + return names +} + +// LabelKeys returns a slice containing the keys of all labels +// assigned to the certificate with the passed idOrName. +func (c *certificateClient) LabelKeys(idOrName string) []string { + certificate, _, err := c.Get(context.Background(), idOrName) + if err != nil || certificate == nil || len(certificate.Labels) == 0 { + return nil + } + return labelKeys(certificate.Labels) +} diff --git a/internal/hcapi2/client.go b/internal/hcapi2/client.go index e918d3e1..3cd3b6a4 100644 --- a/internal/hcapi2/client.go +++ b/internal/hcapi2/client.go @@ -17,6 +17,8 @@ type Client interface { ServerType() ServerTypeClient SSHKey() SSHKeyClient Volume() VolumeClient + Certificate() CertificateClient + LoadBalancer() LoadBalancerClient } type client struct { @@ -29,6 +31,9 @@ func NewClient(c *hcloud.Client) Client { client: c, } } +func (c *client) Certificate() CertificateClient { + return NewCertificateClient(&c.client.Certificate) +} func (c *client) Datacenter() DatacenterClient { return NewDatacenterClient(&c.client.Datacenter) @@ -50,6 +55,10 @@ func (c *client) Location() LocationClient { return NewLocationClient(&c.client.Location) } +func (c *client) LoadBalancer() LoadBalancerClient { + return NewLoadBalancerClient(&c.client.LoadBalancer) +} + func (c *client) Network() NetworkClient { return NewNetworkClient(&c.client.Network) } @@ -71,33 +80,39 @@ func (c *client) Volume() VolumeClient { } type MockClient struct { - DatacenterClient *MockDatacenterClient - FirewallClient *MockFirewallClient - FloatingIPClient *MockFloatingIPClient - ImageClient *MockImageClient - LocationClient *MockLocationClient - NetworkClient *MockNetworkClient - ServerClient *MockServerClient - ServerTypeClient *MockServerTypeClient - SSHKeyClient *MockSSHKeyClient - VolumeClient *MockVolumeClient + CertificateClient *MockCertificateClient + DatacenterClient *MockDatacenterClient + FirewallClient *MockFirewallClient + FloatingIPClient *MockFloatingIPClient + ImageClient *MockImageClient + LocationClient *MockLocationClient + LoadBalancerClient *MockLoadBalancerClient + NetworkClient *MockNetworkClient + ServerClient *MockServerClient + ServerTypeClient *MockServerTypeClient + SSHKeyClient *MockSSHKeyClient + VolumeClient *MockVolumeClient } func NewMockClient(ctrl *gomock.Controller) *MockClient { return &MockClient{ - DatacenterClient: NewMockDatacenterClient(ctrl), - FirewallClient: NewMockFirewallClient(ctrl), - FloatingIPClient: NewMockFloatingIPClient(ctrl), - ImageClient: NewMockImageClient(ctrl), - LocationClient: NewMockLocationClient(ctrl), - NetworkClient: NewMockNetworkClient(ctrl), - ServerClient: NewMockServerClient(ctrl), - ServerTypeClient: NewMockServerTypeClient(ctrl), - SSHKeyClient: NewMockSSHKeyClient(ctrl), - VolumeClient: NewMockVolumeClient(ctrl), + CertificateClient: NewMockCertificateClient(ctrl), + DatacenterClient: NewMockDatacenterClient(ctrl), + FirewallClient: NewMockFirewallClient(ctrl), + FloatingIPClient: NewMockFloatingIPClient(ctrl), + ImageClient: NewMockImageClient(ctrl), + LocationClient: NewMockLocationClient(ctrl), + LoadBalancerClient: NewMockLoadBalancerClient(ctrl), + NetworkClient: NewMockNetworkClient(ctrl), + ServerClient: NewMockServerClient(ctrl), + ServerTypeClient: NewMockServerTypeClient(ctrl), + SSHKeyClient: NewMockSSHKeyClient(ctrl), + VolumeClient: NewMockVolumeClient(ctrl), } } - +func (c *MockClient) Certificate() CertificateClient { + return c.CertificateClient +} func (c *MockClient) Datacenter() DatacenterClient { return c.DatacenterClient } @@ -118,6 +133,10 @@ func (c *MockClient) Location() LocationClient { return c.LocationClient } +func (c *MockClient) LoadBalancer() LoadBalancerClient { + return c.LoadBalancerClient +} + func (c *MockClient) Network() NetworkClient { return c.NetworkClient } diff --git a/internal/hcapi2/firewall.go b/internal/hcapi2/firewall.go index 009a7a29..ced4c3b2 100644 --- a/internal/hcapi2/firewall.go +++ b/internal/hcapi2/firewall.go @@ -23,7 +23,7 @@ type firewallClient struct { FirewallClientBase } -// FirewallNames obtains a list of available firewalls. It returns nil if +// Names obtains a list of available firewalls. It returns nil if // the firewall names could not be fetched or there were no firewalls. func (c *firewallClient) Names() []string { firewalls, err := c.All(context.Background()) @@ -41,7 +41,7 @@ func (c *firewallClient) Names() []string { return names } -// FirewallLabelKeys returns a slice containing the keys of all labels +// LabelKeys returns a slice containing the keys of all labels // assigned to the firewall with the passed idOrName. func (c *firewallClient) LabelKeys(idOrName string) []string { firewall, _, err := c.Get(context.Background(), idOrName) diff --git a/internal/hcapi2/interface_gen.go b/internal/hcapi2/interface_gen.go index 8834e271..68b0ce6c 100644 --- a/internal/hcapi2/interface_gen.go +++ b/internal/hcapi2/interface_gen.go @@ -1,10 +1,12 @@ package hcapi2 +//go:generate interfacer -for github.com/hetznercloud/hcloud-go/hcloud.CertificateClient -as hcapi2.CertificateClientBase -o zz_certificate_client_base.go //go:generate interfacer -for github.com/hetznercloud/hcloud-go/hcloud.DatacenterClient -as hcapi2.DatacenterClientBase -o zz_datacenter_client_base.go //go:generate interfacer -for github.com/hetznercloud/hcloud-go/hcloud.ImageClient -as hcapi2.ImageClientBase -o zz_image_client_base.go //go:generate interfacer -for github.com/hetznercloud/hcloud-go/hcloud.FirewallClient -as hcapi2.FirewallClientBase -o zz_firewall_client_base.go //go:generate interfacer -for github.com/hetznercloud/hcloud-go/hcloud.FloatingIPClient -as hcapi2.FloatingIPClientBase -o zz_floating_ip_client_base.go //go:generate interfacer -for github.com/hetznercloud/hcloud-go/hcloud.LocationClient -as hcapi2.LocationClientBase -o zz_location_client_base.go +//go:generate interfacer -for github.com/hetznercloud/hcloud-go/hcloud.LoadBalancerClient -as hcapi2.LoadBalancerClientBase -o zz_loadbalancer_client_base.go //go:generate interfacer -for github.com/hetznercloud/hcloud-go/hcloud.NetworkClient -as hcapi2.NetworkClientBase -o zz_network_client_base.go //go:generate interfacer -for github.com/hetznercloud/hcloud-go/hcloud.ServerClient -as hcapi2.ServerClientBase -o zz_server_client_base.go //go:generate interfacer -for github.com/hetznercloud/hcloud-go/hcloud.ServerTypeClient -as hcapi2.ServerTypeClientBase -o zz_server_type_client_base.go diff --git a/internal/hcapi2/loadbalancer.go b/internal/hcapi2/loadbalancer.go new file mode 100644 index 00000000..7ec417d7 --- /dev/null +++ b/internal/hcapi2/loadbalancer.go @@ -0,0 +1,91 @@ +package hcapi2 + +import ( + "context" + "github.com/hetznercloud/hcloud-go/hcloud" + "strconv" + "sync" +) + +// LoadBalancerClient embeds the Hetzner Cloud LoadBalancer client and provides some +// additional helper functions. +type LoadBalancerClient interface { + LoadBalancerClientBase + LoadBalancerName(id int) string + Names() []string + LabelKeys(string) []string +} + +func NewLoadBalancerClient(client LoadBalancerClientBase) LoadBalancerClient { + return &loadBalancerClient{ + LoadBalancerClientBase: client, + } +} + +type loadBalancerClient struct { + LoadBalancerClientBase + + lbByID map[int]*hcloud.LoadBalancer + + once sync.Once + err error +} + +// LoadBalancerName obtains the name of the server with id. If the name could not +// be fetched it returns the value id converted to a string. +func (c *loadBalancerClient) LoadBalancerName(id int) string { + if err := c.init(); err != nil { + return strconv.Itoa(id) + } + + lb, ok := c.lbByID[id] + if !ok || lb.Name == "" { + return strconv.Itoa(id) + } + return lb.Name +} + +// Names obtains a list of available data centers. It returns nil if +// data center names could not be fetched. +func (c *loadBalancerClient) Names() []string { + dcs, err := c.All(context.Background()) + if err != nil || len(dcs) == 0 { + return nil + } + names := make([]string, len(dcs)) + for i, dc := range dcs { + name := dc.Name + if name == "" { + name = strconv.Itoa(dc.ID) + } + names[i] = name + } + return names +} + +// LabelKeys returns a slice containing the keys of all labels +// assigned to the loadBalancer with the passed idOrName. +func (c *loadBalancerClient) LabelKeys(idOrName string) []string { + loadBalancer, _, err := c.Get(context.Background(), idOrName) + if err != nil || loadBalancer == nil || len(loadBalancer.Labels) == 0 { + return nil + } + return labelKeys(loadBalancer.Labels) +} + +func (c *loadBalancerClient) init() error { + c.once.Do(func() { + srvs, err := c.All(context.Background()) + if err != nil { + c.err = err + } + if c.err != nil || len(srvs) == 0 { + return + } + c.lbByID = make(map[int]*hcloud.LoadBalancer, len(srvs)) + for _, srv := range srvs { + c.lbByID[srv.ID] = srv + } + }) + return c.err +} diff --git a/internal/hcapi2/mock_gen.go b/internal/hcapi2/mock_gen.go index 965f8e85..fd6bb9ef 100644 --- a/internal/hcapi2/mock_gen.go +++ b/internal/hcapi2/mock_gen.go @@ -1,10 +1,12 @@ package hcapi2 +//go:generate mockgen -package hcapi2 -destination zz_certificate_client_mock.go . CertificateClient //go:generate mockgen -package hcapi2 -destination zz_datacenter_client_mock.go . DatacenterClient //go:generate mockgen -package hcapi2 -destination zz_image_client_mock.go . ImageClient //go:generate mockgen -package hcapi2 -destination zz_firewall_client_mock.go . FirewallClient //go:generate mockgen -package hcapi2 -destination zz_floating_ip_client_mock.go . FloatingIPClient //go:generate mockgen -package hcapi2 -destination zz_location_client_mock.go . LocationClient +//go:generate mockgen -package hcapi2 -destination zz_loadbalancer_client_mock.go . LoadBalancerClient //go:generate mockgen -package hcapi2 -destination zz_network_client_mock.go . NetworkClient //go:generate mockgen -package hcapi2 -destination zz_server_client_mock.go . ServerClient //go:generate mockgen -package hcapi2 -destination zz_server_type_client_mock.go . ServerTypeClient diff --git a/internal/hcapi2/zz_certificate_client_base.go b/internal/hcapi2/zz_certificate_client_base.go new file mode 100644 index 00000000..e43af6eb --- /dev/null +++ b/internal/hcapi2/zz_certificate_client_base.go @@ -0,0 +1,23 @@ +// Code generated by interfacer; DO NOT EDIT + +package hcapi2 + +import ( + "context" + "github.com/hetznercloud/hcloud-go/hcloud" +) + +// CertificateClientBase is an interface generated for "github.com/hetznercloud/hcloud-go/hcloud.CertificateClient". +type CertificateClientBase interface { + All(context.Context) ([]*hcloud.Certificate, error) + AllWithOpts(context.Context, hcloud.CertificateListOpts) ([]*hcloud.Certificate, error) + Create(context.Context, hcloud.CertificateCreateOpts) (*hcloud.Certificate, *hcloud.Response, error) + CreateCertificate(context.Context, hcloud.CertificateCreateOpts) (hcloud.CertificateCreateResult, *hcloud.Response, error) + Delete(context.Context, *hcloud.Certificate) (*hcloud.Response, error) + Get(context.Context, string) (*hcloud.Certificate, *hcloud.Response, error) + GetByID(context.Context, int) (*hcloud.Certificate, *hcloud.Response, error) + GetByName(context.Context, string) (*hcloud.Certificate, *hcloud.Response, error) + List(context.Context, hcloud.CertificateListOpts) ([]*hcloud.Certificate, *hcloud.Response, error) + RetryIssuance(context.Context, *hcloud.Certificate) (*hcloud.Action, *hcloud.Response, error) + Update(context.Context, *hcloud.Certificate, hcloud.CertificateUpdateOpts) (*hcloud.Certificate, *hcloud.Response, error) +} diff --git a/internal/hcapi2/zz_certificate_client_mock.go b/internal/hcapi2/zz_certificate_client_mock.go new file mode 100644 index 00000000..abe3de4c --- /dev/null +++ b/internal/hcapi2/zz_certificate_client_mock.go @@ -0,0 +1,237 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/hetznercloud/cli/internal/hcapi2 (interfaces: CertificateClient) + +// Package hcapi2 is a generated GoMock package. +package hcapi2 + +import ( + context "context" + reflect "reflect" + + gomock "github.com/golang/mock/gomock" + hcloud "github.com/hetznercloud/hcloud-go/hcloud" +) + +// MockCertificateClient is a mock of CertificateClient interface. +type MockCertificateClient struct { + ctrl *gomock.Controller + recorder *MockCertificateClientMockRecorder +} + +// MockCertificateClientMockRecorder is the mock recorder for MockCertificateClient. +type MockCertificateClientMockRecorder struct { + mock *MockCertificateClient +} + +// NewMockCertificateClient creates a new mock instance. +func NewMockCertificateClient(ctrl *gomock.Controller) *MockCertificateClient { + mock := &MockCertificateClient{ctrl: ctrl} + mock.recorder = &MockCertificateClientMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockCertificateClient) EXPECT() *MockCertificateClientMockRecorder { + return m.recorder +} + +// All mocks base method. +func (m *MockCertificateClient) All(arg0 context.Context) ([]*hcloud.Certificate, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "All", arg0) + ret0, _ := ret[0].([]*hcloud.Certificate) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// All indicates an expected call of All. +func (mr *MockCertificateClientMockRecorder) All(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "All", reflect.TypeOf((*MockCertificateClient)(nil).All), arg0) +} + +// AllWithOpts mocks base method. +func (m *MockCertificateClient) AllWithOpts(arg0 context.Context, arg1 hcloud.CertificateListOpts) ([]*hcloud.Certificate, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AllWithOpts", arg0, arg1) + ret0, _ := ret[0].([]*hcloud.Certificate) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// AllWithOpts indicates an expected call of AllWithOpts. +func (mr *MockCertificateClientMockRecorder) AllWithOpts(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AllWithOpts", reflect.TypeOf((*MockCertificateClient)(nil).AllWithOpts), arg0, arg1) +} + +// Create mocks base method. +func (m *MockCertificateClient) Create(arg0 context.Context, arg1 hcloud.CertificateCreateOpts) (*hcloud.Certificate, *hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Create", arg0, arg1) + ret0, _ := ret[0].(*hcloud.Certificate) + ret1, _ := ret[1].(*hcloud.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// Create indicates an expected call of Create. +func (mr *MockCertificateClientMockRecorder) Create(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockCertificateClient)(nil).Create), arg0, arg1) +} + +// CreateCertificate mocks base method. +func (m *MockCertificateClient) CreateCertificate(arg0 context.Context, arg1 hcloud.CertificateCreateOpts) (hcloud.CertificateCreateResult, *hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CreateCertificate", arg0, arg1) + ret0, _ := ret[0].(hcloud.CertificateCreateResult) + ret1, _ := ret[1].(*hcloud.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// CreateCertificate indicates an expected call of CreateCertificate. +func (mr *MockCertificateClientMockRecorder) CreateCertificate(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateCertificate", reflect.TypeOf((*MockCertificateClient)(nil).CreateCertificate), arg0, arg1) +} + +// Delete mocks base method. +func (m *MockCertificateClient) Delete(arg0 context.Context, arg1 *hcloud.Certificate) (*hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Delete", arg0, arg1) + ret0, _ := ret[0].(*hcloud.Response) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Delete indicates an expected call of Delete. +func (mr *MockCertificateClientMockRecorder) Delete(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockCertificateClient)(nil).Delete), arg0, arg1) +} + +// Get mocks base method. +func (m *MockCertificateClient) Get(arg0 context.Context, arg1 string) (*hcloud.Certificate, *hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", arg0, arg1) + ret0, _ := ret[0].(*hcloud.Certificate) + ret1, _ := ret[1].(*hcloud.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// Get indicates an expected call of Get. +func (mr *MockCertificateClientMockRecorder) Get(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockCertificateClient)(nil).Get), arg0, arg1) +} + +// GetByID mocks base method. +func (m *MockCertificateClient) GetByID(arg0 context.Context, arg1 int) (*hcloud.Certificate, *hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetByID", arg0, arg1) + ret0, _ := ret[0].(*hcloud.Certificate) + ret1, _ := ret[1].(*hcloud.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// GetByID indicates an expected call of GetByID. +func (mr *MockCertificateClientMockRecorder) GetByID(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetByID", reflect.TypeOf((*MockCertificateClient)(nil).GetByID), arg0, arg1) +} + +// GetByName mocks base method. +func (m *MockCertificateClient) GetByName(arg0 context.Context, arg1 string) (*hcloud.Certificate, *hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetByName", arg0, arg1) + ret0, _ := ret[0].(*hcloud.Certificate) + ret1, _ := ret[1].(*hcloud.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// GetByName indicates an expected call of GetByName. +func (mr *MockCertificateClientMockRecorder) GetByName(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetByName", reflect.TypeOf((*MockCertificateClient)(nil).GetByName), arg0, arg1) +} + +// LabelKeys mocks base method. +func (m *MockCertificateClient) LabelKeys(arg0 string) []string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LabelKeys", arg0) + ret0, _ := ret[0].([]string) + return ret0 +} + +// LabelKeys indicates an expected call of LabelKeys. +func (mr *MockCertificateClientMockRecorder) LabelKeys(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LabelKeys", reflect.TypeOf((*MockCertificateClient)(nil).LabelKeys), arg0) +} + +// List mocks base method. +func (m *MockCertificateClient) List(arg0 context.Context, arg1 hcloud.CertificateListOpts) ([]*hcloud.Certificate, *hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "List", arg0, arg1) + ret0, _ := ret[0].([]*hcloud.Certificate) + ret1, _ := ret[1].(*hcloud.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// List indicates an expected call of List. +func (mr *MockCertificateClientMockRecorder) List(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockCertificateClient)(nil).List), arg0, arg1) +} + +// Names mocks base method. +func (m *MockCertificateClient) Names() []string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Names") + ret0, _ := ret[0].([]string) + return ret0 +} + +// Names indicates an expected call of Names. +func (mr *MockCertificateClientMockRecorder) Names() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Names", reflect.TypeOf((*MockCertificateClient)(nil).Names)) +} + +// RetryIssuance mocks base method. +func (m *MockCertificateClient) RetryIssuance(arg0 context.Context, arg1 *hcloud.Certificate) (*hcloud.Action, *hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "RetryIssuance", arg0, arg1) + ret0, _ := ret[0].(*hcloud.Action) + ret1, _ := ret[1].(*hcloud.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// RetryIssuance indicates an expected call of RetryIssuance. +func (mr *MockCertificateClientMockRecorder) RetryIssuance(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RetryIssuance", reflect.TypeOf((*MockCertificateClient)(nil).RetryIssuance), arg0, arg1) +} + +// Update mocks base method. +func (m *MockCertificateClient) Update(arg0 context.Context, arg1 *hcloud.Certificate, arg2 hcloud.CertificateUpdateOpts) (*hcloud.Certificate, *hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Update", arg0, arg1, arg2) + ret0, _ := ret[0].(*hcloud.Certificate) + ret1, _ := ret[1].(*hcloud.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// Update indicates an expected call of Update. +func (mr *MockCertificateClientMockRecorder) Update(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockCertificateClient)(nil).Update), arg0, arg1, arg2) +} diff --git a/internal/hcapi2/zz_loadbalancer_client_base.go b/internal/hcapi2/zz_loadbalancer_client_base.go new file mode 100644 index 00000000..e95d711d --- /dev/null +++ b/internal/hcapi2/zz_loadbalancer_client_base.go @@ -0,0 +1,39 @@ +// Code generated by interfacer; DO NOT EDIT + +package hcapi2 + +import ( + "context" + "github.com/hetznercloud/hcloud-go/hcloud" + "net" +) + +// LoadBalancerClientBase is an interface generated for "github.com/hetznercloud/hcloud-go/hcloud.LoadBalancerClient". +type LoadBalancerClientBase interface { + AddIPTarget(context.Context, *hcloud.LoadBalancer, hcloud.LoadBalancerAddIPTargetOpts) (*hcloud.Action, *hcloud.Response, error) + AddLabelSelectorTarget(context.Context, *hcloud.LoadBalancer, hcloud.LoadBalancerAddLabelSelectorTargetOpts) (*hcloud.Action, *hcloud.Response, error) + AddServerTarget(context.Context, *hcloud.LoadBalancer, hcloud.LoadBalancerAddServerTargetOpts) (*hcloud.Action, *hcloud.Response, error) + AddService(context.Context, *hcloud.LoadBalancer, hcloud.LoadBalancerAddServiceOpts) (*hcloud.Action, *hcloud.Response, error) + All(context.Context) ([]*hcloud.LoadBalancer, error) + AllWithOpts(context.Context, hcloud.LoadBalancerListOpts) ([]*hcloud.LoadBalancer, error) + AttachToNetwork(context.Context, *hcloud.LoadBalancer, hcloud.LoadBalancerAttachToNetworkOpts) (*hcloud.Action, *hcloud.Response, error) + ChangeAlgorithm(context.Context, *hcloud.LoadBalancer, hcloud.LoadBalancerChangeAlgorithmOpts) (*hcloud.Action, *hcloud.Response, error) + ChangeProtection(context.Context, *hcloud.LoadBalancer, hcloud.LoadBalancerChangeProtectionOpts) (*hcloud.Action, *hcloud.Response, error) + ChangeType(context.Context, *hcloud.LoadBalancer, hcloud.LoadBalancerChangeTypeOpts) (*hcloud.Action, *hcloud.Response, error) + Create(context.Context, hcloud.LoadBalancerCreateOpts) (hcloud.LoadBalancerCreateResult, *hcloud.Response, error) + Delete(context.Context, *hcloud.LoadBalancer) (*hcloud.Response, error) + DeleteService(context.Context, *hcloud.LoadBalancer, int) (*hcloud.Action, *hcloud.Response, error) + DetachFromNetwork(context.Context, *hcloud.LoadBalancer, hcloud.LoadBalancerDetachFromNetworkOpts) (*hcloud.Action, *hcloud.Response, error) + DisablePublicInterface(context.Context, *hcloud.LoadBalancer) (*hcloud.Action, *hcloud.Response, error) + EnablePublicInterface(context.Context, *hcloud.LoadBalancer) (*hcloud.Action, *hcloud.Response, error) + Get(context.Context, string) (*hcloud.LoadBalancer, *hcloud.Response, error) + GetByID(context.Context, int) (*hcloud.LoadBalancer, *hcloud.Response, error) + GetByName(context.Context, string) (*hcloud.LoadBalancer, *hcloud.Response, error) + GetMetrics(context.Context, *hcloud.LoadBalancer, hcloud.LoadBalancerGetMetricsOpts) (*hcloud.LoadBalancerMetrics, *hcloud.Response, error) + List(context.Context, hcloud.LoadBalancerListOpts) ([]*hcloud.LoadBalancer, *hcloud.Response, error) + RemoveIPTarget(context.Context, *hcloud.LoadBalancer, net.IP) (*hcloud.Action, *hcloud.Response, error) + RemoveLabelSelectorTarget(context.Context, *hcloud.LoadBalancer, string) (*hcloud.Action, *hcloud.Response, error) + RemoveServerTarget(context.Context, *hcloud.LoadBalancer, *hcloud.Server) (*hcloud.Action, *hcloud.Response, error) + Update(context.Context, *hcloud.LoadBalancer, hcloud.LoadBalancerUpdateOpts) (*hcloud.LoadBalancer, *hcloud.Response, error) + UpdateService(context.Context, *hcloud.LoadBalancer, int, hcloud.LoadBalancerUpdateServiceOpts) (*hcloud.Action, *hcloud.Response, error) +} diff --git a/internal/hcapi2/zz_loadbalancer_client_mock.go b/internal/hcapi2/zz_loadbalancer_client_mock.go new file mode 100644 index 00000000..328b223f --- /dev/null +++ b/internal/hcapi2/zz_loadbalancer_client_mock.go @@ -0,0 +1,492 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/hetznercloud/cli/internal/hcapi2 (interfaces: LoadBalancerClient) + +// Package hcapi2 is a generated GoMock package. +package hcapi2 + +import ( + context "context" + net "net" + reflect "reflect" + + gomock "github.com/golang/mock/gomock" + hcloud "github.com/hetznercloud/hcloud-go/hcloud" +) + +// MockLoadBalancerClient is a mock of LoadBalancerClient interface. +type MockLoadBalancerClient struct { + ctrl *gomock.Controller + recorder *MockLoadBalancerClientMockRecorder +} + +// MockLoadBalancerClientMockRecorder is the mock recorder for MockLoadBalancerClient. +type MockLoadBalancerClientMockRecorder struct { + mock *MockLoadBalancerClient +} + +// NewMockLoadBalancerClient creates a new mock instance. +func NewMockLoadBalancerClient(ctrl *gomock.Controller) *MockLoadBalancerClient { + mock := &MockLoadBalancerClient{ctrl: ctrl} + mock.recorder = &MockLoadBalancerClientMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockLoadBalancerClient) EXPECT() *MockLoadBalancerClientMockRecorder { + return m.recorder +} + +// AddIPTarget mocks base method. +func (m *MockLoadBalancerClient) AddIPTarget(arg0 context.Context, arg1 *hcloud.LoadBalancer, arg2 hcloud.LoadBalancerAddIPTargetOpts) (*hcloud.Action, *hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddIPTarget", arg0, arg1, arg2) + ret0, _ := ret[0].(*hcloud.Action) + ret1, _ := ret[1].(*hcloud.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// AddIPTarget indicates an expected call of AddIPTarget. +func (mr *MockLoadBalancerClientMockRecorder) AddIPTarget(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddIPTarget", reflect.TypeOf((*MockLoadBalancerClient)(nil).AddIPTarget), arg0, arg1, arg2) +} + +// AddLabelSelectorTarget mocks base method. +func (m *MockLoadBalancerClient) AddLabelSelectorTarget(arg0 context.Context, arg1 *hcloud.LoadBalancer, arg2 hcloud.LoadBalancerAddLabelSelectorTargetOpts) (*hcloud.Action, *hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddLabelSelectorTarget", arg0, arg1, arg2) + ret0, _ := ret[0].(*hcloud.Action) + ret1, _ := ret[1].(*hcloud.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// AddLabelSelectorTarget indicates an expected call of AddLabelSelectorTarget. +func (mr *MockLoadBalancerClientMockRecorder) AddLabelSelectorTarget(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddLabelSelectorTarget", reflect.TypeOf((*MockLoadBalancerClient)(nil).AddLabelSelectorTarget), arg0, arg1, arg2) +} + +// AddServerTarget mocks base method. +func (m *MockLoadBalancerClient) AddServerTarget(arg0 context.Context, arg1 *hcloud.LoadBalancer, arg2 hcloud.LoadBalancerAddServerTargetOpts) (*hcloud.Action, *hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddServerTarget", arg0, arg1, arg2) + ret0, _ := ret[0].(*hcloud.Action) + ret1, _ := ret[1].(*hcloud.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// AddServerTarget indicates an expected call of AddServerTarget. +func (mr *MockLoadBalancerClientMockRecorder) AddServerTarget(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddServerTarget", reflect.TypeOf((*MockLoadBalancerClient)(nil).AddServerTarget), arg0, arg1, arg2) +} + +// AddService mocks base method. +func (m *MockLoadBalancerClient) AddService(arg0 context.Context, arg1 *hcloud.LoadBalancer, arg2 hcloud.LoadBalancerAddServiceOpts) (*hcloud.Action, *hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddService", arg0, arg1, arg2) + ret0, _ := ret[0].(*hcloud.Action) + ret1, _ := ret[1].(*hcloud.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// AddService indicates an expected call of AddService. +func (mr *MockLoadBalancerClientMockRecorder) AddService(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddService", reflect.TypeOf((*MockLoadBalancerClient)(nil).AddService), arg0, arg1, arg2) +} + +// All mocks base method. +func (m *MockLoadBalancerClient) All(arg0 context.Context) ([]*hcloud.LoadBalancer, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "All", arg0) + ret0, _ := ret[0].([]*hcloud.LoadBalancer) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// All indicates an expected call of All. +func (mr *MockLoadBalancerClientMockRecorder) All(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "All", reflect.TypeOf((*MockLoadBalancerClient)(nil).All), arg0) +} + +// AllWithOpts mocks base method. +func (m *MockLoadBalancerClient) AllWithOpts(arg0 context.Context, arg1 hcloud.LoadBalancerListOpts) ([]*hcloud.LoadBalancer, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AllWithOpts", arg0, arg1) + ret0, _ := ret[0].([]*hcloud.LoadBalancer) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// AllWithOpts indicates an expected call of AllWithOpts. +func (mr *MockLoadBalancerClientMockRecorder) AllWithOpts(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AllWithOpts", reflect.TypeOf((*MockLoadBalancerClient)(nil).AllWithOpts), arg0, arg1) +} + +// AttachToNetwork mocks base method. +func (m *MockLoadBalancerClient) AttachToNetwork(arg0 context.Context, arg1 *hcloud.LoadBalancer, arg2 hcloud.LoadBalancerAttachToNetworkOpts) (*hcloud.Action, *hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AttachToNetwork", arg0, arg1, arg2) + ret0, _ := ret[0].(*hcloud.Action) + ret1, _ := ret[1].(*hcloud.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// AttachToNetwork indicates an expected call of AttachToNetwork. +func (mr *MockLoadBalancerClientMockRecorder) AttachToNetwork(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AttachToNetwork", reflect.TypeOf((*MockLoadBalancerClient)(nil).AttachToNetwork), arg0, arg1, arg2) +} + +// ChangeAlgorithm mocks base method. +func (m *MockLoadBalancerClient) ChangeAlgorithm(arg0 context.Context, arg1 *hcloud.LoadBalancer, arg2 hcloud.LoadBalancerChangeAlgorithmOpts) (*hcloud.Action, *hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ChangeAlgorithm", arg0, arg1, arg2) + ret0, _ := ret[0].(*hcloud.Action) + ret1, _ := ret[1].(*hcloud.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// ChangeAlgorithm indicates an expected call of ChangeAlgorithm. +func (mr *MockLoadBalancerClientMockRecorder) ChangeAlgorithm(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChangeAlgorithm", reflect.TypeOf((*MockLoadBalancerClient)(nil).ChangeAlgorithm), arg0, arg1, arg2) +} + +// ChangeProtection mocks base method. +func (m *MockLoadBalancerClient) ChangeProtection(arg0 context.Context, arg1 *hcloud.LoadBalancer, arg2 hcloud.LoadBalancerChangeProtectionOpts) (*hcloud.Action, *hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ChangeProtection", arg0, arg1, arg2) + ret0, _ := ret[0].(*hcloud.Action) + ret1, _ := ret[1].(*hcloud.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// ChangeProtection indicates an expected call of ChangeProtection. +func (mr *MockLoadBalancerClientMockRecorder) ChangeProtection(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChangeProtection", reflect.TypeOf((*MockLoadBalancerClient)(nil).ChangeProtection), arg0, arg1, arg2) +} + +// ChangeType mocks base method. +func (m *MockLoadBalancerClient) ChangeType(arg0 context.Context, arg1 *hcloud.LoadBalancer, arg2 hcloud.LoadBalancerChangeTypeOpts) (*hcloud.Action, *hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ChangeType", arg0, arg1, arg2) + ret0, _ := ret[0].(*hcloud.Action) + ret1, _ := ret[1].(*hcloud.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// ChangeType indicates an expected call of ChangeType. +func (mr *MockLoadBalancerClientMockRecorder) ChangeType(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChangeType", reflect.TypeOf((*MockLoadBalancerClient)(nil).ChangeType), arg0, arg1, arg2) +} + +// Create mocks base method. +func (m *MockLoadBalancerClient) Create(arg0 context.Context, arg1 hcloud.LoadBalancerCreateOpts) (hcloud.LoadBalancerCreateResult, *hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Create", arg0, arg1) + ret0, _ := ret[0].(hcloud.LoadBalancerCreateResult) + ret1, _ := ret[1].(*hcloud.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// Create indicates an expected call of Create. +func (mr *MockLoadBalancerClientMockRecorder) Create(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockLoadBalancerClient)(nil).Create), arg0, arg1) +} + +// Delete mocks base method. +func (m *MockLoadBalancerClient) Delete(arg0 context.Context, arg1 *hcloud.LoadBalancer) (*hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Delete", arg0, arg1) + ret0, _ := ret[0].(*hcloud.Response) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Delete indicates an expected call of Delete. +func (mr *MockLoadBalancerClientMockRecorder) Delete(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockLoadBalancerClient)(nil).Delete), arg0, arg1) +} + +// DeleteService mocks base method. +func (m *MockLoadBalancerClient) DeleteService(arg0 context.Context, arg1 *hcloud.LoadBalancer, arg2 int) (*hcloud.Action, *hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DeleteService", arg0, arg1, arg2) + ret0, _ := ret[0].(*hcloud.Action) + ret1, _ := ret[1].(*hcloud.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// DeleteService indicates an expected call of DeleteService. +func (mr *MockLoadBalancerClientMockRecorder) DeleteService(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteService", reflect.TypeOf((*MockLoadBalancerClient)(nil).DeleteService), arg0, arg1, arg2) +} + +// DetachFromNetwork mocks base method. +func (m *MockLoadBalancerClient) DetachFromNetwork(arg0 context.Context, arg1 *hcloud.LoadBalancer, arg2 hcloud.LoadBalancerDetachFromNetworkOpts) (*hcloud.Action, *hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DetachFromNetwork", arg0, arg1, arg2) + ret0, _ := ret[0].(*hcloud.Action) + ret1, _ := ret[1].(*hcloud.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// DetachFromNetwork indicates an expected call of DetachFromNetwork. +func (mr *MockLoadBalancerClientMockRecorder) DetachFromNetwork(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DetachFromNetwork", reflect.TypeOf((*MockLoadBalancerClient)(nil).DetachFromNetwork), arg0, arg1, arg2) +} + +// DisablePublicInterface mocks base method. +func (m *MockLoadBalancerClient) DisablePublicInterface(arg0 context.Context, arg1 *hcloud.LoadBalancer) (*hcloud.Action, *hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DisablePublicInterface", arg0, arg1) + ret0, _ := ret[0].(*hcloud.Action) + ret1, _ := ret[1].(*hcloud.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// DisablePublicInterface indicates an expected call of DisablePublicInterface. +func (mr *MockLoadBalancerClientMockRecorder) DisablePublicInterface(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DisablePublicInterface", reflect.TypeOf((*MockLoadBalancerClient)(nil).DisablePublicInterface), arg0, arg1) +} + +// EnablePublicInterface mocks base method. +func (m *MockLoadBalancerClient) EnablePublicInterface(arg0 context.Context, arg1 *hcloud.LoadBalancer) (*hcloud.Action, *hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "EnablePublicInterface", arg0, arg1) + ret0, _ := ret[0].(*hcloud.Action) + ret1, _ := ret[1].(*hcloud.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// EnablePublicInterface indicates an expected call of EnablePublicInterface. +func (mr *MockLoadBalancerClientMockRecorder) EnablePublicInterface(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EnablePublicInterface", reflect.TypeOf((*MockLoadBalancerClient)(nil).EnablePublicInterface), arg0, arg1) +} + +// Get mocks base method. +func (m *MockLoadBalancerClient) Get(arg0 context.Context, arg1 string) (*hcloud.LoadBalancer, *hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", arg0, arg1) + ret0, _ := ret[0].(*hcloud.LoadBalancer) + ret1, _ := ret[1].(*hcloud.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// Get indicates an expected call of Get. +func (mr *MockLoadBalancerClientMockRecorder) Get(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockLoadBalancerClient)(nil).Get), arg0, arg1) +} + +// GetByID mocks base method. +func (m *MockLoadBalancerClient) GetByID(arg0 context.Context, arg1 int) (*hcloud.LoadBalancer, *hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetByID", arg0, arg1) + ret0, _ := ret[0].(*hcloud.LoadBalancer) + ret1, _ := ret[1].(*hcloud.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// GetByID indicates an expected call of GetByID. +func (mr *MockLoadBalancerClientMockRecorder) GetByID(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetByID", reflect.TypeOf((*MockLoadBalancerClient)(nil).GetByID), arg0, arg1) +} + +// GetByName mocks base method. +func (m *MockLoadBalancerClient) GetByName(arg0 context.Context, arg1 string) (*hcloud.LoadBalancer, *hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetByName", arg0, arg1) + ret0, _ := ret[0].(*hcloud.LoadBalancer) + ret1, _ := ret[1].(*hcloud.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// GetByName indicates an expected call of GetByName. +func (mr *MockLoadBalancerClientMockRecorder) GetByName(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetByName", reflect.TypeOf((*MockLoadBalancerClient)(nil).GetByName), arg0, arg1) +} + +// GetMetrics mocks base method. +func (m *MockLoadBalancerClient) GetMetrics(arg0 context.Context, arg1 *hcloud.LoadBalancer, arg2 hcloud.LoadBalancerGetMetricsOpts) (*hcloud.LoadBalancerMetrics, *hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetMetrics", arg0, arg1, arg2) + ret0, _ := ret[0].(*hcloud.LoadBalancerMetrics) + ret1, _ := ret[1].(*hcloud.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// GetMetrics indicates an expected call of GetMetrics. +func (mr *MockLoadBalancerClientMockRecorder) GetMetrics(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMetrics", reflect.TypeOf((*MockLoadBalancerClient)(nil).GetMetrics), arg0, arg1, arg2) +} + +// LabelKeys mocks base method. +func (m *MockLoadBalancerClient) LabelKeys(arg0 string) []string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LabelKeys", arg0) + ret0, _ := ret[0].([]string) + return ret0 +} + +// LabelKeys indicates an expected call of LabelKeys. +func (mr *MockLoadBalancerClientMockRecorder) LabelKeys(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LabelKeys", reflect.TypeOf((*MockLoadBalancerClient)(nil).LabelKeys), arg0) +} + +// List mocks base method. +func (m *MockLoadBalancerClient) List(arg0 context.Context, arg1 hcloud.LoadBalancerListOpts) ([]*hcloud.LoadBalancer, *hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "List", arg0, arg1) + ret0, _ := ret[0].([]*hcloud.LoadBalancer) + ret1, _ := ret[1].(*hcloud.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// List indicates an expected call of List. +func (mr *MockLoadBalancerClientMockRecorder) List(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockLoadBalancerClient)(nil).List), arg0, arg1) +} + +// LoadBalancerName mocks base method. +func (m *MockLoadBalancerClient) LoadBalancerName(arg0 int) string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LoadBalancerName", arg0) + ret0, _ := ret[0].(string) + return ret0 +} + +// LoadBalancerName indicates an expected call of LoadBalancerName. +func (mr *MockLoadBalancerClientMockRecorder) LoadBalancerName(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LoadBalancerName", reflect.TypeOf((*MockLoadBalancerClient)(nil).LoadBalancerName), arg0) +} + +// Names mocks base method. +func (m *MockLoadBalancerClient) Names() []string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Names") + ret0, _ := ret[0].([]string) + return ret0 +} + +// Names indicates an expected call of Names. +func (mr *MockLoadBalancerClientMockRecorder) Names() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Names", reflect.TypeOf((*MockLoadBalancerClient)(nil).Names)) +} + +// RemoveIPTarget mocks base method. +func (m *MockLoadBalancerClient) RemoveIPTarget(arg0 context.Context, arg1 *hcloud.LoadBalancer, arg2 net.IP) (*hcloud.Action, *hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "RemoveIPTarget", arg0, arg1, arg2) + ret0, _ := ret[0].(*hcloud.Action) + ret1, _ := ret[1].(*hcloud.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// RemoveIPTarget indicates an expected call of RemoveIPTarget. +func (mr *MockLoadBalancerClientMockRecorder) RemoveIPTarget(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveIPTarget", reflect.TypeOf((*MockLoadBalancerClient)(nil).RemoveIPTarget), arg0, arg1, arg2) +} + +// RemoveLabelSelectorTarget mocks base method. +func (m *MockLoadBalancerClient) RemoveLabelSelectorTarget(arg0 context.Context, arg1 *hcloud.LoadBalancer, arg2 string) (*hcloud.Action, *hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "RemoveLabelSelectorTarget", arg0, arg1, arg2) + ret0, _ := ret[0].(*hcloud.Action) + ret1, _ := ret[1].(*hcloud.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// RemoveLabelSelectorTarget indicates an expected call of RemoveLabelSelectorTarget. +func (mr *MockLoadBalancerClientMockRecorder) RemoveLabelSelectorTarget(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveLabelSelectorTarget", reflect.TypeOf((*MockLoadBalancerClient)(nil).RemoveLabelSelectorTarget), arg0, arg1, arg2) +} + +// RemoveServerTarget mocks base method. +func (m *MockLoadBalancerClient) RemoveServerTarget(arg0 context.Context, arg1 *hcloud.LoadBalancer, arg2 *hcloud.Server) (*hcloud.Action, *hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "RemoveServerTarget", arg0, arg1, arg2) + ret0, _ := ret[0].(*hcloud.Action) + ret1, _ := ret[1].(*hcloud.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// RemoveServerTarget indicates an expected call of RemoveServerTarget. +func (mr *MockLoadBalancerClientMockRecorder) RemoveServerTarget(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveServerTarget", reflect.TypeOf((*MockLoadBalancerClient)(nil).RemoveServerTarget), arg0, arg1, arg2) +} + +// Update mocks base method. +func (m *MockLoadBalancerClient) Update(arg0 context.Context, arg1 *hcloud.LoadBalancer, arg2 hcloud.LoadBalancerUpdateOpts) (*hcloud.LoadBalancer, *hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Update", arg0, arg1, arg2) + ret0, _ := ret[0].(*hcloud.LoadBalancer) + ret1, _ := ret[1].(*hcloud.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// Update indicates an expected call of Update. +func (mr *MockLoadBalancerClientMockRecorder) Update(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockLoadBalancerClient)(nil).Update), arg0, arg1, arg2) +} + +// UpdateService mocks base method. +func (m *MockLoadBalancerClient) UpdateService(arg0 context.Context, arg1 *hcloud.LoadBalancer, arg2 int, arg3 hcloud.LoadBalancerUpdateServiceOpts) (*hcloud.Action, *hcloud.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UpdateService", arg0, arg1, arg2, arg3) + ret0, _ := ret[0].(*hcloud.Action) + ret1, _ := ret[1].(*hcloud.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// UpdateService indicates an expected call of UpdateService. +func (mr *MockLoadBalancerClientMockRecorder) UpdateService(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateService", reflect.TypeOf((*MockLoadBalancerClient)(nil).UpdateService), arg0, arg1, arg2, arg3) +}