Fix linter warnings
This commit is contained in:
parent
9f53e37693
commit
be15b18259
6 changed files with 23 additions and 17 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright CAcert Inc
|
Copyright CAcert Inc.
|
||||||
SPDX-License-Identifier: Apache-2.0
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@ -28,11 +28,12 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.cacert.org/cacert/oidc-demo-app/ui"
|
|
||||||
"github.com/knadh/koanf"
|
"github.com/knadh/koanf"
|
||||||
"github.com/knadh/koanf/parsers/toml"
|
"github.com/knadh/koanf/parsers/toml"
|
||||||
"github.com/knadh/koanf/providers/confmap"
|
"github.com/knadh/koanf/providers/confmap"
|
||||||
|
|
||||||
|
"code.cacert.org/cacert/oidc-demo-app/ui"
|
||||||
|
|
||||||
"code.cacert.org/cacert/oidc-demo-app/internal/handlers"
|
"code.cacert.org/cacert/oidc-demo-app/internal/handlers"
|
||||||
"code.cacert.org/cacert/oidc-demo-app/internal/services"
|
"code.cacert.org/cacert/oidc-demo-app/internal/services"
|
||||||
)
|
)
|
||||||
|
@ -83,7 +84,7 @@ func (f *StaticFileInfoWrapper) ModTime() time.Time {
|
||||||
return f.fixedModTime
|
return f.fixedModTime
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() { //nolint:cyclop
|
||||||
var (
|
var (
|
||||||
logLevel = new(slog.LevelVar)
|
logLevel = new(slog.LevelVar)
|
||||||
logHandler slog.Handler
|
logHandler slog.Handler
|
||||||
|
@ -100,10 +101,6 @@ func main() {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
oidcServer := config.MustString("oidc.server")
|
|
||||||
oidcClientID := config.MustString("oidc.client-id")
|
|
||||||
oidcClientSecret := config.MustString("oidc.client-secret")
|
|
||||||
|
|
||||||
if level := config.Bytes("log.level"); level != nil {
|
if level := config.Bytes("log.level"); level != nil {
|
||||||
if err := logLevel.UnmarshalText(level); err != nil {
|
if err := logLevel.UnmarshalText(level); err != nil {
|
||||||
logger.Error("could not parse log level", "error", err)
|
logger.Error("could not parse log level", "error", err)
|
||||||
|
@ -121,6 +118,10 @@ func main() {
|
||||||
|
|
||||||
logLogger := slog.NewLogLogger(logger.Handler(), logLevel.Level())
|
logLogger := slog.NewLogLogger(logger.Handler(), logLevel.Level())
|
||||||
|
|
||||||
|
oidcServer := config.MustString("oidc.server")
|
||||||
|
oidcClientID := config.MustString("oidc.client-id")
|
||||||
|
oidcClientSecret := config.MustString("oidc.client-secret")
|
||||||
|
|
||||||
logger.Info(
|
logger.Info(
|
||||||
"Starting CAcert OpenID Connect demo application",
|
"Starting CAcert OpenID Connect demo application",
|
||||||
"version", version, "commit", commit, "date", date,
|
"version", version, "commit", commit, "date", date,
|
||||||
|
@ -152,9 +153,13 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionPath, sessionAuthKey, sessionEncKey, err := configureSessionParameters(logger, config)
|
sessionPath, sessionAuthKey, sessionEncKey, err := configureSessionParameters(logger, config)
|
||||||
if err := services.InitSessionStore(logger, sessionPath, sessionAuthKey, sessionEncKey); err != nil {
|
if err != nil {
|
||||||
logger.Error("could not initialize session store", "error", err)
|
logger.Error("error configuring session parameters", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := services.InitSessionStore(sessionPath, sessionAuthKey, sessionEncKey); err != nil {
|
||||||
|
logger.Error("could not initialize session store", "error", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +170,6 @@ func main() {
|
||||||
tokenInfoService, err := services.InitTokenInfoService(logger, oidcInfo)
|
tokenInfoService, err := services.InitTokenInfoService(logger, oidcInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("could not initialize token info service", "error", err)
|
logger.Error("could not initialize token info service", "error", err)
|
||||||
|
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,9 +24,10 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||||
|
|
||||||
"code.cacert.org/cacert/oidc-demo-app/internal/services"
|
"code.cacert.org/cacert/oidc-demo-app/internal/services"
|
||||||
"code.cacert.org/cacert/oidc-demo-app/ui"
|
"code.cacert.org/cacert/oidc-demo-app/ui"
|
||||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ProtectedResource struct {
|
type ProtectedResource struct {
|
||||||
|
|
|
@ -31,7 +31,9 @@ import (
|
||||||
"github.com/knadh/koanf"
|
"github.com/knadh/koanf"
|
||||||
)
|
)
|
||||||
|
|
||||||
func StartApplication(ctx context.Context, logger *slog.Logger, server *http.Server, publicURL string, config *koanf.Koanf) error {
|
func StartApplication(
|
||||||
|
ctx context.Context, logger *slog.Logger, server *http.Server, publicURL string, config *koanf.Koanf,
|
||||||
|
) error {
|
||||||
done := make(chan bool)
|
done := make(chan bool)
|
||||||
quit := make(chan os.Signal, 1)
|
quit := make(chan os.Signal, 1)
|
||||||
signal.Notify(quit, os.Interrupt)
|
signal.Notify(quit, os.Interrupt)
|
||||||
|
|
|
@ -66,10 +66,10 @@ func DiscoverOIDC(logger *slog.Logger, params *OidcParams) (*OIDCInformation, er
|
||||||
)
|
)
|
||||||
|
|
||||||
return nil, fmt.Errorf("could not parse parameter value: %w", err)
|
return nil, fmt.Errorf("could not parse parameter value: %w", err)
|
||||||
} else {
|
|
||||||
discoveryURL.Path = "/.well-known/openid-configuration"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
discoveryURL.Path = "/.well-known/openid-configuration"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
body []byte
|
body []byte
|
||||||
req *http.Request
|
req *http.Request
|
||||||
|
|
|
@ -27,7 +27,7 @@ func GenerateKey(length int) ([]byte, error) {
|
||||||
|
|
||||||
read, err := rand.Read(key)
|
read, err := rand.Read(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not generate key", err)
|
return nil, fmt.Errorf("could not generate key: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if read != length {
|
if read != length {
|
||||||
|
|
|
@ -19,7 +19,6 @@ package services
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/gorilla/sessions"
|
"github.com/gorilla/sessions"
|
||||||
|
@ -34,7 +33,7 @@ const (
|
||||||
SessionRedirectTarget
|
SessionRedirectTarget
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitSessionStore(logger *slog.Logger, sessionPath string, keys ...[]byte) error {
|
func InitSessionStore(sessionPath string, keys ...[]byte) error {
|
||||||
store = sessions.NewFilesystemStore(sessionPath, keys...)
|
store = sessions.NewFilesystemStore(sessionPath, keys...)
|
||||||
|
|
||||||
if _, err := os.Stat(sessionPath); err != nil {
|
if _, err := os.Stat(sessionPath); err != nil {
|
||||||
|
|
Loading…
Reference in a new issue