-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* dep: update dns sdk * feat: add quota * feat: add dnsec * feat: dnssec * fix: breaking change in test * fix: cols for creation * doc: regen docs * doc: changelog
- Loading branch information
1 parent
19f550f
commit f5d987f
Showing
281 changed files
with
12,897 additions
and
52,720 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package dnssec | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/ionos-cloud/ionosctl/v6/commands/dns/zone" | ||
"github.com/ionos-cloud/ionosctl/v6/internal/client" | ||
"github.com/ionos-cloud/ionosctl/v6/internal/constants" | ||
"github.com/ionos-cloud/ionosctl/v6/internal/core" | ||
"github.com/ionos-cloud/ionosctl/v6/internal/printer/json2table/jsonpaths" | ||
"github.com/ionos-cloud/ionosctl/v6/internal/printer/jsontabwriter" | ||
"github.com/ionos-cloud/ionosctl/v6/internal/printer/tabheaders" | ||
"github.com/ionos-cloud/ionosctl/v6/pkg/pointer" | ||
dns "github.com/ionos-cloud/sdk-go-dns" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func Create() *core.Command { | ||
const ( | ||
FlagAlgorithm = "algorithm" | ||
FlagKskBits = "ksk-bits" | ||
FlagZskBits = "zsk-bits" | ||
FlagNsecMode = "nsec-mode" | ||
FlagNsec3Iterations = "nsec3-iterations" | ||
FlagNsec3SaltBits = "nsec3-salt-bits" | ||
FlagValidity = "validity" | ||
) | ||
|
||
cmd := core.NewCommand(context.Background(), nil, core.CommandBuilder{ | ||
Namespace: "dns", | ||
Resource: "dnssec", | ||
Verb: "create", | ||
Aliases: []string{"c", "post"}, | ||
ShortDesc: "Enable DNSSEC keys and create associated DNSKEY records for your DNS zone", | ||
Example: "ionosctl dns keys create --zone ZONE", | ||
PreCmdRun: func(c *core.PreCommandConfig) error { | ||
if err := core.CheckRequiredFlags(c.Command, c.NS, constants.FlagZone); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
CmdRun: func(c *core.CommandConfig) error { | ||
zoneId, err := zone.Resolve(viper.GetString(core.GetFlagName(c.NS, constants.FlagZone))) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
key, _, err := client.Must().DnsClient.DNSSECApi.ZonesKeysPost(context.Background(), zoneId). | ||
DnssecKeyCreate( | ||
dns.DnssecKeyCreate{ | ||
Properties: &dns.DnssecKeyParameters{ | ||
Validity: pointer.From(viper.GetInt32(core.GetFlagName(c.NS, FlagValidity))), | ||
KeyParameters: &dns.KeyParameters{ | ||
Algorithm: pointer.From(dns.Algorithm(viper.GetString(core.GetFlagName(c.NS, FlagAlgorithm)))), | ||
KskBits: pointer.From(dns.KskBits(viper.GetInt32(core.GetFlagName(c.NS, FlagKskBits)))), | ||
ZskBits: pointer.From(dns.ZskBits(viper.GetInt32(core.GetFlagName(c.NS, FlagZskBits)))), | ||
}, | ||
NsecParameters: &dns.NsecParameters{ | ||
NsecMode: pointer.From(dns.NsecMode(viper.GetString(core.GetFlagName(c.NS, FlagNsecMode)))), | ||
Nsec3Iterations: pointer.From(viper.GetInt32(core.GetFlagName(c.NS, FlagNsec3Iterations))), | ||
Nsec3SaltBits: pointer.From(viper.GetInt32(core.GetFlagName(c.NS, FlagNsec3SaltBits))), | ||
}, | ||
}, | ||
}).Execute() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cols, _ := c.Command.Command.Flags().GetStringSlice(constants.ArgCols) | ||
out, err := jsontabwriter.GenerateOutput("", jsonpaths.DnsSecKey, key, | ||
tabheaders.GetHeadersAllDefault(allCols, cols)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Fprintf(c.Command.Command.OutOrStdout(), out) | ||
return nil | ||
}, | ||
InitClient: true, | ||
}) | ||
|
||
cmd.AddStringFlag(constants.FlagZone, constants.FlagZoneShort, "", constants.DescZone) | ||
_ = cmd.Command.RegisterFlagCompletionFunc(constants.FlagZone, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | ||
return zone.ZonesProperty(func(t dns.ZoneRead) string { | ||
return *t.Properties.ZoneName | ||
}), cobra.ShellCompDirectiveNoFileComp | ||
}) | ||
|
||
cmd.AddStringFlag(FlagAlgorithm, "", "RSASHA256", "Algorithm used to generate signing keys (both Key Signing Keys and Zone Signing Keys)") | ||
cmd.AddIntFlag(FlagKskBits, "", 1024, "Key signing key length in bits. kskBits >= zskBits: [1024/2048/4096]") | ||
_ = cmd.Command.RegisterFlagCompletionFunc(FlagKskBits, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | ||
return []string{"1024", "2048", "4096"}, cobra.ShellCompDirectiveNoFileComp | ||
}) | ||
cmd.AddIntFlag(FlagZskBits, "", 1024, "Zone signing key length in bits. zskBits <= kskBits: [1024/2048/4096]") | ||
_ = cmd.Command.RegisterFlagCompletionFunc(FlagZskBits, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | ||
return []string{"1024", "2048", "4096"}, cobra.ShellCompDirectiveNoFileComp | ||
}) | ||
cmd.AddSetFlag(FlagNsecMode, "", "NSEC", []string{"NSEC", "NSEC3"}, "NSEC mode.") | ||
cmd.AddIntFlag(FlagNsec3Iterations, "", 0, "Number of iterations for NSEC3. [0..50]") | ||
cmd.AddIntFlag(FlagNsec3SaltBits, "", 64, "Salt length in bits for NSEC3. [64..128], multiples of 8") | ||
_ = cmd.Command.RegisterFlagCompletionFunc(FlagNsec3SaltBits, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | ||
return []string{"64", "72", "80", "88", "96", "104", "112", "120", "128"}, cobra.ShellCompDirectiveNoFileComp | ||
}) | ||
cmd.AddIntFlag(FlagValidity, "", 90, "Signature validity in days [90..365]") | ||
|
||
cmd.Command.SilenceUsage = true | ||
cmd.Command.Flags().SortFlags = false | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package dnssec | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/ionos-cloud/ionosctl/v6/commands/dns/zone" | ||
"github.com/ionos-cloud/ionosctl/v6/internal/client" | ||
"github.com/ionos-cloud/ionosctl/v6/internal/constants" | ||
"github.com/ionos-cloud/ionosctl/v6/internal/core" | ||
dns "github.com/ionos-cloud/sdk-go-dns" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func Delete() *core.Command { | ||
cmd := core.NewCommand(context.Background(), nil, core.CommandBuilder{ | ||
Namespace: "dns", | ||
Resource: "dnssec", | ||
Verb: "delete", | ||
Aliases: []string{"del", "rm", "remove"}, | ||
ShortDesc: "Removes ALL associated DNSKEY records for your DNS zone and disables DNSSEC keys.", | ||
Example: `ionosctl dns keys delete --zone ZONE`, | ||
PreCmdRun: func(c *core.PreCommandConfig) error { | ||
if err := core.CheckRequiredFlags(c.Command, c.NS, constants.FlagZone); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
CmdRun: func(c *core.CommandConfig) error { | ||
zoneName := viper.GetString(core.GetFlagName(c.NS, constants.FlagZone)) | ||
zoneId, err := zone.Resolve(zoneName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, _, err = client.Must().DnsClient.DNSSECApi.ZonesKeysDelete(context.Background(), zoneId).Execute() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Fprintf(c.Command.Command.OutOrStdout(), "DNSKEY records deleted and DNSSEC keys disabled for zone %s\n", zoneName) | ||
return nil | ||
}, | ||
InitClient: true, | ||
}) | ||
|
||
cmd.AddStringFlag(constants.FlagZone, constants.FlagZoneShort, "", constants.DescZone) | ||
_ = cmd.Command.RegisterFlagCompletionFunc(constants.FlagZone, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | ||
return zone.ZonesProperty(func(t dns.ZoneRead) string { | ||
return *t.Properties.ZoneName | ||
}), cobra.ShellCompDirectiveNoFileComp | ||
}) | ||
|
||
cmd.Command.SilenceUsage = true | ||
cmd.Command.Flags().SortFlags = false | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package dnssec | ||
|
||
import ( | ||
"github.com/ionos-cloud/ionosctl/v6/internal/constants" | ||
"github.com/ionos-cloud/ionosctl/v6/internal/core" | ||
"github.com/ionos-cloud/ionosctl/v6/internal/printer/tabheaders" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
allCols = []string{"Id", "KeyTag", "DigestAlgorithmMnemonic", "Digest", "Validity", | ||
"Flags", "PubKey", "ComposedKeyData", "Algorithm", "KskBits", "ZskBits", "NsecMode", "Nsec3Iterations", "Nsec3SaltBits"} | ||
|
||
defaultCols = []string{"Id", "KeyTag", "DigestAlgorithmMnemonic", "Digest", "Validity"} | ||
) | ||
|
||
func Root() *core.Command { | ||
cmd := &core.Command{ | ||
Command: &cobra.Command{ | ||
Use: "dnssec", | ||
Aliases: []string{"sec", "dnskey", "key", "keys"}, | ||
Short: "The sub-commands of 'ionosctl dns dnssec' allow you to manage your DNSSEC Keys", | ||
TraverseChildren: true, | ||
}, | ||
} | ||
|
||
cmd.Command.PersistentFlags().StringSlice(constants.ArgCols, defaultCols, tabheaders.ColsMessage(allCols)) | ||
_ = cmd.Command.RegisterFlagCompletionFunc(constants.ArgCols, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | ||
return allCols, cobra.ShellCompDirectiveNoFileComp | ||
}) | ||
|
||
cmd.AddCommand(Get()) | ||
cmd.AddCommand(Create()) | ||
cmd.AddCommand(Delete()) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package dnssec | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/ionos-cloud/ionosctl/v6/commands/dns/zone" | ||
"github.com/ionos-cloud/ionosctl/v6/internal/client" | ||
"github.com/ionos-cloud/ionosctl/v6/internal/constants" | ||
"github.com/ionos-cloud/ionosctl/v6/internal/core" | ||
"github.com/ionos-cloud/ionosctl/v6/internal/printer/json2table/resource2table" | ||
"github.com/ionos-cloud/ionosctl/v6/internal/printer/jsontabwriter" | ||
"github.com/ionos-cloud/ionosctl/v6/internal/printer/tabheaders" | ||
dns "github.com/ionos-cloud/sdk-go-dns" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func Get() *core.Command { | ||
cmd := core.NewCommand(context.Background(), nil, core.CommandBuilder{ | ||
Namespace: "dns", | ||
Resource: "dnssec", | ||
Verb: "list", | ||
Aliases: []string{"l", "ls", "get", "g"}, | ||
ShortDesc: "Retrieve your zone's DNSSEC keys", | ||
Example: `ionosctl dns keys list --zone ZONE | ||
ionosctl dns keys list --zone ZONE --cols ComposedKeyData --no-headers | ||
ionosctl dns keys list --zone ZONE --cols PubKey --no-headers`, | ||
PreCmdRun: func(c *core.PreCommandConfig) error { | ||
if err := core.CheckRequiredFlags(c.Command, c.NS, constants.FlagZone); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
CmdRun: func(c *core.CommandConfig) error { | ||
zoneId, err := zone.Resolve(viper.GetString(core.GetFlagName(c.NS, constants.FlagZone))) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
key, _, err := client.Must().DnsClient.DNSSECApi.ZonesKeysGet(context.Background(), zoneId).Execute() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
table, err := resource2table.ConvertDNSSECToTable(key) | ||
if err != nil { | ||
return fmt.Errorf("could not convert from JSON to Table format: %w", err) | ||
} | ||
cols, _ := c.Command.Command.Flags().GetStringSlice(constants.ArgCols) | ||
out, err := jsontabwriter.GenerateOutputPreconverted(key, table, | ||
tabheaders.GetHeadersAllDefault(allCols, cols)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Fprintf(c.Command.Command.OutOrStdout(), out) | ||
return nil | ||
}, | ||
InitClient: true, | ||
}) | ||
|
||
cmd.AddStringFlag(constants.FlagZone, constants.FlagZoneShort, "", constants.DescZone) | ||
_ = cmd.Command.RegisterFlagCompletionFunc(constants.FlagZone, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | ||
return zone.ZonesProperty(func(t dns.ZoneRead) string { | ||
return *t.Properties.ZoneName | ||
}), cobra.ShellCompDirectiveNoFileComp | ||
}) | ||
|
||
cmd.Command.SilenceUsage = true | ||
cmd.Command.Flags().SortFlags = false | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package quota | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/ionos-cloud/ionosctl/v6/internal/client" | ||
"github.com/ionos-cloud/ionosctl/v6/internal/constants" | ||
"github.com/ionos-cloud/ionosctl/v6/internal/core" | ||
"github.com/ionos-cloud/ionosctl/v6/internal/printer/json2table/jsonpaths" | ||
"github.com/ionos-cloud/ionosctl/v6/internal/printer/jsontabwriter" | ||
"github.com/ionos-cloud/ionosctl/v6/internal/printer/tabheaders" | ||
) | ||
|
||
func Get() *core.Command { | ||
cmd := core.NewCommand(context.Background(), nil, core.CommandBuilder{ | ||
Namespace: "dns", | ||
Resource: "quota", | ||
Verb: "get", | ||
Aliases: []string{"g"}, | ||
ShortDesc: "Retrieve your quotas", | ||
Example: "ionosctl dns quota get", | ||
CmdRun: func(c *core.CommandConfig) error { | ||
q, _, err := client.Must().DnsClient.QuotaApi.QuotaGet(context.Background()).Execute() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cols, _ := c.Command.Command.Flags().GetStringSlice(constants.ArgCols) | ||
out, err := jsontabwriter.GenerateOutput("", jsonpaths.DnsQuota, q, tabheaders.GetHeadersAllDefault(allCols, cols)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Fprintf(c.Command.Command.OutOrStdout(), out) | ||
return nil | ||
}, | ||
InitClient: true, | ||
}) | ||
|
||
cmd.Command.SilenceUsage = true | ||
cmd.Command.Flags().SortFlags = false | ||
|
||
return cmd | ||
} |
Oops, something went wrong.