From e5d80f2ed460b13911b8ab305fde2e258b851a93 Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Tue, 31 Dec 2019 17:59:31 +0800 Subject: [PATCH] feature: allow skip password complexity check when creating user --- cmd/climc/shell/users.go | 5 +++++ pkg/keystone/models/users.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/climc/shell/users.go b/cmd/climc/shell/users.go index 60a6535eac..14cd0bfd8f 100644 --- a/cmd/climc/shell/users.go +++ b/cmd/climc/shell/users.go @@ -159,6 +159,8 @@ func init() { Enabled bool `help:"Enabled"` Disabled bool `help:"Disabled"` + SkipPasswordComplexityCheck bool `help:"do password complexity check, default is false"` + // DefaultProject string `help:"Default project"` SystemAccount bool `help:"is a system account?"` NoWebConsole bool `help:"allow web console access"` @@ -176,6 +178,9 @@ func init() { } if args.Password != nil { params.Add(jsonutils.NewString(*args.Password), "password") + if args.SkipPasswordComplexityCheck { + params.Add(jsonutils.JSONTrue, "skip_password_complexity_check") + } } if len(args.Displayname) > 0 { params.Add(jsonutils.NewString(args.Displayname), "displayname") diff --git a/pkg/keystone/models/users.go b/pkg/keystone/models/users.go index b76889629c..bf41aa424a 100644 --- a/pkg/keystone/models/users.go +++ b/pkg/keystone/models/users.go @@ -389,7 +389,7 @@ func (manager *SUserManager) FilterByHiddenSystemAttributes(q *sqlchemy.SQuery, } func (manager *SUserManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) { - if data.Contains("password") { + if data.Contains("password") && !jsonutils.QueryBoolean(data, "skip_password_complexity_check", false) { passwd, _ := data.GetString("password") err := validatePasswordComplexity(passwd) if err != nil {