fix: remove remaining returned ids from sqlalchemy queries due to RETURNING clause

This commit is contained in:
Marshall Hallenbeck
2023-03-17 09:13:16 -04:00
parent 3e4ce963ee
commit 10efcc9d42
3 changed files with 16 additions and 16 deletions
+3 -3
View File
@@ -791,8 +791,8 @@ class database:
q,
[backup_key]
)
).scalar()
logging.debug(f"add_domain_backupkey(domain={domain}, pvk={pvk_encoded}) => {inserted_id}")
) # .scalar()
logging.debug(f"add_domain_backupkey(domain={domain}, pvk={pvk_encoded})")
# return inserted_id
except Exception as e:
logging.debug(f"Issue while inserting DPAPI Backup Key: {e}")
@@ -856,7 +856,7 @@ class database:
# inserted_result = res_inserted_result.first()
# inserted_id = inserted_result.id
logging.debug(f"add_dpapi_secrets(host={host}, dpapi_type={dpapi_type}, windows_user={windows_user}, username={username}, password={password}, url={url}) => {inserted_id}")
logging.debug(f"add_dpapi_secrets(host={host}, dpapi_type={dpapi_type}, windows_user={windows_user}, username={username}, password={password}, url={url})")
def get_dpapi_secrets(self, filter_term=None, host: str = None, dpapi_type: str = None, windows_user: str = None, username: str = None, url: str = None):
"""
+4 -4
View File
@@ -266,14 +266,14 @@ class winrm(connection):
)
self.logger.debug(f"Adding credential: {domain}/{self.username}:{self.password}")
user_id = self.db.add_credential('plaintext', domain, self.username, self.password)
host_id = self.db.get_hosts(self.host)[0].id
self.db.add_credential('plaintext', domain, self.username, self.password)
# host_id = self.db.get_hosts(self.host)[0].id
self.db.add_loggedin_relation(user_id, host_id)
# self.db.add_loggedin_relation(user_id, host_id)
if self.admin_privs:
self.logger.debug(f"Inside admin privs")
self.db.add_admin_user('plaintext', domain, self.username, self.password, self.host, user_id=user_id)
self.db.add_admin_user('plaintext', domain, self.username, self.password, self.host) # , user_id=user_id)
if not self.args.local_auth:
add_user_bh(self.username, self.domain, self.logger, self.config)
+9 -9
View File
@@ -201,19 +201,19 @@ class database:
credentials.append(cred_data)
# TODO: find a way to abstract this away to a single Upsert call
q_users = Insert(self.UsersTable).returning(self.UsersTable.c.id)
q_users = Insert(self.UsersTable) # .returning(self.UsersTable.c.id)
update_columns_users = {col.name: col for col in q_users.excluded if col.name not in 'id'}
q_users = q_users.on_conflict_do_update(
index_elements=self.UsersTable.primary_key,
set_=update_columns_users
)
user_ids = asyncio.run(
asyncio.run(
self.conn.execute(
q_users,
credentials
)
).scalar()
return user_ids
) # .scalar()
# return user_ids
def remove_credentials(self, creds_id):
"""
@@ -441,19 +441,19 @@ class database:
}
try:
# TODO: find a way to abstract this away to a single Upsert call
q = Insert(self.LoggedinRelationsTable).returning(self.LoggedinRelationsTable.c.id)
inserted_ids = asyncio.run(
q = Insert(self.LoggedinRelationsTable) # .returning(self.LoggedinRelationsTable.c.id)
asyncio.run(
self.conn.execute(
q,
[relation]
)
).scalar()
return inserted_ids
) # .scalar()
# return inserted_ids
except Exception as e:
logging.debug(f"Error inserting LoggedinRelation: {e}")
def get_loggedin_relations(self, user_id=None, host_id=None):
q = select(self.LoggedinRelationsTable).returning(self.LoggedinRelationsTable.c.id)
q = select(self.LoggedinRelationsTable) # .returning(self.LoggedinRelationsTable.c.id)
if user_id:
q = q.filter(
self.LoggedinRelationsTable.c.userid == user_id