@@ -2,12 +2,14 @@ package daemon
22
33import (
44 "errors"
5+ "fmt"
56 "github.com/creasty/defaults"
67 "github.com/icinga/icinga-go-library/config"
78 "github.com/icinga/icinga-go-library/database"
89 "github.com/icinga/icinga-go-library/logging"
910 "github.com/icinga/icinga-go-library/utils"
1011 "github.com/icinga/icinga-notifications/internal"
12+ "net/url"
1113 "os"
1214 "time"
1315)
@@ -25,6 +27,12 @@ type ConfigFile struct {
2527 Icingaweb2URL string `yaml:"icingaweb2-url"`
2628 Database database.Config `yaml:"database"`
2729 Logging logging.Config `yaml:"logging"`
30+
31+ // IcingaWeb2UrlParsed holds the parsed Icinga Web 2 URL after validation of the config file.
32+ //
33+ // This field is not part of the YAML config and is only populated after successful validation.
34+ // The resulting URL always ends with a trailing slash, making it easier to resolve relative paths against it.
35+ IcingaWeb2UrlParsed * url.URL
2836}
2937
3038// SetDefaults implements the defaults.Setter interface.
@@ -44,6 +52,15 @@ func (c *ConfigFile) Validate() error {
4452 return err
4553 }
4654
55+ if c .Icingaweb2URL == "" {
56+ return errors .New ("icingaweb2-url must be set" )
57+ }
58+
59+ parsedUrl , err := url .Parse (c .Icingaweb2URL )
60+ if err != nil {
61+ return fmt .Errorf ("invalid icingaweb2-url: %w" , err )
62+ }
63+ c .IcingaWeb2UrlParsed = parsedUrl .JoinPath ("/" )
4764 return nil
4865}
4966
0 commit comments