Skip to content

Commit fbef1ac

Browse files
committed
refactor: Rename api url option
1 parent acafd93 commit fbef1ac

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2247,7 +2247,7 @@ Here's an example of what the notifications look like:
22472247
| Parameter | Description | Default |
22482248
|:---------------------------------------------|:------------------------------------------------------------------------------------------------------------|:----------------------------|
22492249
| `alerting.threema-gateway` | Configuration for alerts of type `threema-gateway` | `{}` |
2250-
| `alerting.threema-gateway.api-url` | Threema Gateway API URL | `https://msgapi.threema.ch` |
2250+
| `alerting.threema-gateway.api-base-url` | Threema Gateway API Base URL | `https://msgapi.threema.ch` |
22512251
| `alerting.threema-gateway.send-mode` | Mode used to send the alert, currently only `basic` is supported | `"basic"` |
22522252
| `alerting.threema-gateway.api-identity` | Personal Threema API Identity | Required `""` |
22532253
| `alerting.threema-gateway.recipients` | Recipients in format `[<type>:]<identifier>`, where type is `id`, `phone` or `email`. Type defaults to `id` | Required `""` |

alerting/provider/threemagateway/threemagateway.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import (
1717
// TODO#1464: Add tests
1818

1919
const (
20-
defaultApiUrl = "https://msgapi.threema.ch"
21-
defaultMode = "basic"
20+
defaultApiBaseUrl = "https://msgapi.threema.ch"
21+
defaultMode = "basic"
2222
)
2323

2424
var (
@@ -70,7 +70,7 @@ func (m SendMode) MarshalText() ([]byte, error) {
7070
}
7171

7272
type Config struct {
73-
ApiUrl string `yaml:"api-url"`
73+
ApiBaseUrl string `yaml:"api-base-url"`
7474
Mode *SendMode `yaml:"send-mode"`
7575
ApiIdentity string `yaml:"api-identity"`
7676
Recipients []Recipient `yaml:"recipients"`
@@ -79,8 +79,8 @@ type Config struct {
7979

8080
func (cfg *Config) Validate() error {
8181
// Validate API URL
82-
if len(cfg.ApiUrl) == 0 {
83-
cfg.ApiUrl = defaultApiUrl
82+
if len(cfg.ApiBaseUrl) == 0 {
83+
cfg.ApiBaseUrl = defaultApiBaseUrl
8484
}
8585

8686
// Validate Mode
@@ -123,8 +123,8 @@ func (cfg *Config) Validate() error {
123123
}
124124

125125
func (cfg *Config) Merge(override *Config) {
126-
if len(override.ApiUrl) > 0 {
127-
cfg.ApiUrl = override.ApiUrl
126+
if len(override.ApiBaseUrl) > 0 {
127+
cfg.ApiBaseUrl = override.ApiBaseUrl
128128
}
129129
if override.Mode != nil {
130130
cfg.Mode = override.Mode
@@ -152,6 +152,7 @@ type Override struct {
152152
}
153153

154154
func (provider *AlertProvider) Validate() error {
155+
// TODO#1464 Validate overrides?
155156
return provider.DefaultConfig.Validate()
156157
}
157158

@@ -198,7 +199,7 @@ func (provider *AlertProvider) buildMessageBody(ep *endpoint.Endpoint, alert *al
198199
}
199200

200201
func (provider *AlertProvider) prepareRequest(cfg *Config, body string) (*http.Request, error) {
201-
requestUrl := cfg.ApiUrl
202+
requestUrl := cfg.ApiBaseUrl
202203
switch cfg.Mode.Type {
203204
case ModeTypeBasic:
204205
requestUrl += "/send_simple"
@@ -285,7 +286,8 @@ func (provider *AlertProvider) GetConfig(group string, alert *alert.Alert) (*Con
285286
}
286287
cfg.Merge(&overrideConfig)
287288
}
288-
return &cfg, cfg.Validate()
289+
err := cfg.Validate()
290+
return &cfg, err
289291
}
290292

291293
func (provider *AlertProvider) ValidateOverrides(group string, alert *alert.Alert) error {

0 commit comments

Comments
 (0)