Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #242 from wegrata/issue_238

added check/init for passwords field
  • Loading branch information...
commit 723dd57f37702840180e4d06ee0b057f004aa9f2 2 parents 6f7603e + 8b039e8
@jimklo jimklo authored
Showing with 52 additions and 50 deletions.
  1. +52 −50 LR/lr/model/node_config.py
View
102 LR/lr/model/node_config.py
@@ -27,14 +27,14 @@
from urlparse import urlparse, urlunparse, ParseResult
import json
import atexit
-_COUCHDB_FIELDS =['_id', '_rev',
- '_attachments',
- '_deleted',
- '_revisions',
+_COUCHDB_FIELDS =['_id', '_rev',
+ '_attachments',
+ '_deleted',
+ '_revisions',
'_revs_info',
'_conflicts',
'_deleted_conflicts' ]
-
+
log = logging.getLogger(__name__)
_ACCESS_CREDENTIALS_ID = "access_credentials"
@@ -44,29 +44,29 @@ def __init__(self, data):
self._communityDescription = None
self._networkDescription = None
self._nodeStatus = None
-
+
if isinstance(data, dict):
config = h.dictToObject(data)
-
+
# Check first if node description is set. if not look for in the DB if not in the db
# create it from the config data.
-
- self._communityDescription = self._initModel(CommunityModel,
+
+ self._communityDescription = self._initModel(CommunityModel,
config.community_description.community_id,
config.community_description)
-
- self._networkDescription = self._initModel(NetworkModel,
+
+ self._networkDescription = self._initModel(NetworkModel,
config.network_description.network_id,
config.network_description)
-
- self._nodeDescription = self._initModel(NodeModel,
+
+ self._nodeDescription = self._initModel(NodeModel,
config.node_description.node_id,
config.node_description)
-
- self._networkPolicyDescription = self._initModel(NetworkPolicyModel,
+
+ self._networkPolicyDescription = self._initModel(NetworkPolicyModel,
config.network_policy_description.policy_id,
config.network_policy_description)
-
+
try:
self.incoming_url = appConfig['lr.distribute_incoming_url']
except:
@@ -75,7 +75,7 @@ def __init__(self, data):
self._initServices(config.node_services)
self._initFilter(config)
self._initConnections(config)
- self._setNodeStatus()
+ self._setNodeStatus()
self._initConfig(config)
def _initModel(self, modelClass, modelId, modelConf):
@@ -89,14 +89,14 @@ def _initModel(self, modelClass, modelId, modelConf):
model = modelClass(modelDoc)
model.validate()
return model
-
+
def _initFilter(self, config):
if hasattr(self, '_filterDescription') or not hasattr(config, 'node_filter_description') :
return
- self._filterDescription = self._initModel(NodeFilterModel,
+ self._filterDescription = self._initModel(NodeFilterModel,
"Node filter",
config.node_filter_description)
-
+
def _initConfig(self, config):
if hasattr(self, "_config"):
return
@@ -108,7 +108,7 @@ def _initConfig(self, config):
self._config['node_services'] = config.node_services
if hasattr(config, 'node_filter_description'):
self._config['node_filter_description'] = config.node_filter_description
-
+
def _initServices(self, services):
if hasattr(self, "nodeServices"):
return
@@ -127,7 +127,7 @@ def _initConnections(self, config):
self._connections.append(self._initModel(NodeConnectivityModel,
connection['connection_id'],
connection))
-
+
def _setNodeStatus(self):
nodeStatus = None
nodeStatusId = "node status"
@@ -145,12 +145,12 @@ def _setNodeStatus(self):
nodeStatus.start_time = h.nowToISO8601Zformat()
nodeStatus.update()
self._nodeStatus = nodeStatus
-
+
def _getStatusDescription(self):
count = 0
view = ResourceDataModel._defaultDB.view(appConfig['couchdb.db.resourcecount'],stale=appConfig['couchdb.stale.flag'])
if len(view.rows) > 0:
- count = view.rows[0].value
+ count = view.rows[0].value
statusData = {'doc_count': count,
'timestamp': h.nowToISO8601Zformat()}
statusData.update(self._nodeStatus.specData)
@@ -165,7 +165,7 @@ def _getNodeJsonDescription(self):
if hasattr(self, '_filterDescription'):
description['filter'] = self._filterDescription.descriptionDict
return json.dumps(description, indent=2)
-
+
def _getNodeJsonPolicy(self):
policy = {'timestamp': h.nowToISO8601Zformat()}
key="network_description"
@@ -183,90 +183,90 @@ def _getNodeJsonPolicy(self):
# policy.update(self._networkPolicyDescription.descriptionDict)
policy.update(self._networkPolicyDescription.specData)
- return json.dumps(policy, indent=2)
-
+ return json.dumps(policy, indent=2)
+
def isServiceAvailable(self, service_name):
"""Method to test if serviceType is available """
return service_name in self._nodeServices and self._nodeServices[service_name].active
-
-
+
+
def _saveConfig(self, model, modeDB=None):
pass
def save(self):
""" Save the node configuration the couchdb database. The documents will
- be saved to the models default dabase. A document is saved only if
+ be saved to the models default dabase. A document is saved only if
it is not already in the database."""
#Save the model only if it is not already in the database. It's not in the
# database if it doesn't have a id.
if self._nodeDescription is not None and self._nodeDescription.id is None:
self._nodeDescription.save(doc_id=self._nodeDescription.node_id)
-
- if (self._networkDescription is not None and
+
+ if (self._networkDescription is not None and
self._networkDescription.id is None):
self._networkDescription.save(doc_id=self._networkDescription.network_id)
-
- if (self._communityDescription is not None and
+
+ if (self._communityDescription is not None and
self._communityDescription.id is None):
self._communityDescription.save(
doc_id=self._communityDescription.community_id)
-
- if (self._networkPolicyDescription is not None and
+
+ if (self._networkPolicyDescription is not None and
self._networkPolicyDescription.id is None):
self._networkPolicyDescription.save(
doc_id=self._networkPolicyDescription.policy_id)
-
+
if self._connections is not None:
for c in self._connections:
if c.id is None:
c.save(doc_id=c.connection_id)
-
+
if self._nodeServices is not None:
for s in self._nodeServices:
if s.id is None:
s.save(doc_id=s.service_id)
-
+
def saveOrUpdate(self):
""" Save the node configuration the couchdb database. The documents will
- be saved to the models default dabase. A document will be updated if
+ be saved to the models default dabase. A document will be updated if
it is already in the database."""
#Save the model only if it is not already in the database. It's not in the
# database if it doesn't have a id.
- if self._nodeDescription is not None:
+ if self._nodeDescription is not None:
if self._nodeDescription.id is None:
self._nodeDescription.save(doc_id=self._nodeDescription.node_id)
else:
self._nodeDescription.update()
-
+
if self._networkDescription is not None:
if self._networkDescription.id is None:
self._networkDescription.save(doc_id=self._networkDescription.network_id)
else:
self._networkDescription.update()
-
- if self._communityDescription is not None:
+
+ if self._communityDescription is not None:
if self._communityDescription.id is None:
self._communityDescription.save(
doc_id=self._communityDescription.community_id)
else:
self._communityDescription.update()
-
+
if self._networkPolicyDescription is not None:
if self._networkPolicyDescription.id is None:
self._networkPolicyDescription.save(
doc_id=self._networkPolicyDescription.policy_id)
else:
self._networkPolicyDescription.update()
-
+
if self._connections is not None:
for c in self._connections:
if c.id is None:
c.save(doc_id=c.connection_id)
else:
c.update()
-
+
if self._nodeServices is not None:
for s in self._nodeServices:
if s.id is None:
@@ -277,8 +277,10 @@ def addDistributeCredentialFor(self,targetUrl,username,password):
if _ACCESS_CREDENTIALS_ID in NodeModel._defaultDB:
access_credentials = NodeModel._defaultDB[_ACCESS_CREDENTIALS_ID]
else:
- access_credentials = {"_id": _ACCESS_CREDENTIALS_ID,"passwords":{}}
- access_credentials['passwords'][targetUrl] = {"username":username,"password":password}
+ access_credentials = {"_id": _ACCESS_CREDENTIALS_ID, "passwords": {}}
+ if "passwords" not in access_credentials:
+ access_credentials["passwords"] = {}
+ access_credentials['passwords'][targetUrl] = {"username": username, "password": password}
NodeModel._defaultDB.update([access_credentials])
@@ -290,7 +292,7 @@ def getDistributeCredentialFor(self, targetUrl):
passwords = h.dictToObject(NodeModel._defaultDB[_ACCESS_CREDENTIALS_ID])
credential = passwords.passwords.get(targetUrl)
return credential
-
+
def getDistributeInfo(self):
distributeInfo = {'active':self.nodeDescription.active,
'node_id':self.nodeDescription.node_id,
Please sign in to comment.
Something went wrong with that request. Please try again.