refactor: added more logging info

This commit is contained in:
David Allen 2024-12-12 14:29:41 -07:00
parent e1ab1e7102
commit 9951b9a1f3
Signed by: towk
GPG key ID: 793B2924A49B3A3F
2 changed files with 11 additions and 14 deletions

View file

@ -212,7 +212,7 @@ func GenerateWithTarget(config *config.Config, target string) (FileMap, error) {
// load target information from config // load target information from config
targetInfo, ok = config.Targets[target] targetInfo, ok = config.Targets[target]
if !ok { if !ok {
log.Warn().Msg("target not found in config") log.Warn().Str("target", target).Msg("target not found in config")
} }
// if no plugin supplied in config target, then using the target supplied // if no plugin supplied in config target, then using the target supplied
@ -224,7 +224,7 @@ func GenerateWithTarget(config *config.Config, target string) (FileMap, error) {
generator, ok = DefaultGenerators[target] generator, ok = DefaultGenerators[target]
if !ok { if !ok {
// only load the plugin needed for this target if we don't find default // only load the plugin needed for this target if we don't find default
log.Error().Msg("could not find target in default generators") log.Warn().Str("target", target).Msg("could not find target in default generators")
generator, err = LoadPlugin(targetInfo.Plugin) generator, err = LoadPlugin(targetInfo.Plugin)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to load plugin: %v", err) return nil, fmt.Errorf("failed to load plugin: %v", err)

View file

@ -58,7 +58,7 @@ func New(conf *config.Config) *Server {
// return based on config values // return based on config values
return &Server{ return &Server{
Config: conf, Config: conf,
Server: &http.Server{Addr: fmt.Sprintf("%s", conf.Server.Host)}, Server: &http.Server{Addr: conf.Server.Host},
Jwks: Jwks{ Jwks: Jwks{
Uri: conf.Server.Jwks.Uri, Uri: conf.Server.Jwks.Uri,
Retries: conf.Server.Jwks.Retries, Retries: conf.Server.Jwks.Retries,
@ -138,29 +138,26 @@ func (s *Server) Generate(opts ...client.Option) func(w http.ResponseWriter, r *
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
// get all of the expect query URL params and validate // get all of the expect query URL params and validate
var ( var (
target string = r.URL.Query().Get("target") targetParam string = r.URL.Query().Get("target")
target *Target = s.getTarget(targetParam)
outputs generator.FileMap
err error
) )
s.GeneratorParams = parseGeneratorParams(r, opts...) s.GeneratorParams = parseGeneratorParams(r, opts...)
if target == "" { if targetParam == "" {
writeErrorResponse(w, "must specify a target") writeErrorResponse(w, "must specify a target")
return return
} }
// try to generate with target supplied by client first // try to generate with target supplied by client first
var ( if target != nil {
t *Target = s.getTarget(target) outputs, err = generator.Generate(target.PluginPath, s.GeneratorParams)
outputs generator.FileMap
err error
)
if t != nil {
outputs, err = generator.Generate(t.PluginPath, s.GeneratorParams)
if err != nil { if err != nil {
} }
} else { } else {
// try and generate a new config file from supplied params // try and generate a new config file from supplied params
outputs, err = generator.GenerateWithTarget(s.Config, target) outputs, err = generator.GenerateWithTarget(s.Config, targetParam)
if err != nil { if err != nil {
writeErrorResponse(w, "failed to generate file: %v", err) writeErrorResponse(w, "failed to generate file: %v", err)
return return