Skip to content

Commit

Permalink
Merge branch 'main' into olove/enable-control-plane-firewall-pointer-…
Browse files Browse the repository at this point in the history
…arguments
  • Loading branch information
llDrLove committed Jul 18, 2024
2 parents 6098926 + 8615667 commit 582d3f8
Show file tree
Hide file tree
Showing 92 changed files with 9,439 additions and 4,459 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ jobs:
go-version: 1.21.x

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: latest
version: "~> v2"
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/typos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Check spelling

on:
push:
branches: [ main ]
pull_request:
branches:
- main
- feature/**

jobs:
run:
name: Spell Check with Typos
runs-on: ubuntu-latest
steps:
- name: Checkout Actions Repository
uses: actions/checkout@v4

- name: Check spelling
uses: crate-ci/[email protected]

4 changes: 2 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
project_name: doctl

version: 2
builds:
- main: ./cmd/doctl/main.go
env:
Expand Down Expand Up @@ -50,4 +50,4 @@ release:
name: doctl

changelog:
skip: false
disable: false
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ or `make help` for a list of available commands with descriptions.
- Avoid the passive voice ("When a tag is provided, access is granted") and use the active voice ("Entering a tag provides access")
- Be helpful when users have to enter a input that is from a list of possible values. Give examples, list the possible values inline (if the list is relatively short), or point them to a command that can list the possible values for them.

## Spell Check

`doctl` is setup to use the code aware spell checker called [typos](https://github.com/crate-ci/typos) to keep an eye on any spelling mistakes.

To install your own copy,follow the instructions on the [typos readme](https://github.com/crate-ci/typos?tab=readme-ov-file#install), and then run the `typos` binary

### Go environment

Expand Down
16 changes: 16 additions & 0 deletions _typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[files]
extend-exclude = [
"vendor/**",
"go.mod"
]

[default.extend-identifiers]
vas = "vas"
splitted = "splitted"

[default.extend-words]
# Its not perfect at hashes yet
cace = "cace"
Wqs = "Wqs"
# example and exmaple as two domain examples
exmaple = "exmaple"
4 changes: 2 additions & 2 deletions args.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,8 @@ const (
ArgDatabaseTopicMaxCompactionLagMS = "max-compaction-lag-ms"
// ArgDatabaseTopicMaxMessageBytes is the maximum size, in bytes, of the largest record batch that can be sent to the server
ArgDatabaseTopicMaxMessageBytes = "max-message-bytes"
// ArgDatabaseTopicMesssageDownConversionEnable determines whether brokers should convert messages for consumers expecting older message formats
ArgDatabaseTopicMesssageDownConversionEnable = "message-down-conversion-enable"
// ArgDatabaseTopicMessageDownConversionEnable determines whether brokers should convert messages for consumers expecting older message formats
ArgDatabaseTopicMessageDownConversionEnable = "message-down-conversion-enable"
// ArgDatabaseTopicMessageFormatVersion is the version used by the broker to append messages to the kafka topic logs
ArgDatabaseTopicMessageFormatVersion = "message-format-version"
// ArgDatabaseTopicMessageTimestampType is the timestamp used for messages
Expand Down
35 changes: 33 additions & 2 deletions commands/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ limitations under the License.
package commands

import (
"encoding/json"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -218,11 +219,16 @@ func RunAuthList(c *CmdConfig) error {
}
contexts := viper.GetStringMap("auth-contexts")

displayAuthContexts(c.Out, context, contexts)
if viper.GetString("output") == "json" {
displayAuthContextsJSON(c.Out, context, contexts)
} else {
displayAuthContexts(c.Out, context, contexts)
}

return nil
}

func displayAuthContexts(out io.Writer, currentContext string, contexts map[string]any) {
func ensureDefaultContextAndKeysOrder(contexts map[string]any) []string {
// Because the default context isn't present on the auth-contexts field,
// we add it manually so that it's always included in the output, and so
// we can check if it's the current context.
Expand All @@ -236,6 +242,31 @@ func displayAuthContexts(out io.Writer, currentContext string, contexts map[stri
}
sort.Strings(keys)

return keys
}

func displayAuthContextsJSON(out io.Writer, currentContext string, contexts map[string]any) {
type contextJSON struct {
Name string `json:"name"`
Current bool `json:"current"`
}

var contextsJSON []contextJSON

keys := ensureDefaultContextAndKeysOrder(contexts)
for _, ctx := range keys {
contextsJSON = append(contextsJSON, contextJSON{
Name: ctx,
Current: ctx == currentContext,
})
}

jsonData, _ := json.MarshalIndent(contextsJSON, "", " ")
fmt.Fprintln(out, string(jsonData))
}

func displayAuthContexts(out io.Writer, currentContext string, contexts map[string]any) {
keys := ensureDefaultContextAndKeysOrder(contexts)
for _, ctx := range keys {
if ctx == currentContext {
fmt.Fprintln(out, ctx, "(current)")
Expand Down
67 changes: 62 additions & 5 deletions commands/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,12 @@ func TestAuthList(t *testing.T) {

func Test_displayAuthContexts(t *testing.T) {
testCases := []struct {
Name string
Out *bytes.Buffer
Context string
Contexts map[string]any
Expected string
Name string
Out *bytes.Buffer
Context string
Contexts map[string]any
Expected string
ExpectedJSON string
}{
{
Name: "default context only",
Expand Down Expand Up @@ -227,6 +228,62 @@ func Test_displayAuthContexts(t *testing.T) {
}
}

func Test_displayAuthContextsJSON(t *testing.T) {
testCases := []struct {
Name string
Out *bytes.Buffer
Context string
Contexts map[string]any
ExpectedJSON string
}{
{
Name: "default context only",
Out: &bytes.Buffer{},
Context: doctl.ArgDefaultContext,
Contexts: map[string]any{
doctl.ArgDefaultContext: true,
},
ExpectedJSON: "[\n {\n \"name\": \"default\",\n \"current\": true\n }\n]\n",
},
{
Name: "default context and additional context",
Out: &bytes.Buffer{},
Context: doctl.ArgDefaultContext,
Contexts: map[string]any{
doctl.ArgDefaultContext: true,
"test": true,
},
ExpectedJSON: "[\n {\n \"name\": \"default\",\n \"current\": true\n },\n {\n \"name\": \"test\",\n \"current\": false\n }\n]\n",
},
{
Name: "default context and additional context set to additional context",
Out: &bytes.Buffer{},
Context: "test",
Contexts: map[string]any{
doctl.ArgDefaultContext: true,
"test": true,
},
ExpectedJSON: "[\n {\n \"name\": \"default\",\n \"current\": false\n },\n {\n \"name\": \"test\",\n \"current\": true\n }\n]\n",
},
{
Name: "unset context",
Out: &bytes.Buffer{},
Context: "missing",
Contexts: map[string]any{
doctl.ArgDefaultContext: true,
"test": true,
},
ExpectedJSON: "[\n {\n \"name\": \"default\",\n \"current\": false\n },\n {\n \"name\": \"test\",\n \"current\": false\n }\n]\n",
},
}

for _, tc := range testCases {
t.Run(tc.Name, func(t *testing.T) {
displayAuthContextsJSON(tc.Out, tc.Context, tc.Contexts)
assert.Equal(t, tc.ExpectedJSON, tc.Out.String())
})
}
}
func TestTokenInputValidator(t *testing.T) {
tests := []struct {
name string
Expand Down
2 changes: 1 addition & 1 deletion commands/command_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func (c *CmdConfig) Display(d displayers.Displayable) error {
return dc.Display()
}

// An urner implements the URN method, wihich returns a valid uniform resource
// An urner implements the URN method, which returns a valid uniform resource
// name.
type urner interface {
URN() string
Expand Down
4 changes: 2 additions & 2 deletions commands/databases.go
Original file line number Diff line number Diff line change
Expand Up @@ -1791,7 +1791,7 @@ func getDatabaseTopicConfigArgs(c *CmdConfig) *godo.TopicConfig {
res.MaxMessageBytes = &i
}
}
bVal, err := c.Doit.GetBoolPtr(c.NS, doctl.ArgDatabaseTopicMesssageDownConversionEnable)
bVal, err := c.Doit.GetBoolPtr(c.NS, doctl.ArgDatabaseTopicMessageDownConversionEnable)
if err == nil && bVal != nil {
res.MessageDownConversionEnable = bVal
}
Expand Down Expand Up @@ -1936,7 +1936,7 @@ This command lists the following details for each partition of a given topic in
"Specifies the maximum time (in ms) that a message will remain uncompacted. This is only applicable if the logs have compaction enabled")
AddStringFlag(c, doctl.ArgDatabaseTopicMaxMessageBytes, "", "",
"Specifies the largest record batch (in bytes) that can be sent to the server. This is calculated after compression, if compression is enabled")
AddBoolFlag(c, doctl.ArgDatabaseTopicMesssageDownConversionEnable, "", true,
AddBoolFlag(c, doctl.ArgDatabaseTopicMessageDownConversionEnable, "", true,
"Specifies whether down-conversion of message formats is enabled to satisfy consumer requests")
AddStringFlag(c, doctl.ArgDatabaseTopicMessageFormatVersion, "", "",
"Specifies the message format version used by the broker to append messages to the logs. By setting a format version, all existing messages on disk must be smaller or equal to the specified version")
Expand Down
4 changes: 2 additions & 2 deletions commands/firewalls.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Inbound access rules specify the protocol (TCP, UDP, or ICMP), ports, and source
- The inbound rules for the firewall
- The outbound rules for the firewall
- The IDs of Droplets assigned to the firewall
- The tags assigned to the firewall
- The tags of Droplets assigned to the firewall
`
inboundRulesTxt := `A comma-separated key-value list that defines an inbound rule. The rule must define a communication protocol, a port number, and a traffic source location, such as a Droplet ID, IP address, or a tag. For example, the following rule defines that resources can only receive TCP traffic on port 22 from addresses in the specified CIDR: ` + "`" + `protocol:tcp,ports:22,address:192.0.2.0/24` + "`" + `.
Expand All @@ -68,7 +68,7 @@ Available destination keys are: ` + "`" + `address` + "`" + `, ` + "`" + `drople
Use a quoted string of space-separated values for multiple rules.`
dropletIDRulesTxt := "A comma-separated list of Droplet IDs to place behind the cloud firewall, for example: `386734086,391669331`"
tagNameRulesTxt := "A comma-separated list of tag names to apply to the cloud firewall, for example: `frontend,backend`"
tagNameRulesTxt := "A comma-separated list of existing tags, for example: `frontend,backend`. Droplets with these tags will be placed behind the cloud firewall"

cmdFirewallGet := CmdBuilder(cmd, RunFirewallGet, "get <id>", "Retrieve information about a cloud firewall", `Retrieves information about an existing cloud firewall, including:`+fwDetail, Writer, aliasOpt("g"), displayerType(&displayers.Firewall{}))
cmdFirewallGet.Example = `The following example retrieves information about the cloud firewall with the ID ` + "`" + `f81d4fae-7dec-11d0-a765-00a0c91e6bf6` + "`" + `: doctl compute firewall get f81d4fae-7dec-11d0-a765-00a0c91e6bf6`
Expand Down
3 changes: 2 additions & 1 deletion commands/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ import (
"strings"

"github.com/apache/openwhisk-client-go/whisk"
"github.com/spf13/cobra"

"github.com/digitalocean/doctl"
"github.com/digitalocean/doctl/commands/charm/template"
"github.com/digitalocean/doctl/commands/displayers"
"github.com/digitalocean/doctl/do"
"github.com/spf13/cobra"
)

// Functions generates the serverless 'functions' subtree for addition to the doctl command
Expand Down
2 changes: 1 addition & 1 deletion commands/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ func kubernetesOneClicks() *Command {
cmdKubernetesOneClickList.Example = `The following example lists all available 1-click apps for Kubernetes: doctl kubernetes 1-click list`
cmdKubeOneClickInstall := CmdBuilder(cmd, RunKubernetesOneClickInstall, "install <cluster-id>", "Install 1-click apps on a Kubernetes cluster", "Installs 1-click applications on a Kubernetes cluster. Use the `--1-click` flag to specify one or multiple pieces of software to install on the cluster.", Writer, aliasOpt("in"), displayerType(&displayers.OneClick{}))
AddStringSliceFlag(cmdKubeOneClickInstall, doctl.ArgOneClicks, "", nil, "The 1-clicks application to install on the cluster. Multiple 1-clicks can be added simultaneously, for example: `--1-clicks moon,loki,netdata`")
cmdKubeOneClickInstall.Example = `The following example installs Loki and Netdata on a Kubernetes cluster with the ID ` + "`" + `f81d4fae-7dec-11d0-a765-00a0c91e6bf6` + "`" + `: doctl kubernetes 1-click install f81d4fae-7dec-11d0-a765-00a0c91e6bf6> --1-clicks loki,netdata`
cmdKubeOneClickInstall.Example = `The following example installs Loki and Netdata on a Kubernetes cluster with the ID ` + "`" + `f81d4fae-7dec-11d0-a765-00a0c91e6bf6` + "`" + `: doctl kubernetes 1-click install f81d4fae-7dec-11d0-a765-00a0c91e6bf6 --1-clicks loki,netdata`

return cmd
}
Expand Down
2 changes: 1 addition & 1 deletion commands/serverless_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ func TestServerlessInit(t *testing.T) {
}

sawOverwrite := false
// Grab the overrideable commands so they can be mocked
// Grab the overridable commands so they can be mocked
writeAFile = func(path string, contents []byte) error {
return nil
}
Expand Down
1 change: 0 additions & 1 deletion commands/vpc_peerings.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func VPCPeerings() *Command {
Short: "Display commands that manage VPC Peerings",
Long: `The commands under ` + "`" + `doctl vpcs peerings` + "`" + ` are for managing your VPC Peerings.
With the VPC Peerings commands, you can get, list, create, update, or delete VPC Peerings, and manage their configuration details.`,
Hidden: true,
},
}

Expand Down
2 changes: 1 addition & 1 deletion do/serverless.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type OutputNamespace struct {
}

// FunctionParameter is the type of a parameter in the response body of action.get. We do our
// own JSON unmarshaling of these because the go OpenWhisk client doesn't include the "init" and
// own JSON unmarshalling of these because the go OpenWhisk client doesn't include the "init" and
// "encryption" members, of which at least "init" is needed.
type FunctionParameter struct {
Key string `json:"key"`
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ require (
github.com/docker/docker v24.0.9+incompatible
github.com/docker/docker-credential-helpers v0.7.0 // indirect
github.com/dustin/go-humanize v1.0.0
github.com/fatih/color v1.13.0
github.com/fatih/color v1.16.0
github.com/gobwas/glob v0.2.3
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.3.0
github.com/gorilla/websocket v1.5.0
github.com/hashicorp/go-multierror v1.1.1
github.com/imdario/mergo v0.3.13 // indirect
github.com/mattn/go-isatty v0.0.14
github.com/mattn/go-isatty v0.0.20
github.com/mitchellh/copystructure v1.0.0
github.com/natefinch/pie v0.0.0-20170715172608-9a0d72014007
github.com/opencontainers/image-spec v1.1.0-rc3
Expand All @@ -32,7 +32,7 @@ require (
golang.org/x/crypto v0.22.0
golang.org/x/net v0.24.0 // indirect
golang.org/x/oauth2 v0.19.0
golang.org/x/sys v0.19.0 // indirect
golang.org/x/sys v0.20.0 // indirect
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.26.2
k8s.io/apimachinery v0.26.2
Expand Down Expand Up @@ -77,15 +77,15 @@ require (
github.com/google/gofuzz v1.2.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.5 // indirect
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hokaccha/go-prettyjson v0.0.0-20210113012101-fb4e108d2519 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.2 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/mitchellh/reflectwalk v1.0.0 // indirect
Expand Down
Loading

0 comments on commit 582d3f8

Please sign in to comment.