Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Crans Passwords
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
5
Issues
5
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nounous
Crans Passwords
Commits
74ee60e8
Commit
74ee60e8
authored
Jun 03, 2015
by
Daniel STAN
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
début de réplication
parent
6377ccb9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
2 deletions
+63
-2
cpasswords/clientlib.py
cpasswords/clientlib.py
+25
-0
server.py
server.py
+26
-2
serverconfigs/tudor/serverconfig.py
serverconfigs/tudor/serverconfig.py
+12
-0
No files found.
cpasswords/clientlib.py
0 → 100644
View file @
74ee60e8
# -*- coding: utf-8 -*-
"""Client class definition for cpasswords protocol.
(WIP)
"""
from
cpasswords
import
client
as
_old_client
class
Client
(
object
):
"""A client connection."""
verbose
=
False
def
__init__
(
self
,
serverdata
):
"""
serverdata should be a classic dict object (from eg a clientconfig
module)
"""
self
.
serverdata
=
serverdata
def
put_file
(
self
,
data
):
"""Send file to server"""
# TODO put code here
_old_client
.
put_files
(
self
,
[
data
])
server.py
View file @
74ee60e8
...
...
@@ -17,10 +17,19 @@ import itertools
from
email.mime.text
import
MIMEText
from
email.mime.multipart
import
MIMEMultipart
try
:
from
cpasswords
import
clientlib
except
ImportError
:
print
(
"Couldn't import clientlib. Remote sync may not work"
)
# Même problème que pour le client, il faut bootstraper le nom de la commande
# Pour accéder à la config
cmd_name
=
os
.
path
.
split
(
sys
.
argv
[
0
])[
1
].
replace
(
"-server"
,
""
)
sys
.
path
.
append
(
"/etc/%s/"
%
(
cmd_name
,))
conf_path
=
os
.
getenv
(
'CRANSPASSWORDS_SERVER_CONFIG_DIR'
,
None
)
if
not
conf_path
:
cmd_name
=
os
.
path
.
split
(
sys
.
argv
[
0
])[
1
].
replace
(
"-server"
,
""
)
conf_path
=
"/etc/%s/"
%
(
cmd_name
,)
sys
.
path
.
append
(
conf_path
)
import
serverconfig
MYUID
=
pwd
.
getpwuid
(
os
.
getuid
())[
0
]
...
...
@@ -190,6 +199,11 @@ def _putfile(filename, roles, contents):
# Or fuck yourself
writefile
(
filepath
,
json
.
dumps
({
'roles'
:
roles
,
'contents'
:
contents
}))
data
=
{
'filename'
:
filename
,
'roles'
:
roles
,
'contents'
:
contents
}
for
client
in
_list_to_replicate
(
data
):
client
.
put_file
(
data
)
return
[
True
,
u
"Modification effectuée."
]
@
server_command
(
'putfile'
,
stdin_input
=
True
,
write
=
True
)
...
...
@@ -245,6 +259,16 @@ def backup(corps, fname, old):
back
.
write
((
u
'* %s: %s
\n
'
%
(
str
(
datetime
.
datetime
.
now
()),
corps
)).
encode
(
"utf-8"
))
back
.
close
()
def
_list_to_replicate
(
data
):
"""Renvoie une liste d'options clients sur lesquels appliquer relancer
la procédure (pour réplication auto)"""
roles
=
data
.
get
(
'roles'
,
[])
backups
=
getattr
(
serverconfig
,
'BACKUP_ROLES'
,
{})
servers
=
getattr
(
serverconfig
,
'BACKUP_SERVERS'
,
{})
configs
=
set
(
name
for
role
in
roles
for
name
in
backups
.
get
(
role
,
[]))
return
[
clientlib
.
Client
(
servers
[
name
])
for
name
in
configs
]
_notif_todo
=
[]
def
notification
(
action
,
fname
,
actor
):
"""Enregistre une notification"""
...
...
serverconfigs/tudor/serverconfig.py
View file @
74ee60e8
...
...
@@ -37,3 +37,15 @@ ROLES = {
'moi'
:
_ME
,
'moi-w'
:
_ME
,
}
BACKUP_SERVERS
=
{
'gladys'
:
{
'server_cmd'
:
[
'/usr/bin/ssh'
,
'home.b2moo.fr'
,
'/home/dstan/cranspasswords/serverconfigs/tudor/cpasswords-server'
,
],
'keep-alive'
:
True
,
},
}
BACKUP_ROLES
=
{
'moi'
:
[
'gladys'
],
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment