def get_credential_details(self, tenant_id, credential_id): """Get a particular credential""" LOG.debug("get_credential_details() called\n") try: credential = cdb.get_credential(tenant_id, credential_id) except Exception: raise cexc.CredentialNotFound(tenant_id=tenant_id, credential_id=credential_id) return credential
def rename_credential(self, tenant_id, credential_id, new_name): """Rename the particular credential resource""" LOG.debug("rename_credential() called\n") try: credential = cdb.get_credential(tenant_id, credential_id) except Exception: raise cexc.CredentialNotFound(tenant_id=tenant_id, credential_id=credential_id) credential = cdb.update_credential(tenant_id, credential_id, new_name) return credential
def delete_credential(self, tenant_id, credential_id): """Delete a credential""" LOG.debug("delete_credential() called\n") try: credential = cdb.get_credential(tenant_id, credential_id) except Exception: raise cexc.CredentialNotFound(tenant_id=tenant_id, credential_id=credential_id) credential = cdb.remove_credential(tenant_id, credential_id) return credential
def get_credential(tenant_id, credential_id): """Lists the creds for given a cred_id and tenant_id""" session = db.get_session() try: cred = (session.query(network_models_v2.Credential).filter_by( tenant_id=tenant_id).filter_by(credential_id=credential_id).one()) return cred except exc.NoResultFound: raise c_exc.CredentialNotFound(credential_id=credential_id, tenant_id=tenant_id)
def update_credential(tenant_id, credential_id, new_user_name=None, new_password=None): """Updates a credential for a tenant""" session = db.get_session() try: cred = (session.query(l2network_models.Credential). filter_by(tenant_id=tenant_id). filter_by(credential_id=credential_id).one()) if new_user_name: cred["user_name"] = new_user_name if new_password: cred["password"] = new_password session.merge(cred) session.flush() return cred except exc.NoResultFound: raise c_exc.CredentialNotFound(credential_id=credential_id, tenant_id=tenant_id)