Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
rabbitmq_agents
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
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
e63b229b
Unverified
Commit
e63b229b
authored
4 years ago
by
Ravi Tripathi
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Plain Diff
Merge branch 'feat-cod-rmq' into feat-notify-user-agent
parents
4be0752f
ecc4069e
No related branches found
No related tags found
6 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
,
!24
Add notify user agent
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
create_account.py
+1
-1
1 addition, 1 deletion
create_account.py
dir_verify.py
+65
-0
65 additions, 0 deletions
dir_verify.py
git_commit.py
+103
-0
103 additions, 0 deletions
git_commit.py
requirements.txt
+1
-0
1 addition, 0 deletions
requirements.txt
with
170 additions
and
1 deletion
create_account.py
+
1
−
1
View file @
e63b229b
#!/usr/bin/env python
#!/usr/bin/env python
3
import
sys
import
rc_util
...
...
This diff is collapsed.
Click to expand it.
dir_verify.py
0 → 100644
+
65
−
0
View file @
e63b229b
#!/usr/bin/env python
import
sys
import
json
import
shutil
import
rc_util
from
pathlib
import
Path
from
rc_rmq
import
RCRMQ
task
=
'
dir_verify
'
dirs
=
[
'
/home
'
,
'
/data/user
'
,
'
/data/scratch
'
]
args
=
rc_util
.
get_args
()
logger
=
rc_util
.
get_logger
(
args
)
# Instantiate rabbitmq object
rc_rmq
=
RCRMQ
({
'
exchange
'
:
'
RegUsr
'
,
'
exchange_type
'
:
'
topic
'
})
def
dir_verify
(
ch
,
method
,
properties
,
body
):
msg
=
json
.
loads
(
body
)
username
=
msg
[
'
username
'
]
msg
[
'
task
'
]
=
task
msg
[
'
success
'
]
=
False
try
:
for
d
in
dirs
:
path
=
Path
(
d
)
/
msg
[
'
username
'
]
if
args
.
dry_run
:
logger
.
info
(
f
'
Checking dirs:
{
path
}
'
)
else
:
if
not
path
.
exists
():
# Make sure folder exists and with right permission
path
.
mkdir
(
mode
=
0o700
)
# Make sure ownership is correct
shutil
.
chown
(
path
,
int
(
msg
[
'
uid
'
]),
int
(
msg
[
'
gid
'
]))
logger
.
debug
(
f
'
{
path
}
created
'
)
msg
[
'
success
'
]
=
True
except
Exception
as
exception
:
logger
.
error
(
''
,
exc_info
=
True
)
# send confirm message
rc_rmq
.
publish_msg
({
'
routing_key
'
:
'
confirm.
'
+
username
,
'
msg
'
:
msg
})
logger
.
debug
(
f
'
User
{
username
}
confirmation sent
'
)
ch
.
basic_ack
(
delivery_tag
=
method
.
delivery_tag
)
logger
.
info
(
f
'
Start listening to queue:
{
task
}
'
)
rc_rmq
.
start_consume
({
'
queue
'
:
task
,
'
routing_key
'
:
"
verify.*
"
,
'
cb
'
:
dir_verify
})
logger
.
info
(
'
Disconnected
'
)
rc_rmq
.
disconnect
()
This diff is collapsed.
Click to expand it.
git_commit.py
0 → 100644
+
103
−
0
View file @
e63b229b
#!/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 @
e63b229b
pika
==1.1.0
dataset
==1.3.1
Jinja2
==2.11.2
sh
==1.12.14
\ No newline at end of file
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