mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 02:37:24 +08:00
fix: change domain to project_domain
This commit is contained in:
@@ -23,7 +23,7 @@ func init() {
|
||||
[]string{"ID", "Name", "Enabled", "Status", "Access_url",
|
||||
"balance", "error_count", "health_status",
|
||||
"Sync_Status", "Last_sync",
|
||||
"guest_count", "domain", "domain_id",
|
||||
"guest_count", "project_domain", "domain_id",
|
||||
"Provider", "Brand",
|
||||
"Enable_Auto_Sync", "Sync_Interval_Seconds",
|
||||
"Is_Public"},
|
||||
|
||||
@@ -36,7 +36,7 @@ var (
|
||||
func init() {
|
||||
Groups = GroupManager{NewIdentityV3Manager("group", "groups",
|
||||
[]string{},
|
||||
[]string{"ID", "Name", "Domain_Id", "domain", "domain_readonly",
|
||||
[]string{"ID", "Name", "Domain_Id", "project_domain",
|
||||
"User_Count", "Description"})}
|
||||
|
||||
register(&Groups)
|
||||
|
||||
@@ -22,193 +22,6 @@ var (
|
||||
IdentityProviders IdentityProviderManager
|
||||
)
|
||||
|
||||
/*
|
||||
func (this *IdentityProviderManager) GetConfig(s *mcclient.ClientSession, idpId string) (jsonutils.JSONObject, error) {
|
||||
return this.GetSpecific(s, idpId, "config", nil)
|
||||
}
|
||||
|
||||
func (this *IdentityProviderManager) UpdateConfig(s *mcclient.ClientSession, idpId string, config jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
return this.PerformAction(s, idpId, "config", config)
|
||||
}
|
||||
|
||||
func (this *IdentityProviderManager) GetIdpConfig(s *mcclient.ClientSession, idpId string, params jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
ret := jsonutils.NewDict()
|
||||
|
||||
idpDetail, err := this.Get(s, idpId, nil)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
|
||||
config, err := this.GetConfig(s, idpId)
|
||||
if err != nil {
|
||||
// for empty domain config
|
||||
log.Infof("err fetch domain config for %s with error: %s", idpId, err)
|
||||
config = jsonutils.NewDict()
|
||||
}
|
||||
|
||||
ret.Add(idpDetail, "domain")
|
||||
ret.Add(config, "config")
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (this *IdentityProviderManager) DoIdpConfigUpdate(s *mcclient.ClientSession, idpId string, params jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
// params example:
|
||||
// {
|
||||
// "config": {
|
||||
// "identity": {
|
||||
// "driver": "ldap"
|
||||
// },
|
||||
// "ldap": {
|
||||
// "group_id_attribute": "cn",
|
||||
// "group_member_attribute": "member",
|
||||
// "group_name_attribute": "cn",
|
||||
// "group_objectclass": "ipausergroup",
|
||||
// "group_tree_dn": "CN=groups,CN=accounts,DC=ipa,DC=yunionyun,DC=com",
|
||||
// "page_size": 20,
|
||||
// "query_scope": "sub",
|
||||
// "suffix": "DC=ipa,DC=yunionyun,DC=com",
|
||||
// "url": "ldap://192.168.0.222",
|
||||
// "user": "UID=dcadmin,CN=users,CN=accounts,DC=ipa,DC=yunionyun,DC=com",
|
||||
// "user_additional_attribute_mapping": [
|
||||
// "displayName:displayname",
|
||||
// "telephoneNumber:mobile"
|
||||
// ],
|
||||
// "user_enabled_attribute": "nsAccountLock",
|
||||
// "user_enabled_default": "FALSE",
|
||||
// "user_enabled_invert": true,
|
||||
// "user_enabled_mask": 0,
|
||||
// "user_id_attribute": "uid",
|
||||
// "user_name_attribute": "uid",
|
||||
// "user_objectclass": "person",
|
||||
// "user_tree_dn": "CN=users,CN=accounts,DC=ipa,DC=yunionyun,DC=com"
|
||||
// }
|
||||
// },
|
||||
// "domain": {
|
||||
// "description": "SqnkThciWBq7",
|
||||
// "enabled": true,
|
||||
// "name": "os8vFdmqlgji-delete-free"
|
||||
// }
|
||||
// }
|
||||
|
||||
ret := jsonutils.NewDict()
|
||||
|
||||
idp, err := params.Get("identity_provider")
|
||||
if err != nil {
|
||||
return ret, httperrors.NewMissingParameterError("domain")
|
||||
}
|
||||
name, _ := idp.GetString("name")
|
||||
if domain == "default" && name != "Default" {
|
||||
return nil, httperrors.NewUnsupportOperationError("domain %s did not allowed update Name", domain)
|
||||
}
|
||||
|
||||
domain, err = this.Update(s, idpId, idp)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
|
||||
config := jsonutils.NewDict()
|
||||
_config, _ := params.Get("config")
|
||||
if _config == nil {
|
||||
_config = jsonutils.NewDict()
|
||||
}
|
||||
_driver, _ := _config.GetString("identity", "driver")
|
||||
|
||||
if _driver == "ldap" {
|
||||
config.Add(_config, "config")
|
||||
log.Infof("to update config: %s", config)
|
||||
_config, err = this.UpdateConfig(s, domain, config)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
ret.Add(_config, "config")
|
||||
}
|
||||
|
||||
ret.Add(_domain, "domain")
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (this *DomainManager) DoDomainConfigCreate(s *mcclient.ClientSession, params jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
ret := jsonutils.NewDict()
|
||||
_domain, err := params.Get("domain")
|
||||
|
||||
if err != nil {
|
||||
return ret, httperrors.NewMissingParameterError("domain")
|
||||
}
|
||||
|
||||
_domain, err = this.Create(s, _domain)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
|
||||
objId, err := _domain.GetString("id")
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
|
||||
config := jsonutils.NewDict()
|
||||
_config, _ := params.Get("config")
|
||||
_driver, _ := _config.Get("identity")
|
||||
|
||||
if _driver != nil {
|
||||
config.Add(_config, "config")
|
||||
_config, err = this.UpdateConfig(s, objId, config)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
ret.Add(_config, "config")
|
||||
}
|
||||
|
||||
ret.Add(_domain, "domain")
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
|
||||
func (this *DomainManager) DoDomainConfigDelete(s *mcclient.ClientSession, params jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
ret := jsonutils.NewDict()
|
||||
|
||||
ids, _ := params.GetArray("ids")
|
||||
domains := jsonutils.JSONArray2StringArray(ids)
|
||||
|
||||
for _, domain := range domains {
|
||||
objId, err := this.GetId(s, domain, nil)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
this.DeleteConfig(s, objId)
|
||||
this.Delete(s, objId, nil)
|
||||
}
|
||||
}()
|
||||
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(objId), "domain_id")
|
||||
|
||||
detail, err := this.GetById(s, domain, nil)
|
||||
if err != nil {
|
||||
log.Errorf("got domain detail error: %v", err)
|
||||
return ret, httperrors.NewResourceNotFoundError("%s %s not find", "Domain", domain)
|
||||
}
|
||||
|
||||
driver, _ := detail.GetString("driver")
|
||||
if driver != "ldap" {
|
||||
if result, err := UsersV3.List(s, params); err != nil {
|
||||
log.Errorf("user list got error: %v", err)
|
||||
return ret, httperrors.NewInternalServerError("fetching user list failed: %s", err)
|
||||
} else if len(result.Data) > 0 {
|
||||
return ret, httperrors.NewForbiddenError("cannot delete: there still exists %d user related with domain %s.", len(result.Data), objId)
|
||||
}
|
||||
}
|
||||
|
||||
this.DeleteConfig(s, objId)
|
||||
this.Delete(s, objId, nil)
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
*/
|
||||
|
||||
func init() {
|
||||
IdentityProviders = IdentityProviderManager{
|
||||
NewIdentityV3Manager("identity_provider",
|
||||
|
||||
@@ -29,7 +29,7 @@ var Policies SPolicyManager
|
||||
|
||||
func policyReadFilter(session *mcclient.ClientSession, s jsonutils.JSONObject, query jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
ss := s.(*jsonutils.JSONDict)
|
||||
ret := ss.CopyIncludes("id", "type", "enabled", "domain_id", "domain", "can_update", "can_delete", "is_public")
|
||||
ret := ss.CopyIncludes("id", "type", "enabled", "domain_id", "domain", "project_domain", "can_update", "can_delete", "is_public")
|
||||
blobJson, _ := ss.Get("blob")
|
||||
if blobJson != nil {
|
||||
policy := rbacutils.SRbacPolicy{}
|
||||
@@ -81,7 +81,7 @@ func policyWriteFilter(session *mcclient.ClientSession, s jsonutils.JSONObject,
|
||||
ret.Add(blobJson, "blob")
|
||||
}
|
||||
for _, k := range []string{
|
||||
"type", "enabled", "domain", "domain_id",
|
||||
"type", "enabled", "domain", "domain_id", "project_domain",
|
||||
} {
|
||||
if s.Contains(k) {
|
||||
val, err := s.Get(k)
|
||||
@@ -96,7 +96,7 @@ func policyWriteFilter(session *mcclient.ClientSession, s jsonutils.JSONObject,
|
||||
|
||||
func init() {
|
||||
Policies = SPolicyManager{NewIdentityV3Manager("policy", "policies",
|
||||
[]string{"id", "type", "policy", "enabled", "domain_id", "domain", "is_public"},
|
||||
[]string{"id", "type", "policy", "enabled", "domain_id", "domain", "project_domain", "is_public"},
|
||||
[]string{})}
|
||||
|
||||
Policies.SetReadFilter(policyReadFilter).SetWriteFilter(policyWriteFilter).SetNameField("type")
|
||||
|
||||
@@ -312,7 +312,7 @@ func (this *ProjectManagerV3) AddTags(session *mcclient.ClientSession, id string
|
||||
func init() {
|
||||
Projects = ProjectManagerV3{NewIdentityV3Manager("project", "projects",
|
||||
[]string{},
|
||||
[]string{"ID", "Name", "Domain_Id", "Domain", "Parent_Id", "Enabled", "Description", "Created_At"})}
|
||||
[]string{"ID", "Name", "Domain_Id", "Project_Domain", "Parent_Id", "Enabled", "Description", "Created_At"})}
|
||||
|
||||
register(&Projects)
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ func init() {
|
||||
|
||||
RolesV3 = RolesManager{ResourceManager: NewIdentityV3Manager("role", "roles",
|
||||
[]string{},
|
||||
[]string{"ID", "Name", "Domain_Id", "Domain", "Description", "is_public"})}
|
||||
[]string{"ID", "Name", "Domain_Id", "Project_Domain", "Description", "is_public"})}
|
||||
|
||||
register(&RolesV3)
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ func init() {
|
||||
|
||||
UsersV3 = UserManagerV3{NewIdentityV3Manager("user", "users",
|
||||
[]string{},
|
||||
[]string{"ID", "Name", "Domain_Id", "Domain", "readonly", "idp_id",
|
||||
[]string{"ID", "Name", "Domain_Id", "Project_Domain", "readonly", "idp_id",
|
||||
"Enabled", "Email", "Mobile", "Displayname",
|
||||
"is_system_account", "allow_web_console", "enable_mfa"})}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user