-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(notifier): add new Telegram notifier
- Loading branch information
Showing
11 changed files
with
384 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/aerialls/scaleway-ddns/scaleway" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// Notifier interface to represent any notifier | ||
type Notifier interface { | ||
Notify(domain string, record string, previousIP string, newIP string) error | ||
} | ||
|
||
// Container structure to hold global objects | ||
type Container struct { | ||
Logger *logrus.Logger | ||
Config *Config | ||
DNS *scaleway.DNS | ||
Notifiers []Notifier | ||
} | ||
|
||
// NewContainer returns a new container instance | ||
func NewContainer( | ||
logger *logrus.Logger, | ||
config *Config, | ||
dns *scaleway.DNS, | ||
|
||
) *Container { | ||
return &Container{ | ||
Config: config, | ||
Logger: logger, | ||
DNS: dns, | ||
Notifiers: []Notifier{}, | ||
} | ||
} | ||
|
||
// AddNotifier adds a new notifier into the container | ||
func (c *Container) AddNotifier(notifier Notifier) { | ||
c.Logger.Debugf("New notifier %T added", notifier) | ||
c.Notifiers = append(c.Notifiers, notifier) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package config | ||
|
||
const ( | ||
// IntervalMinValue is the lowest possible value between two updates (in sec) | ||
IntervalMinValue = 60 | ||
) | ||
|
||
// Config struct for the configuration file | ||
type Config struct { | ||
Interval uint `yaml:"interval"` | ||
IPv4Config IPConfig `yaml:"ipv4"` | ||
IPv6Config IPConfig `yaml:"ipv6"` | ||
ScalewayConfig ScalewayConfig `yaml:"scaleway"` | ||
DomainConfig DomainConfig `yaml:"domain"` | ||
TelegramConfig TelegramConfig `yaml:"telegram"` | ||
} | ||
|
||
// IPConfig struct for the required configuration for IPv4 or IPv6 | ||
type IPConfig struct { | ||
URL string `yaml:"url"` | ||
Enabled bool `yaml:"enabled"` | ||
} | ||
|
||
// ScalewayConfig struct for the required configuration to use the Scaleway API | ||
type ScalewayConfig struct { | ||
OrganizationID string `yaml:"organization_id"` | ||
AccessKey string `yaml:"access_key"` | ||
SecretKey string `yaml:"secret_key"` | ||
} | ||
|
||
// DomainConfig struct for the domain parameters | ||
type DomainConfig struct { | ||
Name string `yaml:"name"` | ||
Record string `yaml:"record"` | ||
TTL uint32 `yaml:"ttl"` | ||
} | ||
|
||
// TelegramConfig struct for Telegram notifications after updates | ||
type TelegramConfig struct { | ||
Enabled bool `yaml:"enabled"` | ||
Token string `yaml:"token"` | ||
ChatID int64 `yaml:"chat_id"` | ||
Template string `yaml:"template"` | ||
} | ||
|
||
var ( | ||
// DefaultIPv4Config is the default configuration for IPv4 | ||
DefaultIPv4Config = IPConfig{ | ||
URL: "https://api-ipv4.ip.sb/ip", | ||
Enabled: true, | ||
} | ||
|
||
// DefaultIPv6Config is the default configuration for IPv6 | ||
DefaultIPv6Config = IPConfig{ | ||
URL: "https://api-ipv6.ip.sb/ip", | ||
Enabled: false, | ||
} | ||
|
||
// DefaultScalewayConfig is the default configuration to use the Scaleway API | ||
DefaultScalewayConfig = ScalewayConfig{} | ||
|
||
// DefaultDomainConfig is the default domain configuration for common parameters | ||
DefaultDomainConfig = DomainConfig{ | ||
Record: "ddns", | ||
TTL: 60, | ||
} | ||
|
||
// DefaultTelegramConfig is the default configuration to use Telegram notifications | ||
DefaultTelegramConfig = TelegramConfig{ | ||
Enabled: false, | ||
Template: "DNS record *{{ .Record }}.{{ .Domain }}* has been updated from *{{ .PreviousIP }}* to *{{ .NewIP }}*", | ||
} | ||
|
||
// DefaultConfig is the global default configuration. | ||
DefaultConfig = Config{ | ||
Interval: 300, | ||
DomainConfig: DefaultDomainConfig, | ||
IPv4Config: DefaultIPv4Config, | ||
IPv6Config: DefaultIPv6Config, | ||
ScalewayConfig: DefaultScalewayConfig, | ||
TelegramConfig: DefaultTelegramConfig, | ||
} | ||
) |
Oops, something went wrong.