def makeDBPublicReadOnly(server, dbname): import couch_utils, os from services.service_template import getCouchAppPath dba_url = nodeSetup['couchDBUrlDBA'] db = server[dbname] # Add doc change handler couch_utils.pushCouchApp(os.path.join(getCouchAppPath(),"resource_data","apps","restrict-writers"), "%s/%s" % (dba_url, dbname)) # Add security object _, _, exist_sec_obj = db.resource.get_json('_security') sec_obj = { "admins": { "names": [], "roles": [] }, "readers": { "names": [], "roles": [] } } sec_obj.update(exist_sec_obj) parts = urlparse.urlsplit(dba_url) if (hasattr(parts,'username') and parts.username is not None and parts.username not in sec_obj["admins"]["roles"]): sec_obj["admins"]["names"].append(parts.username) db = server[dbname] _, _, result = db.resource.put_json('_security', sec_obj) print json.dumps(result)
def _setupResourceData(self): #Push the filter design document for the ressource_data. setup_utils.CreateDB(self._server, dblist=[self._nodeConfig.get("couch_info", "resourcedata")], deleteDB=True) couch_utils.pushCouchApp(_RESOURCE_DATA_FILTER_APP, urlparse.urljoin(self._nodeConfig.get("couch_info", "server"), self._nodeConfig.get("couch_info", "resourcedata")))
def _installCouchApps(self, couchappsDir, server): if (self.opts['active'] ==False) or (len(self.couchapps) == 0): return for db in self.couchapps.keys(): for app in self.couchapps[db]: appPath = path.abspath(path.join(path.join(couchappsDir, db), app)) dbUrl = urljoin(server.resource.url, db) pushCouchApp(appPath, dbUrl)
def _setupResourceData(self): #Push the filter design document for the ressource_data. setup_utils.CreateDB( self._server, dblist=[self._nodeConfig.get("couch_info", "resourcedata")], deleteDB=True) couch_utils.pushCouchApp( _RESOURCE_DATA_FILTER_APP, urlparse.urljoin( self._nodeConfig.get("couch_info", "server"), self._nodeConfig.get("couch_info", "resourcedata")))
def _installCouchApps(self, couchappsDir, server): if (self.opts["active"] == False) or (len(self.couchapps) == 0): return for db in self.couchapps.keys(): for app in self.couchapps[db]: appPath = path.abspath(path.join(path.join(couchappsDir, db), app)) if server.resource.credentials: username, password = server.resource.credentials parts = list(urlsplit(server.resource.url)) parts[1] = "%s:%s@%s" % (username, password, parts[1]) server_url = urlunsplit(parts) else: server_url = server.resource.url dbUrl = urljoin(server_url, db) pushCouchApp(appPath, dbUrl)
def _installCouchApps(self, couchappsDir, server): if (self.opts['active'] == False) or (len(self.couchapps) == 0): return for db in self.couchapps.keys(): for app in self.couchapps[db]: appPath = path.abspath( path.join(path.join(couchappsDir, db), app)) if server.resource.credentials: username, password = server.resource.credentials parts = list(urlsplit(server.resource.url)) parts[1] = "%s:%s@%s" % (username, password, parts[1]) server_url = urlunsplit(parts) else: server_url = server.resource.url dbUrl = urljoin(server_url, db) pushCouchApp(appPath, dbUrl)
def makeDBPublicReadOnly(server, dbname): import couch_utils, os from services.service_template import getCouchAppPath dba_url = nodeSetup['couchDBUrlDBA'] db = server[dbname] # Add doc change handler couch_utils.pushCouchApp( os.path.join(getCouchAppPath(), "resource_data", "apps", "restrict-writers"), "%s/%s" % (dba_url, dbname)) # Add security object _, _, exist_sec_obj = db.resource.get_json('_security') sec_obj = { "admins": { "names": [], "roles": [] }, "readers": { "names": [], "roles": [] } } sec_obj.update(exist_sec_obj) parts = urlparse.urlsplit(dba_url) if (hasattr(parts, 'username') and parts.username is not None and parts.username not in sec_obj["admins"]["roles"]): sec_obj["admins"]["names"].append(parts.username) db = server[dbname] _, _, result = db.resource.put_json('_security', sec_obj) print json.dumps(result)