Skip to content

Commit

Permalink
Merge pull request #3055 from stephenfin/any-keyword
Browse files Browse the repository at this point in the history
trivial: Replace 'interface{}' with any
  • Loading branch information
pierreprinetti committed May 22, 2024
2 parents a7ecc2e + de76eeb commit 571ae75
Show file tree
Hide file tree
Showing 368 changed files with 2,063 additions and 2,063 deletions.
48 changes: 24 additions & 24 deletions auth_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,21 @@ type AuthScope struct {

// ToTokenV2CreateMap allows AuthOptions to satisfy the AuthOptionsBuilder
// interface in the v2 tokens package
func (opts AuthOptions) ToTokenV2CreateMap() (map[string]interface{}, error) {
func (opts AuthOptions) ToTokenV2CreateMap() (map[string]any, error) {
// Populate the request map.
authMap := make(map[string]interface{})
authMap := make(map[string]any)

if opts.Username != "" {
if opts.Password != "" {
authMap["passwordCredentials"] = map[string]interface{}{
authMap["passwordCredentials"] = map[string]any{
"username": opts.Username,
"password": opts.Password,
}
} else {
return nil, ErrMissingInput{Argument: "Password"}
}
} else if opts.TokenID != "" {
authMap["token"] = map[string]interface{}{
authMap["token"] = map[string]any{
"id": opts.TokenID,
}
} else {
Expand All @@ -135,12 +135,12 @@ func (opts AuthOptions) ToTokenV2CreateMap() (map[string]interface{}, error) {
authMap["tenantName"] = opts.TenantName
}

return map[string]interface{}{"auth": authMap}, nil
return map[string]any{"auth": authMap}, nil
}

// ToTokenV3CreateMap allows AuthOptions to satisfy the AuthOptionsBuilder
// interface in the v3 tokens package
func (opts *AuthOptions) ToTokenV3CreateMap(scope map[string]interface{}) (map[string]interface{}, error) {
func (opts *AuthOptions) ToTokenV3CreateMap(scope map[string]any) (map[string]any, error) {
type domainReq struct {
ID *string `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
Expand Down Expand Up @@ -392,15 +392,15 @@ func (opts *AuthOptions) ToTokenV3CreateMap(scope map[string]interface{}) (map[s
}

if len(scope) != 0 {
b["auth"].(map[string]interface{})["scope"] = scope
b["auth"].(map[string]any)["scope"] = scope
}

return b, nil
}

// ToTokenV3ScopeMap builds a scope from AuthOptions and satisfies interface in
// the v3 tokens package.
func (opts *AuthOptions) ToTokenV3ScopeMap() (map[string]interface{}, error) {
func (opts *AuthOptions) ToTokenV3ScopeMap() (map[string]any, error) {
// For backwards compatibility.
// If AuthOptions.Scope was not set, try to determine it.
// This works well for common scenarios.
Expand All @@ -418,15 +418,15 @@ func (opts *AuthOptions) ToTokenV3ScopeMap() (map[string]interface{}, error) {
}

if opts.Scope.System {
return map[string]interface{}{
"system": map[string]interface{}{
return map[string]any{
"system": map[string]any{
"all": true,
},
}, nil
}

if opts.Scope.TrustID != "" {
return map[string]interface{}{
return map[string]any{
"OS-TRUST:trust": map[string]string{
"id": opts.Scope.TrustID,
},
Expand All @@ -445,20 +445,20 @@ func (opts *AuthOptions) ToTokenV3ScopeMap() (map[string]interface{}, error) {

if opts.Scope.DomainID != "" {
// ProjectName + DomainID
return map[string]interface{}{
"project": map[string]interface{}{
return map[string]any{
"project": map[string]any{
"name": &opts.Scope.ProjectName,
"domain": map[string]interface{}{"id": &opts.Scope.DomainID},
"domain": map[string]any{"id": &opts.Scope.DomainID},
},
}, nil
}

if opts.Scope.DomainName != "" {
// ProjectName + DomainName
return map[string]interface{}{
"project": map[string]interface{}{
return map[string]any{
"project": map[string]any{
"name": &opts.Scope.ProjectName,
"domain": map[string]interface{}{"name": &opts.Scope.DomainName},
"domain": map[string]any{"name": &opts.Scope.DomainName},
},
}, nil
}
Expand All @@ -472,8 +472,8 @@ func (opts *AuthOptions) ToTokenV3ScopeMap() (map[string]interface{}, error) {
}

// ProjectID
return map[string]interface{}{
"project": map[string]interface{}{
return map[string]any{
"project": map[string]any{
"id": &opts.Scope.ProjectID,
},
}, nil
Expand All @@ -484,15 +484,15 @@ func (opts *AuthOptions) ToTokenV3ScopeMap() (map[string]interface{}, error) {
}

// DomainID
return map[string]interface{}{
"domain": map[string]interface{}{
return map[string]any{
"domain": map[string]any{
"id": &opts.Scope.DomainID,
},
}, nil
} else if opts.Scope.DomainName != "" {
// DomainName
return map[string]interface{}{
"domain": map[string]interface{}{
return map[string]any{
"domain": map[string]any{
"name": &opts.Scope.DomainName,
},
}, nil
Expand All @@ -512,6 +512,6 @@ func (opts AuthOptions) CanReauth() bool {

// ToTokenV3HeadersMap allows AuthOptions to satisfy the AuthOptionsBuilder
// interface in the v3 tokens package.
func (opts *AuthOptions) ToTokenV3HeadersMap(map[string]interface{}) (map[string]string, error) {
func (opts *AuthOptions) ToTokenV3HeadersMap(map[string]any) (map[string]string, error) {
return nil, nil
}
2 changes: 1 addition & 1 deletion errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (e ErrMissingInput) Error() string {
// ErrInvalidInput is an error type used for most non-HTTP Gophercloud errors.
type ErrInvalidInput struct {
ErrMissingInput
Value interface{}
Value any
}

func (e ErrInvalidInput) Error() string {
Expand Down
18 changes: 9 additions & 9 deletions internal/acceptance/clients/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ func (lrt *LogRoundTripper) logResponse(original io.ReadCloser, contentType stri
// formatJSON will try to pretty-format a JSON body.
// It will also mask known fields which contain sensitive information.
func (lrt *LogRoundTripper) formatJSON(raw []byte) string {
var rawData interface{}
var rawData any

err := json.Unmarshal(raw, &rawData)
if err != nil {
log.Printf("[DEBUG] Unable to parse OpenStack JSON: %s", err)
return string(raw)
}

data, ok := rawData.(map[string]interface{})
data, ok := rawData.(map[string]any)
if !ok {
pretty, err := json.MarshalIndent(rawData, "", " ")
if err != nil {
Expand All @@ -121,24 +121,24 @@ func (lrt *LogRoundTripper) formatJSON(raw []byte) string {
}

// Mask known password fields
if v, ok := data["auth"].(map[string]interface{}); ok {
if v, ok := v["identity"].(map[string]interface{}); ok {
if v, ok := v["password"].(map[string]interface{}); ok {
if v, ok := v["user"].(map[string]interface{}); ok {
if v, ok := data["auth"].(map[string]any); ok {
if v, ok := v["identity"].(map[string]any); ok {
if v, ok := v["password"].(map[string]any); ok {
if v, ok := v["user"].(map[string]any); ok {
v["password"] = "***"
}
}
if v, ok := v["application_credential"].(map[string]interface{}); ok {
if v, ok := v["application_credential"].(map[string]any); ok {
v["secret"] = "***"
}
if v, ok := v["token"].(map[string]interface{}); ok {
if v, ok := v["token"].(map[string]any); ok {
v["id"] = "***"
}
}
}

// Ignore the catalog
if v, ok := data["token"].(map[string]interface{}); ok {
if v, ok := data["token"].(map[string]any); ok {
if _, ok := v["catalog"]; ok {
return ""
}
Expand Down
4 changes: 2 additions & 2 deletions internal/acceptance/openstack/baremetal/v1/baremetal.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func CreateNode(t *testing.T, client *gophercloud.ServiceClient) (*nodes.Node, e
Driver: "ipmi",
BootInterface: "ipxe",
RAIDInterface: "agent",
DriverInfo: map[string]interface{}{
DriverInfo: map[string]any{
"ipmi_port": "6230",
"ipmi_username": "admin",
"deploy_kernel": "http://172.22.0.1/images/tinyipa-stable-rocky.vmlinuz",
Expand Down Expand Up @@ -86,7 +86,7 @@ func CreateFakeNode(t *testing.T, client *gophercloud.ServiceClient) (*nodes.Nod
Driver: "fake-hardware",
BootInterface: "fake",
DeployInterface: "fake",
DriverInfo: map[string]interface{}{
DriverInfo: map[string]any{
"ipmi_port": "6230",
"ipmi_username": "admin",
"deploy_kernel": "http://172.22.0.1/images/tinyipa-stable-rocky.vmlinuz",
Expand Down
2 changes: 1 addition & 1 deletion internal/acceptance/openstack/baremetal/v1/nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func TestNodesRAIDConfig(t *testing.T) {
IsRootVolume: &isTrue,
RAIDLevel: nodes.RAID5,
Controller: "software",
PhysicalDisks: []interface{}{
PhysicalDisks: []any{
map[string]string{
"size": "> 100",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var UpdateQuotaOpts = quotasets.UpdateOpts{
Backups: gophercloud.IntToPointer(2),
BackupGigabytes: gophercloud.IntToPointer(300),
Groups: gophercloud.IntToPointer(350),
Extra: map[string]interface{}{
Extra: map[string]any{
"volumes_foo": gophercloud.IntToPointer(100),
},
}
Expand Down Expand Up @@ -133,7 +133,7 @@ func TestQuotasetUpdate(t *testing.T) {

// unpopulate resultQuotas.Extra as it is different per cloud and test
// rest of the quotaSet
resultQuotas.Extra = map[string]interface{}(nil)
resultQuotas.Extra = map[string]any(nil)
th.AssertDeepEquals(t, UpdatedQuotas, *resultQuotas)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/acceptance/openstack/compute/v2/aggregates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestAggregatesSetRemoveMetadata(t *testing.T) {
defer DeleteAggregate(t, client, aggregate)

opts := aggregates.SetMetadataOpts{
Metadata: map[string]interface{}{"key": "value"},
Metadata: map[string]any{"key": "value"},
}

aggregateWithMetadata, err := aggregates.SetMetadata(context.TODO(), client, aggregate.ID, opts).Extract()
Expand All @@ -120,7 +120,7 @@ func TestAggregatesSetRemoveMetadata(t *testing.T) {
}

optsToRemove := aggregates.SetMetadataOpts{
Metadata: map[string]interface{}{"key": nil},
Metadata: map[string]any{"key": nil},
}

aggregateWithRemovedKey, err := aggregates.SetMetadata(context.TODO(), client, aggregate.ID, optsToRemove).Extract()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func TestAttachDetachInterface(t *testing.T) {
th.AssertNoErr(t, err)

var found bool
for _, networkAddresses := range server.Addresses[choices.NetworkName].([]interface{}) {
address := networkAddresses.(map[string]interface{})
for _, networkAddresses := range server.Addresses[choices.NetworkName].([]any) {
address := networkAddresses.(map[string]any)
if address["OS-EXT-IPS:type"] == "fixed" {
fixedIP := address["addr"].(string)

Expand Down
2 changes: 1 addition & 1 deletion internal/acceptance/openstack/db/v1/configurations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestConfigurationsCRUD(t *testing.T) {
}
createOpts.Datastore = &datastore

values := make(map[string]interface{})
values := make(map[string]any)
values["collation_server"] = "latin1_swedish_ci"
createOpts.Values = values

Expand Down
4 changes: 2 additions & 2 deletions internal/acceptance/openstack/identity/v3/groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestGroupCRUD(t *testing.T) {
createOpts := groups.CreateOpts{
Description: description,
DomainID: domainID,
Extra: map[string]interface{}{
Extra: map[string]any{
"email": "testgroup@example.com",
},
}
Expand All @@ -43,7 +43,7 @@ func TestGroupCRUD(t *testing.T) {
description = ""
updateOpts := groups.UpdateOpts{
Description: &description,
Extra: map[string]interface{}{
Extra: map[string]any{
"email": "thetestgroup@example.com",
},
}
Expand Down
4 changes: 2 additions & 2 deletions internal/acceptance/openstack/identity/v3/policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestPoliciesCRUD(t *testing.T) {
createOpts := policies.CreateOpts{
Type: "application/json",
Blob: []byte("{'foobar_user': 'role:compute-user'}"),
Extra: map[string]interface{}{
Extra: map[string]any{
"description": "policy for foobar_user",
},
}
Expand Down Expand Up @@ -124,7 +124,7 @@ func TestPoliciesCRUD(t *testing.T) {
updateOpts := policies.UpdateOpts{
Type: "text/plain",
Blob: []byte("'foobar_user': 'role:compute-user'"),
Extra: map[string]interface{}{
Extra: map[string]any{
"description": "updated policy for foobar_user",
},
}
Expand Down
4 changes: 2 additions & 2 deletions internal/acceptance/openstack/identity/v3/regions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestRegionsCRUD(t *testing.T) {
createOpts := regions.CreateOpts{
ID: "testregion",
Description: "Region for testing",
Extra: map[string]interface{}{
Extra: map[string]any{
"email": "testregion@example.com",
},
}
Expand All @@ -84,7 +84,7 @@ func TestRegionsCRUD(t *testing.T) {
// is not updatable, see: https://bugs.launchpad.net/keystone/+bug/1729933
// The following lines should be uncommented once the fix is merged.
Extra: map[string]interface{}{
Extra: map[string]any{
"email": "testregionA@example.com",
},
*/
Expand Down
10 changes: 5 additions & 5 deletions internal/acceptance/openstack/identity/v3/roles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestRolesCRUD(t *testing.T) {

createOpts := roles.CreateOpts{
Name: "testrole",
Extra: map[string]interface{}{
Extra: map[string]any{
"description": "test role description",
},
}
Expand Down Expand Up @@ -92,7 +92,7 @@ func TestRolesCRUD(t *testing.T) {
th.AssertEquals(t, found, true)

updateOpts := roles.UpdateOpts{
Extra: map[string]interface{}{
Extra: map[string]any{
"description": "updated test role description",
},
}
Expand All @@ -114,7 +114,7 @@ func TestRolesFilterList(t *testing.T) {

createOpts := roles.CreateOpts{
Name: "testrole",
Extra: map[string]interface{}{
Extra: map[string]any{
"description": "test role description",
},
}
Expand Down Expand Up @@ -798,7 +798,7 @@ func TestCRUDRoleInferenceRule(t *testing.T) {

priorRoleCreateOpts := roles.CreateOpts{
Name: "priorRole",
Extra: map[string]interface{}{
Extra: map[string]any{
"description": "prior_role description",
},
}
Expand All @@ -811,7 +811,7 @@ func TestCRUDRoleInferenceRule(t *testing.T) {

impliedRoleCreateOpts := roles.CreateOpts{
Name: "impliedRole",
Extra: map[string]interface{}{
Extra: map[string]any{
"description": "implied_role description",
},
}
Expand Down
Loading

0 comments on commit 571ae75

Please sign in to comment.