This is an automated email from the ASF dual-hosted git repository.
gstein pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/steve.git
The following commit(s) were added to refs/heads/trunk by this push:
new d362cf1 start drafting app-level work
d362cf1 is described below
commit d362cf15e33bb36710a56e0ff775c72632bc7ae6
Author: Greg Stein <[email protected]>
AuthorDate: Sun May 29 05:01:48 2022 -0500
start drafting app-level work
---
v3/steve/election.py | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 67 insertions(+)
diff --git a/v3/steve/election.py b/v3/steve/election.py
new file mode 100644
index 0000000..3452295
--- /dev/null
+++ b/v3/steve/election.py
@@ -0,0 +1,67 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# ----
+#
+# ### TBD: DOCCO
+#
+#
+
+import sys
+
+from . import crypto
+from . import db
+
+
+class Election:
+
+ def __init__(self, eid, db_fname):
+ self.eid = eid
+ self.db = db.DB(db_fname)
+
+ # Construct cursors for all operations.
+ self.c_salt_issue = self.db.add_statement(
+ '''UPDATE ISSUES SET salt = ? WHERE _ROWID_ = ?''')
+ self.c_salt_record = self.db.add_statement(
+ '''UPDATE RECORD SET salt = ? WHERE _ROWID_ = ?''')
+
+ def open(self):
+ pass
+
+ def close(self):
+ pass
+
+ def add_salts(self):
+ "Set the SALT column in the ISSUES and RECORD tables."
+
+ cur = self.db.conn.cursor()
+
+ def for_table(table, mod_cursor):
+ "Use MOD_CURSOR to salt each row of TABLE."
+
+ # Fetch all ROWID values now, to avoid two cursors
+ # attempting to work on TABLE at the same time.
+ cur.execute(f'SELECT _ROWID_ FROM {table}')
+ ids = cur.fetchall()
+
+ # Now, add a salt to every row.
+ for r in ids:
+ salt = crypto.gen_salt()
+ print('ROW will use:', table, r[0], salt)
+ mod_cursor.perform((salt, r[0]))
+
+ for_table('issues', self.c_salt_issue)
+ for_table('record', self.c_salt_record)