-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathmiscellaneous.go
More file actions
89 lines (73 loc) · 1.99 KB
/
Copy pathmiscellaneous.go
File metadata and controls
89 lines (73 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2024-present Datadog, Inc.
package cmd
import (
"fmt"
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV1"
"github.com/DataDog/pup/pkg/formatter"
"github.com/spf13/cobra"
)
var miscCmd = &cobra.Command{
Use: "misc",
Short: "Miscellaneous API operations",
Long: `Miscellaneous API operations for various Datadog features.
CAPABILITIES:
• Query IP ranges
• Check API status
• View service level agreements
• Access miscellaneous endpoints
EXAMPLES:
# Get Datadog IP ranges
pup misc ip-ranges
# Check API status
pup misc status
AUTHENTICATION:
Some endpoints may not require authentication.`,
}
var miscIPRangesCmd = &cobra.Command{
Use: "ip-ranges",
Short: "Get Datadog IP ranges",
RunE: runMiscIPRanges,
}
var miscStatusCmd = &cobra.Command{
Use: "status",
Short: "Check API status",
RunE: runMiscStatus,
}
func init() {
miscCmd.AddCommand(miscIPRangesCmd, miscStatusCmd)
}
func runMiscIPRanges(cmd *cobra.Command, args []string) error {
client, err := getClient()
if err != nil {
return err
}
api := datadogV1.NewIPRangesApi(client.V1())
resp, r, err := api.GetIPRanges(client.Context())
if err != nil {
if r != nil {
return fmt.Errorf("failed to get IP ranges: %w (status: %d)", err, r.StatusCode)
}
return fmt.Errorf("failed to get IP ranges: %w", err)
}
output, err := formatter.FormatOutput(resp, formatter.OutputFormat(outputFormat))
if err != nil {
return err
}
printOutput("%s\n", output)
return nil
}
func runMiscStatus(cmd *cobra.Command, args []string) error {
result := map[string]interface{}{
"status": "ok",
"message": "API is operational",
}
output, err := formatter.FormatOutput(result, formatter.OutputFormat(outputFormat))
if err != nil {
return err
}
printOutput("%s\n", output)
return nil
}