From 520fa31dea856a4b340a208dde0c0d53458e7ce7 Mon Sep 17 00:00:00 2001 From: "Jonathan R." Date: Thu, 12 Dec 2024 16:12:52 +0100 Subject: [PATCH] feat(rdb): fetch latest engine version from API (#2317) --- api/rdb/v1/rdb_utils.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/api/rdb/v1/rdb_utils.go b/api/rdb/v1/rdb_utils.go index 77338451a..77c08c8f2 100644 --- a/api/rdb/v1/rdb_utils.go +++ b/api/rdb/v1/rdb_utils.go @@ -1,6 +1,7 @@ package rdb import ( + "fmt" "time" "github.com/scaleway/scaleway-sdk-go/errors" @@ -199,3 +200,25 @@ func (s *API) WaitForReadReplica(req *WaitForReadReplicaRequest, opts ...scw.Req } return readReplica.(*ReadReplica), nil } + +func (s *API) FetchLatestEngineVersion(engineName string) (*EngineVersion, error) { + engines, err := s.ListDatabaseEngines(&ListDatabaseEnginesRequest{}) + if err != nil { + return nil, err + } + + var latestEngineVersion *EngineVersion + for _, engine := range engines.Engines { + if engine.Name == engineName { + if len(engine.Versions) > 0 { + latestEngineVersion = engine.Versions[0] + break + } + } + } + + if latestEngineVersion == nil { + return nil, fmt.Errorf("no versions found for engine: %s", engineName) + } + return latestEngineVersion, nil +}