Skip to content

Commit 8ca184d

Browse files
authored
feat(mongodb): add Get Snapshot Endpoint (scaleway#2262)
1 parent 2eefb48 commit 8ca184d

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

api/mongodb/v1alpha1/mongodb_sdk.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,15 @@ type GetInstanceRequest struct {
754754
InstanceID string `json:"-"`
755755
}
756756

757+
// GetSnapshotRequest: get snapshot request.
758+
type GetSnapshotRequest struct {
759+
// Region: region to target. If none is passed will use default region from the config.
760+
Region scw.Region `json:"-"`
761+
762+
// SnapshotID: UUID of the snapshot.
763+
SnapshotID string `json:"-"`
764+
}
765+
757766
// ListInstancesRequest: list instances request.
758767
type ListInstancesRequest struct {
759768
// Region: region to target. If none is passed will use default region from the config.
@@ -1441,6 +1450,37 @@ func (s *API) CreateSnapshot(req *CreateSnapshotRequest, opts ...scw.RequestOpti
14411450
return &resp, nil
14421451
}
14431452

1453+
// GetSnapshot: Retrieve information about a given snapshot of a Database Instance. You must specify, in the endpoint, the `snapshot_id` parameter of the snapshot you want to retrieve.
1454+
func (s *API) GetSnapshot(req *GetSnapshotRequest, opts ...scw.RequestOption) (*Snapshot, error) {
1455+
var err error
1456+
1457+
if req.Region == "" {
1458+
defaultRegion, _ := s.client.GetDefaultRegion()
1459+
req.Region = defaultRegion
1460+
}
1461+
1462+
if fmt.Sprint(req.Region) == "" {
1463+
return nil, errors.New("field Region cannot be empty in request")
1464+
}
1465+
1466+
if fmt.Sprint(req.SnapshotID) == "" {
1467+
return nil, errors.New("field SnapshotID cannot be empty in request")
1468+
}
1469+
1470+
scwReq := &scw.ScalewayRequest{
1471+
Method: "GET",
1472+
Path: "/mongodb/v1alpha1/regions/" + fmt.Sprint(req.Region) + "/snapshots/" + fmt.Sprint(req.SnapshotID) + "",
1473+
}
1474+
1475+
var resp Snapshot
1476+
1477+
err = s.client.Do(scwReq, &resp, opts...)
1478+
if err != nil {
1479+
return nil, err
1480+
}
1481+
return &resp, nil
1482+
}
1483+
14441484
// UpdateSnapshot:
14451485
func (s *API) UpdateSnapshot(req *UpdateSnapshotRequest, opts ...scw.RequestOption) (*Snapshot, error) {
14461486
var err error

0 commit comments

Comments
 (0)