Merging upstream version 0.8.13.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
4ccf9dc8f1
commit
bc0f764250
28 changed files with 556 additions and 76 deletions
|
@ -55,12 +55,18 @@ func (config *Config) SetURL(url *url.URL) error {
|
|||
// It sets the host, path, and query parameters, validating host and path, and returns an error if parsing or validation fails.
|
||||
func (config *Config) setURL(resolver types.ConfigQueryResolver, url *url.URL) error {
|
||||
config.Host = url.Host
|
||||
if config.Host != larkHost && config.Host != feishuHost {
|
||||
// Handle documentation generation or empty host
|
||||
if config.Host == "" || (url.User != nil && url.User.Username() == "dummy") {
|
||||
config.Host = "open.larksuite.com"
|
||||
} else if config.Host != larkHost && config.Host != feishuHost {
|
||||
return ErrInvalidHost
|
||||
}
|
||||
|
||||
config.Path = strings.Trim(url.Path, "/")
|
||||
if config.Path == "" {
|
||||
// Handle documentation generation with empty path
|
||||
if config.Path == "" && (url.User != nil && url.User.Username() == "dummy") {
|
||||
config.Path = "token"
|
||||
} else if config.Path == "" {
|
||||
return ErrNoPath
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ var httpClient = &http.Client{Timeout: defaultTime}
|
|||
// Service sends notifications to Lark.
|
||||
type Service struct {
|
||||
standard.Standard
|
||||
config *Config
|
||||
Config *Config
|
||||
pkr format.PropKeyResolver
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ func (service *Service) Send(message string, params *types.Params) error {
|
|||
return ErrLargeMessage
|
||||
}
|
||||
|
||||
config := *service.config
|
||||
config := *service.Config
|
||||
if err := service.pkr.UpdateConfigFromParams(&config, params); err != nil {
|
||||
return fmt.Errorf("updating params: %w", err)
|
||||
}
|
||||
|
@ -79,10 +79,10 @@ func (service *Service) Send(message string, params *types.Params) error {
|
|||
// Initialize configures the service with a URL and logger.
|
||||
func (service *Service) Initialize(configURL *url.URL, logger types.StdLogger) error {
|
||||
service.SetLogger(logger)
|
||||
service.config = &Config{}
|
||||
service.pkr = format.NewPropKeyResolver(service.config)
|
||||
service.Config = &Config{}
|
||||
service.pkr = format.NewPropKeyResolver(service.Config)
|
||||
|
||||
return service.config.SetURL(configURL)
|
||||
return service.Config.SetURL(configURL)
|
||||
}
|
||||
|
||||
// GetID returns the service identifier.
|
||||
|
@ -174,8 +174,8 @@ func (service *Service) handleResponse(resp *http.Response) error {
|
|||
|
||||
service.Logf(
|
||||
"Notification sent successfully to %s/%s",
|
||||
service.config.Host,
|
||||
service.config.Path,
|
||||
service.Config.Host,
|
||||
service.Config.Path,
|
||||
)
|
||||
|
||||
return nil
|
||||
|
|
|
@ -88,14 +88,14 @@ var _ = ginkgo.Describe("Lark Test", func() {
|
|||
data[i] = "0123456789"
|
||||
}
|
||||
message := strings.Join(data, "")
|
||||
service := Service{config: &Config{Host: larkHost, Path: "token"}}
|
||||
service := Service{Config: &Config{Host: larkHost, Path: "token"}}
|
||||
gomega.Expect(service.Send(message, nil)).To(gomega.MatchError(ErrLargeMessage))
|
||||
})
|
||||
})
|
||||
|
||||
ginkgo.When("an invalid param is passed", func() {
|
||||
ginkgo.It("should fail to send messages", func() {
|
||||
service := Service{config: &Config{Host: larkHost, Path: "token"}}
|
||||
service := Service{Config: &Config{Host: larkHost, Path: "token"}}
|
||||
gomega.Expect(
|
||||
service.Send("test message", &types.Params{"invalid": "value"}),
|
||||
).To(gomega.MatchError(gomega.ContainSubstring("not a valid config key: invalid")))
|
||||
|
|
|
@ -119,7 +119,10 @@ func (config *Config) setURL(resolver types.ConfigQueryResolver, url *url.URL) e
|
|||
return err
|
||||
}
|
||||
|
||||
if config.Host == "" {
|
||||
// Allow dummy URL during documentation generation
|
||||
if config.Host == "" && (url.User != nil && url.User.Username() == "dummy") {
|
||||
config.Host = "dummy.webhook.office.com"
|
||||
} else if config.Host == "" {
|
||||
return ErrMissingHostParameter
|
||||
}
|
||||
|
||||
|
|
|
@ -14,5 +14,11 @@ func DocsURL(path string) string {
|
|||
path = path[1:]
|
||||
}
|
||||
|
||||
return fmt.Sprintf("https://nicholas-fedor.github.io/shoutrrr/%s/%s", meta.DocsVersion, path)
|
||||
// Use commit for dev builds, version for releases
|
||||
version := meta.GetVersion()
|
||||
if version == "unknown" || version == "dev" {
|
||||
version = meta.GetCommit()
|
||||
}
|
||||
|
||||
return fmt.Sprintf("https://nicholas-fedor.github.io/shoutrrr/%s/%s", version, path)
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ var _ = ginkgo.Describe("the util package", func() {
|
|||
ginkgo.It("should return the expected URL", func() {
|
||||
expectedBase := fmt.Sprintf(
|
||||
`https://nicholas-fedor.github.io/shoutrrr/%s/`,
|
||||
meta.DocsVersion,
|
||||
meta.GetVersion(),
|
||||
)
|
||||
gomega.Expect(util.DocsURL(``)).To(gomega.Equal(expectedBase))
|
||||
gomega.Expect(util.DocsURL(`services/logger`)).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue