Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
rabbitmq_agents
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container 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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bo-Chun Chen
rabbitmq_agents
Commits
864c9025
Commit
864c9025
authored
3 years ago
by
Eesaan Atluri
Browse files
Options
Downloads
Patches
Plain Diff
Publish a msg to agents based on action (lock/unlock) and service given by user.
parent
73c52f38
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
block_account.py
+58
-16
58 additions, 16 deletions
block_account.py
with
58 additions
and
16 deletions
block_account.py
+
58
−
16
View file @
864c9025
...
@@ -3,12 +3,17 @@ import json
...
@@ -3,12 +3,17 @@ import json
import
rc_util
import
rc_util
import
argparse
import
argparse
import
signal
import
signal
import
uuid
import
parser
=
argparse
.
ArgumentParser
()
parser
=
argparse
.
ArgumentParser
(
description
=
"
Account management driver script
"
)
parser
.
add_argument
(
"
username
"
,
help
=
"
username that will be created
"
)
parser
.
add_argument
(
"
username
"
,
help
=
"
Username that should be locked/unlocked
"
)
parser
.
add_argument
(
"
action
"
,
help
=
"
Choose lock or unlock action to be taken
"
)
parser
.
add_argument
(
"
service
"
,
nargs
=
'
*
'
,
help
=
"
List one or more services to be blocked
"
)
parser
.
add_argument
(
parser
.
add_argument
(
"
-v
"
,
"
--verbose
"
,
action
=
"
store_true
"
,
help
=
"
verbose output
"
"
-a
"
,
"
--all
"
,
help
=
"
Block all services
"
)
)
parser
.
add_argument
(
"
-v
"
,
"
--verbose
"
,
action
=
"
store_true
"
,
help
=
"
verbose output
"
)
parser
.
add_argument
(
parser
.
add_argument
(
"
-n
"
,
"
--dry-run
"
,
action
=
"
store_true
"
,
help
=
"
enable dry run mode
"
"
-n
"
,
"
--dry-run
"
,
action
=
"
store_true
"
,
help
=
"
enable dry run mode
"
)
)
...
@@ -16,8 +21,46 @@ args = parser.parse_args()
...
@@ -16,8 +21,46 @@ args = parser.parse_args()
timeout
=
60
timeout
=
60
username
=
args
.
username
action
=
args
.
action
service
=
args
.
service
corr_id
=
str
(
uuid
.
uuid4
())
callback_queue
=
rc_rmq
.
bind_queue
(
exclusive
=
True
)
callback_queue
=
rc_rmq
.
bind_queue
(
exclusive
=
True
)
msg
=
{}
if
args
.
all
is
not
None
:
# send a broadcast message to all agents
rc_rmq
.
publish_msg
(
{
"
routing_key
"
:
f
"
{
action
}
.
{
username
}
"
,
"
msg
"
:
{
"
username
"
:
username
,
"
action
"
:
action
,
"
service
"
:
service
},
}
)
else
:
for
each_service
in
service
:
if
action
==
'
lock
'
:
rc_rmq
.
publish_msg
(
{
"
routing_key
"
:
f
"
{
service
}
.
{
username
}
"
,
"
props
"
:
pika
.
BasicProperties
(
correlation_id
=
corr_id
,
reply_to
=
callback_queue
),
"
msg
"
:
{
"
username
"
:
username
,
"
action
"
:
action
,
"
service
"
:
service
},
}
)
elif
action
==
'
unlock
'
:
rc_rmq
.
publish_msg
(
{
"
routing_key
"
:
f
"
{
service
}
.
{
username
}
"
,
"
props
"
:
pika
.
BasicProperties
(
correlation_id
=
corr_id
,
reply_to
=
callback_queue
),
"
msg
"
:
{
"
username
"
:
username
,
"
action
"
:
action
,
"
service
"
:
service
},
}
)
def
timeout_handler
(
signum
,
frame
):
def
timeout_handler
(
signum
,
frame
):
print
(
"
Process timeout, there
'
s some issue with agents
"
)
print
(
"
Process timeout, there
'
s some issue with agents
"
)
rc_util
.
rc_rmq
.
stop_consume
()
rc_util
.
rc_rmq
.
stop_consume
()
...
@@ -26,33 +69,32 @@ def timeout_handler(signum, frame):
...
@@ -26,33 +69,32 @@ def timeout_handler(signum, frame):
def
callback
(
channel
,
method
,
properties
,
body
):
def
callback
(
channel
,
method
,
properties
,
body
):
msg
=
json
.
loads
(
body
)
msg
=
json
.
loads
(
body
)
username
=
msg
[
"
username
"
]
username
=
msg
[
"
username
"
]
msg
[
"
success
"
]
=
false
if
msg
[
"
success
"
]:
if
msg
[
"
success
"
]:
print
(
f
"
Account for
{
username
}
has been blocked :.
"
)
print
(
f
"
Account for
{
username
}
has been blocked :.
"
)
else
:
else
:
print
(
f
"
There
'
s some issue
while block
in
g
account for
{
username
}
"
)
print
(
f
"
There
'
s some issue in account
management agents
for
{
username
}
"
)
errmsg
=
msg
.
get
(
"
errmsg
"
,
[])
errmsg
=
msg
.
get
(
"
errmsg
"
,
[])
for
err
in
errmsg
:
for
err
in
errmsg
:
print
(
err
)
print
(
err
)
rc_util
.
rc_rmq
.
stop_consume
()
rc_util
.
rc_rmq
.
stop_consume
()
rc_util
.
rc_rmq
.
d
elete_queue
()
rc_util
.
rc_rmq
.
d
isconnect
()
rc_util
.
block_account
(
print
(
f
"
{
args
.
action
}
action for
{
args
.
username
}
requested.
"
)
args
.
username
,
queuename
=
queuename
,
email
=
args
.
email
,
full
=
args
.
full_name
,
reason
=
args
.
reason
,
)
print
(
f
"
Lock action for
{
args
.
username
}
requested.
"
)
# Set initial timeout timer
# Set initial timeout timer
signal
.
signal
(
signal
.
SIGALRM
,
timeout_handler
)
signal
.
signal
(
signal
.
SIGALRM
,
timeout_handler
)
signal
.
setitimer
(
signal
.
ITIMER_REAL
,
timeout
)
signal
.
setitimer
(
signal
.
ITIMER_REAL
,
timeout
)
print
(
"
Waiting for completion...
"
)
print
(
"
Waiting for completion...
"
)
rc_util
.
consume
(
rc_rmq
.
start_consume
(
callback_queue
,
routing_key
=
f
"
complete.
{
queuename
}
"
,
callback
=
callback
{
"
queue
"
:
callback_queue
,
"
exclusive
"
:
True
,
"
bind
"
:
False
,
"
cb
"
:
callback
,
}
)
)
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