feature: identity provider improvements

This commit is contained in:
Qiu Jian
2020-04-03 01:54:07 +08:00
parent 193d014034
commit c1c9aa300d
6 changed files with 75 additions and 23 deletions
+5
View File
@@ -216,6 +216,11 @@ func init() {
return doIdentityEventList(s, &nargs)
})
R(&TypeEventListOptions{}, "idp-event", "Show operation event logs of keystone identity provider", func(s *mcclient.ClientSession, args *TypeEventListOptions) error {
nargs := EventListOptions{BaseEventListOptions: args.BaseEventListOptions, Id: args.ID, Type: []string{"identity_provider"}}
return doIdentityEventList(s, &nargs)
})
R(&TypeEventListOptions{}, "project-event", "Show operation event logs of keystone projects", func(s *mcclient.ClientSession, args *TypeEventListOptions) error {
nargs := EventListOptions{BaseEventListOptions: args.BaseEventListOptions, Id: args.ID, Type: []string{"project"}}
return doIdentityEventList(s, &nargs)
+31
View File
@@ -23,6 +23,7 @@ import (
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
"yunion.io/x/onecloud/pkg/util/shellutils"
)
func init() {
@@ -294,4 +295,34 @@ func init() {
return nil
})
type IdentityProviderConfigEditOptions struct {
IDP string `help:"identity provider name or ID"`
}
R(&IdentityProviderConfigEditOptions{}, "idp-config-edit", "Edit config yaml of an identity provider", func(s *mcclient.ClientSession, args *IdentityProviderConfigEditOptions) error {
conf, err := modules.IdentityProviders.GetSpecific(s, args.IDP, "config", nil)
if err != nil {
return err
}
confJson, err := conf.Get("config")
if err != nil {
return err
}
content, err := shellutils.Edit(confJson.YAMLString())
if err != nil {
return err
}
yamlJson, err := jsonutils.ParseYAML(content)
if err != nil {
return err
}
config := jsonutils.NewDict()
config.Add(yamlJson, "config")
nconf, err := modules.IdentityProviders.PerformAction(s, args.IDP, "config", config)
if err != nil {
return err
}
fmt.Println(nconf.PrettyString())
return nil
})
}
+16
View File
@@ -93,3 +93,19 @@ var (
IdpTemplateOpenLDAPSingleDomain: IdentityDriverLDAP,
}
)
type PerformConfigInput struct {
// 更新配置的方式
// example: update
//
// | action | 含义 |
// |---------|-----------------------------------------------|
// | update | 增量更新配置 |
// | remove | 删除指定配置 |
// | replace | 全量替换配置,如果action为空,则默认为replace |
//
Action string `json:"action"`
// 配置信息
Config TConfigs `json:"config"`
}
+10 -3
View File
@@ -27,6 +27,8 @@ import (
"yunion.io/x/onecloud/pkg/cloudcommon/consts"
"yunion.io/x/onecloud/pkg/cloudcommon/db"
common_options "yunion.io/x/onecloud/pkg/cloudcommon/options"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/util/logclient"
)
type SConfigOptionManager struct {
@@ -310,7 +312,7 @@ func GetConfigs(model db.IModel, all bool) (api.TConfigs, error) {
return config2map(opts), nil
}
func saveConfigs(action string, model db.IModel, opts api.TConfigs, whiteList map[string][]string, blackList map[string][]string, sensitiveConfs map[string][]string) error {
func saveConfigs(userCred mcclient.TokenCredential, action string, model db.IModel, opts api.TConfigs, whiteList map[string][]string, blackList map[string][]string, sensitiveConfs map[string][]string) error {
whiteListedOpts, sensitiveOpts := getConfigOptions(opts, model, whiteList, blackList, sensitiveConfs)
if action == "update" {
err := WhitelistedConfigManager.updateConfigs(whiteListedOpts)
@@ -340,6 +342,11 @@ func saveConfigs(action string, model db.IModel, opts api.TConfigs, whiteList ma
return errors.Wrap(err, "SensitiveConfigManager.syncConfig")
}
}
if userCred == nil {
userCred = getDefaultAdminCred()
}
db.OpsLog.LogEvent(model, db.ACT_CHANGE_CONFIG, opts, userCred)
logclient.AddSimpleActionLog(model, logclient.ACT_CHANGE_CONFIG, whiteListedOpts, userCred, true)
return nil
}
@@ -410,9 +417,9 @@ func uploadConfig(service *SService, config jsonutils.JSONObject) {
return
}
if service.isCommonService() {
err = saveConfigs("", service, tconf, api.CommonWhitelistOptionMap, nil, nil)
err = saveConfigs(nil, "", service, tconf, api.CommonWhitelistOptionMap, nil, nil)
} else {
err = saveConfigs("", service, tconf, nil, api.ServiceBlacklistOptionMap, nil)
err = saveConfigs(nil, "", service, tconf, nil, api.ServiceBlacklistOptionMap, nil)
}
if err != nil {
log.Errorf("saveConfigs fail %s", err)
+6 -10
View File
@@ -212,24 +212,20 @@ func (self *SIdentityProvider) GetDetailsConfig(ctx context.Context, userCred mc
return result, nil
}
func (ident *SIdentityProvider) AllowPerformConfig(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data *jsonutils.JSONDict) bool {
func (ident *SIdentityProvider) AllowPerformConfig(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.PerformConfigInput) bool {
return db.IsAdminAllowUpdateSpec(userCred, ident, "config")
}
func (ident *SIdentityProvider) PerformConfig(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data *jsonutils.JSONDict) (jsonutils.JSONObject, error) {
func (ident *SIdentityProvider) PerformConfig(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.PerformConfigInput) (jsonutils.JSONObject, error) {
if ident.Status == api.IdentityDriverStatusConnected && ident.GetEnabled() {
return nil, httperrors.NewInvalidStatusError("cannot update config when enabled and connected")
}
if ident.SyncStatus != api.IdentitySyncStatusIdle {
return nil, httperrors.NewInvalidStatusError("cannot update config when not idle")
}
opts := api.TConfigs{}
err := data.Unmarshal(&opts, "config")
if err != nil {
return nil, httperrors.NewInputParameterError("invalid input data")
}
action, _ := data.GetString("action")
err = saveConfigs(action, ident, opts, nil, nil, api.SensitiveDomainConfigMap)
opts := input.Config
action := input.Action
err := saveConfigs(userCred, action, ident, opts, nil, nil, api.SensitiveDomainConfigMap)
if err != nil {
return nil, httperrors.NewInternalServerError("saveConfig fail %s", err)
}
@@ -328,7 +324,7 @@ func (ident *SIdentityProvider) PostCreate(ctx context.Context, userCred mcclien
log.Errorf("parse config error %s", err)
return
}
err = saveConfigs("", ident, opts, nil, nil, api.SensitiveDomainConfigMap)
err = saveConfigs(userCred, "", ident, opts, nil, nil, api.SensitiveDomainConfigMap)
if err != nil {
log.Errorf("saveConfig fail %s", err)
return
+7 -10
View File
@@ -169,7 +169,7 @@ func (service *SService) GetDetailsConfig(ctx context.Context, userCred mcclient
return result, nil
}
func (service *SService) AllowPerformConfig(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data *jsonutils.JSONDict) bool {
func (service *SService) AllowPerformConfig(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.PerformConfigInput) bool {
return db.IsAdminAllowUpdateSpec(userCred, service, "config")
}
@@ -181,17 +181,14 @@ func (service *SService) isCommonService() bool {
}
}
func (service *SService) PerformConfig(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data *jsonutils.JSONDict) (jsonutils.JSONObject, error) {
action, _ := data.GetString("action")
opts := api.TConfigs{}
err := data.Unmarshal(&opts, "config")
if err != nil {
return nil, httperrors.NewInputParameterError("invalid input data")
}
func (service *SService) PerformConfig(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.PerformConfigInput) (jsonutils.JSONObject, error) {
var err error
action := input.Action
opts := input.Config
if service.isCommonService() {
err = saveConfigs(action, service, opts, api.CommonWhitelistOptionMap, nil, nil)
err = saveConfigs(userCred, action, service, opts, api.CommonWhitelistOptionMap, nil, nil)
} else {
err = saveConfigs(action, service, opts, nil, api.ServiceBlacklistOptionMap, nil)
err = saveConfigs(userCred, action, service, opts, nil, api.ServiceBlacklistOptionMap, nil)
}
if err != nil {
return nil, httperrors.NewInternalServerError("saveConfig fail %s", err)