Compare commits

..

5 Commits

2 changed files with 95 additions and 14 deletions

30
README.md Normal file
View File

@ -0,0 +1,30 @@
# 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()
```

View File

@ -256,8 +256,8 @@ l dc values from base
return basecopy
def pullfrom(self, source)->int:
pulled = 0
def fetchfrom(self, source)->int:
fetched = 0
basecopy = self.getbasecopy(source)
self.refreshtotal(basecopy)
@ -273,9 +273,9 @@ l dc values from base
attributes = log['attributes']
self.setlog(attributes, basecopy)
pulled += 1
fetched += 1
return pulled
return fetched
def applyfrom(self, source)->int:
basecopy = self.getbasecopy(source)
@ -284,6 +284,25 @@ l dc values from base
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):
'''
Return time of last password change for the user set to current time
@ -292,7 +311,7 @@ l dc values from base
return str((datetime.utcnow() - datetime(1970,1,1)).days)
class ldapsync():
class lgit():
def __init__(self):
self.servers = []
@ -304,22 +323,22 @@ class ldapsync():
self.servers.remove(log_server)
return self.servers
def pullfromall(self, log_server: logserver)->int:
pulledlogs = 0
def fetchfromall(self, log_server: logserver)->int:
fetchedlogs = 0
for source in self.servers:
if source != log_server:
pulledlogs += log_server.pullfrom(source)
fetchedlogs += log_server.fetchedfrom(source)
return pulledlogs
def pull(self)->int:
pulledlogs = 0
def fetch(self)->int:
fetchedlogs = 0
for server in self.servers:
pulledlogs += self.pullfromall(server)
fetchedlogs += self.fetchfromall(server)
return pulledlogs
return fetchedlogs
def applyfromall(self, log_server: logserver)->int:
appliedlogs = 0
@ -330,6 +349,15 @@ class ldapsync():
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:
appliedlogs = 0
@ -338,8 +366,31 @@ class ldapsync():
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:
pulledlogs = self.pull()
appliedlogs = self.apply()
return appliedlogs
return pulledlogs