-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add renewal config stucture. Integrate with account objects
- Loading branch information
Showing
4 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from letssync.structures import base | ||
from letssync.structures import account | ||
from letssync.structures import renewal | ||
|
||
def build_tree(root_path): | ||
return base.Directory(path=root_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import sys | ||
import os | ||
import io | ||
|
||
from configobj import ConfigObj | ||
|
||
from letssync.structures.base import Directory, FileObj | ||
|
||
PY2 = sys.version_info.major == 2 | ||
|
||
class Renewals(Directory): | ||
def __init__(self, **kwargs): | ||
self.domains = {} | ||
self.accounts = {} | ||
super(Renewals, self).__init__(**kwargs) | ||
@classmethod | ||
def _child_class_override(cls, child_class, **kwargs): | ||
parent = kwargs.get('parent') | ||
if kwargs.get('id') == 'renewal' and parent.parent is None: | ||
return Renewals | ||
def add_child(self, cls, **kwargs): | ||
cls = RenewalConf | ||
obj = super(Renewals, self).add_child(cls, **kwargs) | ||
self.domains[obj.domain] = obj | ||
if obj.account_id not in self.accounts: | ||
self.accounts[obj.account_id] = {} | ||
self.accounts[obj.account_id][obj.domain] = obj | ||
return obj | ||
|
||
|
||
class RenewalConf(FileObj): | ||
serialize_attrs = ['account_id', 'domain'] | ||
def read(self, **kwargs): | ||
super(RenewalConf, self).read(**kwargs) | ||
if PY2: | ||
b = io.BytesIO(self.content) | ||
else: | ||
b = io.StringIO(self.content) | ||
self.config = ConfigObj(b) | ||
self.account_id = kwargs.get('account_id') | ||
if self.account_id is None: | ||
try: | ||
self.account_id = self.config['renewalparams']['account'] | ||
except TypeError: | ||
print(self.config['renewalparams'], type(self.config['renewalparams'])) | ||
raise | ||
self.domain = kwargs.get('domain') | ||
if self.domain is None: | ||
self.domain = self.id.rstrip('.conf') | ||
def on_tree_built(self): | ||
accounts = self.root.children['accounts'] | ||
self.account = accounts.accounts.get(self.account_id) | ||
def _write(self, overwrite=False): | ||
p = self.path | ||
if os.path.exists(p) and overwrite is False: | ||
return | ||
with open(self.path, 'wb') as f: | ||
self.config.write(f) | ||
def __eq__(self, other): | ||
return self.config.dict() == other.config.dict() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
PyOpenSSL | ||
configobj |