Skip to content

Commit

Permalink
chore: Rewrite interface{} to any
Browse files Browse the repository at this point in the history
  • Loading branch information
johanbrandhorst committed Oct 12, 2022
1 parent 3be8b6e commit 785885b
Show file tree
Hide file tree
Showing 297 changed files with 1,756 additions and 1,756 deletions.
2 changes: 1 addition & 1 deletion api/accounts/changepassword.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (c *Client) ChangePassword(ctx context.Context, accountId, currentPassword,
version = existingTarget.Item.Version
}

reqBody := map[string]interface{}{
reqBody := map[string]any{
"version": version,
"current_password": currentPassword,
"new_password": newPassword,
Expand Down
2 changes: 1 addition & 1 deletion api/accounts/setpassword.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (c *Client) SetPassword(ctx context.Context, accountId, password string, ve
version = existingTarget.Item.Version
}

reqBody := map[string]interface{}{
reqBody := map[string]any{
"version": version,
"password": password,
}
Expand Down
12 changes: 6 additions & 6 deletions api/authmethods/authenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
)

type AuthenticateResult struct {
Command string `json:"-"`
Attributes map[string]interface{} `json:"-"`
Command string `json:"-"`
Attributes map[string]any `json:"-"`
attributesRaw json.RawMessage

response *api.Response
Expand All @@ -20,7 +20,7 @@ func (a *AuthenticateResult) MarshalJSON() ([]byte, error) {
// Note that a will not be nil per contract of the interface. Using a map
// here causes Go to sort the resulting JSON, which makes tests easier and
// output more predictable.
out := make(map[string]interface{})
out := make(map[string]any)
if a.Command != "" {
out["command"] = a.Command
}
Expand All @@ -41,7 +41,7 @@ func (a *AuthenticateResult) UnmarshalJSON(inBytes []byte) error {
}
a.Command = i.Command
a.attributesRaw = i.Attributes
a.Attributes = make(map[string]interface{})
a.Attributes = make(map[string]any)
if err := json.Unmarshal(i.Attributes, &a.Attributes); err != nil {
return err
}
Expand All @@ -57,7 +57,7 @@ func (n AuthenticateResult) GetResponse() *api.Response {
}

// Authenticate is a generic authenticate API call that returns a generic result.
func (c *Client) Authenticate(ctx context.Context, authMethodId, command string, attributes map[string]interface{}, opt ...Option) (*AuthenticateResult, error) {
func (c *Client) Authenticate(ctx context.Context, authMethodId, command string, attributes map[string]any, opt ...Option) (*AuthenticateResult, error) {
if c.client == nil {
return nil, fmt.Errorf("nil client in Authenticate request")
}
Expand All @@ -70,7 +70,7 @@ func (c *Client) Authenticate(ctx context.Context, authMethodId, command string,

_, apiOpts := getOpts(opt...)

reqBody := map[string]interface{}{
reqBody := map[string]any{
"command": command,
}
if attributes != nil {
Expand Down
2 changes: 1 addition & 1 deletion api/authmethods/authenticate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestAuthenticateResultMarshaling(t *testing.T) {

exp := &AuthenticateResult{
Command: "foo",
Attributes: map[string]interface{}{
Attributes: map[string]any{
"key": "value",
},
attributesRaw: json.RawMessage(`{"key":"value"}`),
Expand Down
4 changes: 2 additions & 2 deletions api/authmethods/changestate.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ func (c *Client) ChangeState(ctx context.Context, authMethodId string, version u

reqBody := opts.postMap
reqBody[versionPostBodyKey] = version
attrMap, ok := reqBody[attributesPostBodyKey].(map[string]interface{})
attrMap, ok := reqBody[attributesPostBodyKey].(map[string]any)
if !ok {
attrMap = make(map[string]interface{})
attrMap = make(map[string]any)
reqBody[attributesPostBodyKey] = attrMap
}
attrMap[statePostBodyKey] = state
Expand Down
4 changes: 2 additions & 2 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,15 +594,15 @@ func copyHeaders(in http.Header) http.Header {
// NewRequest creates a new raw request object to query the Boundary controller
// configured for this client. This is an advanced method and generally
// doesn't need to be called externally.
func (c *Client) NewRequest(ctx context.Context, method, requestPath string, body interface{}, opt ...Option) (*retryablehttp.Request, error) {
func (c *Client) NewRequest(ctx context.Context, method, requestPath string, body any, opt ...Option) (*retryablehttp.Request, error) {
if c == nil {
return nil, fmt.Errorf("client is nil")
}

// Figure out what to do with the body. If it's already a reader it might
// be marshaled or raw bytes in a reader, so pass it through. Otherwise
// attempt JSON encoding and then pop in a bytes.Buffer.
var rawBody interface{}
var rawBody any
if body != nil {
switch t := body.(type) {
case io.ReadCloser, io.Reader:
Expand Down
6 changes: 3 additions & 3 deletions api/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Response struct {
resp *http.Response

Body *bytes.Buffer
Map map[string]interface{}
Map map[string]any
}

// HttpResponse returns the underlying HTTP response
Expand All @@ -27,7 +27,7 @@ func (r *Response) StatusCode() int {
return r.resp.StatusCode
}

func (r *Response) Decode(inStruct interface{}) (*Error, error) {
func (r *Response) Decode(inStruct any) (*Error, error) {
if r == nil || r.resp == nil {
return nil, fmt.Errorf("nil response, cannot decode")
}
Expand Down Expand Up @@ -57,7 +57,7 @@ func (r *Response) Decode(inStruct interface{}) (*Error, error) {
reader := bytes.NewReader(r.Body.Bytes())
dec := json.NewDecoder(reader)
dec.UseNumber()
r.Map = make(map[string]interface{})
r.Map = make(map[string]any)
if err := dec.Decode(&r.Map); err != nil {
return nil, fmt.Errorf("error decoding response to map: %w; response was %s", err, r.Body.String())
}
Expand Down
2 changes: 1 addition & 1 deletion api/targets/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type SessionAuthorizationResult struct {
response *api.Response
}

func (n SessionAuthorizationResult) GetItem() interface{} {
func (n SessionAuthorizationResult) GetItem() any {
return n.Item
}

Expand Down
6 changes: 3 additions & 3 deletions internal/auth/additional_verification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func TestRecursiveListingDifferentOutputFields(t *testing.T) {
require.NotNil(resp)
require.NotNil(resp.GetItems())
assert.Len(resp.GetItems(), 3)
items := resp.GetResponse().Map["items"].([]interface{})
items := resp.GetResponse().Map["items"].([]any)
require.NotNil(items)

// The default generated roles don't have output field definitions for them,
Expand All @@ -171,7 +171,7 @@ func TestRecursiveListingDifferentOutputFields(t *testing.T) {
// auto generated one.
var globalAms, orgAms int
for _, item := range items {
m := item.(map[string]interface{})
m := item.(map[string]any)
require.NotNil(m)
switch m["scope_id"].(string) {
case scope.Global.String():
Expand Down Expand Up @@ -200,7 +200,7 @@ func TestRecursiveListingDifferentOutputFields(t *testing.T) {
require.NotNil(resp)
require.NotNil(resp.GetItems())
assert.Len(resp.GetItems(), 1)
item := resp.GetResponse().Map["items"].([]interface{})[0].(map[string]interface{})
item := resp.GetResponse().Map["items"].([]any)[0].(map[string]any)
assert.NotContains(item, "created_time")
assert.NotContains(item, "attributes")
}
Expand Down
14 changes: 7 additions & 7 deletions internal/auth/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ select count(*) from test_auth_method where public_id = @public_id
org, _ := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper))

id := "l1Ocw0TpHn800CekIxIXlmQqRDgFDfYl"
inserted, err := rw.Exec(ctx, insert, []interface{}{sql.Named("public_id", id), sql.Named("scoped_id", org.GetPublicId())})
inserted, err := rw.Exec(ctx, insert, []any{sql.Named("public_id", id), sql.Named("scoped_id", org.GetPublicId())})
require.NoError(err)
require.Equal(1, inserted)

type c struct {
Count int
}
var count c
rows, err := rw.Query(ctx, baseTableQuery, []interface{}{sql.Named("public_id", id)})
rows, err := rw.Query(ctx, baseTableQuery, []any{sql.Named("public_id", id)})
require.NoError(err)
defer rows.Close()
for rows.Next() {
Expand All @@ -74,7 +74,7 @@ select count(*) from test_auth_method where public_id = @public_id
assert.Equal(1, count.Count)

count.Count = 0
rows, err = rw.Query(ctx, testTableQuery, []interface{}{sql.Named("public_id", id)})
rows, err = rw.Query(ctx, testTableQuery, []any{sql.Named("public_id", id)})
require.NoError(err)
defer rows.Close()
for rows.Next() {
Expand Down Expand Up @@ -135,18 +135,18 @@ values

org, _ := iam.TestScopes(t, repo)
meth_id := "31Ocw0TpHn800CekIxIXlmQqRDgFDfYl"
_, err = rw.Exec(ctx, insertAuthMethod, []interface{}{meth_id, org.GetPublicId()})
_, err = rw.Exec(ctx, insertAuthMethod, []any{meth_id, org.GetPublicId()})
require.NoError(err)

id := "l1Ocw0TpHn800CekIxIXlmQqRDgFDfYl"
_, err = rw.Exec(ctx, insert, []interface{}{id, meth_id})
_, err = rw.Exec(ctx, insert, []any{id, meth_id})
require.NoError(err)

type c struct {
Count int
}
var count c
rows, err := rw.Query(ctx, baseTableQuery, []interface{}{id})
rows, err := rw.Query(ctx, baseTableQuery, []any{id})
require.NoError(err)
defer rows.Close()
for rows.Next() {
Expand All @@ -156,7 +156,7 @@ values
assert.Equal(1, count.Count)

count.Count = 0
rows, err = rw.Query(ctx, testTableQuery, []interface{}{id})
rows, err = rw.Query(ctx, testTableQuery, []any{id})
require.NoError(err)
defer rows.Close()
for rows.Next() {
Expand Down
4 changes: 2 additions & 2 deletions internal/auth/oidc/account_claim_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func TestAccountClaimMap_Create(t *testing.T) {
assert.NoError(err)
}
found := AllocAccountClaimMap()
require.NoError(rw.LookupWhere(ctx, &found, "oidc_method_id = ? and to_claim = ?", []interface{}{tt.args.authMethodId, tt.args.to}))
require.NoError(rw.LookupWhere(ctx, &found, "oidc_method_id = ? and to_claim = ?", []any{tt.args.authMethodId, tt.args.to}))
assert.Equal(got, &found)
}
})
Expand Down Expand Up @@ -208,7 +208,7 @@ func TestAccountClaimMap_Delete(t *testing.T) {
}
assert.Equal(tt.wantRowsDeleted, deletedRows)
found := AllocAccountClaimMap()
err = rw.LookupWhere(ctx, &found, "oidc_method_id = ? and to_claim = ?", []interface{}{tt.AccountClaimMap.OidcMethodId, tt.AccountClaimMap.ToClaim})
err = rw.LookupWhere(ctx, &found, "oidc_method_id = ? and to_claim = ?", []any{tt.AccountClaimMap.OidcMethodId, tt.AccountClaimMap.ToClaim})
assert.True(errors.IsNotFoundError(err))
})
}
Expand Down
4 changes: 2 additions & 2 deletions internal/auth/oidc/aud_claim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestAudClaim_Create(t *testing.T) {
assert.NoError(err)
}
found := AllocAudClaim()
require.NoError(rw.LookupWhere(ctx, &found, "oidc_method_id = ? and aud_claim = ?", []interface{}{tt.args.authMethodId, tt.args.aud}))
require.NoError(rw.LookupWhere(ctx, &found, "oidc_method_id = ? and aud_claim = ?", []any{tt.args.authMethodId, tt.args.aud}))
assert.Equal(got, &found)
}
})
Expand Down Expand Up @@ -191,7 +191,7 @@ func TestAudClaim_Delete(t *testing.T) {
}
assert.Equal(tt.wantRowsDeleted, deletedRows)
found := AllocAudClaim()
err = rw.LookupWhere(ctx, &found, "oidc_method_id = ? and aud_claim = ?", []interface{}{tt.AudClaim.OidcMethodId, tt.AudClaim.Aud})
err = rw.LookupWhere(ctx, &found, "oidc_method_id = ? and aud_claim = ?", []any{tt.AudClaim.OidcMethodId, tt.AudClaim.Aud})
assert.True(errors.IsNotFoundError(err))
})
}
Expand Down
32 changes: 16 additions & 16 deletions internal/auth/oidc/auth_method.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,11 @@ func (am *AuthMethod) isComplete(ctx context.Context) error {
}

type convertedValues struct {
Algs []interface{}
Auds []interface{}
Certs []interface{}
ClaimsScopes []interface{}
AccountClaimMaps []interface{}
Algs []any
Auds []any
Certs []any
ClaimsScopes []any
AccountClaimMaps []any
}

// convertValueObjects converts the embedded value objects. It will return an
Expand All @@ -289,7 +289,7 @@ func (am *AuthMethod) convertValueObjects(ctx context.Context) (*convertedValues
return nil, errors.New(ctx, errors.InvalidPublicId, op, "missing public id")
}
var err error
var addAlgs, addAuds, addCerts, addScopes, addAccountClaimMaps []interface{}
var addAlgs, addAuds, addCerts, addScopes, addAccountClaimMaps []any
if addAlgs, err = am.convertSigningAlgs(ctx); err != nil {
return nil, errors.Wrap(ctx, err, op)
}
Expand Down Expand Up @@ -317,12 +317,12 @@ func (am *AuthMethod) convertValueObjects(ctx context.Context) (*convertedValues
// convertSigningAlgs converts the embedded signing algorithms from []string
// to []interface{} where each slice element is a *SigningAlg. It will return an
// error if the AuthMethod's public id is not set.
func (am *AuthMethod) convertSigningAlgs(ctx context.Context) ([]interface{}, error) {
func (am *AuthMethod) convertSigningAlgs(ctx context.Context) ([]any, error) {
const op = "oidc.(AuthMethod).convertSigningAlgs"
if am.PublicId == "" {
return nil, errors.New(ctx, errors.InvalidPublicId, op, "missing public id")
}
newInterfaces := make([]interface{}, 0, len(am.SigningAlgs))
newInterfaces := make([]any, 0, len(am.SigningAlgs))
for _, a := range am.SigningAlgs {
obj, err := NewSigningAlg(ctx, am.PublicId, Alg(a))
if err != nil {
Expand All @@ -336,12 +336,12 @@ func (am *AuthMethod) convertSigningAlgs(ctx context.Context) ([]interface{}, er
// convertAudClaims converts the embedded audience claims from []string
// to []interface{} where each slice element is a *AudClaim. It will return an
// error if the AuthMethod's public id is not set.
func (am *AuthMethod) convertAudClaims(ctx context.Context) ([]interface{}, error) {
func (am *AuthMethod) convertAudClaims(ctx context.Context) ([]any, error) {
const op = "oidc.(AuthMethod).convertAudClaims"
if am.PublicId == "" {
return nil, errors.New(ctx, errors.InvalidPublicId, op, "missing public id")
}
newInterfaces := make([]interface{}, 0, len(am.AudClaims))
newInterfaces := make([]any, 0, len(am.AudClaims))
for _, a := range am.AudClaims {
obj, err := NewAudClaim(ctx, am.PublicId, a)
if err != nil {
Expand All @@ -355,12 +355,12 @@ func (am *AuthMethod) convertAudClaims(ctx context.Context) ([]interface{}, erro
// convertCertificates converts the embedded certificates from []string
// to []interface{} where each slice element is a *Certificate. It will return an
// error if the AuthMethod's public id is not set.
func (am *AuthMethod) convertCertificates(ctx context.Context) ([]interface{}, error) {
func (am *AuthMethod) convertCertificates(ctx context.Context) ([]any, error) {
const op = "oidc.(AuthMethod).convertCertificates"
if am.PublicId == "" {
return nil, errors.New(ctx, errors.InvalidPublicId, op, "missing public id")
}
newInterfaces := make([]interface{}, 0, len(am.Certificates))
newInterfaces := make([]any, 0, len(am.Certificates))
for _, cert := range am.Certificates {
obj, err := NewCertificate(ctx, am.PublicId, cert)
if err != nil {
Expand All @@ -374,12 +374,12 @@ func (am *AuthMethod) convertCertificates(ctx context.Context) ([]interface{}, e
// convertClaimsScopes converts the embedded claims scopes from []string
// to []interface{} where each slice element is a *ClaimsScope. It will return an
// error if the AuthMethod's public id is not set.
func (am *AuthMethod) convertClaimsScopes(ctx context.Context) ([]interface{}, error) {
func (am *AuthMethod) convertClaimsScopes(ctx context.Context) ([]any, error) {
const op = "oidc.(AuthMethod).convertClaimsScopes"
if am.PublicId == "" {
return nil, errors.New(ctx, errors.InvalidPublicId, op, "missing public id")
}
newInterfaces := make([]interface{}, 0, len(am.ClaimsScopes))
newInterfaces := make([]any, 0, len(am.ClaimsScopes))
for _, cs := range am.ClaimsScopes {
obj, err := NewClaimsScope(ctx, am.PublicId, cs)
if err != nil {
Expand All @@ -394,12 +394,12 @@ func (am *AuthMethod) convertClaimsScopes(ctx context.Context) ([]interface{}, e
// []string to []interface{} where each slice element is a *AccountClaimMap. It
// will return an error if the AuthMethod's public id is not set or it can
// convert the account claim maps.
func (am *AuthMethod) convertAccountClaimMaps(ctx context.Context) ([]interface{}, error) {
func (am *AuthMethod) convertAccountClaimMaps(ctx context.Context) ([]any, error) {
const op = "oidc.(AuthMethod).convertAccountClaimMaps"
if am.PublicId == "" {
return nil, errors.New(ctx, errors.InvalidPublicId, op, "missing public id")
}
newInterfaces := make([]interface{}, 0, len(am.AccountClaimMaps))
newInterfaces := make([]any, 0, len(am.AccountClaimMaps))
const (
from = 0
to = 1
Expand Down
Loading

0 comments on commit 785885b

Please sign in to comment.