Skip to content

Commit

Permalink
Merge branch 'digitalocean:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
titanventura authored Oct 14, 2023
2 parents 9934792 + 07dabc1 commit 3f0c3de
Show file tree
Hide file tree
Showing 241 changed files with 21,669 additions and 5,130 deletions.
17 changes: 17 additions & 0 deletions args.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,23 @@ const (
// ArgUptimeCheckEnabled is whether or not an uptime check is enabled.
ArgUptimeCheckEnabled = "enabled"

// ArgUptimeAlertName is the name of an uptime alert.
ArgUptimeAlertName = "name"
// ArgUptimeAlertType is the type of an uptime alert.
ArgUptimeAlertType = "type"
// ArgUptimeAlertThreshold the threshold at which an uptime alert will trigger.
ArgUptimeAlertThreshold = "threshold"
// ArgUptimeAlertComparison is the uptime alert comparator.
ArgUptimeAlertComparison = "comparison"
// ArgUptimeAlertEmails are the emails to send uptime alerts to.
ArgUptimeAlertEmails = "emails"
// ArgUptimeAlertSlackChannels are the Slack channels to send uptime alerts to.
ArgUptimeAlertSlackChannels = "slack-channels"
// ArgUptimeAlertSlackURLs are the Slack URLs to send uptime alerts to.
ArgUptimeAlertSlackURLs = "slack-urls"
// ArgUptimeAlertPeriod is the time threshold at which an uptime alert will trigger.
ArgUptimeAlertPeriod = "period"

// ArgVolumeSize is the size of a volume.
ArgVolumeSize = "size"
// ArgVolumeDesc is the description of a volume.
Expand Down
78 changes: 78 additions & 0 deletions commands/displayers/uptime_alert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
Copyright 2023 The Doctl Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package displayers

import (
"io"
"strings"

"github.com/digitalocean/doctl/do"
)

type UptimeAlert struct {
UptimeAlerts []do.UptimeAlert
}

func (uc *UptimeAlert) JSON(out io.Writer) error {
return writeJSON(uc.UptimeAlerts, out)
}

func (uc *UptimeAlert) Cols() []string {
return []string{
"ID", "Name", "Type", "Threshold", "Comparison", "Period", "Emails", "Slack Channels",
}
}

func (ua *UptimeAlert) ColMap() map[string]string {
return map[string]string{
"ID": "ID",
"Name": "Name",
"Type": "Type",
"Threshold": "Threshold",
"Comparison": "Comparison",
"Period": "Period",
"Emails": "Emails",
"Slack Channels": "Slack Channels",
}
}

func (ua *UptimeAlert) KV() []map[string]interface{} {
out := make([]map[string]interface{}, 0, len(ua.UptimeAlerts))
for _, uptimeAlert := range ua.UptimeAlerts {
emails := ""
if uptimeAlert.Notifications.Email != nil {
emails = strings.Join(uptimeAlert.Notifications.Email, ",")
}
slackChannels := make([]string, 0)
if uptimeAlert.Notifications.Slack != nil {
for _, v := range uptimeAlert.Notifications.Slack {
slackChannels = append(slackChannels, v.Channel)
}
}
slacks := strings.Join(slackChannels, ",")

m := map[string]interface{}{
"ID": uptimeAlert.ID,
"Name": uptimeAlert.Name,
"Type": uptimeAlert.Type,
"Threshold": uptimeAlert.Threshold,
"Comparison": uptimeAlert.Comparison,
"Period": uptimeAlert.Period,
"Emails": emails,
"Slack Channels": slacks,
}
out = append(out, m)
}
return out
}
2 changes: 1 addition & 1 deletion commands/firewalls.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Inbound access rules specify the protocol (TCP, UDP, or ICMP), ports, and source

CmdBuilder(cmd, RunFirewallListByDroplet, "list-by-droplet <droplet_id>", "List firewalls by Droplet", `Use this command to list cloud firewalls by the ID of a Droplet assigned to the firewall.`, Writer, displayerType(&displayers.Firewall{}))

cmdRunRecordDelete := CmdBuilder(cmd, RunFirewallDelete, "delete <id>...", "Permanently delete a cloud firewall", `Use this command to permanently delete a cloud firewall. This is irreversable, but does not delete any Droplets assigned to the cloud firewall.`, Writer, aliasOpt("d", "rm"))
cmdRunRecordDelete := CmdBuilder(cmd, RunFirewallDelete, "delete <id>...", "Permanently delete a cloud firewall", `Use this command to permanently delete a cloud firewall. This is irreversible, but does not delete any Droplets assigned to the cloud firewall.`, Writer, aliasOpt("d", "rm"))
AddBoolFlag(cmdRunRecordDelete, doctl.ArgForce, doctl.ArgShortForce, false, "Delete firewall without confirmation prompt")

cmdAddDroplets := CmdBuilder(cmd, RunFirewallAddDroplets, "add-droplets <id>", "Add Droplets to a cloud firewall", `Use this command to add Droplets to the cloud firewall.`, Writer)
Expand Down
2 changes: 1 addition & 1 deletion commands/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ This command creates a new node pool for the specified cluster. At a minimum, yo

cmdKubeNodePoolDelete := CmdBuilder(cmd, k8sCmdService.RunKubernetesNodePoolDelete,
"delete <cluster-id|cluster-name> <pool-id|pool-name>",
"Delete a node pool", `This command deletes the specified node pool in the specified cluster, which also removes all the nodes inside that pool. This action is irreversable.`, Writer, aliasOpt("d", "rm"))
"Delete a node pool", `This command deletes the specified node pool in the specified cluster, which also removes all the nodes inside that pool. This action is irreversible.`, Writer, aliasOpt("d", "rm"))
AddBoolFlag(cmdKubeNodePoolDelete, doctl.ArgForce, doctl.ArgShortForce,
false, "Delete node pool without confirmation prompt")

Expand Down
2 changes: 1 addition & 1 deletion commands/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ A valid URN has the format: ` + "`" + `do:resource_type:resource_id` + "`" + `.
"List all of the resources assigned to the specified project displaying their uniform resource names (\"URNs\").",
Writer, aliasOpt("ls"), displayerType(&displayers.ProjectResource{}))
CmdBuilder(cmd, RunProjectResourcesGet, "get <urn>", "Retrieve a resource by its URN",
"Retrieve information about a resource by specifying its uniform resource name (\"URN\"). Currently, ony Droplets, floating IPs, load balancers, domains, volumes, and App Platform apps are supported."+urnDesc,
"Retrieve information about a resource by specifying its uniform resource name (\"URN\"). Currently, only Droplets, floating IPs, load balancers, domains, volumes, and App Platform apps are supported."+urnDesc,
Writer, aliasOpt("g"), displayerType(&displayers.ProjectResource{}))

cmdProjectResourcesAssign := CmdBuilder(cmd, RunProjectResourcesAssign,
Expand Down
10 changes: 5 additions & 5 deletions commands/serverless.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,17 +392,17 @@ func RunServerlessStatus(c *CmdConfig) error {
credentials, _ := c.Doit.GetBool(c.NS, "credentials")
if credentials {
type showCreds struct {
Auth string `json:auth`
APIHost string `json:apihost`
Namespace string `json:namespace`
Path string `json:path`
Auth string `json:"auth"`
APIHost string `json:"apihost"`
Namespace string `json:"namespace"`
Path string `json:"path"`
}
toShow := showCreds{Auth: auth, APIHost: creds.APIHost, Namespace: creds.Namespace, Path: sls.CredentialsPath()}
credsOutput, err := json.MarshalIndent(toShow, "", " ")
if err != nil {
return err
}
fmt.Println(string(credsOutput))
fmt.Fprintln(c.Out, string(credsOutput))
return nil
}

Expand Down
27 changes: 27 additions & 0 deletions commands/serverless_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,33 @@ func TestServerlessStatusWhenConnected(t *testing.T) {
})
}

func TestServerlessStatusDisplayCredentials(t *testing.T) {
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
buf := &bytes.Buffer{}
config.Out = buf
config.Doit.Set(config.NS, "credentials", true)

tm.serverless.EXPECT().CheckServerlessStatus().MinTimes(1).Return(nil)
tm.serverless.EXPECT().ReadCredentials().Return(do.ServerlessCredentials{
APIHost: "https://api.example.com",
Namespace: "hello",
Credentials: map[string]map[string]do.ServerlessCredential{
"https://api.example.com": {
"hello": do.ServerlessCredential{
Auth: "here-are-some-credentials",
},
},
},
}, nil)
tm.serverless.EXPECT().GetNamespaceFromCluster("https://api.example.com", "here-are-some-credentials").Return("hello", nil)
tm.serverless.EXPECT().CredentialsPath().Return("/path")

err := RunServerlessStatus(config)
require.NoError(t, err)
assert.JSONEq(t, `{"apihost":"https://api.example.com","auth":"here-are-some-credentials","namespace":"hello","path":"/path"}`, buf.String())
})
}

func TestServerlessStatusWithLanguages(t *testing.T) {
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
buf := &bytes.Buffer{}
Expand Down
Loading

0 comments on commit 3f0c3de

Please sign in to comment.