Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var CreateCmd = base.CreateCmd{ BaseCobraCommand: func(hcapi2.Client) *cobra.Command { cmd := &cobra.Command{ Use: "create [options] --name <name> (--type managed --domain <domain> | --type uploaded --cert-file <file> --key-file <file>)", Short: "Create or upload a Certificate", } cmd.Flags().String("name", "", "Certificate name (required)") _ = cmd.MarkFlagRequired("name") cmd.Flags().StringP("type", "t", string(hcloud.CertificateTypeUploaded), fmt.Sprintf("Type of certificate to create. Valid choices: %v, %v", hcloud.CertificateTypeUploaded, hcloud.CertificateTypeManaged)) _ = cmd.RegisterFlagCompletionFunc( "type", cmpl.SuggestCandidates(string(hcloud.CertificateTypeUploaded), string(hcloud.CertificateTypeManaged)), ) cmd.Flags().String("cert-file", "", "File containing the PEM encoded certificate (required if type is uploaded)") cmd.Flags().String("key-file", "", "File containing the PEM encoded private key for the certificate (required if type is uploaded)") cmd.Flags().StringSlice("domain", nil, "One or more domains the certificate is valid for.") return cmd }, Run: func(s state.State, cmd *cobra.Command, _ []string) (any, any, error) { certType, err := cmd.Flags().GetString("type") if err != nil { return nil, nil, err } var cert *hcloud.Certificate switch hcloud.CertificateType(certType) { case hcloud.CertificateTypeManaged: cert, err = createManaged(s, cmd) default: cert, err = createUploaded(s, cmd) } if err != nil { return nil, nil, err } return cert, util.Wrap("certificate", hcloud.SchemaFromCertificate(cert)), nil }, }
View Source
var DeleteCmd = base.DeleteCmd{ ResourceNameSingular: "certificate", ResourceNamePlural: "certificates", ShortDescription: "Delete a certificate", NameSuggestions: func(c hcapi2.Client) func() []string { return c.Firewall().Names }, Fetch: func(s state.State, _ *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) { return s.Client().Certificate().Get(s, idOrName) }, Delete: func(s state.State, _ *cobra.Command, resource interface{}) (*hcloud.Action, error) { certificate := resource.(*hcloud.Certificate) _, err := s.Client().Certificate().Delete(s, certificate) return nil, err }, }
View Source
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(s state.State, _ *cobra.Command, idOrName string) (interface{}, interface{}, error) { cert, _, err := s.Client().Certificate().Get(s, idOrName) if err != nil { return nil, nil, err } return cert, hcloud.SchemaFromCertificate(cert), nil }, PrintText: func(s state.State, cmd *cobra.Command, resource interface{}) error { cert := resource.(*hcloud.Certificate) cmd.Printf("ID:\t\t\t%d\n", cert.ID) cmd.Printf("Name:\t\t\t%s\n", cert.Name) cmd.Printf("Type:\t\t\t%s\n", cert.Type) cmd.Printf("Fingerprint:\t\t%s\n", cert.Fingerprint) cmd.Printf("Created:\t\t%s (%s)\n", util.Datetime(cert.Created), humanize.Time(cert.Created)) cmd.Printf("Not valid before:\t%s (%s)\n", util.Datetime(cert.NotValidBefore), humanize.Time(cert.NotValidBefore)) cmd.Printf("Not valid after:\t%s (%s)\n", util.Datetime(cert.NotValidAfter), humanize.Time(cert.NotValidAfter)) if cert.Status != nil { cmd.Printf("Status:\n") cmd.Printf(" Issuance:\t%s\n", cert.Status.Issuance) cmd.Printf(" Renewal:\t%s\n", cert.Status.Renewal) if cert.Status.IsFailed() { cmd.Printf(" Failure reason: %s\n", cert.Status.Error.Message) } } cmd.Printf("Domain names:\n") for _, domainName := range cert.DomainNames { cmd.Printf(" - %s\n", domainName) } cmd.Print("Labels:\n") if len(cert.Labels) == 0 { cmd.Print(" No labels\n") } else { for key, value := range cert.Labels { cmd.Printf(" %s:\t%s\n", key, value) } } cmd.Println("Used By:") if len(cert.UsedBy) == 0 { cmd.Println(" Certificate unused") } else { for _, ub := range cert.UsedBy { cmd.Printf(" - Type: %s\n", ub.Type) if ub.Type != hcloud.CertificateUsedByRefTypeLoadBalancer { cmd.Printf(" - ID: %d\n", ub.ID) continue } cmd.Printf(" - Name: %s\n", s.Client().LoadBalancer().LoadBalancerName(ub.ID)) } } return nil }, }
View Source
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(s state.State, idOrName string) (map[string]string, int64, error) { certificate, _, err := s.Client().Certificate().Get(s, 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(s state.State, id int64, labels map[string]string) error { opts := hcloud.CertificateUpdateOpts{ Labels: labels, } _, _, err := s.Client().Certificate().Update(s, &hcloud.Certificate{ID: id}, opts) return err }, }
View Source
var ListCmd = base.ListCmd{ ResourceNamePlural: "Certificates", JSONKeyGetByName: "certificates", DefaultColumns: []string{"id", "name", "type", "domain_names", "not_valid_after", "age"}, SortOption: config.OptionSortCertificate, Fetch: func(s state.State, _ *pflag.FlagSet, listOpts hcloud.ListOpts, sorts []string) ([]interface{}, error) { opts := hcloud.CertificateListOpts{ListOpts: listOpts} if len(sorts) > 0 { opts.Sort = sorts } certificates, err := s.Client().Certificate().AllWithOpts(s, opts) var resources []interface{} for _, n := range certificates { resources = append(resources, n) } return resources, err }, OutputTable: func(t *output.Table, _ hcapi2.Client) { t. 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) })). AddFieldFn("age", output.FieldFn(func(obj interface{}) string { cert := obj.(*hcloud.Certificate) return util.Age(cert.Created, time.Now()) })) }, Schema: func(resources []interface{}) interface{} { certSchemas := make([]schema.Certificate, 0, len(resources)) for _, resource := range resources { cert := resource.(*hcloud.Certificate) certSchemas = append(certSchemas, hcloud.SchemaFromCertificate(cert)) } return certSchemas }, }
View Source
var RetryCmd = base.Cmd{ BaseCobraCommand: func(_ hcapi2.Client) *cobra.Command { return &cobra.Command{ Use: "retry <certificate>", Short: "Retry a managed certificate's issuance", TraverseChildren: true, DisableFlagsInUseLine: true, } }, Run: func(s state.State, cmd *cobra.Command, args []string) error { idOrName := args[0] certificate, _, err := s.Client().Certificate().Get(s, idOrName) if err != nil { return err } if certificate == nil { return fmt.Errorf("certificate not found: %s", idOrName) } action, _, err := s.Client().Certificate().RetryIssuance(s, certificate) if err != nil { return err } if err := s.WaitForActions(s, cmd, action); err != nil { return err } cmd.Printf("Retried issuance of certificate %s\n", certificate.Name) return nil }, }
View Source
var UpdateCmd = base.UpdateCmd{ ResourceNameSingular: "certificate", ShortDescription: "Update a certificate", NameSuggestions: func(c hcapi2.Client) func() []string { return c.Firewall().Names }, Fetch: func(s state.State, _ *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) { return s.Client().Certificate().Get(s, idOrName) }, DefineFlags: func(cmd *cobra.Command) { cmd.Flags().String("name", "", "Certificate Name") }, Update: func(s state.State, _ *cobra.Command, resource interface{}, flags map[string]pflag.Value) error { certificate := resource.(*hcloud.Certificate) updOpts := hcloud.CertificateUpdateOpts{ Name: flags["name"].String(), } _, _, err := s.Client().Certificate().Update(s, certificate, updOpts) if err != nil { return err } return nil }, }
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.