mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
Merge pull request #9135 from ioito/hotfix/qx-cloud-user-notify
feat(cloudid): notify clouduser created
This commit is contained in:
+6
@@ -0,0 +1,6 @@
|
||||
公有云子账号创建成功
|
||||
主账号:{{ .account }}
|
||||
名称:{{ .name }}
|
||||
密码:{{ .password }}
|
||||
登录地址: {{ .iam_login_url }}
|
||||
资源ID: {{ .id }}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
Clouduser has been created successfully
|
||||
Root Account: {{ .account }}
|
||||
Name:{{ .name }}
|
||||
Password:{{ .password }}
|
||||
IAM Login URL: {{ .iam_login_url }}
|
||||
Resource ID: {{ .id }}
|
||||
+1
@@ -0,0 +1 @@
|
||||
公有云子账号 {{ .name }} 创建成功
|
||||
+1
@@ -0,0 +1 @@
|
||||
The clouduser {{ .name }} created successfully
|
||||
@@ -82,6 +82,10 @@ type ClouduserCreateInput struct {
|
||||
|
||||
// swagger:ignore
|
||||
ExternalId string `json:"external_id"`
|
||||
|
||||
// 是否发送邮件通知(仅设置email不为空生效)
|
||||
// default: false
|
||||
Notify bool `json:"notify"`
|
||||
}
|
||||
|
||||
type ClouduserListInput struct {
|
||||
|
||||
@@ -149,10 +149,11 @@ func Notify(recipientId []string, isGroup bool, priority npk.TNotifyPriority, ev
|
||||
notify(context.Background(), recipientId, isGroup, priority, event, data)
|
||||
}
|
||||
|
||||
func NotifyWithContact(ctx context.Context, contacts []string, priority npk.TNotifyPriority, event string, data jsonutils.JSONObject) {
|
||||
func NotifyWithContact(ctx context.Context, contacts []string, channel npk.TNotifyChannel, priority npk.TNotifyPriority, event string, data jsonutils.JSONObject) {
|
||||
p := sNotifyParams{
|
||||
contacts: contacts,
|
||||
priority: priority,
|
||||
channel: channel,
|
||||
event: event,
|
||||
data: data,
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import (
|
||||
|
||||
proxyapi "yunion.io/x/onecloud/pkg/apis/cloudcommon/proxy"
|
||||
api "yunion.io/x/onecloud/pkg/apis/cloudid"
|
||||
computeapi "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
@@ -110,6 +111,30 @@ func (manager *SCloudaccountManager) GetICloudaccounts() ([]SCloudaccount, error
|
||||
return accounts, nil
|
||||
}
|
||||
|
||||
func (self *SCloudaccount) GetClouduserAccountName(name string) (string, string) {
|
||||
account := ""
|
||||
switch self.Provider {
|
||||
case computeapi.CLOUD_PROVIDER_ALIYUN:
|
||||
suffix := strings.TrimPrefix(self.IamLoginUrl, "https://signin.aliyun.com/")
|
||||
suffix = strings.TrimSuffix(suffix, "/login.htm")
|
||||
if len(suffix) > 0 {
|
||||
name = fmt.Sprintf("%s@%s", name, suffix)
|
||||
account = suffix
|
||||
}
|
||||
case computeapi.CLOUD_PROVIDER_QCLOUD, computeapi.CLOUD_PROVIDER_HUAWEI:
|
||||
u, _ := url.Parse(self.IamLoginUrl)
|
||||
if u != nil {
|
||||
account = u.Query().Get("account")
|
||||
}
|
||||
case computeapi.CLOUD_PROVIDER_AWS:
|
||||
account := strings.TrimPrefix(self.IamLoginUrl, "https://")
|
||||
if info := strings.Split(account, "."); len(info) > 0 {
|
||||
account = info[0]
|
||||
}
|
||||
}
|
||||
return account, name
|
||||
}
|
||||
|
||||
func (manager *SCloudaccountManager) GetCloudaccounts() ([]SCloudaccount, error) {
|
||||
accounts := []SCloudaccount{}
|
||||
q := manager.Query()
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/tristate"
|
||||
"yunion.io/x/pkg/util/compare"
|
||||
"yunion.io/x/pkg/util/regutils"
|
||||
"yunion.io/x/pkg/utils"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
@@ -33,9 +34,11 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
npk "yunion.io/x/onecloud/pkg/mcclient/modules/notify"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
"yunion.io/x/onecloud/pkg/util/seclib2"
|
||||
"yunion.io/x/onecloud/pkg/util/stringutils2"
|
||||
@@ -363,6 +366,10 @@ func (manager *SClouduserManager) ValidateCreateData(ctx context.Context, userCr
|
||||
return input, err
|
||||
}
|
||||
|
||||
if len(input.Email) > 0 && !regutils.MatchEmail(input.Email) {
|
||||
return input, httperrors.NewInputParameterError("invalid email address")
|
||||
}
|
||||
|
||||
if len(input.OwnerId) > 0 {
|
||||
user, err := db.UserCacheManager.FetchUserById(ctx, input.OwnerId)
|
||||
if err != nil {
|
||||
@@ -523,6 +530,21 @@ func (self *SClouduser) PostCreate(ctx context.Context, userCred mcclient.TokenC
|
||||
for _, groupId := range input.CloudgroupIds {
|
||||
self.joinGroup(groupId)
|
||||
}
|
||||
if len(self.Email) > 0 && input.Notify {
|
||||
msg := struct {
|
||||
Account string
|
||||
Name string
|
||||
Password string
|
||||
IamLoginUrl string
|
||||
Id string
|
||||
}{
|
||||
Id: self.Id,
|
||||
Password: input.Password,
|
||||
IamLoginUrl: account.IamLoginUrl,
|
||||
}
|
||||
msg.Account, msg.Name = account.GetClouduserAccountName(self.Name)
|
||||
notifyclient.NotifyWithContact(ctx, []string{self.Email}, npk.NotifyByEmail, npk.NotifyPriorityNormal, "CLOUD_USER_CREATED", jsonutils.Marshal(msg))
|
||||
}
|
||||
self.StartClouduserSyncTask(ctx, userCred, "")
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ type ClouduserCreateOptions struct {
|
||||
MobilePhone string `help:"phone number"`
|
||||
IsConsoleLogin *bool `help:"is console login"`
|
||||
Password string `help:"clouduser password"`
|
||||
Notify *bool `help:"Notify user which set email when clouduser created"`
|
||||
}
|
||||
|
||||
func (opts *ClouduserCreateOptions) Params() (jsonutils.JSONObject, error) {
|
||||
|
||||
Reference in New Issue
Block a user