Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
rabbitmq_agents
Manage
Activity
Members
Labels
Plan
Issues
14
Issue boards
Milestones
Wiki
Code
Merge requests
8
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
05246993
Unverified
Commit
05246993
authored
4 years ago
by
Ravi Tripathi
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #21 from diedpigs/feat-git-commit-agent
Feat git commit agent
parents
8d63ca44
d75c72d8
No related branches found
Branches containing commit
No related tags found
5 merge requests
!147
Merge previous default branch feat-cod-rmq into main
,
!85
kill nginx process running under user from login node
,
!51
Fix acct create wait
,
!39
WIP:Feat cod rmq
,
!38
WIP: Feat cod rmq
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
git_commit.py
+103
-0
103 additions, 0 deletions
git_commit.py
requirements.txt
+1
-0
1 addition, 0 deletions
requirements.txt
with
104 additions
and
0 deletions
git_commit.py
0 → 100644
+
103
−
0
View file @
05246993
#!/usr/bin/env python
import
os
import
sh
import
sys
import
json
import
rc_util
from
rc_rmq
import
RCRMQ
task
=
'
git_commit
'
# Instantiate rabbitmq object
rc_rmq
=
RCRMQ
({
'
exchange
'
:
'
RegUsr
'
,
'
exchange_type
'
:
'
topic
'
})
# Define some location
repo_location
=
os
.
path
.
expanduser
(
'
~/git/rc-users
'
)
users_dir
=
repo_location
+
'
/users
'
groups_dir
=
repo_location
+
'
/groups
'
args
=
rc_util
.
get_args
()
logger
=
rc_util
.
get_logger
(
args
)
if
not
args
.
dry_run
:
git
=
sh
.
git
.
bake
(
'
-C
'
,
repo_location
)
ldapsearch
=
sh
.
Command
(
'
ldapsearch
'
)
else
:
git
=
sh
.
echo
.
bake
(
'
git
'
,
'
-C
'
,
repo_location
)
ldapsearch
=
sh
.
echo
.
bake
(
'
ldapsearch
'
)
def
git_commit
(
ch
,
method
,
properties
,
body
):
msg
=
json
.
loads
(
body
)
username
=
msg
[
'
username
'
]
ticketnum
=
msg
.
get
(
'
ticketnum
'
,
'
add-users-
'
+
username
.
lower
())
msg
[
'
task
'
]
=
task
msg
[
'
success
'
]
=
False
branch_name
=
'
issue-
'
+
ticketnum
user_ldif
=
users_dir
+
f
'
/
{
username
}
.ldif
'
group_ldif
=
groups_dir
+
f
'
/
{
username
}
.ldif
'
logger
.
info
(
"
Received: %s
"
,
msg
)
logger
.
debug
(
"
ticketnum: %s
"
,
ticketnum
)
logger
.
debug
(
"
branch_name: %s
"
,
branch_name
)
try
:
logger
.
debug
(
'
git checkout master
'
)
git
.
checkout
(
'
master
'
)
logger
.
debug
(
'
git pull
'
)
git
.
pull
()
logger
.
debug
(
'
git checkout -b %s
'
,
branch_name
)
git
.
checkout
(
'
-b
'
,
branch_name
)
logger
.
debug
(
"
open(%s,
'
w
'
), open(%s,
'
w
'
)
"
,
user_ldif
,
group_ldif
)
with
open
(
user_ldif
,
'
w
'
)
as
ldif_u
,
\
open
(
group_ldif
,
'
w
'
)
as
ldif_g
:
logger
.
debug
(
f
"
ldapsearch -LLL -x -h ldapserver -b
'
dc=cm,dc=cluster
'
uid=
{
username
}
>
{
user_ldif
}
"
)
ldapsearch
(
'
-LLL
'
,
'
-x
'
,
'
-h
'
,
'
ldapserver
'
,
'
-b
'
,
"
dc=cm,dc=cluster
"
,
f
"
uid=
{
username
}
"
,
_out
=
ldif_u
)
logger
.
debug
(
f
"
ldapsearch -LLL -x -h ldapserver -b
'
ou=Group,dc=cm,dc=cluster
'
cn=
{
username
}
>
{
group_ldif
}
"
)
ldapsearch
(
'
-LLL
'
,
'
-x
'
,
'
-h
'
,
'
ldapserver
'
,
'
-b
'
,
"
ou=Group,dc=cm,dc=cluster
"
,
f
"
cn=
{
username
}
"
,
_out
=
ldif_g
)
logger
.
info
(
'
user ldif files generated.
'
)
logger
.
debug
(
'
git add %s
'
,
user_ldif
)
git
.
add
(
user_ldif
)
logger
.
debug
(
'
git add %s
'
,
group_ldif
)
git
.
add
(
group_ldif
)
logger
.
debug
(
"
git commit -m
'
Added new cheaha user: %s
'"
,
username
)
git
.
commit
(
m
=
"
Added new cheaha user:
"
+
username
)
logger
.
debug
(
'
git checkout master
'
)
git
.
checkout
(
'
master
'
)
logger
.
debug
(
'
git merge %s --no-ff --no-edit
'
,
branch_name
)
git
.
merge
(
branch_name
,
'
--no-ff
'
,
'
--no-edit
'
)
logger
.
debug
(
'
git push origin master
'
)
git
.
push
(
'
origin
'
,
'
master
'
)
# merge with gitlab api
logger
.
info
(
'
Added ldif files and committed to git repo
'
)
msg
[
'
success
'
]
=
True
except
Exception
as
exception
:
logger
.
error
(
''
,
exc_info
=
True
)
# Send confirm message
logger
.
debug
(
'
rc_rmq.publish_msge()
'
)
rc_rmq
.
publish_msg
({
'
routing_key
'
:
'
confirm.
'
+
username
,
'
msg
'
:
msg
})
logger
.
info
(
'
confirmation sent
'
)
# Acknowledge message
logger
.
debug
(
'
ch.basic_ack()
'
)
ch
.
basic_ack
(
delivery_tag
=
method
.
delivery_tag
)
logger
.
info
(
"
Start listening to queue: %s
"
,
task
)
rc_rmq
.
start_consume
({
'
queue
'
:
task
,
'
routing_key
'
:
"
verify.*
"
,
'
cb
'
:
git_commit
})
logger
.
info
(
"
Disconnected
"
)
rc_rmq
.
disconnect
()
This diff is collapsed.
Click to expand it.
requirements.txt
+
1
−
0
View file @
05246993
pika
==1.1.0
pika
==1.1.0
sh
==1.12.14
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