-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathfleet_configuration_version_list.go
More file actions
57 lines (49 loc) · 1.91 KB
/
fleet_configuration_version_list.go
File metadata and controls
57 lines (49 loc) · 1.91 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
package fleetcontrol
import (
"fmt"
"github.com/spf13/cobra"
"github.com/newrelic/newrelic-cli/internal/client"
)
// handleFleetGetConfigurationVersions implements the 'get-versions' command to retrieve all versions of a fleet configuration.
//
// This command retrieves the complete version history for a fleet configuration,
// including version numbers, blob IDs, entity GUIDs, and timestamps.
//
// Use cases:
// - View all available versions of a configuration
// - Check version history and timestamps
// - Find specific version details for rollback or comparison
//
// The command:
// 1. Validates flag values (done automatically by framework via YAML rules)
// 2. Derives organization ID if not provided
// 3. Calls the New Relic API to retrieve all configuration versions
// 4. Returns a list of versions with their metadata
//
// Parameters:
// - cmd: The cobra command being executed
// - args: Command arguments (not used)
// - flags: Validated flag values from YAML configuration
//
// Returns:
// - Error if version retrieval fails, nil on success
func handleFleetGetConfigurationVersions(_ *cobra.Command, _ []string, flags *FlagValues) error {
// Get typed flag values - no hardcoded strings!
f := flags.GetVersions()
// Get organization ID (provided or fetched from API)
orgID := GetOrganizationID(f.OrganizationID)
// Call New Relic API to get all configuration versions
result, err := client.NRClient.FleetControl.FleetControlGetConfigurationVersions(
f.ConfigurationID,
orgID,
)
if err != nil {
return PrintError(fmt.Errorf("failed to get configuration versions: %w", err))
}
// Validate that versions were returned
if result == nil || len(result.Versions) == 0 {
return PrintError(fmt.Errorf("no version details found, please check the GUID of the configuration entity provided"))
}
// Print the versions list to stdout with status wrapper
return PrintConfigurationSuccess(result)
}