Compare commits
No commits in common. "49cb37eda2d756c284d8c250b3284c5243d06845" and "a1a2bf34b3d3fced9b026240691692257d1f1468" have entirely different histories.
49cb37eda2
...
a1a2bf34b3
30
README.md
30
README.md
@ -1,30 +0,0 @@
|
|||||||
# LGit (pronounced "legit")
|
|
||||||
|
|
||||||
python library that allows to use LDAP user database, based on luser project with git-like functions
|
|
||||||
|
|
||||||
Examples:
|
|
||||||
|
|
||||||
Following script copies changes made on 192.168.1.13 LDAP server to the 192.168.1.21 server
|
|
||||||
|
|
||||||
```
|
|
||||||
import lgit
|
|
||||||
|
|
||||||
server1 = lgit.logserver("192.168.1.13", "cn=admin,dc=example,dc=com", "adminpass", "ou=Users,dc=example,dc=com")
|
|
||||||
server2 = lgit.logserver("192.168.1.21", "ou=bob,ou=Users,dc=example,dc=com", "pasSw0rd", "ou=Users,dc=example,dc=com")
|
|
||||||
|
|
||||||
server1.pull(server2)
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
Following script pulls all user changes from both servers to each other
|
|
||||||
|
|
||||||
```
|
|
||||||
import lgit
|
|
||||||
|
|
||||||
server1 = lgit.logserver("192.168.1.13", "cn=admin,dc=example,dc=com", "adminpass", "ou=Users,dc=example,dc=com")
|
|
||||||
server2 = lgit.logserver("192.168.1.21", "ou=bob,ou=Users,dc=example,dc=com", "pasSw0rd", "ou=Users,dc=example,dc=com")
|
|
||||||
|
|
||||||
lg = lgit.lgit()
|
|
||||||
lg.sync()
|
|
||||||
|
|
||||||
```
|
|
@ -256,8 +256,8 @@ l dc values from base
|
|||||||
|
|
||||||
return basecopy
|
return basecopy
|
||||||
|
|
||||||
def fetchfrom(self, source)->int:
|
def pullfrom(self, source)->int:
|
||||||
fetched = 0
|
pulled = 0
|
||||||
basecopy = self.getbasecopy(source)
|
basecopy = self.getbasecopy(source)
|
||||||
|
|
||||||
self.refreshtotal(basecopy)
|
self.refreshtotal(basecopy)
|
||||||
@ -273,9 +273,9 @@ l dc values from base
|
|||||||
attributes = log['attributes']
|
attributes = log['attributes']
|
||||||
|
|
||||||
self.setlog(attributes, basecopy)
|
self.setlog(attributes, basecopy)
|
||||||
fetched += 1
|
pulled += 1
|
||||||
|
|
||||||
return fetched
|
return pulled
|
||||||
|
|
||||||
def applyfrom(self, source)->int:
|
def applyfrom(self, source)->int:
|
||||||
basecopy = self.getbasecopy(source)
|
basecopy = self.getbasecopy(source)
|
||||||
@ -284,25 +284,6 @@ l dc values from base
|
|||||||
|
|
||||||
return appliedlogs
|
return appliedlogs
|
||||||
|
|
||||||
def applyto(self, destination)->int:
|
|
||||||
basecopy = destination.getbasecopy(self)
|
|
||||||
|
|
||||||
appliedlogs = destination.applylogs(basecopy)
|
|
||||||
|
|
||||||
return appliedlogs
|
|
||||||
|
|
||||||
def pullfrom(self, source)->int:
|
|
||||||
self.fetchfrom(source)
|
|
||||||
applied = self.applyfrom(source)
|
|
||||||
|
|
||||||
return applied
|
|
||||||
|
|
||||||
def pushto(self, destination)->int:
|
|
||||||
destination.pullfrom(self)
|
|
||||||
pushed = destination.pullfrom(self)
|
|
||||||
|
|
||||||
return pushed
|
|
||||||
|
|
||||||
def lastpwchangenow(self):
|
def lastpwchangenow(self):
|
||||||
'''
|
'''
|
||||||
Return time of last password change for the user set to current time
|
Return time of last password change for the user set to current time
|
||||||
@ -311,7 +292,7 @@ l dc values from base
|
|||||||
|
|
||||||
return str((datetime.utcnow() - datetime(1970,1,1)).days)
|
return str((datetime.utcnow() - datetime(1970,1,1)).days)
|
||||||
|
|
||||||
class lgit():
|
class ldapsync():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.servers = []
|
self.servers = []
|
||||||
|
|
||||||
@ -323,22 +304,22 @@ class lgit():
|
|||||||
self.servers.remove(log_server)
|
self.servers.remove(log_server)
|
||||||
return self.servers
|
return self.servers
|
||||||
|
|
||||||
def fetchfromall(self, log_server: logserver)->int:
|
def pullfromall(self, log_server: logserver)->int:
|
||||||
fetchedlogs = 0
|
pulledlogs = 0
|
||||||
|
|
||||||
for source in self.servers:
|
for source in self.servers:
|
||||||
if source != log_server:
|
if source != log_server:
|
||||||
fetchedlogs += log_server.fetchedfrom(source)
|
pulledlogs += log_server.pullfrom(source)
|
||||||
|
|
||||||
return pulledlogs
|
return pulledlogs
|
||||||
|
|
||||||
def fetch(self)->int:
|
def pull(self)->int:
|
||||||
fetchedlogs = 0
|
pulledlogs = 0
|
||||||
|
|
||||||
for server in self.servers:
|
for server in self.servers:
|
||||||
fetchedlogs += self.fetchfromall(server)
|
pulledlogs += self.pullfromall(server)
|
||||||
|
|
||||||
return fetchedlogs
|
return pulledlogs
|
||||||
|
|
||||||
def applyfromall(self, log_server: logserver)->int:
|
def applyfromall(self, log_server: logserver)->int:
|
||||||
appliedlogs = 0
|
appliedlogs = 0
|
||||||
@ -349,15 +330,6 @@ class lgit():
|
|||||||
|
|
||||||
return appliedlogs
|
return appliedlogs
|
||||||
|
|
||||||
def applytoall(self, log_server: logserver)->int:
|
|
||||||
appliedlogs = 0
|
|
||||||
|
|
||||||
for destination in self.servers:
|
|
||||||
if destination != log_server:
|
|
||||||
appliedlogs += log_server.applyto(destination)
|
|
||||||
|
|
||||||
return appliedlogs
|
|
||||||
|
|
||||||
def apply(self)->int:
|
def apply(self)->int:
|
||||||
appliedlogs = 0
|
appliedlogs = 0
|
||||||
|
|
||||||
@ -366,31 +338,8 @@ class lgit():
|
|||||||
|
|
||||||
return appliedlogs
|
return appliedlogs
|
||||||
|
|
||||||
def pullfromall(self, log_server: logserver)->int:
|
|
||||||
self.fetchfromall(log_server)
|
|
||||||
pulled = self.applyfromall(log_server)
|
|
||||||
|
|
||||||
return pulled
|
|
||||||
|
|
||||||
def pushtoall(self, log_server: logserver)->int:
|
|
||||||
pushed = 0
|
|
||||||
|
|
||||||
for destination in self.servers:
|
|
||||||
if destination != log_server:
|
|
||||||
pushed += log_server.pushto(destination)
|
|
||||||
|
|
||||||
return pushed
|
|
||||||
|
|
||||||
def pull(self)->int:
|
|
||||||
self.fetch()
|
|
||||||
pulled = self.apply()
|
|
||||||
|
|
||||||
return pulled
|
|
||||||
|
|
||||||
def push(self)->int:
|
|
||||||
return self.pull()
|
|
||||||
|
|
||||||
def sync(self)->int:
|
def sync(self)->int:
|
||||||
pulledlogs = self.pull()
|
pulledlogs = self.pull()
|
||||||
|
appliedlogs = self.apply()
|
||||||
|
|
||||||
return pulledlogs
|
return appliedlogs
|
Loading…
Reference in New Issue
Block a user