[agent-operator] - 增加镜像同步的消息通知内容
This commit is contained in:
@@ -32,6 +32,8 @@ const imageSyncTemplate = `
|
|||||||
中转节点名称: {{.InnerWorkTopicName}}
|
中转节点名称: {{.InnerWorkTopicName}}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const ImageSyncTopicName = "imageSync"
|
||||||
|
|
||||||
var ImageSyncPushOptions = []pusher.PublishOption{
|
var ImageSyncPushOptions = []pusher.PublishOption{
|
||||||
pusher.WithTitle("镜像同步更新"),
|
pusher.WithTitle("镜像同步更新"),
|
||||||
pusher.WithPriority("3"),
|
pusher.WithPriority("3"),
|
||||||
@@ -59,6 +61,8 @@ func (d *ImageSyncMessage) PublishMessage() *pusher.Message {
|
|||||||
|
|
||||||
parseTemplate := d.ParseTemplate()
|
parseTemplate := d.ParseTemplate()
|
||||||
|
|
||||||
|
pusher.DefaultPusherClient.ChangeTopicName(ImageSyncTopicName)
|
||||||
|
|
||||||
result, err := pusher.DefaultPusherClient.PublishDefault(parseTemplate, ImageSyncPushOptions)
|
result, err := pusher.DefaultPusherClient.PublishDefault(parseTemplate, ImageSyncPushOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorF("[ImageSyncMessage] - message push error ! %s", err.Error())
|
log.ErrorF("[ImageSyncMessage] - message push error ! %s", err.Error())
|
||||||
|
|||||||
@@ -68,6 +68,10 @@ func NewDefaultClient() *Client {
|
|||||||
return New(defaultConfig)
|
return New(defaultConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) ChangeTopicName(topicName string) {
|
||||||
|
c.config.DefaultTopic = topicName
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) PublishDefault(message bytes.Buffer, options []PublishOption) (*Message, error) {
|
func (c *Client) PublishDefault(message bytes.Buffer, options []PublishOption) (*Message, error) {
|
||||||
if c.config.DefaultTopic == "" {
|
if c.config.DefaultTopic == "" {
|
||||||
return nil, errors.New("[PublishDefault] - topic empty")
|
return nil, errors.New("[PublishDefault] - topic empty")
|
||||||
@@ -135,17 +139,17 @@ func (c *Client) expandTopicURL(topic string) (string, error) {
|
|||||||
if !topicRegex.MatchString(topic) {
|
if !topicRegex.MatchString(topic) {
|
||||||
return "", fmt.Errorf("invalid topic name: %s", topic)
|
return "", fmt.Errorf("invalid topic name: %s", topic)
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%s/%s", c.config.DefaultHost, topic), nil
|
return fmt.Sprintf("%s/%s", c.config.Host, topic), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) parseConfigToOption(options []PublishOption) []PublishOption {
|
func (c *Client) parseConfigToOption(options []PublishOption) []PublishOption {
|
||||||
config := c.config
|
config := c.config
|
||||||
|
|
||||||
if config.DefaultToken != "" {
|
if config.Token != "" {
|
||||||
options = append(options, WithBearerAuth(config.DefaultToken))
|
options = append(options, WithBearerAuth(config.Token))
|
||||||
} else if config.DefaultUser != "" {
|
} else if config.User != "" {
|
||||||
if *config.DefaultPassword != "" {
|
if *config.Password != "" {
|
||||||
options = append(options, WithBasicAuth(config.DefaultUser, *config.DefaultPassword))
|
options = append(options, WithBasicAuth(config.User, *config.Password))
|
||||||
} else {
|
} else {
|
||||||
log.ErrorF("[parseConfigToOption] - default password is empty!")
|
log.ErrorF("[parseConfigToOption] - default password is empty!")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,13 +16,13 @@ const (
|
|||||||
|
|
||||||
// Config is the config struct for a Client
|
// Config is the config struct for a Client
|
||||||
type Config struct {
|
type Config struct {
|
||||||
DefaultHost string `yaml:"default-host"`
|
Host string `yaml:"default-host"`
|
||||||
DefaultUser string `yaml:"default-user"`
|
User string `yaml:"default-user"`
|
||||||
DefaultPassword *string `yaml:"default-password"`
|
Password *string `yaml:"default-password"`
|
||||||
DefaultToken string `yaml:"default-token"`
|
Token string `yaml:"default-token"`
|
||||||
DefaultCommand string `yaml:"default-command"`
|
DefaultCommand string `yaml:"default-command"`
|
||||||
DefaultTopic string `yaml:"default-topic"`
|
DefaultTopic string `yaml:"default-topic"`
|
||||||
Subscribe []Subscribe `yaml:"subscribe"`
|
Subscribe []Subscribe `yaml:"subscribe"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subscribe is the struct for a Subscription within Config
|
// Subscribe is the struct for a Subscription within Config
|
||||||
@@ -38,13 +38,13 @@ type Subscribe struct {
|
|||||||
// NewDefaultConfig creates a new Config struct for a Client
|
// NewDefaultConfig creates a new Config struct for a Client
|
||||||
func NewDefaultConfig() *Config {
|
func NewDefaultConfig() *Config {
|
||||||
return &Config{
|
return &Config{
|
||||||
DefaultHost: DefaultBaseURL,
|
Host: DefaultBaseURL,
|
||||||
DefaultUser: "",
|
User: "",
|
||||||
DefaultPassword: nil,
|
Password: nil,
|
||||||
DefaultToken: DefaultBaseToken,
|
Token: DefaultBaseToken,
|
||||||
DefaultTopic: DefaultTopic,
|
DefaultTopic: DefaultTopic,
|
||||||
DefaultCommand: "",
|
DefaultCommand: "",
|
||||||
Subscribe: nil,
|
Subscribe: nil,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,12 @@ package router
|
|||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"io.wdd.message_pusher/cmii"
|
"io.wdd.message_pusher/cmii"
|
||||||
|
"io.wdd.message_pusher/pusher"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const CmiiUpdateTopicName = "cmii"
|
||||||
|
|
||||||
func CMIIRouter(r *gin.Engine) {
|
func CMIIRouter(r *gin.Engine) {
|
||||||
|
|
||||||
cmiiGroup := r.Group("/cmii")
|
cmiiGroup := r.Group("/cmii")
|
||||||
@@ -37,6 +40,8 @@ func CmiiUpdate(c *gin.Context) {
|
|||||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body"})
|
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pusher.DefaultPusherClient.ChangeTopicName(CmiiUpdateTopicName)
|
||||||
// 处理请求
|
// 处理请求
|
||||||
upgradeMessage := messageBody.DefaultPushUpgradeMessage()
|
upgradeMessage := messageBody.DefaultPushUpgradeMessage()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user