Skip to content

Commit 5748b04

Browse files
authored
#762 Version Info (#778)
* Infrastructure for showing version info * Show the git commit * Detect if in docker * Don't bother showing the version info on docker * fix linting issues * fix security issues by replacing GitPython with a subprocess command * fix linting issues
1 parent da4fd4b commit 5748b04

8 files changed

Lines changed: 97 additions & 148 deletions

File tree

poetry.lock

Lines changed: 27 additions & 147 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/electionguard_gui/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
MODE_KEY,
9494
PORT_KEY,
9595
ServiceBase,
96+
VersionService,
9697
announce_guardians,
9798
authorization_service,
9899
backup_to_dict,
@@ -139,6 +140,7 @@
139140
status_descriptions,
140141
to_ballot_share_raw,
141142
verification_to_dict,
143+
version_service,
142144
)
143145
from electionguard_gui.start import (
144146
run,
@@ -192,6 +194,7 @@
192194
"PORT_KEY",
193195
"ServiceBase",
194196
"UploadBallotsComponent",
197+
"VersionService",
195198
"ViewDecryptionComponent",
196199
"ViewElectionComponent",
197200
"ViewSpoiledBallotComponent",
@@ -271,6 +274,7 @@
271274
"upload_ballots_component",
272275
"utc_to_str",
273276
"verification_to_dict",
277+
"version_service",
274278
"view_decryption_component",
275279
"view_election_component",
276280
"view_spoiled_ballot_component",

src/electionguard_gui/containers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
DecryptionService,
3636
DbWatcherService,
3737
ConfigurationService,
38+
VersionService,
3839
)
3940
from electionguard_gui.services.decryption_stages import (
4041
DecryptionS1JoinService,
@@ -58,6 +59,9 @@ class Container(containers.DeclarativeContainer):
5859
config_service: Factory[ConfigurationService] = providers.Factory(
5960
ConfigurationService
6061
)
62+
version_service: Factory[VersionService] = providers.Factory(
63+
VersionService, log_service=log_service
64+
)
6165
db_service: Singleton[DbService] = providers.Singleton(
6266
DbService, log_service=log_service, config_service=config_service
6367
)
@@ -302,4 +306,5 @@ class Container(containers.DeclarativeContainer):
302306
export_election_record_component=export_election_record_component,
303307
view_tally_component=view_tally_component,
304308
view_spoiled_ballot_component=view_spoiled_ballot_component,
309+
version_service=version_service,
305310
)

src/electionguard_gui/main_app.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
EelLogService,
2626
ServiceBase,
2727
ConfigurationService,
28+
VersionService,
2829
)
2930

3031

@@ -55,6 +56,7 @@ def __init__(
5556
export_election_record_component: ExportElectionRecordComponent,
5657
view_tally_component: ViewTallyComponent,
5758
view_spoiled_ballot_component: ViewSpoiledBallotComponent,
59+
version_service: VersionService,
5860
) -> None:
5961
super().__init__()
6062

@@ -83,6 +85,7 @@ def __init__(
8385
authorization_service,
8486
db_service,
8587
log_service,
88+
version_service,
8689
]
8790

8891
def start(self) -> None:

src/electionguard_gui/services/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from electionguard_gui.services import key_ceremony_state_service
1818
from electionguard_gui.services import plaintext_ballot_service
1919
from electionguard_gui.services import service_base
20+
from electionguard_gui.services import version_service
2021

2122
from electionguard_gui.services.authorization_service import (
2223
AuthorizationService,
@@ -113,6 +114,9 @@
113114
from electionguard_gui.services.service_base import (
114115
ServiceBase,
115116
)
117+
from electionguard_gui.services.version_service import (
118+
VersionService,
119+
)
116120

117121
__all__ = [
118122
"AuthorizationService",
@@ -145,6 +149,7 @@
145149
"MODE_KEY",
146150
"PORT_KEY",
147151
"ServiceBase",
152+
"VersionService",
148153
"announce_guardians",
149154
"authorization_service",
150155
"backup_to_dict",
@@ -191,4 +196,5 @@
191196
"status_descriptions",
192197
"to_ballot_share_raw",
193198
"verification_to_dict",
199+
"version_service",
194200
]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from os import path
2+
from subprocess import check_output
3+
from typing import Optional
4+
import eel
5+
from electionguard_gui.services.eel_log_service import EelLogService
6+
from electionguard_gui.services.service_base import ServiceBase
7+
8+
9+
class VersionService(ServiceBase):
10+
"""Responsible for retrieving version information"""
11+
12+
_log: EelLogService
13+
14+
def __init__(self, log_service: EelLogService) -> None:
15+
self._log = log_service
16+
17+
def expose(self) -> None:
18+
eel.expose(self.get_version)
19+
20+
def get_version(self) -> Optional[str]:
21+
if not path.exists(".git"):
22+
return None
23+
commit_hash = (
24+
check_output(["git", "rev-parse", "--short", "HEAD"])
25+
.decode("ascii")
26+
.strip()
27+
)
28+
self._log.info(f"Version: {commit_hash}")
29+
return commit_hash
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export default {
2+
data() {
3+
return {
4+
version: null,
5+
};
6+
},
7+
async mounted() {
8+
this.version = await eel.get_version()();
9+
},
10+
template: /*html*/ `
11+
<nav class="navbar fixed-bottom bg-light" v-if="version">
12+
<div class="container-fluid">
13+
<div class="col-12 pe-0 text-end text-secondary text-opacity-75">
14+
ElectionGuard version {{version}}
15+
</div>
16+
</div>
17+
</nav>
18+
`,
19+
};

src/electionguard_gui/web/index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020

2121
<div id="app">
2222
<navbar :user-id="userId"></navbar>
23-
<div class="container mt-3">
23+
<div class="container mt-3 mb-4">
2424
<Login @login="login" v-if="showLogin"></Login>
2525
<component :is="currentView" v-bind="currentViewProperties" />
2626
</div>
27+
<eg-footer></eg-footer>
2728
</div>
2829

2930
<script type="module">
@@ -32,6 +33,7 @@
3233
// components
3334
import Navbar from "./components/shared/navbar-component.js";
3435
import Login from "./components/shared/login-component.js";
36+
import EgFooter from "./components/shared/footer-component.js";
3537

3638
// services
3739
import AuthorizationService from "./services/authorization-service.js";
@@ -83,6 +85,7 @@
8385
components: {
8486
Navbar,
8587
Login,
88+
EgFooter,
8689
},
8790
}).mount("#app");
8891
</script>

0 commit comments

Comments
 (0)