Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
rabbitmq_agents
Manage
Activity
Members
Labels
Plan
Issues
16
Issue boards
Milestones
Wiki
Code
Merge requests
10
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
rc
rabbitmq_agents
Commits
e781343f
Commit
e781343f
authored
3 years ago
by
Eesaan Atluri
Browse files
Options
Downloads
Patches
Plain Diff
Improved logging, comments.
parent
be0e2644
No related branches found
No related tags found
2 merge requests
!147
Merge previous default branch feat-cod-rmq into main
,
!137
Refactor ssh access agent
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
prod_rmq_agents/ssh_access.py
+6
-11
6 additions, 11 deletions
prod_rmq_agents/ssh_access.py
with
6 additions
and
11 deletions
prod_rmq_agents/ssh_access.py
+
6
−
11
View file @
e781343f
...
...
@@ -17,7 +17,6 @@ logger = rc_util.get_logger(args)
# Instantiate rabbitmq object
rc_rmq
=
RCRMQ
({
"
exchange
"
:
rcfg
.
Exchange
,
"
exchange_type
"
:
"
topic
"
})
print
(
"
ssh_agent entered
"
)
def
ssh_access
(
ch
,
method
,
properties
,
body
):
msg
=
json
.
loads
(
body
)
...
...
@@ -32,10 +31,9 @@ def ssh_access(ch, method, properties, body):
try
:
# check if it's a response from group_member_agent
if
routing_key
==
task
:
print
(
"
routing_key matches
"
)
print
(
f
"
corr_id sent by group_member agent:
{
properties
.
correlation_id
}
"
)
logger
.
debug
(
f
"
corr_id sent by group_member agent:
{
properties
.
correlation_id
}
"
)
if
corr_id
==
properties
.
correlation_id
:
print
(
f
'
group_member agent confirmation msg[
"
success
"
]:
{
msg
[
"
success
"
]
}
'
)
logger
.
debug
(
f
'
group_member agent confirmation msg[
"
success
"
]:
{
msg
[
"
success
"
]
}
'
)
# forward confirmation response to acct_mgmt_workflow agent
rc_rmq
.
publish_msg
(
{
...
...
@@ -47,7 +45,7 @@ def ssh_access(ch, method, properties, body):
else
:
corr_id
=
str
(
uuid
.
uuid4
())
print
(
f
'
corr_id generated:
{
corr_id
}
'
)
logger
.
debug
(
f
'
corr_id generated:
{
corr_id
}
'
)
msg
[
"
groups
"
]
=
{}
proc
=
Popen
([
'
/usr/bin/groups
'
,
username
],
stdout
=
PIPE
,
stderr
=
PIPE
)
...
...
@@ -65,28 +63,24 @@ def ssh_access(ch, method, properties, body):
# Depending on state add user to the group corresponding to state.
# Remove user from lock_groups they are already part of.
# eg: {"groups": { "add":[a,b,c], "remove":[d,e,f] }
if
state
==
'
certification
'
:
# eg: {"groups": { "add":[a,b,c], "remove":[d,e,f] }
msg
[
"
groups
"
][
"
add
"
]
=
[
lock_groups
[
state
]]
msg
[
"
groups
"
][
"
remove
"
]
=
spl_groups
elif
state
==
'
hold
'
:
# eg: {"groups": { "add":[a,b,c], "remove":[d,e,f] }
msg
[
"
groups
"
][
"
add
"
]
=
[
lock_groups
[
state
]]
msg
[
"
groups
"
][
"
remove
"
]
=
spl_groups
elif
state
==
'
pre_certification
'
:
# eg: {"groups": { "add":[a,b,c], "remove":[d,e,f] }
msg
[
"
groups
"
][
"
add
"
]
=
[
lock_groups
[
state
]]
msg
[
"
groups
"
][
"
remove
"
]
=
spl_groups
elif
state
==
'
ok
'
:
msg
[
"
groups
"
][
"
remove
"
]
=
spl_groups
# send a message to group_member.py agent
logger
.
info
(
f
"
Request sent to add/remove user
{
username
}
to spl groups
"
)
print
(
f
"
sending msg to group agent
{
msg
}
"
)
logger
.
debug
(
f
"
sending msg to group agent:
{
msg
}
"
)
rc_rmq
.
publish_msg
(
{
"
routing_key
"
:
f
'
group_member.
{
queuename
}
'
,
...
...
@@ -97,6 +91,7 @@ def ssh_access(ch, method, properties, body):
"
msg
"
:
msg
}
)
logger
.
info
(
f
"
Request sent to add/remove user
{
username
}
to/from spl groups
"
)
except
Exception
:
msg
[
"
success
"
]
=
False
...
...
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