def connect(self, force_reset=False): if not self._collection or force_reset: if self.mgclient_config_path: config = Config(check=check, path=self.mgclient_config_path) client = Client(config) else: client = Client() db = client.db(self.mongogrant_spec) self._collection = db[self.collection_name]
def __init__( self, mongogrant_spec: str, collection_name: str, mgclient_config_path: Optional[str] = None, **kwargs, ): """ Args: mongogrant_spec: of the form `<role>`:`<host>`/`<db>`, where role is one of {"read", "readWrite"} or aliases {"ro", "rw"}; host is a db host (w/ optional port) or alias; and db is a db on that host, or alias. See mongogrant documentation. collection_name: name of mongo collection mgclient_config_path: Path to mongogrant client config file, or None if default path (`mongogrant.client.path`). """ self.mongogrant_spec = mongogrant_spec self.collection_name = collection_name self.mgclient_config_path = mgclient_config_path self._collection = None if self.mgclient_config_path: config = Config(check=check, path=self.mgclient_config_path) client = Client(config) else: client = Client() if set(("username", "password", "database", "host")) & set(kwargs): raise StoreError("MongograntStore does not accept " "username, password, database, or host " "arguments. Use `mongogrant_spec`.") self.kwargs = kwargs _auth_info = client.get_db_auth_from_spec(self.mongogrant_spec) super(MongograntStore, self).__init__( host=_auth_info["host"], database=_auth_info["authSource"], username=_auth_info["username"], password=_auth_info["password"], collection_name=self.collection_name, **kwargs, )
def setUpClass(cls): # `nosetests` does not see class decorators # https://github.com/nose-devs/nose/issues/946 if "TRAVIS" in os.environ and os.environ["TRAVIS"] == "true": raise unittest.SkipTest("Skipping this test on Travis CI.") cls.client = Client() cls.db_stag = cls.client.db("ro:staging/mp_core") cls.db_prod = cls.client.db("ro:prod/mp_emmet_prod") cls.db_phonons = cls.client.db("ro:prod/phonondb") cls.mats_stag = cls.db_stag.materials cls.mats_prod = cls.db_prod.materials idset_stag = set(cls.mats_stag.distinct("task_id")) idset_prod = set(cls.mats_prod.distinct("task_id")) n_new_ids = len(idset_stag - idset_prod) if n_new_ids: logging.info("{} new material ids".format(n_new_ids)) n_retiring_ids = len(idset_prod - idset_stag) if n_retiring_ids: logging.warning("{} retiring material ids".format(n_retiring_ids))
def mgrant_user(mgrant_server): config_path, mdport, dbname = mgrant_server config = Config(check=check, path=config_path, seed=seed()) client = Client(config) client.set_auth( host=f"localhost:{mdport}", db=dbname, role="read", username="******", password="******", ) client.set_auth( host=f"localhost:{mdport}", db=dbname, role="readWrite", username="******", password="******", ) client.set_alias("testhost", f"localhost:{mdport}", which="host") client.set_alias("testdb", dbname, which="db") return client
@app.route('/cubism') def cubism(): return current_app.send_static_file('cubism.v1.js') @app.route('/structureViewer') def structure_viewer(): return current_app.send_static_file('structureViewerBuilt.js') @app.route("/container") def get_style(): return current_app.send_static_file('container.css') client = Client() client.set_alias("mg2.lbl", "matgen2.lbl.gov", "host") client.set_alias("m01.nersc", "mongodb01.nersc.gov", "host") client.set_alias("m03.nersc", "mongodb03.nersc.gov", "host") client.set_alias("m04.nersc", "mongodb04.nersc.gov", "host") client.set_alias("build", "mp_prod", "db") client.set_alias("core", "fw_mp_prod_atomate", "db") client.set_alias("app", "mg_apps_prod", "db") client.set_alias("elastic", "fw_jhm_kpoints", "db") client.set_alias("SCAN", "fw_shyamd", "db") dbs = { "elastic": client.db("ro:m03.nersc/elastic", connect=False), "SCAN": client.db("ro:m03.nersc/SCAN", connect=False),
def __init__(self): from mongogrant import Client self.client = Client() self.core_db = self.client.db("ro:dev/optimade_core")