Skip to content

Commit

Permalink
Merge pull request #1 from JamesJonesConsulting/release/3.1.0
Browse files Browse the repository at this point in the history
Release/3.1.0
  • Loading branch information
jamjon3 authored Dec 5, 2022
2 parents d30b0b8 + 479c001 commit 0f972b3
Show file tree
Hide file tree
Showing 13 changed files with 270 additions and 116 deletions.
81 changes: 55 additions & 26 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
build-job:
runs-on: self-hosted
container:
image: registry.fedoraproject.org/fedora:latest
image: quay.io/podman/stable:latest
options: --userns=keep-id --privileged --user root
steps:
# Downloads a copy of the code in your repository before running CI tests
Expand All @@ -16,8 +16,8 @@ jobs:
- name: Install RPM dependencies
run: |
dnf install -y rpm-build rpm-sign rubygems ruby-devel gcc gcc-c++ make \
libffi-devel python3 python3-pip python3-virtualenv
# Sets up Rubygems packaging
libffi-devel python3 python3-pip python3-virtualenv curl pinentry
# Sets up Rubygems packaging pinentry-program /usr/bin/pinentry-curses
- name: Setup FPM with it's dependent package for building a package
run: |
gem install ffi
Expand All @@ -39,44 +39,73 @@ jobs:
VERSION=$GITHUB_REF_NAME
else
VERSION=$(./dist/voterwarehouse -v)
VERSION+=$(echo "~${GITHUB_REF_NAME}" | sed 's|/|-|g')
VERSION+=$(echo "~${GITHUB_REF_NAME}" | sed "s|/${VERSION}||g" | sed 's|/|-|g')
fi
echo "$VERSION"
echo "$GITHUB_RUN_NUMBER"
fpm -s dir -t rpm -n voterwarehouse -v ${VERSION} --iteration ${GITHUB_RUN_NUMBER} \
--description "VoterWarehouse: Imports and Extracts Voter and History data" \
--url "https://github.com/jamjon3/VoterWarehouse" \
--license "LGPL-3.0" --vendor "James Jones" \
--config-files /etc/VoterWarehouse/config.yml \
-p ./dist \
./dist/voterwarehouse=/usr/bin/voterwarehouse \
./config.sample.yml=/etc/VoterWarehouse/config.yml
--description "VoterWarehouse: Imports and Extracts Voter and History data" \
--url "https://github.com/JamesJonesConsulting/VoterWarehouse" \
--license "LGPL-3.0" --vendor "James Jones" --maintainer "James Jones <[email protected]>" \
--config-files /etc/VoterWarehouse/config.yml \
-p ./dist \
./dist/voterwarehouse=/usr/bin/voterwarehouse \
./config.sample.yml=/etc/VoterWarehouse/config.yml
PACKAGE_FILE=$(find . -type f -name "voterwarehouse*.rpm")
package_cloud push $PACKAGE_CLOUD_REPO $PACKAGE_FILE
rpm --import https://nexus.jamjon3.sytes.net/repository/gpg/RPM-GPG-KEY-JAMJON3
echo "${{ secrets.JAMJON3_RPM_SIGN_GPG_KEY }}" | base64 -d > key.gpg
echo "${{ secrets.JAMJON3_RPM_SIGN_GPG_SECRET_KEY }}" | base64 -d > private.gpg
export GPG_TTY=$(tty)
gpg --import key.gpg
echo '${{ secrets.JAMJON3_RPM_SIGN_PASSPHRASE }}' | gpg --batch --import private.gpg
rpm --define "_gpg_name James Jones <[email protected]>" \
--define "_gpg_sign_cmd_extra_args --pinentry-mode loopback --passphrase ${{ secrets.JAMJON3_RPM_SIGN_PASSPHRASE }}" \
--addsign $PACKAGE_FILE
curl -u "$YUM_USER:$YUM_PASSWORD" --upload-file $PACKAGE_FILE $NEXUS_YUM_REPO
# package_cloud push $PACKAGE_CLOUD_REPO $PACKAGE_FILE
shell: bash
env:
PACKAGE_CLOUD_REPO: jamjon3/yum/rpm_any/rpm_any
YUM_USER: ${{ secrets.HOME_NEXUS_YUM_USER }}
YUM_PASSWORD: ${{ secrets.HOME_NEXUS_YUM_PASSWORD }}
NEXUS_YUM_REPO: https://nexus.jamjon3.sytes.net/repository/yum-hosted/voting/
- name: Build the DEB package
run: |
if [[ "$GITHUB_REF" =~ ^refs/tags.* ]]; then
VERSION=$GITHUB_REF_NAME
else
VERSION=$(./dist/voterwarehouse -v)
VERSION+=$(echo "~${GITHUB_REF_NAME}" | sed 's|/|-|g')
# VERSION+=$(echo "~${GITHUB_REF_NAME}" | sed 's|/|-|g')
VERSION+=$(echo "~${GITHUB_REF_NAME}" | sed "s|/${VERSION}||g" | sed 's|/|-|g')
fi
echo "$VERSION"
echo "$GITHUB_RUN_NUMBER"
fpm -s dir -t deb -n voterwarehouse -v ${VERSION} --iteration ${GITHUB_RUN_NUMBER} \
--description "VoterWarehouse: Imports and Extracts Voter and History data" \
--url "https://github.com/jamjon3/VoterWarehouse" \
--license "LGPL-3.0" --vendor "James Jones" \
--config-files /etc/VoterWarehouse/config.yml \
-p ./dist \
./dist/voterwarehouse=/usr/bin/voterwarehouse \
./config.sample.yml=/etc/VoterWarehouse/config.yml
PACKAGE_FILE=$(find . -type f -name "voterwarehouse*.deb")
package_cloud push $PACKAGE_CLOUD_REPO $PACKAGE_FILE
--description "VoterWarehouse: Imports and Extracts Voter and History data" \
--url "https://github.com/jamjon3/VoterWarehouse" \
--license "LGPL-3.0" --vendor "James Jones" \
--config-files /etc/VoterWarehouse/config.yml \
-p ./dist \
./dist/voterwarehouse=/usr/bin/voterwarehouse \
./config.sample.yml=/etc/VoterWarehouse/config.yml
echo "${{ secrets.JAMJON3_RPM_SIGN_GPG_KEY }}" | base64 -d > dist/key.gpg
echo "${{ secrets.JAMJON3_RPM_SIGN_GPG_SECRET_KEY }}" | base64 -d > dist/private.gpg
podman build --no-cache \
--build-arg PRIVATE_KEY_PASS=${{ secrets.JAMJON3_RPM_SIGN_PASSPHRASE }} \
-f Dockerfile.ubuntu \
-v "$(pwd)/dist:/dist:Z" .
PACKAGE_FILE=$(find . -type f -name "voterwarehouse*.deb")
apt_repos=(
apt-focal-hosted
)
for repo in ${apt_repos[@]}; do
DATA_BINARY='@'
DATA_BINARY+="$PACKAGE_FILE"
echo "$DATA_BINARY"
echo "${NEXUS_APT_REPOSITORY_ROOT}${repo}/"
curl -u "${APT_USER}:${APT_PASSWORD}" -H "Content-Type: multipart/form-data" --data-binary "${DATA_BINARY}" "${NEXUS_APT_REPOSITORY_ROOT}${repo}/"
done
# package_cloud push $PACKAGE_CLOUD_REPO $PACKAGE_FILE
shell: bash
env:
PACKAGE_CLOUD_REPO: jamjon3/deb/any/any
APT_USER: ${{ secrets.HOME_NEXUS_APT_USER }}
APT_PASSWORD: ${{ secrets.HOME_NEXUS_APT_PASSWORD }}
NEXUS_APT_REPOSITORY_ROOT: https://nexus.jamjon3.sytes.net/repository/

2 changes: 1 addition & 1 deletion .idea/VoterWarehouse.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions .idea/runConfigurations/voterwarehouse.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions Dockerfile.ubuntu
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM docker.io/ubuntu:jammy AS jammy

ARG PRIVATE_KEY_PASS

ENV GPG_TTY /dev/console

RUN apt-get update; apt-get install -y dpkg-sig gnupg

WORKDIR /dist

RUN gpg --import key.gpg \
&& echo '${PRIVATE_KEY_PASS}' | gpg --batch --import private.gpg \
&& PUBLIC_KEY_ID=$(gpg --list-keys | grep "^\s" | xargs) \
&& PACKAGE_FILE=$(find . -type f -name "voterwarehouse*.deb" | xargs basename)
# && dpkg-sig -k $PUBLIC_KEY_ID --sign $PACKAGE_FILE
# && dpkg-sig --verify $PACKAGE_FILE

31 changes: 2 additions & 29 deletions Import/Florida.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import datetime
import zipfile
import Warehouse.FloridaSQL
from Import.State import State


class Florida:
class Florida(State):
"""
Import.Florida class provides methods to import voter and voter history from provided Zip files
"""
Expand Down Expand Up @@ -104,34 +105,6 @@ class Florida:
"email_address"
]

def __init__(self, db):
"""
__init__ Sets the instance of Warehouse.Florida to a class variable named 'db'.
:param db: An instance of Warehouse.Florida
:return: None
"""
self.db = db

def __enter__(self):
"""
__enter__ Returns itself.
:return: Instance of Import.Florida
"""
return self

def __exit__(self, exc_type, exc_val, exc_tb):
"""
__exit__ Sets Exits the class.
:param exc_type: Execution Type
:param exc_val: Execution Value
:param exc_tb: Execution
:return: self
"""
return self

def parse_raw_history_into_tuple(self, history_raw, export_date):
# Build a temporary dictionary from raw voter binary string
row = dict(
Expand Down
69 changes: 69 additions & 0 deletions Import/State.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# -*- coding: utf-8 -*-

# Abstract class for handling Raw data import methods for State data

from abc import ABC, abstractmethod


class State(ABC):
"""
Import.Florida class provides methods to import voter and voter history from provided Zip files
"""
@property
@abstractmethod
def valid_import_types(self):
pass

@property
@abstractmethod
def history_keys(self):
pass

@property
@abstractmethod
def voter_keys(self):
pass

@property
@abstractmethod
def suppress_keys(self):
pass

def __init__(self, db):
"""
__init__ Sets the instance of Warehouse.Florida to a class variable named 'db'.
:param db: An instance of Warehouse.Florida
:return: None
"""
self.db = db

def __enter__(self):
"""
__enter__ Returns itself.
:return: Instance of Import.Florida
"""
return self

def __exit__(self, exc_type, exc_val, exc_tb):
"""
__exit__ Sets Exits the class.
:param exc_type: Execution Type
:param exc_val: Execution Value
:param exc_tb: Execution
:return: self
"""
return self

@abstractmethod
def import_source(self, file, t) -> None:
"""
import_source Reads in a Voter or History File in Zip format and sends it to the datastore.
:param t: String representing the type of zip file to import
:param file: The full path to the Zip file
:return: None
"""
pass
9 changes: 9 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,16 @@ Any DEB based (debian based) system to install the APT repo and the package
curl -s https://packagecloud.io/install/repositories/jamjon3/deb/script.deb.sh | sudo bash
sudo apt-get install voterwarehouse
Installing from Self-Hosted (James Jones Consulting)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Installing the RPM that is GPG Signed is easy off my Nexus Repository.

.. code:: commandline
curl https://nexus.jamjon3.sytes.net/repository/package-config/yum/jamjon3-voters.repo | sudo tee /etc/yum.repos.d/jamjon3-voters.repo
sudo yum install voterwarehouse
Command line syntax
^^^^^^^^^^^^^^^^^^^

Expand Down
61 changes: 5 additions & 56 deletions Warehouse/Florida.py
Original file line number Diff line number Diff line change
@@ -1,68 +1,18 @@
# -*- coding: utf-8 -*-

# Handles Database methods for FLorida data
# Handles Database methods for Florida data

import yaml
import pymysql
import pymysql.cursors
import Warehouse.FloridaSQL
from Warehouse.State import State


class Florida:
class Florida(State):
"""
Warehouse.Florida class provides methods for storage of voter and voter history records and
associated assistive methods,
"""

def __init__(self, config_file):
"""
__init__ Sets the config dictionary of database credentials into variable named 'db'.
:param config_file: Path to the YAML config file
:return: None
"""
try:
with open(config_file) as file:
self.config = yaml.full_load(file)['UnitedStates']['Florida']
except Exception as error:
print('Caught this error: ' + repr(error))
raise

def __enter__(self):
"""
__enter__ Creates the database connection and sets it to the class as 'db'
:return: Instance of Warehouse.Florida
"""
try:
self.db = pymysql.connect(
host=self.config["database"]["host"],
port=self.config["database"]["port"],
user=self.config["database"]["user"],
password=self.config["database"]["password"],
database=self.config["database"]["schema"],
cursorclass=pymysql.cursors.DictCursor
)
except Exception as error:
print('Caught this error: ' + repr(error))
raise
return self

def __exit__(self, exc_type, exc_val, exc_tb):
"""
__exit__ Sets Exits the class and closes the database connection
:param exc_type: Execution Type
:param exc_val: Execution Value
:param exc_tb: Execution
:return: self
"""
try:
self.db.close()
except Exception as error:
print('Caught this error: ' + repr(error))
raise
return self
country_designation = "UnitedStates"
state_designation = "Florida"

def execute_prepared_sql(self, prepared_sql, prepared_tuple) -> None:
"""
Expand Down Expand Up @@ -113,4 +63,3 @@ def init_schema(self) -> None:
except Exception as error:
print('Caught this error: ' + repr(error))
raise

Loading

0 comments on commit 0f972b3

Please sign in to comment.