Skip to content

Commit

Permalink
add warning banner on non-prod IMS instances
Browse files Browse the repository at this point in the history
  • Loading branch information
srabraham committed Nov 11, 2024
1 parent 8c357f9 commit bdb71d6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/ims/config/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,10 @@ def fromConfigFile(cls, configFile: Path | None) -> "Configuration":
)
)

deployment = parser.valueFromConfig(
"DEPLOYMENT", "Core", "Deployment", "Dev"
)

#
# Persist some objects
#
Expand All @@ -408,6 +412,7 @@ def fromConfigFile(cls, configFile: Path | None) -> "Configuration":
configFile=configFile,
configRoot=configRoot,
dataRoot=dataRoot,
deployment=deployment,
directory=directory,
hostName=hostName,
imsAdmins=imsAdmins,
Expand All @@ -427,6 +432,7 @@ def fromConfigFile(cls, configFile: Path | None) -> "Configuration":
configFile: Path | None
configRoot: Path
dataRoot: Path
deployment: str
directory: IMSDirectory
hostName: str
imsAdmins: frozenset[str]
Expand Down Expand Up @@ -482,6 +488,7 @@ def __str__(self) -> str:
f"Core.ConfigRoot: {self.configRoot}\n"
f"Core.DataRoot: {self.dataRoot}\n"
f"Core.CachedResources: {self.cachedResourcesRoot}\n"
f"Core.Deployment: {self.deployment}\n"
f"Core.LogLevel: {self.logLevelName}\n"
f"Core.LogFile: {self.logFilePath}\n"
f"Core.LogFormat: {self.logFormat}\n"
Expand Down
1 change: 1 addition & 0 deletions src/ims/config/test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ def test_str(self) -> None:
f"Core.ConfigRoot: {config.configRoot}\n"
f"Core.DataRoot: {config.dataRoot}\n"
f"Core.CachedResources: {config.cachedResourcesRoot}\n"
f"Core.Deployment: {config.deployment}\n"
f"Core.LogLevel: {config.logLevelName}\n"
f"Core.LogFile: {config.logFilePath}\n"
f"Core.LogFormat: {config.logFormat}\n"
Expand Down
14 changes: 14 additions & 0 deletions src/ims/element/_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,20 @@ def logged_in_user(self, request: IRequest, tag: Tag) -> KleinRenderable:
else:
return tag(username)

@renderer

Check warning on line 153 in src/ims/element/_element.py

View check run for this annotation

Codecov / codecov/patch

src/ims/element/_element.py#L153

Added line #L153 was not covered by tests
def deployment_warning(
self, request: IRequest, tag: Tag
) -> KleinRenderable:
deployment = self.config.deployment.lower()

Check warning on line 157 in src/ims/element/_element.py

View check run for this annotation

Codecov / codecov/patch

src/ims/element/_element.py#L157

Added line #L157 was not covered by tests
if deployment == "prod":
return ""
return tag(

Check warning on line 160 in src/ims/element/_element.py

View check run for this annotation

Codecov / codecov/patch

src/ims/element/_element.py#L159-L160

Added lines #L159 - L160 were not covered by tests
tags.p(
f"☢️ This is not production. "
f"You are on a {deployment} IMS server. ☢️"
)
)

##
# Data
##
Expand Down
3 changes: 3 additions & 0 deletions src/ims/element/page/nav/template.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,7 @@

</div>

<div class="bg-danger text-center" t:render="deployment_warning">
</div>

</nav>

0 comments on commit bdb71d6

Please sign in to comment.