@@ -25,6 +25,7 @@ import (
2525 "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/store"
2626 "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/usage"
2727 "github.com/spf13/cobra"
28+ atlasv2 "go.mongodb.org/atlas-sdk/v20241113002/admin"
2829)
2930
3031type DescribeOpts struct {
@@ -47,23 +48,44 @@ var restoreDescribeTemplate = `ID SNAPSHOT CLUSTER TYPE EXPIRES AT URLs
4748{{.Id}} {{.SnapshotId}} {{.TargetClusterName}} {{.DeliveryType}} {{.ExpiresAt}} {{range $index, $element := valueOrEmptySlice .DeliveryUrl}}{{if $index}}; {{end}}{{$element}}{{end}}
4849`
4950
51+ var restoreDescribeFlexClusterTemplate = `ID SNAPSHOT CLUSTER TYPE EXPIRES AT URLs
52+ {{.Id}} {{.SnapshotId}} {{.TargetDeploymentItemName}} {{.DeliveryType}} {{.ExpirationDate}} {{range $index, $element := valueOrEmptySlice .SnapshotUrl}}{{if $index}}; {{end}}{{$element}}{{end}}
53+ `
54+
5055func (opts * DescribeOpts ) Run () error {
51- r , err := opts .store .RestoreJob (opts .ConfigProjectID (), opts .clusterName , opts .id )
56+ r , err := opts .store .RestoreFlexClusterJob (opts .ConfigProjectID (), opts .clusterName , opts .id )
57+ if err == nil {
58+ opts .Template = restoreDescribeFlexClusterTemplate
59+ return opts .Print (r )
60+ }
61+
62+ apiError , ok := atlasv2 .AsError (err )
63+ if ! ok {
64+ return err
65+ }
66+
67+ if apiError .ErrorCode != cannotUseNotFlexWithFlexApisErrorCode {
68+ return err
69+ }
70+
71+ restoreJob , err := opts .store .RestoreJob (opts .ConfigProjectID (), opts .clusterName , opts .id )
5272 if err != nil {
5373 return err
5474 }
5575
56- return opts .Print (r )
76+ return opts .Print (restoreJob )
5777}
5878
79+ // DescribeBuilder builds a cobra.Command that can run as:
5980// atlas backup(s) restore(s) job(s) describe <ID>.
6081func DescribeBuilder () * cobra.Command {
6182 opts := new (DescribeOpts )
6283 cmd := & cobra.Command {
63- Use : "describe <restoreJobId>" ,
64- Short : "Describe a cloud backup restore job." ,
65- Long : fmt .Sprintf (usage .RequiredRole , "Project Owner" ),
66- Args : require .ExactArgs (1 ),
84+ Use : "describe <restoreJobId>" ,
85+ Aliases : []string {"get" },
86+ Short : "Describe a cloud backup restore job." ,
87+ Long : fmt .Sprintf (usage .RequiredRole , "Project Owner" ),
88+ Args : require .ExactArgs (1 ),
6789 Annotations : map [string ]string {
6890 "restoreJobIdDesc" : "ID of the restore job." ,
6991 },
0 commit comments