Merge branch 'master' of https://github.com/future-architect/vuls
* 'master' of https://github.com/future-architect/vuls: Add Telegram support (#762)
This commit is contained in:
		@@ -133,6 +133,7 @@ type Config struct {
 | 
			
		||||
	Stride   StrideConf   `json:"-"`
 | 
			
		||||
	HipChat  HipChatConf  `json:"-"`
 | 
			
		||||
	ChatWork ChatWorkConf `json:"-"`
 | 
			
		||||
	Telegram TelegramConf `json:"-"`
 | 
			
		||||
	Saas     SaasConf     `json:"-"`
 | 
			
		||||
 | 
			
		||||
	RefreshCve        bool `json:"refreshCve"`
 | 
			
		||||
@@ -140,6 +141,7 @@ type Config struct {
 | 
			
		||||
	ToStride          bool `json:"toStride"`
 | 
			
		||||
	ToHipChat         bool `json:"toHipChat"`
 | 
			
		||||
	ToChatWork        bool `json:"toChatWork"`
 | 
			
		||||
	ToTelegram        bool `json:"ToTelegram"`
 | 
			
		||||
	ToEmail           bool `json:"toEmail"`
 | 
			
		||||
	ToSyslog          bool `json:"toSyslog"`
 | 
			
		||||
	ToLocalFile       bool `json:"toLocalFile"`
 | 
			
		||||
@@ -287,6 +289,10 @@ func (c Config) ValidateOnReport() bool {
 | 
			
		||||
		errs = append(errs, strideerrs...)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if telegramerrs := c.Telegram.Validate(); 0 < len(telegramerrs) {
 | 
			
		||||
		errs = append(errs, telegramerrs...)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if saaserrs := c.Saas.Validate(); 0 < len(saaserrs) {
 | 
			
		||||
		errs = append(errs, saaserrs...)
 | 
			
		||||
	}
 | 
			
		||||
@@ -557,6 +563,32 @@ func (c *ChatWorkConf) Validate() (errs []error) {
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// TelegramConf is Telegram config
 | 
			
		||||
type TelegramConf struct {
 | 
			
		||||
	Token  string `json:"-"`
 | 
			
		||||
	ChatID string `json:"-"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Validate validates configuration
 | 
			
		||||
func (c *TelegramConf) Validate() (errs []error) {
 | 
			
		||||
	if !Conf.ToTelegram {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	if len(c.ChatID) == 0 {
 | 
			
		||||
		errs = append(errs, fmt.Errorf("TelegramConf.ChatID must not be empty"))
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if len(c.Token) == 0 {
 | 
			
		||||
		errs = append(errs, fmt.Errorf("TelegramConf.Token must not be empty"))
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	_, err := valid.ValidateStruct(c)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		errs = append(errs, err)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// SaasConf is stride config
 | 
			
		||||
type SaasConf struct {
 | 
			
		||||
	GroupID int    `json:"-"`
 | 
			
		||||
 
 | 
			
		||||
@@ -42,6 +42,7 @@ func (c TOMLLoader) Load(pathToToml, keyPass string) error {
 | 
			
		||||
	Conf.Stride = conf.Stride
 | 
			
		||||
	Conf.HipChat = conf.HipChat
 | 
			
		||||
	Conf.ChatWork = conf.ChatWork
 | 
			
		||||
	Conf.Telegram = conf.Telegram
 | 
			
		||||
	Conf.Saas = conf.Saas
 | 
			
		||||
	Conf.Syslog = conf.Syslog
 | 
			
		||||
	Conf.HTTP = conf.HTTP
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user