mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
feat(notify): user cmdline helpler for climc notify-receiver-xxx
This commit is contained in:
@@ -15,165 +15,21 @@
|
||||
package notifyv2
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/cmd/climc/shell"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
options "yunion.io/x/onecloud/pkg/mcclient/options/notify"
|
||||
)
|
||||
|
||||
func init() {
|
||||
type ReceiverListOptions struct {
|
||||
options.BaseListOptions
|
||||
UId string `help:"user id in keystone"`
|
||||
UName string `help:"user name in keystone"`
|
||||
EnabledContactType string `help:"enabled contact type"`
|
||||
VerifiedContactType string `help:"verified contact type"`
|
||||
}
|
||||
R(&ReceiverListOptions{}, "notify-receiver-list", "List notify receiver", func(s *mcclient.ClientSession, args *ReceiverListOptions) error {
|
||||
params, err := options.ListStructToParams(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
result, err := modules.NotifyReceiver.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, modules.NotifyReceiver.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
type ReceiverCreateOptions struct {
|
||||
UID string `help:"user id in keystone"`
|
||||
Email string `help:"email of receiver"`
|
||||
Mobile string `help:"mobile of receiver"`
|
||||
EnabledContactTypes []string `help:"enabled contact type"`
|
||||
}
|
||||
R(&ReceiverCreateOptions{}, "notify-receiver-create", "Create notify receiver", func(s *mcclient.ClientSession, args *ReceiverCreateOptions) error {
|
||||
params := jsonutils.Marshal(args).(*jsonutils.JSONDict)
|
||||
receiver, err := modules.NotifyReceiver.Create(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(receiver)
|
||||
return nil
|
||||
})
|
||||
type ReceiverUpdateInput struct {
|
||||
ID string `help:"Id or Name of receiver"`
|
||||
Email string `help:"email of receiver"`
|
||||
Mobile string `help:"mobile of receiver"`
|
||||
EnabledContactType []string `help:"enabled contact type"`
|
||||
}
|
||||
R(&ReceiverUpdateInput{}, "notify-receiver-update", "Update notify receiver", func(s *mcclient.ClientSession, args *ReceiverUpdateInput) error {
|
||||
params := jsonutils.NewDict()
|
||||
if len(args.Email) > 0 {
|
||||
params.Set("email", jsonutils.NewString(args.Email))
|
||||
}
|
||||
if len(args.Mobile) > 0 {
|
||||
params.Set("mobile", jsonutils.NewString(args.Mobile))
|
||||
}
|
||||
if len(args.EnabledContactType) > 0 {
|
||||
params.Set("enabled_contact_types", jsonutils.NewStringArray(args.EnabledContactType))
|
||||
}
|
||||
ret, err := modules.NotifyReceiver.Update(s, args.ID, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(ret)
|
||||
return nil
|
||||
})
|
||||
type ReceiverOptions struct {
|
||||
ID string `help:"Id or Name of receiver"`
|
||||
}
|
||||
R(&ReceiverOptions{}, "notify-receiver-show", "Show notify receiver", func(s *mcclient.ClientSession, args *ReceiverOptions) error {
|
||||
ret, err := modules.NotifyReceiver.Get(s, args.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(ret)
|
||||
return nil
|
||||
})
|
||||
R(&ReceiverOptions{}, "notify-receiver-delete", "Delete notify receiver", func(s *mcclient.ClientSession, args *ReceiverOptions) error {
|
||||
receiver, err := modules.NotifyReceiver.Delete(s, args.ID, jsonutils.NewDict())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(receiver)
|
||||
return nil
|
||||
})
|
||||
R(&ReceiverOptions{}, "notify-receiver-enable", "Enable notify receiver", func(s *mcclient.ClientSession, args *ReceiverOptions) error {
|
||||
ret, err := modules.NotifyReceiver.PerformAction(s, args.ID, "enable", jsonutils.NewDict())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(ret)
|
||||
return nil
|
||||
})
|
||||
R(&ReceiverOptions{}, "notify-receiver-disable", "Disable notify receiver", func(s *mcclient.ClientSession, args *ReceiverOptions) error {
|
||||
ret, err := modules.NotifyReceiver.PerformAction(s, args.ID, "disable", jsonutils.NewDict())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(ret)
|
||||
return nil
|
||||
})
|
||||
type ReceiverTriggerVerifyInput struct {
|
||||
ID string `help:"Id or Name of receiver"`
|
||||
ContactType string `help:"Contact type to trigger verify" choices:"email|mobile"`
|
||||
}
|
||||
R(&ReceiverTriggerVerifyInput{}, "notify-receiver-trigger-verify", "Trigger verification for receiver about some contact", func(s *mcclient.ClientSession, args *ReceiverTriggerVerifyInput) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Set("contact_type", jsonutils.NewString(args.ContactType))
|
||||
ret, err := modules.NotifyReceiver.PerformAction(s, args.ID, "trigger-verify", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(ret)
|
||||
return nil
|
||||
})
|
||||
type ReceiverVerifyInput struct {
|
||||
ID string `help:"Id or Name of receiver"`
|
||||
ContactType string `help:"Contact type to trigger verify" choices:"email|mobile"`
|
||||
Token string `help:"Token from verify message sent to you"`
|
||||
}
|
||||
R(&ReceiverVerifyInput{}, "notify-receiver-verify", "Verify receiver about some contact type", func(s *mcclient.ClientSession, args *ReceiverVerifyInput) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Set("contact_type", jsonutils.NewString(args.ContactType))
|
||||
params.Set("token", jsonutils.NewString(args.Token))
|
||||
ret, err := modules.NotifyReceiver.PerformAction(s, args.ID, "verify", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(ret)
|
||||
return nil
|
||||
})
|
||||
R(&ReceiverOptions{}, "notify-receiver-enable", "Enable receiver", func(s *mcclient.ClientSession, args *ReceiverOptions) error {
|
||||
ret, err := modules.NotifyReceiver.PerformAction(s, args.ID, "enable", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(ret)
|
||||
return nil
|
||||
})
|
||||
R(&ReceiverOptions{}, "notify-receiver-disable", "Disable receiver", func(s *mcclient.ClientSession, args *ReceiverOptions) error {
|
||||
ret, err := modules.NotifyReceiver.PerformAction(s, args.ID, "disable", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(ret)
|
||||
return nil
|
||||
})
|
||||
type ReceiverIntellijGetOptions struct {
|
||||
USERID string `help:"user id in keystone" json:"user_id"`
|
||||
CreateIfNo *bool `help:"create if receiver with UserId does not exist"`
|
||||
SCOPE string `help:"scope"`
|
||||
}
|
||||
R(&ReceiverIntellijGetOptions{}, "notify-receiver-intellij-get", "Intellij get receiver", func(s *mcclient.ClientSession, args *ReceiverIntellijGetOptions) error {
|
||||
params := jsonutils.Marshal(args)
|
||||
ret, err := modules.NotifyReceiver.PerformClassAction(s, "intellij-get", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(ret)
|
||||
return nil
|
||||
})
|
||||
cmd := shell.NewResourceCmd(&modules.NotifyReceiver).WithKeyword("notify-receiver")
|
||||
cmd.List(new(options.ReceiverListOptions))
|
||||
cmd.Create(new(options.ReceiverCreateOptions))
|
||||
cmd.Update(new(options.ReceiverUpdateOptions))
|
||||
cmd.Show(new(options.ReceiverOptions))
|
||||
cmd.Delete(new(options.ReceiverOptions))
|
||||
cmd.Perform("enable", new(options.ReceiverOptions))
|
||||
cmd.Perform("disable", new(options.ReceiverOptions))
|
||||
cmd.Perform("trigger-verify", new(options.ReceiverTriggerVerifyOptions))
|
||||
cmd.Perform("verify", new(options.ReceiverVerifyOptions))
|
||||
cmd.PerformClass("intellij-get", new(options.ReceiverIntellijGetOptions))
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
package notify // import "yunion.io/x/onecloud/pkg/mcclient/options/notify"
|
||||
@@ -0,0 +1,94 @@
|
||||
package notify
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
type ReceiverListOptions struct {
|
||||
options.BaseListOptions
|
||||
UId string `help:"user id in keystone"`
|
||||
UName string `help:"user name in keystone"`
|
||||
EnabledContactType string `help:"enabled contact type"`
|
||||
VerifiedContactType string `help:"verified contact type"`
|
||||
}
|
||||
|
||||
func (rl *ReceiverListOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return options.ListStructToParams(rl)
|
||||
}
|
||||
|
||||
type ReceiverCreateOptions struct {
|
||||
UID string `help:"user id in keystone"`
|
||||
Email string `help:"email of receiver"`
|
||||
Mobile string `help:"mobile of receiver"`
|
||||
EnabledContactTypes []string `help:"enabled contact type"`
|
||||
}
|
||||
|
||||
func (rc *ReceiverCreateOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return options.StructToParams(rc)
|
||||
}
|
||||
|
||||
type ReceiverOptions struct {
|
||||
ID string `help:"Id or Name of receiver"`
|
||||
}
|
||||
|
||||
func (r *ReceiverOptions) GetId() string {
|
||||
return r.ID
|
||||
}
|
||||
|
||||
func (r *ReceiverOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
type ReceiverUpdateOptions struct {
|
||||
ReceiverOptions
|
||||
receiverUpdateOptions
|
||||
}
|
||||
|
||||
type receiverUpdateOptions struct {
|
||||
Email string `help:"email of receiver"`
|
||||
Mobile string `help:"mobile of receiver"`
|
||||
EnabledContactType []string `help:"enabled contact type"`
|
||||
}
|
||||
|
||||
func (ru *ReceiverUpdateOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return jsonutils.Marshal(ru.receiverUpdateOptions), nil
|
||||
}
|
||||
|
||||
type ReceiverTriggerVerifyOptions struct {
|
||||
ReceiverOptions
|
||||
receiverTriggerVerifyOptions
|
||||
}
|
||||
|
||||
type receiverTriggerVerifyOptions struct {
|
||||
ContactType string `help:"Contact type to trigger verify" choices:"email|mobile"`
|
||||
}
|
||||
|
||||
func (rt *ReceiverTriggerVerifyOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return jsonutils.Marshal(rt.receiverTriggerVerifyOptions), nil
|
||||
}
|
||||
|
||||
type ReceiverVerifyOptions struct {
|
||||
ReceiverOptions
|
||||
receiverVerifyOptions
|
||||
}
|
||||
|
||||
type receiverVerifyOptions struct {
|
||||
ContactType string `help:"Contact type to trigger verify" choices:"email|mobile"`
|
||||
Token string `help:"Token from verify message sent to you"`
|
||||
}
|
||||
|
||||
func (rv *ReceiverVerifyOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return jsonutils.Marshal(rv.receiverVerifyOptions), nil
|
||||
}
|
||||
|
||||
type ReceiverIntellijGetOptions struct {
|
||||
USERID string `help:"user id in keystone" json:"user_id"`
|
||||
CreateIfNo *bool `help:"create if receiver with UserId does not exist"`
|
||||
SCOPE string `help:"scope"`
|
||||
}
|
||||
|
||||
func (ri *ReceiverIntellijGetOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return jsonutils.Marshal(ri), nil
|
||||
}
|
||||
Reference in New Issue
Block a user