Skip to content

Commit 2e85f59

Browse files
authored
feat(mongodb): fetch latest engine version (scaleway#2475)
1 parent 4b6fcfb commit 2e85f59

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

api/mongodb/v1alpha1/mongodb_utils.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package mongodb
22

33
import (
4+
"context"
5+
"fmt"
6+
"sort"
47
"time"
58

69
"github.com/scaleway/scaleway-sdk-go/errors"
@@ -109,3 +112,20 @@ func (s *API) WaitForSnapshot(req *WaitForSnapshotRequest, opts ...scw.RequestOp
109112
}
110113
return snapshot.(*Snapshot), nil
111114
}
115+
116+
func (s *API) FetchLatestEngineVersion() (*Version, error) {
117+
resp, err := s.ListVersions(&ListVersionsRequest{}, scw.WithContext(context.Background()))
118+
if err != nil {
119+
return nil, fmt.Errorf("error fetching MongoDB versions: %w", err)
120+
}
121+
122+
if len(resp.Versions) == 0 {
123+
return nil, errors.New("no MongoDB versions found")
124+
}
125+
126+
sort.Slice(resp.Versions, func(i, j int) bool {
127+
return resp.Versions[i].Version > resp.Versions[j].Version
128+
})
129+
130+
return resp.Versions[0], nil
131+
}

0 commit comments

Comments
 (0)