Skip to content

Commit

Permalink
instanceconfigapi: Implement additional parameters.
Browse files Browse the repository at this point in the history
Adds support for new parameters 'show_deleted', 'show_max_zones' and 'config_version'.
  • Loading branch information
gigerdo committed May 8, 2024
1 parent 0cc4c74 commit 586a2e1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 11 deletions.
23 changes: 18 additions & 5 deletions pkg/api/platformapi/instanceconfigapi/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ import (
// GetParams is used to obtain an instance configuration from an ID.
type GetParams struct {
*api.API
ID string
Region string
ID string
Region string
ShowDeleted bool
ShowMaxZones bool
ConfigVersion *int64
}

// Validate ensures that the parameters are correct.
Expand All @@ -60,10 +63,20 @@ func Get(params GetParams) (*models.InstanceConfiguration, error) {
return nil, err
}

requestParams := platform_configuration_instances.NewGetInstanceConfigurationParams().
WithContext(api.WithRegion(context.Background(), params.Region)).
WithID(params.ID).
WithConfigVersion(params.ConfigVersion)

if params.ShowDeleted {
requestParams = requestParams.WithShowDeleted(ec.Bool(true))
}
if params.ShowMaxZones {
requestParams = requestParams.WithShowMaxZones(ec.Bool(true))
}

res, err := params.API.V1API.PlatformConfigurationInstances.GetInstanceConfiguration(
platform_configuration_instances.NewGetInstanceConfigurationParams().
WithContext(api.WithRegion(context.Background(), params.Region)).
WithID(params.ID),
requestParams,
params.AuthWriter,
)

Expand Down
13 changes: 11 additions & 2 deletions pkg/api/platformapi/instanceconfigapi/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package instanceconfigapi
import (
"errors"
"net/http"
"net/url"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -45,8 +46,11 @@ func TestGet(t *testing.T) {
{
name: "Get succeeds",
args: args{params: GetParams{
Region: "us-east-1",
ID: "data.highstorage",
Region: "us-east-1",
ID: "data.highstorage",
ShowDeleted: true,
ShowMaxZones: true,
ConfigVersion: ec.Int64(3),
API: api.NewMock(mock.Response{
Response: http.Response{
Body: mock.NewStringBody(getInstanceConfigsSuccess),
Expand All @@ -57,6 +61,11 @@ func TestGet(t *testing.T) {
Method: "GET",
Host: api.DefaultMockHost,
Path: "/api/v1/regions/us-east-1/platform/configuration/instances/data.highstorage",
Query: url.Values{
"show_deleted": []string{"true"},
"show_max_zones": []string{"true"},
"config_version": []string{"3"},
},
},
}),
}},
Expand Down
21 changes: 18 additions & 3 deletions pkg/api/platformapi/instanceconfigapi/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ import (
// ListParams is used to list all of the available instance configurations.
type ListParams struct {
*api.API
Region string
Region string
ShowDeleted bool
ShowMaxZones bool
IncludeVersions bool
}

// Validate ensures that the parameters are correct.
Expand All @@ -54,9 +57,21 @@ func List(params ListParams) ([]*models.InstanceConfiguration, error) {
return nil, err
}

requestParams := platform_configuration_instances.NewGetInstanceConfigurationsParams().
WithContext(api.WithRegion(context.Background(), params.Region))

if params.ShowDeleted {
requestParams = requestParams.WithShowDeleted(ec.Bool(true))
}
if params.ShowMaxZones {
requestParams = requestParams.WithShowMaxZones(ec.Bool(true))
}
if params.IncludeVersions {
requestParams = requestParams.WithIncludeVersions(ec.Bool(true))
}

res, err := params.API.V1API.PlatformConfigurationInstances.GetInstanceConfigurations(
platform_configuration_instances.NewGetInstanceConfigurationsParams().
WithContext(api.WithRegion(context.Background(), params.Region)),
requestParams,
params.AuthWriter,
)

Expand Down
11 changes: 10 additions & 1 deletion pkg/api/platformapi/instanceconfigapi/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package instanceconfigapi
import (
"errors"
"net/http"
"net/url"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -46,7 +47,10 @@ func TestList(t *testing.T) {
name: "List succeeds",
args: args{
params: ListParams{
Region: "us-east-1",
Region: "us-east-1",
ShowDeleted: true,
ShowMaxZones: true,
IncludeVersions: true,
API: api.NewMock(mock.Response{
Response: http.Response{
Body: mock.NewStringBody(listInstanceConfigsSuccess),
Expand All @@ -57,6 +61,11 @@ func TestList(t *testing.T) {
Method: "GET",
Host: api.DefaultMockHost,
Path: "/api/v1/regions/us-east-1/platform/configuration/instances",
Query: url.Values{
"show_deleted": []string{"true"},
"show_max_zones": []string{"true"},
"include_versions": []string{"true"},
},
},
}),
},
Expand Down

0 comments on commit 586a2e1

Please sign in to comment.