Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

instanceconfigapi: Implement additional parameters. #467

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading