fix: make old notify send SDK compatible (#7628)

This commit is contained in:
Rain Zheng
2020-08-25 18:48:32 +08:00
committed by GitHub
parent 4593c1fb99
commit 707051ec0b
2 changed files with 35 additions and 13 deletions
+33 -11
View File
@@ -20,6 +20,7 @@ import (
api "yunion.io/x/onecloud/pkg/apis/notify"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/modules/notify"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
@@ -30,20 +31,41 @@ func init() {
TOPIC string `help:"Topic"`
Priority string `help:"Priority"`
MESSAGE string `help:"Message"`
Oldsdk bool `help:"Old sdk"`
}
R(&NotificationCreateInput{}, "notify-send", "Send a notify message", func(s *mcclient.ClientSession, args *NotificationCreateInput) error {
input := api.NotificationCreateInput{
Receivers: args.Receivers,
ContactType: args.ContactType,
Topic: args.TOPIC,
Priority: args.Priority,
Message: args.MESSAGE,
var (
ret jsonutils.JSONObject
err error
)
if args.Oldsdk {
msg := notify.SNotifyMessage{
Uid: args.Receivers,
ContactType: notify.TNotifyChannel(args.ContactType),
Topic: args.TOPIC,
Priority: notify.TNotifyPriority(args.Priority),
Msg: args.MESSAGE,
Remark: "",
Broadcast: false,
}
err = notify.Notifications.Send(s, msg)
if err != nil {
return err
}
} else {
input := api.NotificationCreateInput{
Receivers: args.Receivers,
ContactType: args.ContactType,
Topic: args.TOPIC,
Priority: args.Priority,
Message: args.MESSAGE,
}
ret, err = modules.Notification.Create(s, jsonutils.Marshal(input))
if err != nil {
return err
}
printObject(ret)
}
ret, err := modules.Notification.Create(s, jsonutils.Marshal(input))
if err != nil {
return err
}
printObject(ret)
return nil
})
type NotificationInput struct {
@@ -40,7 +40,7 @@ type SNotifyMessage struct {
}
type SNotifyV2Message struct {
ReceiverIds []string `json:"receiver_ids"`
Receivers []string `json:"receivers"`
ContactType string `json:"contact_type"`
Topic string `json:"topic"`
Priority string `json:"priority"`
@@ -73,7 +73,7 @@ func (manager *NotificationManager) Send(s *mcclient.ClientSession, msg SNotifyM
receiverIds = append(receiverIds, msg.Uid...)
v2msg := SNotifyV2Message{
ReceiverIds: receiverIds,
Receivers: receiverIds,
ContactType: string(msg.ContactType),
Topic: msg.Topic,
Priority: string(msg.Priority),