From dc79c8ea59622d19db22dae6753936da2be6412f Mon Sep 17 00:00:00 2001 From: James Elliott Date: Wed, 5 Oct 2022 16:05:23 +1100 Subject: [PATCH] refactor: any (#4133) * refactor: any * refactor: fix test --- cmd/authelia-gen/cmd_docs_date.go | 2 +- cmd/authelia-scripts/cmd/bootstrap.go | 4 ++-- cmd/authelia-scripts/cmd/types.go | 8 ++++---- .../authentication/ldap_user_provider_test.go | 4 ++-- internal/commands/crypto.go | 12 +++++------ internal/commands/crypto_helper.go | 6 +++--- internal/commands/util.go | 2 +- internal/configuration/decode_hooks.go | 12 +++++------ internal/configuration/decode_hooks_test.go | 8 ++++---- internal/configuration/deprecation.go | 2 +- internal/configuration/koanf_callbacks.go | 12 +++++------ .../configuration/koanf_callbacks_test.go | 4 ++-- internal/configuration/koanf_util.go | 6 +++--- internal/configuration/provider.go | 6 +++--- internal/configuration/sources.go | 4 ++-- internal/configuration/types.go | 4 ++-- internal/handlers/handler_sign_webauthn.go | 2 +- internal/handlers/oidc.go | 4 ++-- internal/middlewares/authelia_context.go | 6 +++--- internal/middlewares/identity_verification.go | 2 +- internal/middlewares/types.go | 4 ++-- internal/model/oidc.go | 2 +- internal/model/types.go | 8 ++++---- internal/oidc/types_test.go | 2 +- internal/utils/crypto.go | 20 +++++++++---------- 25 files changed, 73 insertions(+), 73 deletions(-) diff --git a/cmd/authelia-gen/cmd_docs_date.go b/cmd/authelia-gen/cmd_docs_date.go index b7a2f2794..2f752db4b 100644 --- a/cmd/authelia-gen/cmd_docs_date.go +++ b/cmd/authelia-gen/cmd_docs_date.go @@ -79,7 +79,7 @@ func docsDateRunE(cmd *cobra.Command, args []string) (err error) { return nil } - frontmatter := map[string]interface{}{} + frontmatter := map[string]any{} if err = yaml.Unmarshal(frontmatterBytes, frontmatter); err != nil { return err diff --git a/cmd/authelia-scripts/cmd/bootstrap.go b/cmd/authelia-scripts/cmd/bootstrap.go index befd60994..47a630818 100644 --- a/cmd/authelia-scripts/cmd/bootstrap.go +++ b/cmd/authelia-scripts/cmd/bootstrap.go @@ -168,8 +168,8 @@ func pnpmInstall() { shell(fmt.Sprintf("cd %s/web && pnpm install", cwd)) } -func bootstrapPrintln(args ...interface{}) { - a := make([]interface{}, 0) +func bootstrapPrintln(args ...any) { + a := make([]any, 0) a = append(a, "[BOOTSTRAP]") a = append(a, args...) fmt.Println(a...) diff --git a/cmd/authelia-scripts/cmd/types.go b/cmd/authelia-scripts/cmd/types.go index a2712908c..e18f95391 100644 --- a/cmd/authelia-scripts/cmd/types.go +++ b/cmd/authelia-scripts/cmd/types.go @@ -20,10 +20,10 @@ type DockerImages []DockerImage // DockerImage represents some of the data from the docker images API. type DockerImage struct { - Architecture string `json:"architecture"` - Variant interface{} `json:"variant"` - Digest string `json:"digest"` - OS string `json:"os"` + Architecture string `json:"architecture"` + Variant any `json:"variant"` + Digest string `json:"digest"` + OS string `json:"os"` } // Match returns true if this image matches the platform. diff --git a/internal/authentication/ldap_user_provider_test.go b/internal/authentication/ldap_user_provider_test.go index 2123ad4dd..aeaf5b835 100644 --- a/internal/authentication/ldap_user_provider_test.go +++ b/internal/authentication/ldap_user_provider_test.go @@ -140,7 +140,7 @@ func NewExtendedSearchRequestMatcher(filter, base string, scope, derefAliases in return &ExtendedSearchRequestMatcher{filter, base, scope, derefAliases, typesOnly, attributes} } -func (e *ExtendedSearchRequestMatcher) Matches(x interface{}) bool { +func (e *ExtendedSearchRequestMatcher) Matches(x any) bool { sr := x.(*ldap.SearchRequest) if e.filter != sr.Filter || e.baseDN != sr.BaseDN || e.scope != sr.Scope || e.derefAliases != sr.DerefAliases || @@ -502,7 +502,7 @@ func NewSearchRequestMatcher(expected string) *SearchRequestMatcher { return &SearchRequestMatcher{expected} } -func (srm *SearchRequestMatcher) Matches(x interface{}) bool { +func (srm *SearchRequestMatcher) Matches(x any) bool { sr := x.(*ldap.SearchRequest) return sr.Filter == srm.expected } diff --git a/internal/commands/crypto.go b/internal/commands/crypto.go index 63a331e5e..0ffd245f1 100644 --- a/internal/commands/crypto.go +++ b/internal/commands/crypto.go @@ -235,7 +235,7 @@ func newCryptoGenerateCmd(category, algorithm string) (cmd *cobra.Command) { func cryptoGenerateRunE(cmd *cobra.Command, args []string) (err error) { var ( - privateKey interface{} + privateKey any ) if privateKey, err = cryptoGenPrivateKeyFromCmd(cmd); err != nil { @@ -251,7 +251,7 @@ func cryptoGenerateRunE(cmd *cobra.Command, args []string) (err error) { func cryptoCertificateRequestRunE(cmd *cobra.Command, _ []string) (err error) { var ( - privateKey interface{} + privateKey any ) if privateKey, err = cryptoGenPrivateKeyFromCmd(cmd); err != nil { @@ -320,10 +320,10 @@ func cryptoCertificateRequestRunE(cmd *cobra.Command, _ []string) (err error) { return nil } -func cryptoCertificateGenerateRunE(cmd *cobra.Command, _ []string, privateKey interface{}) (err error) { +func cryptoCertificateGenerateRunE(cmd *cobra.Command, _ []string, privateKey any) (err error) { var ( template, caCertificate, parent *x509.Certificate - publicKey, caPrivateKey, signatureKey interface{} + publicKey, caPrivateKey, signatureKey any ) if publicKey = utils.PublicKeyFromPrivateKey(privateKey); publicKey == nil { @@ -412,7 +412,7 @@ func cryptoCertificateGenerateRunE(cmd *cobra.Command, _ []string, privateKey in return nil } -func cryptoPairGenerateRunE(cmd *cobra.Command, _ []string, privateKey interface{}) (err error) { +func cryptoPairGenerateRunE(cmd *cobra.Command, _ []string, privateKey any) (err error) { var ( privateKeyPath, publicKeyPath string pkcs8 bool @@ -451,7 +451,7 @@ func cryptoPairGenerateRunE(cmd *cobra.Command, _ []string, privateKey interface return err } - var publicKey interface{} + var publicKey any if publicKey = utils.PublicKeyFromPrivateKey(privateKey); publicKey == nil { return fmt.Errorf("failed to obtain public key from private key") diff --git a/internal/commands/crypto_helper.go b/internal/commands/crypto_helper.go index 96e23f673..1a097f37c 100644 --- a/internal/commands/crypto_helper.go +++ b/internal/commands/crypto_helper.go @@ -130,7 +130,7 @@ func cryptoGetWritePathsFromCmd(cmd *cobra.Command) (privateKey, publicKey strin return filepath.Join(dir, private), filepath.Join(dir, public), nil } -func cryptoGenPrivateKeyFromCmd(cmd *cobra.Command) (privateKey interface{}, err error) { +func cryptoGenPrivateKeyFromCmd(cmd *cobra.Command) (privateKey any, err error) { switch cmd.Parent().Use { case cmdUseRSA: var ( @@ -170,7 +170,7 @@ func cryptoGenPrivateKeyFromCmd(cmd *cobra.Command) (privateKey interface{}, err return privateKey, nil } -func cryptoGetCAFromCmd(cmd *cobra.Command) (privateKey interface{}, cert *x509.Certificate, err error) { +func cryptoGetCAFromCmd(cmd *cobra.Command) (privateKey any, cert *x509.Certificate, err error) { if !cmd.Flags().Changed(cmdFlagNamePathCA) { return nil, nil, nil } @@ -180,7 +180,7 @@ func cryptoGetCAFromCmd(cmd *cobra.Command) (privateKey interface{}, cert *x509. ok bool - certificate interface{} + certificate any ) if dir, err = cmd.Flags().GetString(cmdFlagNamePathCA); err != nil { diff --git a/internal/commands/util.go b/internal/commands/util.go index 26c308648..ef83e1627 100644 --- a/internal/commands/util.go +++ b/internal/commands/util.go @@ -4,7 +4,7 @@ import ( "fmt" ) -func recoverErr(i interface{}) error { +func recoverErr(i any) error { switch v := i.(type) { case nil: return nil diff --git a/internal/configuration/decode_hooks.go b/internal/configuration/decode_hooks.go index 9dd236690..d3c5d5c44 100644 --- a/internal/configuration/decode_hooks.go +++ b/internal/configuration/decode_hooks.go @@ -19,7 +19,7 @@ import ( // StringToMailAddressHookFunc decodes a string into a mail.Address or *mail.Address. func StringToMailAddressHookFunc() mapstructure.DecodeHookFuncType { - return func(f reflect.Type, t reflect.Type, data interface{}) (value interface{}, err error) { + return func(f reflect.Type, t reflect.Type, data any) (value any, err error) { var ptr bool if f.Kind() != reflect.String { @@ -65,7 +65,7 @@ func StringToMailAddressHookFunc() mapstructure.DecodeHookFuncType { // StringToURLHookFunc converts string types into a url.URL or *url.URL. func StringToURLHookFunc() mapstructure.DecodeHookFuncType { - return func(f reflect.Type, t reflect.Type, data interface{}) (value interface{}, err error) { + return func(f reflect.Type, t reflect.Type, data any) (value any, err error) { var ptr bool if f.Kind() != reflect.String { @@ -111,7 +111,7 @@ func StringToURLHookFunc() mapstructure.DecodeHookFuncType { // ToTimeDurationHookFunc converts string and integer types to a time.Duration. func ToTimeDurationHookFunc() mapstructure.DecodeHookFuncType { - return func(f reflect.Type, t reflect.Type, data interface{}) (value interface{}, err error) { + return func(f reflect.Type, t reflect.Type, data any) (value any, err error) { var ptr bool switch f.Kind() { @@ -172,7 +172,7 @@ func ToTimeDurationHookFunc() mapstructure.DecodeHookFuncType { // StringToRegexpHookFunc decodes a string into a *regexp.Regexp or regexp.Regexp. func StringToRegexpHookFunc() mapstructure.DecodeHookFuncType { - return func(f reflect.Type, t reflect.Type, data interface{}) (value interface{}, err error) { + return func(f reflect.Type, t reflect.Type, data any) (value any, err error) { var ptr bool if f.Kind() != reflect.String { @@ -218,7 +218,7 @@ func StringToRegexpHookFunc() mapstructure.DecodeHookFuncType { // StringToAddressHookFunc decodes a string into an Address or *Address. func StringToAddressHookFunc() mapstructure.DecodeHookFuncType { - return func(f reflect.Type, t reflect.Type, data interface{}) (value interface{}, err error) { + return func(f reflect.Type, t reflect.Type, data any) (value any, err error) { var ptr bool if f.Kind() != reflect.String { @@ -258,7 +258,7 @@ func StringToAddressHookFunc() mapstructure.DecodeHookFuncType { // StringToX509CertificateHookFunc decodes strings to x509.Certificate's. func StringToX509CertificateHookFunc() mapstructure.DecodeHookFuncType { - return func(f reflect.Type, t reflect.Type, data interface{}) (value interface{}, err error) { + return func(f reflect.Type, t reflect.Type, data any) (value interface{}, err error) { if f.Kind() != reflect.String { return data, nil } diff --git a/internal/configuration/decode_hooks_test.go b/internal/configuration/decode_hooks_test.go index 6a752e5f9..b13d350c7 100644 --- a/internal/configuration/decode_hooks_test.go +++ b/internal/configuration/decode_hooks_test.go @@ -993,8 +993,8 @@ func TestStringToX509CertificateHookFunc(t *testing.T) { testCases := []struct { desc string - have interface{} - want interface{} + have any + want any err string decode bool }{ @@ -1069,8 +1069,8 @@ func TestStringToX509CertificateChainHookFunc(t *testing.T) { testCases := []struct { desc string - have interface{} - expected interface{} + have any + expected any err, verr string decode bool }{ diff --git a/internal/configuration/deprecation.go b/internal/configuration/deprecation.go index 040d346c2..fbe881ef1 100644 --- a/internal/configuration/deprecation.go +++ b/internal/configuration/deprecation.go @@ -10,7 +10,7 @@ type Deprecation struct { Key string NewKey string AutoMap bool - MapFunc func(value interface{}) interface{} + MapFunc func(value any) any ErrText string } diff --git a/internal/configuration/koanf_callbacks.go b/internal/configuration/koanf_callbacks.go index 26d11ebcc..d62984eb1 100644 --- a/internal/configuration/koanf_callbacks.go +++ b/internal/configuration/koanf_callbacks.go @@ -11,8 +11,8 @@ import ( ) // koanfEnvironmentCallback returns a koanf callback to map the environment vars to Configuration keys. -func koanfEnvironmentCallback(keyMap map[string]string, ignoredKeys []string, prefix, delimiter string) func(key, value string) (finalKey string, finalValue interface{}) { - return func(key, value string) (finalKey string, finalValue interface{}) { +func koanfEnvironmentCallback(keyMap map[string]string, ignoredKeys []string, prefix, delimiter string) func(key, value string) (finalKey string, finalValue any) { + return func(key, value string) (finalKey string, finalValue any) { if k, ok := keyMap[key]; ok { return k, value } @@ -33,8 +33,8 @@ func koanfEnvironmentCallback(keyMap map[string]string, ignoredKeys []string, pr } // koanfEnvironmentSecretsCallback returns a koanf callback to map the environment vars to Configuration keys. -func koanfEnvironmentSecretsCallback(keyMap map[string]string, validator *schema.StructValidator) func(key, value string) (finalKey string, finalValue interface{}) { - return func(key, value string) (finalKey string, finalValue interface{}) { +func koanfEnvironmentSecretsCallback(keyMap map[string]string, validator *schema.StructValidator) func(key, value string) (finalKey string, finalValue any) { + return func(key, value string) (finalKey string, finalValue any) { k, ok := keyMap[key] if !ok { return "", nil @@ -50,8 +50,8 @@ func koanfEnvironmentSecretsCallback(keyMap map[string]string, validator *schema } } -func koanfCommandLineWithMappingCallback(mapping map[string]string, includeValidKeys, includeUnchangedKeys bool) func(flag *pflag.Flag) (string, interface{}) { - return func(flag *pflag.Flag) (string, interface{}) { +func koanfCommandLineWithMappingCallback(mapping map[string]string, includeValidKeys, includeUnchangedKeys bool) func(flag *pflag.Flag) (string, any) { + return func(flag *pflag.Flag) (string, any) { if !includeUnchangedKeys && !flag.Changed { return "", nil } diff --git a/internal/configuration/koanf_callbacks_test.go b/internal/configuration/koanf_callbacks_test.go index 107884ab7..43461fe28 100644 --- a/internal/configuration/koanf_callbacks_test.go +++ b/internal/configuration/koanf_callbacks_test.go @@ -16,7 +16,7 @@ import ( func TestKoanfEnvironmentCallback(t *testing.T) { var ( key string - value interface{} + value any ) keyMap := map[string]string{ @@ -46,7 +46,7 @@ func TestKoanfEnvironmentCallback(t *testing.T) { func TestKoanfSecretCallbackWithValidSecrets(t *testing.T) { var ( key string - value interface{} + value any ) keyMap := map[string]string{ diff --git a/internal/configuration/koanf_util.go b/internal/configuration/koanf_util.go index 589b4b05e..e656cf25c 100644 --- a/internal/configuration/koanf_util.go +++ b/internal/configuration/koanf_util.go @@ -15,13 +15,13 @@ func koanfGetKeys(ko *koanf.Koanf) (keys []string) { keys = ko.Keys() for key, value := range ko.All() { - slc, ok := value.([]interface{}) + slc, ok := value.([]any) if !ok { continue } for _, item := range slc { - m, mok := item.(map[string]interface{}) + m, mok := item.(map[string]any) if !mok { continue } @@ -53,7 +53,7 @@ func koanfRemapKeys(val *schema.StructValidator, ko *koanf.Koanf, ds map[string] return final, nil } -func koanfRemapKeysStandard(keys map[string]interface{}, val *schema.StructValidator, ds map[string]Deprecation) (keysFinal map[string]interface{}) { +func koanfRemapKeysStandard(keys map[string]any, val *schema.StructValidator, ds map[string]Deprecation) (keysFinal map[string]interface{}) { var ( ok bool d Deprecation diff --git a/internal/configuration/provider.go b/internal/configuration/provider.go index 22b179331..679589c12 100644 --- a/internal/configuration/provider.go +++ b/internal/configuration/provider.go @@ -19,7 +19,7 @@ func Load(val *schema.StructValidator, sources ...Source) (keys []string, config } // LoadAdvanced is intended to give more flexibility over loading a particular path to a specific interface. -func LoadAdvanced(val *schema.StructValidator, path string, result interface{}, sources ...Source) (keys []string, err error) { +func LoadAdvanced(val *schema.StructValidator, path string, result any, sources ...Source) (keys []string, err error) { if val == nil { return keys, errNoValidator } @@ -44,7 +44,7 @@ func LoadAdvanced(val *schema.StructValidator, path string, result interface{}, return koanfGetKeys(final), nil } -func mapHasKey(k string, m map[string]interface{}) bool { +func mapHasKey(k string, m map[string]any) bool { if _, ok := m[k]; ok { return true } @@ -52,7 +52,7 @@ func mapHasKey(k string, m map[string]interface{}) bool { return false } -func unmarshal(ko *koanf.Koanf, val *schema.StructValidator, path string, o interface{}) { +func unmarshal(ko *koanf.Koanf, val *schema.StructValidator, path string, o any) { c := koanf.UnmarshalConf{ DecoderConfig: &mapstructure.DecoderConfig{ DecodeHook: mapstructure.ComposeDecodeHookFunc( diff --git a/internal/configuration/sources.go b/internal/configuration/sources.go index 67aba6d5a..e7b5e4ccc 100644 --- a/internal/configuration/sources.go +++ b/internal/configuration/sources.go @@ -145,8 +145,8 @@ func (s *CommandLineSource) Load(_ *schema.StructValidator) (err error) { return s.koanf.Load(posflag.Provider(s.flags, ".", s.koanf), nil) } -// NewMapSource returns a new map[string]interface{} source. -func NewMapSource(m map[string]interface{}) (source *MapSource) { +// NewMapSource returns a new map[string]any source. +func NewMapSource(m map[string]any) (source *MapSource) { return &MapSource{ m: m, koanf: koanf.New(constDelimiter), diff --git a/internal/configuration/types.go b/internal/configuration/types.go index 90dbaa63c..5946ea7f2 100644 --- a/internal/configuration/types.go +++ b/internal/configuration/types.go @@ -38,11 +38,11 @@ type SecretsSource struct { type CommandLineSource struct { koanf *koanf.Koanf flags *pflag.FlagSet - callback func(flag *pflag.Flag) (string, interface{}) + callback func(flag *pflag.Flag) (string, any) } // MapSource loads configuration from the command line flags. type MapSource struct { - m map[string]interface{} + m map[string]any koanf *koanf.Koanf } diff --git a/internal/handlers/handler_sign_webauthn.go b/internal/handlers/handler_sign_webauthn.go index d4007e4e2..6dec89009 100644 --- a/internal/handlers/handler_sign_webauthn.go +++ b/internal/handlers/handler_sign_webauthn.go @@ -41,7 +41,7 @@ func WebauthnAssertionGET(ctx *middlewares.AutheliaCtx) { webauthn.WithAllowedCredentials(user.WebAuthnCredentialDescriptors()), } - extensions := make(map[string]interface{}) + extensions := map[string]any{} if user.HasFIDOU2F() { extensions["appid"] = w.Config.RPOrigin diff --git a/internal/handlers/oidc.go b/internal/handlers/oidc.go index 20c51d2c2..2b2051f1b 100644 --- a/internal/handlers/oidc.go +++ b/internal/handlers/oidc.go @@ -8,8 +8,8 @@ import ( "github.com/authelia/authelia/v4/internal/session" ) -func oidcGrantRequests(ar fosite.AuthorizeRequester, consent *model.OAuth2ConsentSession, userSession *session.UserSession) (extraClaims map[string]interface{}) { - extraClaims = map[string]interface{}{} +func oidcGrantRequests(ar fosite.AuthorizeRequester, consent *model.OAuth2ConsentSession, userSession *session.UserSession) (extraClaims map[string]any) { + extraClaims = map[string]any{} for _, scope := range consent.GrantedScopes { if ar != nil { diff --git a/internal/middlewares/authelia_context.go b/internal/middlewares/authelia_context.go index aa7fd4926..af5bcbd66 100644 --- a/internal/middlewares/authelia_context.go +++ b/internal/middlewares/authelia_context.go @@ -95,7 +95,7 @@ func (ctx *AutheliaCtx) ReplyStatusCode(statusCode int) { } // ReplyJSON writes a JSON response. -func (ctx *AutheliaCtx) ReplyJSON(data interface{}, statusCode int) (err error) { +func (ctx *AutheliaCtx) ReplyJSON(data any, statusCode int) (err error) { var ( body []byte ) @@ -246,7 +246,7 @@ func (ctx *AutheliaCtx) ReplyOK() { } // ParseBody parse the request body into the type of value. -func (ctx *AutheliaCtx) ParseBody(value interface{}) error { +func (ctx *AutheliaCtx) ParseBody(value any) error { err := json.Unmarshal(ctx.PostBody(), &value) if err != nil { @@ -267,7 +267,7 @@ func (ctx *AutheliaCtx) ParseBody(value interface{}) error { } // SetJSONBody Set json body. -func (ctx *AutheliaCtx) SetJSONBody(value interface{}) error { +func (ctx *AutheliaCtx) SetJSONBody(value any) error { return ctx.ReplyJSON(OKResponse{Status: "OK", Data: value}, 0) } diff --git a/internal/middlewares/identity_verification.go b/internal/middlewares/identity_verification.go index 6189331e4..e4cbabce9 100644 --- a/internal/middlewares/identity_verification.go +++ b/internal/middlewares/identity_verification.go @@ -132,7 +132,7 @@ func IdentityVerificationFinish(args IdentityVerificationFinishArgs, next func(c } token, err := jwt.ParseWithClaims(finishBody.Token, &model.IdentityVerificationClaim{}, - func(token *jwt.Token) (interface{}, error) { + func(token *jwt.Token) (any, error) { return []byte(ctx.Configuration.JWTSecret), nil }) diff --git a/internal/middlewares/types.go b/internal/middlewares/types.go index 59cc95f77..58991a049 100644 --- a/internal/middlewares/types.go +++ b/internal/middlewares/types.go @@ -108,8 +108,8 @@ type IdentityVerificationFinishBody struct { // OKResponse model of a status OK response. type OKResponse struct { - Status string `json:"status"` - Data interface{} `json:"data,omitempty"` + Status string `json:"status"` + Data any `json:"data,omitempty"` } // ErrorResponse model of an error response. diff --git a/internal/model/oidc.go b/internal/model/oidc.go index c25e46eb4..99c778ac2 100644 --- a/internal/model/oidc.go +++ b/internal/model/oidc.go @@ -227,7 +227,7 @@ type OpenIDSession struct { ChallengeID uuid.UUID `db:"challenge_id"` ClientID string - Extra map[string]interface{} `json:"extra"` + Extra map[string]any `json:"extra"` } // Clone copies the OpenIDSession to a new fosite.Session. diff --git a/internal/model/types.go b/internal/model/types.go index 674e6aa43..325e9485c 100644 --- a/internal/model/types.go +++ b/internal/model/types.go @@ -49,7 +49,7 @@ func (ip IP) Value() (value driver.Value, err error) { } // Scan is the IP implementation of the sql.Scanner. -func (ip *IP) Scan(src interface{}) (err error) { +func (ip *IP) Scan(src any) (err error) { if src == nil { return fmt.Errorf(errFmtScanNil, ip) } @@ -85,7 +85,7 @@ func (ip NullIP) Value() (value driver.Value, err error) { } // Scan is the NullIP implementation of the sql.Scanner. -func (ip *NullIP) Scan(src interface{}) (err error) { +func (ip *NullIP) Scan(src any) (err error) { if src == nil { ip.IP = nil return nil @@ -128,7 +128,7 @@ func (b Base64) Value() (value driver.Value, err error) { } // Scan is the Base64 implementation of the sql.Scanner. -func (b *Base64) Scan(src interface{}) (err error) { +func (b *Base64) Scan(src any) (err error) { if src == nil { return fmt.Errorf(errFmtScanNil, b) } @@ -158,7 +158,7 @@ type StartupCheck interface { type StringSlicePipeDelimited []string // Scan is the StringSlicePipeDelimited implementation of the sql.Scanner. -func (s *StringSlicePipeDelimited) Scan(value interface{}) (err error) { +func (s *StringSlicePipeDelimited) Scan(value any) (err error) { var nullStr sql.NullString if err = nullStr.Scan(value); err != nil { diff --git a/internal/oidc/types_test.go b/internal/oidc/types_test.go index 936804f83..04e4aec8f 100644 --- a/internal/oidc/types_test.go +++ b/internal/oidc/types_test.go @@ -44,7 +44,7 @@ func TestNewSessionWithAuthorizeRequest(t *testing.T) { }, } - extra := map[string]interface{}{ + extra := map[string]any{ "preferred_username": "john", } diff --git a/internal/utils/crypto.go b/internal/utils/crypto.go index 853abf511..bf7ea44ff 100644 --- a/internal/utils/crypto.go +++ b/internal/utils/crypto.go @@ -122,7 +122,7 @@ func ConvertDERToPEM(der []byte, blockType PEMBlockType) ([]byte, error) { return buf.Bytes(), nil } -func publicKey(privateKey interface{}) interface{} { +func publicKey(privateKey any) any { switch k := privateKey.(type) { case *rsa.PrivateKey: return &k.PublicKey @@ -137,7 +137,7 @@ func publicKey(privateKey interface{}) interface{} { // PrivateKeyBuilder interface for a private key builder. type PrivateKeyBuilder interface { - Build() (interface{}, error) + Build() (any, error) } // RSAKeyBuilder builder of RSA private key. @@ -152,7 +152,7 @@ func (rkb RSAKeyBuilder) WithKeySize(bits int) RSAKeyBuilder { } // Build a RSA private key. -func (rkb RSAKeyBuilder) Build() (interface{}, error) { +func (rkb RSAKeyBuilder) Build() (any, error) { return rsa.GenerateKey(rand.Reader, rkb.keySizeInBits) } @@ -160,7 +160,7 @@ func (rkb RSAKeyBuilder) Build() (interface{}, error) { type Ed25519KeyBuilder struct{} // Build an Ed25519 private key. -func (ekb Ed25519KeyBuilder) Build() (interface{}, error) { +func (ekb Ed25519KeyBuilder) Build() (any, error) { _, priv, err := ed25519.GenerateKey(rand.Reader) return priv, err } @@ -177,7 +177,7 @@ func (ekb ECDSAKeyBuilder) WithCurve(curve elliptic.Curve) ECDSAKeyBuilder { } // Build an ECDSA private key. -func (ekb ECDSAKeyBuilder) Build() (interface{}, error) { +func (ekb ECDSAKeyBuilder) Build() (any, error) { return ecdsa.GenerateKey(ekb.curve, rand.Reader) } @@ -213,7 +213,7 @@ func ParseX509FromPEM(data []byte) (key any, err error) { } // CastX509AsCertificate converts an interface to an *x509.Certificate. -func CastX509AsCertificate(c interface{}) (certificate *x509.Certificate, ok bool) { +func CastX509AsCertificate(c any) (certificate *x509.Certificate, ok bool) { switch t := c.(type) { case x509.Certificate: return &t, true @@ -225,7 +225,7 @@ func CastX509AsCertificate(c interface{}) (certificate *x509.Certificate, ok boo } // IsX509PrivateKey returns true if the provided interface is an rsa.PrivateKey, ecdsa.PrivateKey, or ed25519.PrivateKey. -func IsX509PrivateKey(i interface{}) bool { +func IsX509PrivateKey(i any) bool { switch i.(type) { case rsa.PrivateKey, *rsa.PrivateKey, ecdsa.PrivateKey, *ecdsa.PrivateKey, ed25519.PrivateKey, *ed25519.PrivateKey: return true @@ -328,7 +328,7 @@ func WriteCertificateBytesToPEM(cert []byte, path string, csr bool) (err error) } // WriteKeyToPEM writes a key that can be encoded as a PEM to a file in the PEM format. -func WriteKeyToPEM(key interface{}, path string, pkcs8 bool) (err error) { +func WriteKeyToPEM(key any, path string, pkcs8 bool) (err error) { pemBlock, err := PEMBlockFromX509Key(key, pkcs8) if err != nil { return err @@ -349,7 +349,7 @@ func WriteKeyToPEM(key interface{}, path string, pkcs8 bool) (err error) { } // PEMBlockFromX509Key turns a PublicKey or PrivateKey into a pem.Block. -func PEMBlockFromX509Key(key interface{}, pkcs8 bool) (pemBlock *pem.Block, err error) { +func PEMBlockFromX509Key(key any, pkcs8 bool) (pemBlock *pem.Block, err error) { var ( data []byte blockType string @@ -491,7 +491,7 @@ func EllipticCurveFromString(curveString string) (curve elliptic.Curve) { } // PublicKeyFromPrivateKey returns a PublicKey when provided with a PrivateKey. -func PublicKeyFromPrivateKey(privateKey interface{}) (publicKey interface{}) { +func PublicKeyFromPrivateKey(privateKey any) (publicKey any) { switch k := privateKey.(type) { case *rsa.PrivateKey: return &k.PublicKey