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