Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GitLab Helper
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LSDS
admin
GitLab Helper
Commits
1e083ddf
Commit
1e083ddf
authored
2 years ago
by
marcoemi.poleggi
Browse files
Options
Downloads
Patches
Plain Diff
Added memberid filter to skip project bots
parent
18b580f3
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
group-sandbox.py
+20
-6
20 additions, 6 deletions
group-sandbox.py
with
20 additions
and
6 deletions
group-sandbox.py
+
20
−
6
View file @
1e083ddf
...
@@ -126,7 +126,7 @@ What do you mean? ;-)
...
@@ -126,7 +126,7 @@ What do you mean? ;-)
* API requests that return a list of items do not support pagination yet --
* API requests that return a list of items do not support pagination yet --
max 100 items in one single page are returned. Command `userlist``is one such
max 100 items in one single page are returned. Command `userlist``is one such
offender.
offender.
* There
'
s no configuration file.
* There
'
s no configuration file.
TO-DO: use configparse for this.
Notes
Notes
...
@@ -265,13 +265,14 @@ def handle_command(command, g, api_url, src_project, dst_path,
...
@@ -265,13 +265,14 @@ def handle_command(command, g, api_url, src_project, dst_path,
(
api_url_endpoint
,
data
)
=
pre_cmnd_ref
[
'
handler
'
](
(
api_url_endpoint
,
data
)
=
pre_cmnd_ref
[
'
handler
'
](
pre_command
,
g
,
api_url
,
src_project
,
dst_path
,
users
pre_command
,
g
,
api_url
,
src_project
,
dst_path
,
users
)
)
skip_dryrun
=
command_xref
[
pre_command
][
'
skip_dryrun
'
]
if
command_xref
[
pre_command
][
'
skip_dryrun
'
]
else
false
;
(
pstatus
,
pdata
)
=
send_rest_request
(
(
pstatus
,
pdata
)
=
send_rest_request
(
pre_cmnd_ref
[
'
method
'
],
pre_cmnd_ref
[
'
method
'
],
api_url_endpoint
,
api_url_endpoint
,
json
.
dumps
(
data
)
if
data
else
None
,
json
.
dumps
(
data
)
if
data
else
None
,
dry_run
dry_run
and
not
skip_dryrun
)
)
if
dry_run
:
if
dry_run
and
not
skip_dryrun
:
logger
.
info
(
"
[DRY RUN] {}: Using fake results as loop data
"
.
format
(
pre_command
))
logger
.
info
(
"
[DRY RUN] {}: Using fake results as loop data
"
.
format
(
pre_command
))
pdata
=
command_xref
[
pre_command
][
'
fake_results
'
]
pdata
=
command_xref
[
pre_command
][
'
fake_results
'
]
else
:
else
:
...
@@ -541,8 +542,6 @@ def _memberid(command, g, api_url, src_project, dst_path, users=None, jdata=None
...
@@ -541,8 +542,6 @@ def _memberid(command, g, api_url, src_project, dst_path, users=None, jdata=None
"""
Handle
'
userdel
'
command calls as per `GitLab project
"""
Handle
'
userdel
'
command calls as per `GitLab project
mem API <https://docs.gitlab.com/ee/api/invitations.html>`_
mem API <https://docs.gitlab.com/ee/api/invitations.html>`_
Call :py:func: `_userlist` to get the members
'
ID and
:returns tuple: 2 elements
:returns tuple: 2 elements
:tuple member_id, member_name: extracted from :param jdata: or None if
:tuple member_id, member_name: extracted from :param jdata: or None if
filtered out
filtered out
...
@@ -556,12 +555,24 @@ def _memberid(command, g, api_url, src_project, dst_path, users=None, jdata=None
...
@@ -556,12 +555,24 @@ def _memberid(command, g, api_url, src_project, dst_path, users=None, jdata=None
:param obj jdata: JSON data to process
:param obj jdata: JSON data to process
the remaining ones are ignored.
the remaining ones are ignored.
Filters
*******
So far, two filters (AND-wise) are supported:
:int access_level: must be > than given
:str username: regex must match username -- usually a negative
lookahead to skip certain members, like bots, etc.
"""
"""
cmnd_ref
=
command_xref
[
command
]
cmnd_ref
=
command_xref
[
command
]
member_id
=
jdata
[
'
id
'
]
member_id
=
jdata
[
'
id
'
]
member_name
=
jdata
[
'
username
'
]
member_name
=
jdata
[
'
username
'
]
max_access_level
=
cmnd_ref
[
'
filter
'
][
'
access_level
'
]
max_access_level
=
cmnd_ref
[
'
filter
'
][
'
access_level
'
]
keep
=
True
if
jdata
[
'
access_level
'
]
<=
max_access_level
else
False
uname_regex
=
cmnd_ref
[
'
filter
'
][
'
username
'
]
keep
=
True
\
if
(
jdata
[
'
access_level
'
]
<=
max_access_level
and
re
.
match
(
uname_regex
,
jdata
[
'
username
'
])
)
else
False
logger
.
debug
(
"
Member #{} ({}) is filtered {}
"
.
format
(
logger
.
debug
(
"
Member #{} ({}) is filtered {}
"
.
format
(
member_id
,
member_name
,
'
_in_
'
if
keep
else
'
_out_
'
)
member_id
,
member_name
,
'
_in_
'
if
keep
else
'
_out_
'
)
...
@@ -679,6 +690,7 @@ command_xref = {
...
@@ -679,6 +690,7 @@ command_xref = {
'
api_rendpoint
'
:
'
members/all?per_page=100
'
,
# Warning! No pagination
'
api_rendpoint
'
:
'
members/all?per_page=100
'
,
# Warning! No pagination
# handled.
# handled.
'
force
'
:
False
,
'
force
'
:
False
,
'
skip_dryrun
'
:
True
,
# this is always safe to run
'
fake_results
'
:
[
# for dry-run/debugging purpose
'
fake_results
'
:
[
# for dry-run/debugging purpose
{
{
"
id
"
:
0
,
"
id
"
:
0
,
...
@@ -722,8 +734,10 @@ command_xref = {
...
@@ -722,8 +734,10 @@ command_xref = {
# ignored. This is supposed to be found in
# ignored. This is supposed to be found in
# some input data, usually coming from a
# some input data, usually coming from a
# pre-handler call
# pre-handler call
'
username
'
:
'
(?!project.+bot)
'
# negative lookahead regex: skip "bot" members
},
},
'
force
'
:
False
,
'
force
'
:
False
,
'
skip_dryrun
'
:
True
,
},
},
}
}
...
...
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