diff --git a/cmd/instance/instance.go b/cmd/instance/instance.go index 79e49df8..3a147fe0 100644 --- a/cmd/instance/instance.go +++ b/cmd/instance/instance.go @@ -53,7 +53,6 @@ func init() { instanceCreateCmd.Flags().StringVarP(&network, "network", "r", "", "the instance's network you can use the Name or the ID") instanceCreateCmd.Flags().StringVarP(&firewall, "firewall", "l", "", "the instance's firewall you can use the Name or the ID") instanceCreateCmd.Flags().StringVarP(&tags, "tags", "g", "", "the instance's tags") - instanceCreateCmd.Flags().StringVarP(&tags, "region", "e", "", "the region code identifier to have your instance built in") instanceCreateCmd.Flags().StringVar(&script, "script", "", "path to a script that will be uploaded to /usr/local/bin/civo-user-init-script on your instance, read/write/executable only by root and then will be executed at the end of the cloud initialization") instanceCreateCmd.Flags().BoolVar(&skipShebangCheck, "skip-shebang-check", false, "skip the shebang line check when passing a user init script") diff --git a/cmd/instance/instance_list.go b/cmd/instance/instance_list.go index 8ca74db2..80653fb9 100644 --- a/cmd/instance/instance_list.go +++ b/cmd/instance/instance_list.go @@ -62,29 +62,26 @@ If you wish to use a custom format, the available fields are: for _, instance := range instances { ow.StartLine() - ow.AppendDataWithLabel("id", instance.ID, "ID") + ow.AppendDataWithLabel("id", utility.TruncateID(instance.ID), "ID") ow.AppendDataWithLabel("hostname", instance.Hostname, "Hostname") ow.AppendDataWithLabel("region", client.Region, "Region") ow.AppendDataWithLabel("size", instance.Size, "Size") - ow.AppendDataWithLabel("cpu_cores", strconv.Itoa(instance.CPUCores), "Cpu Cores") - ow.AppendDataWithLabel("ram_mb", strconv.Itoa(instance.RAMMegabytes), "Ram") - ow.AppendDataWithLabel("disk_gb", strconv.Itoa(instance.DiskGigabytes), "SSD disk") ow.AppendDataWithLabel("public_ip", instance.PublicIP, "Public IP") ow.AppendDataWithLabel("private_ip", instance.PrivateIP, "Private IP") + ow.AppendDataWithLabel("ipv6", instance.IPv6, "IPv6") ow.AppendDataWithLabel("status", utility.ColorStatus(instance.Status), "Status") if common.OutputFormat == "json" || common.OutputFormat == "custom" { ow.AppendDataWithLabel("network_id", instance.NetworkID, "Network ID") - // ow.AppendDataWithLabel("PrivateIP", instance.PrivateIP, "") - // ow.AppendDataWithLabel("PublicIP", instance.PublicIP, "") + ow.AppendDataWithLabel("cpu_cores", strconv.Itoa(instance.CPUCores), "Cpu Cores") + ow.AppendDataWithLabel("ram_mb", strconv.Itoa(instance.RAMMegabytes), "Ram") + ow.AppendDataWithLabel("disk_gb", strconv.Itoa(instance.DiskGigabytes), "SSD disk") ow.AppendDataWithLabel("diskimage_id", instance.SourceID, "Disk image ID") ow.AppendDataWithLabel("initial_user", instance.InitialUser, "Initial User") ow.AppendDataWithLabel("ssh_key", instance.SSHKey, "SSH Key") ow.AppendDataWithLabel("notes", instance.Notes, "Notes") ow.AppendDataWithLabel("firewall_id", instance.FirewallID, "Firewall ID") ow.AppendDataWithLabel("tags", strings.Join(instance.Tags, " "), "Tags") - // ow.AppendDataWithLabel("CivostatsdToken", instance.CivostatsdToken, "") - // ow.AppendDataWithLabel("CivostatsdStats", instance.CivostatsdStats, "") ow.AppendDataWithLabel("script", instance.Script, "Script") ow.AppendDataWithLabel("created_at", instance.CreatedAt.Format(time.RFC1123), "Created At") ow.AppendDataWithLabel("status", instance.Status, "Status") diff --git a/cmd/network/network.go b/cmd/network/network.go index d3ec590a..8977ef51 100644 --- a/cmd/network/network.go +++ b/cmd/network/network.go @@ -6,6 +6,9 @@ import ( "github.com/spf13/cobra" ) +var v4enabled, v6enabled bool +var cidrv4 string + // NetworkCmd manages Civo networks var NetworkCmd = &cobra.Command{ Use: "network", @@ -20,9 +23,44 @@ var NetworkCmd = &cobra.Command{ }, } +var networkSubnetCmd = &cobra.Command{ + Use: "subnet", + Aliases: []string{"subnets"}, + Short: "Details of Civo network subnets", + RunE: func(cmd *cobra.Command, args []string) error { + err := cmd.Help() + if err != nil { + return err + } + return errors.New("a valid subcommand is required") + }, +} + func init() { NetworkCmd.AddCommand(networkListCmd) NetworkCmd.AddCommand(networkCreateCmd) NetworkCmd.AddCommand(networkUpdateCmd) NetworkCmd.AddCommand(networkRemoveCmd) + NetworkCmd.AddCommand(networkSubnetCmd) + + networkCreateCmd.Flags().BoolVarP(&v4enabled, "v4", "", true, "Enable IPv4 on the network") + networkCreateCmd.Flags().BoolVarP(&v6enabled, "v6", "", false, "Enable IPv6 on the network") + networkCreateCmd.Flags().StringVarP(&cidrv4, "cidr-v4", "c", "", "The CIDR for the IPv4 network") + + networkSubnetCmd.AddCommand(networkSubnetListCmd) + networkSubnetCmd.AddCommand(networkSubnetCreateCmd) + networkSubnetCmd.AddCommand(networkSubnetShowCmd) + networkSubnetCmd.AddCommand(networkSubnetRemoveCmd) + networkSubnetCmd.AddCommand(networkSubnetAttachCmd) + networkSubnetCmd.AddCommand(networkSubnetDetachCmd) + + networkSubnetAttachCmd.Flags().StringVarP(&subnetID, "subnet", "", "", "the id of subnet you want to attach to the instance") + networkSubnetAttachCmd.Flags().StringVarP(&instanceID, "instance", "", "", "the id of instance you want to attach your subnet to") + networkSubnetAttachCmd.MarkFlagRequired("subnet") + networkSubnetAttachCmd.MarkFlagRequired("instance") + + networkSubnetDetachCmd.Flags().StringVarP(&subnetID, "subnet", "", "", "the id of subnet you want to attach to the instance") + networkSubnetDetachCmd.Flags().StringVarP(&instanceID, "instance", "", "", "the id of instance you want to attach your subnet to") + networkSubnetDetachCmd.MarkFlagRequired("subnet") + networkSubnetDetachCmd.MarkFlagRequired("instance") } diff --git a/cmd/network/network_create.go b/cmd/network/network_create.go index 08384354..91e35e08 100644 --- a/cmd/network/network_create.go +++ b/cmd/network/network_create.go @@ -4,6 +4,7 @@ import ( "fmt" "os" + "github.com/civo/civogo" "github.com/civo/cli/common" "github.com/civo/cli/config" "github.com/civo/cli/utility" @@ -28,9 +29,22 @@ var networkCreateCmd = &cobra.Command{ os.Exit(1) } - network, err := client.NewNetwork(args[0]) + var network *civogo.NetworkResult + + nc := civogo.NetworkConfig{ + Label: args[0], + Region: client.Region, + IPv4Enabled: &v4enabled, + IPv6Enabled: &v6enabled, + } + + if cidrv4 != "" { + nc.CIDRv4 = cidrv4 + } + + network, err = client.CreateNetwork(nc) if err != nil { - utility.Error("%s", err) + utility.Error("Error creating the network: %s", err) os.Exit(1) } diff --git a/cmd/network/network_list.go b/cmd/network/network_list.go index 32196338..8a0d3ed4 100644 --- a/cmd/network/network_list.go +++ b/cmd/network/network_list.go @@ -47,6 +47,8 @@ If you wish to use a custom format, the available fields are: ow.AppendDataWithLabel("id", network.ID, "ID") ow.AppendDataWithLabel("label", network.Label, "Label") ow.AppendDataWithLabel("region", client.Region, "Region") + ow.AppendDataWithLabel("ipv4_enabled", strconv.FormatBool(network.IPv4Enabled), "IPv4 Enabled") + ow.AppendDataWithLabel("ipv6_enabled", strconv.FormatBool(network.IPv6Enabled), "IPv6 Enabled") ow.AppendDataWithLabel("default", strconv.FormatBool(network.Default), "Default") ow.AppendDataWithLabel("status", network.Status, "Status") } diff --git a/cmd/network/network_subnet_attach.go b/cmd/network/network_subnet_attach.go new file mode 100644 index 00000000..d9470bc8 --- /dev/null +++ b/cmd/network/network_subnet_attach.go @@ -0,0 +1,88 @@ +package network + +import ( + "fmt" + "os" + "time" + + "github.com/briandowns/spinner" + "github.com/civo/civogo" + "github.com/civo/cli/common" + "github.com/civo/cli/config" + "github.com/civo/cli/utility" + "github.com/spf13/cobra" +) + +var instanceID, subnetID string +var waitSubnetAttach bool + +var networkSubnetAttachCmd = &cobra.Command{ + Use: "attach", + Short: "Attach a subnet to a resource", + Example: "civo network subnet attach --instance INSTANCE-ID --subnet SUBNET-ID", + Run: func(cmd *cobra.Command, args []string) { + utility.EnsureCurrentRegion() + + client, err := config.CivoAPIClient() + if common.RegionSet != "" { + client.Region = common.RegionSet + } + if err != nil { + utility.Error("Creating the connection to Civo's API failed with %s", err) + os.Exit(1) + } + + instance, err := client.FindInstance(instanceID) + if err != nil { + utility.Error("Instance %s", err) + os.Exit(1) + } + + subnet, err := client.FindSubnet(subnetID, instance.NetworkID) + if err != nil { + utility.Error("Subnet %s", err) + os.Exit(1) + } + + _, err = client.AttachSubnetToInstance(instance.NetworkID, subnet.ID, &civogo.CreateRoute{ + ResourceID: instance.ID, + ResourceType: "instance", + }) + if err != nil { + utility.Error("error attaching the subnet: %s", err) + os.Exit(1) + } + + if waitSubnetAttach { + stillAttaching := true + s := spinner.New(spinner.CharSets[9], 100*time.Millisecond) + s.Prefix = "Attaching subnet to the instance... " + s.Start() + + for stillAttaching { + subnetCheck, err := client.FindSubnet(subnet.ID, instance.NetworkID) + if err != nil { + utility.Error("Finding the subnet failed with %s", err) + os.Exit(1) + } + if subnetCheck.Status == "attached" { + stillAttaching = false + s.Stop() + } else { + time.Sleep(2 * time.Second) + } + } + } + + ow := utility.NewOutputWriterWithMap(map[string]string{"id": subnet.ID, "name": subnet.Name}) + + switch common.OutputFormat { + case "json": + ow.WriteSingleObjectJSON(common.PrettySet) + case "custom": + ow.WriteCustomOutput(common.OutputFields) + default: + fmt.Printf("The subnet (%s) was attached to the instance with ID (%s)\n", utility.Green(subnet.Name), utility.Green(instance.ID)) + } + }, +} diff --git a/cmd/network/network_subnet_create.go b/cmd/network/network_subnet_create.go new file mode 100644 index 00000000..ef673bbc --- /dev/null +++ b/cmd/network/network_subnet_create.go @@ -0,0 +1,59 @@ +package network + +import ( + "fmt" + "os" + + "github.com/civo/civogo" + "github.com/civo/cli/common" + "github.com/civo/cli/config" + "github.com/civo/cli/utility" + "github.com/spf13/cobra" +) + +var networkSubnetCreateCmd = &cobra.Command{ + Use: "create", + Aliases: []string{"create", "add"}, + Short: "Create a new subnet", + Example: "civo network subnet create ", + Args: cobra.MinimumNArgs(2), + Run: func(cmd *cobra.Command, args []string) { + utility.EnsureCurrentRegion() + + client, err := config.CivoAPIClient() + if common.RegionSet != "" { + client.Region = common.RegionSet + } + if err != nil { + utility.Error("Creating the connection to Civo's API failed with %s", err) + os.Exit(1) + } + + network, err := client.FindNetwork(args[1]) + if err != nil { + utility.Error("Network %s", err) + os.Exit(1) + } + + subnetConfig := civogo.SubnetConfig{ + Name: args[0], + } + + subnet, err := client.CreateSubnet(network.ID, subnetConfig) + if err != nil { + utility.Error("Subnet %s", err) + os.Exit(1) + } + + ow := utility.NewOutputWriterWithMap(map[string]string{"id": subnet.ID, "name": subnet.Name}) + + switch common.OutputFormat { + case "json": + ow.WriteSingleObjectJSON(common.PrettySet) + case "custom": + ow.WriteCustomOutput(common.OutputFields) + default: + fmt.Printf("The subnet (%s) was created in network with ID (%s)\n", utility.Green(subnet.Name), utility.Green(network.ID)) + } + }, +} diff --git a/cmd/network/network_subnet_detach.go b/cmd/network/network_subnet_detach.go new file mode 100644 index 00000000..592864ed --- /dev/null +++ b/cmd/network/network_subnet_detach.go @@ -0,0 +1,83 @@ +package network + +import ( + "fmt" + "os" + "time" + + "github.com/briandowns/spinner" + "github.com/civo/cli/common" + "github.com/civo/cli/config" + "github.com/civo/cli/utility" + "github.com/spf13/cobra" +) + +var waitSubnetDetach bool + +var networkSubnetDetachCmd = &cobra.Command{ + Use: "detach", + Short: "Detach a subnet from a resource", + Example: "civo network subnet detach --instance INSTANCE-ID --subnet SUBNET-ID", + Run: func(cmd *cobra.Command, args []string) { + utility.EnsureCurrentRegion() + + client, err := config.CivoAPIClient() + if common.RegionSet != "" { + client.Region = common.RegionSet + } + if err != nil { + utility.Error("Creating the connection to Civo's API failed with %s", err) + os.Exit(1) + } + + instance, err := client.FindInstance(instanceID) + if err != nil { + utility.Error("Instance %s", err) + os.Exit(1) + } + + subnet, err := client.FindSubnet(subnetID, instance.NetworkID) + if err != nil { + utility.Error("Subnet %s", err) + os.Exit(1) + } + + _, err = client.DetachSubnetFromInstance(instance.NetworkID, subnet.ID) + if err != nil { + utility.Error("error detaching the subnet: %s", err) + os.Exit(1) + } + + if waitSubnetDetach { + stillDetaching := true + s := spinner.New(spinner.CharSets[9], 100*time.Millisecond) + s.Prefix = "Detaching the subnet... " + s.Start() + + for stillDetaching { + subnetCheck, err := client.FindSubnet(subnet.ID, instance.NetworkID) + if err != nil { + utility.Error("%s", err) + os.Exit(1) + } + if subnetCheck.Status == "available" { + stillDetaching = false + s.Stop() + } else { + time.Sleep(2 * time.Second) + } + } + } + + ow := utility.NewOutputWriterWithMap(map[string]string{"id": subnet.ID, "name": subnet.Name}) + + switch common.OutputFormat { + case "json": + ow.WriteSingleObjectJSON(common.PrettySet) + case "custom": + ow.WriteCustomOutput(common.OutputFields) + default: + fmt.Printf("The subnet (%s) was detached from instance with ID (%s)\n", utility.Green(subnet.Name), utility.Green(instance.ID)) + } + }, +} diff --git a/cmd/network/network_subnet_list.go b/cmd/network/network_subnet_list.go new file mode 100644 index 00000000..bc3c106e --- /dev/null +++ b/cmd/network/network_subnet_list.go @@ -0,0 +1,58 @@ +package network + +import ( + "github.com/civo/cli/common" + "github.com/civo/cli/config" + "github.com/civo/cli/utility" + "github.com/spf13/cobra" +) + +var networkSubnetListCmd = &cobra.Command{ + Use: "list", + Aliases: []string{"ls"}, + Example: `civo network subnet ls "`, + Args: cobra.MinimumNArgs(1), + Short: "List all subnets within a network", + Run: func(cmd *cobra.Command, args []string) { + utility.EnsureCurrentRegion() + + client, err := config.CivoAPIClient() + if common.RegionSet != "" { + client.Region = common.RegionSet + } + if err != nil { + utility.Error("Creating the connection to Civo's API failed with %s", err) + return + } + + subnets, err := client.ListSubnets(args[0]) + if err != nil { + utility.Error("%s", err) + return + } + + ow := utility.NewOutputWriter() + + for _, subnet := range subnets { + ow.StartLine() + ow.AppendDataWithLabel("id", utility.TruncateID(subnet.ID), "ID") + ow.AppendDataWithLabel("name", subnet.Name, "Name") + ow.AppendDataWithLabel("subnet_size", subnet.SubnetSize, "Subnet Size") + ow.AppendDataWithLabel("region", client.Region, "Region") + ow.AppendDataWithLabel("status", subnet.Status, "Status") + + if common.OutputFormat == "json" || common.OutputFormat == "custom" { + ow.AppendDataWithLabel("network_id", subnet.NetworkID, "Network ID") + } + } + + switch common.OutputFormat { + case "json": + ow.WriteMultipleObjectsJSON(common.PrettySet) + case "custom": + ow.WriteCustomOutput(common.OutputFields) + default: + ow.WriteTable() + } + }, +} diff --git a/cmd/network/network_subnet_remove.go b/cmd/network/network_subnet_remove.go new file mode 100644 index 00000000..18858dd2 --- /dev/null +++ b/cmd/network/network_subnet_remove.go @@ -0,0 +1,104 @@ +package network + +import ( + "errors" + "fmt" + "strings" + + pluralize "github.com/alejandrojnm/go-pluralize" + "github.com/civo/civogo" + "github.com/civo/cli/common" + "github.com/civo/cli/config" + "github.com/civo/cli/utility" + + "os" + + "github.com/spf13/cobra" +) + +var subnetsList []utility.ObjecteList +var networkSubnetRemoveCmd = &cobra.Command{ + Use: "remove", + Aliases: []string{"rm", "delete", "destroy"}, + Short: "Delete a Subnet from a network", + Example: "civo network subnet delete ", + Args: cobra.MinimumNArgs(2), + Run: func(cmd *cobra.Command, args []string) { + utility.EnsureCurrentRegion() + client, err := config.CivoAPIClient() + if err != nil { + utility.Error("Creating the connection to Civo's API failed with %s", err) + os.Exit(1) + } + + if common.RegionSet != "" { + client.Region = common.RegionSet + } + + if len(args) == 2 { + subnet, err := client.FindSubnet(args[0], args[1]) + if err != nil { + if errors.Is(err, civogo.ZeroMatchesError) { + utility.Error("sorry there is no %s subnet in your account", utility.Red(args[0])) + os.Exit(1) + } + if errors.Is(err, civogo.MultipleMatchesError) { + utility.Error("sorry we found more than one subnet with that name in your account") + os.Exit(1) + } + } + subnetsList = append(subnetsList, utility.ObjecteList{ID: subnet.ID, Name: subnet.Name}) + } else { + for _, v := range args { + subnet, err := client.FindSubnet(v, args[1]) + if err == nil { + subnetsList = append(subnetsList, utility.ObjecteList{ID: subnet.ID, Name: subnet.Name}) + } + } + } + + subnetNameList := []string{} + for _, v := range subnetsList { + subnetNameList = append(subnetNameList, v.Name) + } + + if utility.UserConfirmedDeletion(pluralize.Pluralize(len(subnetNameList), "Subnet"), common.DefaultYes, strings.Join(subnetNameList, ", ")) { + + for _, v := range subnetsList { + subnet, err := client.FindSubnet(v.ID, args[1]) + if err != nil { + utility.Error("%s", err) + os.Exit(1) + } + _, err = client.DeleteSubnet(args[1], subnet.ID) + if err != nil { + utility.Error("Error deleting the Subnet: %s", err) + os.Exit(1) + } + } + + ow := utility.NewOutputWriter() + + for _, v := range subnetsList { + ow.StartLine() + ow.AppendDataWithLabel("id", v.ID, "ID") + ow.AppendDataWithLabel("subnet", v.Name, "Subnet") + } + + switch common.OutputFormat { + case "json": + if len(subnetsList) == 1 { + ow.WriteSingleObjectJSON(common.PrettySet) + } else { + ow.WriteMultipleObjectsJSON(common.PrettySet) + } + case "custom": + ow.WriteCustomOutput(common.OutputFields) + default: + fmt.Printf("The %s (%s) has been deleted\n", pluralize.Pluralize(len(subnetsList), "subnet"), utility.Green(strings.Join(subnetNameList, ", "))) + } + } else { + fmt.Println("Operation aborted") + } + }, +} diff --git a/cmd/network/network_subnet_show.go b/cmd/network/network_subnet_show.go new file mode 100644 index 00000000..4fda4b14 --- /dev/null +++ b/cmd/network/network_subnet_show.go @@ -0,0 +1,58 @@ +package network + +import ( + "fmt" + "os" + + "github.com/civo/cli/common" + "github.com/civo/cli/config" + "github.com/civo/cli/utility" + "github.com/spf13/cobra" +) + +var networkSubnetShowCmd = &cobra.Command{ + Use: "show", + Aliases: []string{"get", "info"}, + Example: `civo network subnet show SUBNET_NAME NETWORK_ID`, + Short: "Prints information about a subnet", + Args: cobra.MinimumNArgs(2), + Run: func(cmd *cobra.Command, args []string) { + utility.EnsureCurrentRegion() + + client, err := config.CivoAPIClient() + if err != nil { + utility.Error("Creating the connection to Civo's API failed with %s", err) + os.Exit(1) + } + + if common.RegionSet != "" { + client.Region = common.RegionSet + } + + subnet, err := client.FindSubnet(args[0], args[1]) + if err != nil { + utility.Error("%s", err) + os.Exit(1) + } + + ow := utility.NewOutputWriter() + + ow.StartLine() + fmt.Println() + ow.AppendDataWithLabel("id", subnet.ID, "ID") + ow.AppendDataWithLabel("name", subnet.Name, "Name") + ow.AppendDataWithLabel("size", subnet.SubnetSize, "Subnet Size") + ow.AppendDataWithLabel("network_id", subnet.NetworkID, "Network ID") + ow.AppendDataWithLabel("region", client.Region, "Region") + ow.AppendDataWithLabel("status", subnet.Status, "Status") + + switch common.OutputFormat { + case "json": + ow.WriteMultipleObjectsJSON(common.PrettySet) + case "custom": + ow.WriteCustomOutput(common.OutputFields) + default: + ow.WriteKeyValues() + } + }, +} diff --git a/go.mod b/go.mod index 8e069a16..928c5d7e 100644 --- a/go.mod +++ b/go.mod @@ -9,11 +9,11 @@ require ( github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8 // indirect github.com/briandowns/spinner v1.11.1 github.com/c4milo/unpackit v0.0.0-20170704181138-4ed373e9ef1c // indirect - github.com/civo/civogo v0.3.13 + github.com/civo/civogo v0.3.17 github.com/dsnet/compress v0.0.1 // indirect github.com/fatih/color v1.13.0 // indirect github.com/google/go-github v17.0.0+incompatible - github.com/google/go-querystring v1.0.0 // indirect + github.com/google/go-querystring v1.1.0 // indirect github.com/google/uuid v1.2.0 github.com/gookit/color v1.3.8 github.com/gosuri/uilive v0.0.4 // indirect @@ -50,11 +50,11 @@ require ( github.com/klauspost/cpuid v1.2.0 // indirect github.com/kyokomi/emoji v2.1.0+incompatible // indirect github.com/lucasb-eyer/go-colorful v1.0.3 // indirect - github.com/mattn/go-isatty v0.0.14 // indirect + github.com/mattn/go-isatty v0.0.16 // indirect github.com/mattn/go-runewidth v0.0.8 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/spf13/pflag v1.0.5 // indirect golang.org/x/image v0.0.0-20191206065243-da761ea9ff43 // indirect - golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect - golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect + golang.org/x/net v0.0.0-20221002022538-bcab6841153b // indirect + golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect ) diff --git a/go.sum b/go.sum index d93249a0..d501d57c 100644 --- a/go.sum +++ b/go.sum @@ -55,8 +55,8 @@ github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghf github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= -github.com/civo/civogo v0.3.13 h1:CtZIaXHPN7IUXKgCwSQMiLw42+HV9lRN8EB8NZjaneE= -github.com/civo/civogo v0.3.13/go.mod h1:7+GeeFwc4AYTULaEshpT2vIcl3Qq8HPoxA17viX3l6g= +github.com/civo/civogo v0.3.17 h1:8B8rsQ1K+pkOp25U2UTSRi1GFqrJc/BYmMzG7S4Ocwc= +github.com/civo/civogo v0.3.17/go.mod h1:SbS06e0JPgIF27r1sLC97gjU1xWmONQeHgzF1hfLpak= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= @@ -119,11 +119,13 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY= github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= -github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= -github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= +github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= +github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= @@ -216,8 +218,9 @@ github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.8 h1:3tS41NlGYSmhhe/8fhGRzc+z3AYCw1Fe1WAyLuujKs0= github.com/mattn/go-runewidth v0.0.8/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= @@ -382,8 +385,9 @@ golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= -golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc= golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.0.0-20221002022538-bcab6841153b h1:6e93nYa3hNqAvLr0pD4PN1fFS+gKzp2zAXqrnTCstqU= +golang.org/x/net v0.0.0-20221002022538-bcab6841153b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -425,8 +429,10 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY= diff --git a/utility/truncate_id.go b/utility/truncate_id.go new file mode 100644 index 00000000..9a13b110 --- /dev/null +++ b/utility/truncate_id.go @@ -0,0 +1,9 @@ +package utility + +// TruncateID is a function to truncate the ID +func TruncateID(id string) string { + if len(id) > 6 { + return id[:6] + } + return id +}