Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dm-docs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hammonds
dm-docs
Commits
6c09397d
Commit
6c09397d
authored
9 years ago
by
sveseli
Browse files
Options
Downloads
Patches
Plain Diff
added delete local user method via ldap
parent
f57d6653
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/python/dm/common/utility/ldapLinuxPlatformUtility.py
+34
-9
34 additions, 9 deletions
src/python/dm/common/utility/ldapLinuxPlatformUtility.py
with
34 additions
and
9 deletions
src/python/dm/common/utility/ldapLinuxPlatformUtility.py
+
34
−
9
View file @
6c09397d
...
...
@@ -166,6 +166,38 @@ class LdapLinuxPlatformUtility:
logger
.
error
(
'
Could not add user %s to group %s: %s
'
%
(
username
,
groupName
,
ex
))
raise
InternalError
(
exception
=
ex
)
def
deleteUserFromGroup
(
self
,
username
,
groupName
):
"""
Remove user from group.
"""
logger
=
self
.
getLogger
()
ldapClient
=
self
.
getLdapClient
()
username
=
str
(
username
)
groupName
=
str
(
groupName
)
try
:
groupDn
=
self
.
groupDnFormat
%
groupName
resultList
=
ldapClient
.
search_s
(
groupDn
,
ldap
.
SCOPE_BASE
)
groupTuple
=
resultList
[
0
]
groupAttrs
=
groupTuple
[
1
]
memberUidList
=
groupAttrs
.
get
(
'
memberUid
'
,
[])
if
username
not
in
memberUidList
:
logger
.
debug
(
'
Group %s does not contain user %s
'
%
(
groupName
,
username
))
return
except
Exception
,
ex
:
raise
InternalError
(
exception
=
ex
)
logger
.
debug
(
'
Adding user %s to group %s
'
%
(
username
,
groupName
))
memberUidList2
=
copy
.
copy
(
memberUidList
)
memberUidList2
.
remove
(
username
)
groupAttrs2
=
copy
.
copy
(
groupAttrs
)
groupAttrs2
[
'
memberUid
'
]
=
memberUidList2
try
:
groupLdif
=
ldap
.
modlist
.
modifyModlist
(
groupAttrs
,
groupAttrs2
)
ldapClient
.
modify_s
(
groupDn
,
groupLdif
)
except
Exception
,
ex
:
logger
.
error
(
'
Could not remove user %s from group %s: %s
'
%
(
username
,
groupName
,
ex
))
raise
InternalError
(
exception
=
ex
)
@classmethod
def
createLocalGroup
(
cls
,
name
):
"""
Create local group if it does not exist.
"""
@classmethod
def
createLocalGroup
(
cls
,
name
):
"""
Create local group if it does not exist.
"""
...
...
@@ -184,19 +216,12 @@ class LdapLinuxPlatformUtility:
@classmethod
def
addLocalUserToGroup
(
cls
,
username
,
groupName
):
"""
Add local user to group.
"""
cls
.
createLocalGroup
(
groupName
)
logger
=
cls
.
getLogger
()
logger
.
debug
(
'
Adding local user %s to group %s
'
%
(
username
,
groupName
))
cmd
=
'
%s -a %s %s
'
%
(
cls
.
GPASSWD_CMD
,
username
,
groupName
)
cls
.
executeSudoCommand
(
cmd
)
cls
.
addUserFromGroup
(
username
,
groupName
)
@classmethod
def
deleteLocalUserFromGroup
(
cls
,
username
,
groupName
):
"""
Remove local user from group.
"""
logger
=
cls
.
getLogger
()
logger
.
debug
(
'
Removing local user %s from group %s
'
%
(
username
,
groupName
))
cmd
=
'
%s -d %s %s
'
%
(
cls
.
GPASSWD_CMD
,
username
,
groupName
)
cls
.
executeSudoCommand
(
cmd
)
cls
.
deleteUserFromGroup
(
username
,
groupName
)
def
getGroupInfo
(
self
,
groupName
):
"""
Get given group info.
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment