-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathfleet_configuration_get.go
More file actions
65 lines (57 loc) · 2.03 KB
/
fleet_configuration_get.go
File metadata and controls
65 lines (57 loc) · 2.03 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
package fleetcontrol
import (
"fmt"
"github.com/spf13/cobra"
"github.com/newrelic/newrelic-cli/internal/client"
)
// handleFleetGetConfiguration implements the 'get-configuration' command to retrieve a fleet configuration.
//
// This command retrieves a fleet configuration or a specific version of a configuration.
// You can:
// - Get the latest version of a configuration
// - Get a specific version by number
// - Get a configuration version by its entity GUID
//
// The command:
// 1. Validates flag values (done automatically by framework via YAML rules)
// 2. Maps the validated mode string to the client library type
// 3. Derives organization ID if not provided
// 4. Calls the New Relic API to retrieve the configuration
//
// Parameters:
// - cmd: The cobra command being executed
// - args: Command arguments (not used)
// - flags: Validated flag values from YAML configuration
//
// Returns:
// - Error if configuration retrieval fails, nil on success
func handleFleetGetConfiguration(cmd *cobra.Command, args []string, flags *FlagValues) error {
// Get typed flag values - no hardcoded strings!
f := flags.GetConfiguration()
// Get organization ID (provided or fetched from API)
orgID, err := GetOrganizationID(f.OrganizationID)
if err != nil {
return PrintError(fmt.Errorf("failed to determine organization ID: %w", err))
}
// Map validated mode to client library type
// YAML validation has already confirmed this value is in allowed_values
mode, err := MapConfigurationMode(f.Mode)
if err != nil {
return PrintError(err)
}
// Call New Relic API to get the configuration
result, err := client.NRClient.FleetControl.FleetControlGetConfiguration(
f.ConfigurationID,
orgID,
mode,
f.Version,
)
if err != nil {
return PrintError(fmt.Errorf("failed to get configuration: %w", err))
}
// Print the raw configuration directly to stdout
// Bypass the output formatter entirely since this is raw YAML content
// that should be displayed exactly as returned by the API
fmt.Print(string(*result))
return nil
}