Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
netvs-middleware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
scc-net
netvs
netvs-middleware
Commits
2e6cb5e5
Commit
2e6cb5e5
authored
4 weeks ago
by
Alexander Kaschta
Browse files
Options
Downloads
Patches
Plain Diff
ADD: BCD request emails
parent
b28ac80b
No related branches found
No related tags found
No related merge requests found
Pipeline
#419769
failed
4 weeks ago
Stage: lint
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/bcd_request.py
+75
-3
75 additions, 3 deletions
api/bcd_request.py
model/settings.py
+3
-0
3 additions, 0 deletions
model/settings.py
templates/bcd_request_template.j2
+45
-0
45 additions, 0 deletions
templates/bcd_request_template.j2
with
123 additions
and
3 deletions
api/bcd_request.py
+
75
−
3
View file @
2e6cb5e5
import
html
import
pathlib
from
fastapi
import
APIRouter
,
Depends
,
HTTPException
from
starlette
import
status
from
api
import
get_conn
from
api
import
db
,
get_conn
from
model.bcd_request
import
BCDRequestModel
,
BCDProtectionRequirements
,
BCDSystemType
,
IPAddressVersion
from
model.settings
import
settings
from
model.wapi.cntl
import
APIToken
,
Mgr
from
util.auth
import
check_auth
from
util.util
import
render_jinja_template
,
send_email
from
util.wapi_util
import
execute_wapi_function
router
=
APIRouter
(
...
...
@@ -72,8 +77,10 @@ async def handle_request(bcd_request: BCDRequestModel, token: APIToken = Depends
)
if
validate_bcd_request
(
bcd_request
):
# TODO: Send e-mail
return
{
'
result
'
:
'
success
'
}
mailstatus
=
send_bcd_request
(
bcd_request
=
bcd_request
,
mgr
=
user
)
if
mailstatus
:
send_bcd_request_confirmation
(
bcd_request
=
bcd_request
,
mgr
=
user
,
receiver
=
user
.
email
)
return
{
'
result
'
:
'
success
'
}
raise
HTTPException
(
status_code
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
...
...
@@ -220,3 +227,68 @@ def validate_bcd_request(bcd_request: BCDRequestModel) -> bool:
)
return
True
def
send_bcd_request
(
bcd_request
:
BCDRequestModel
,
mgr
:
Mgr
,
receiver
=
settings
.
bcd_request_email_receivers
)
->
bool
:
try
:
host_mode
=
db
.
host_omdl
.
OP_ENV_MODE
.
upper
()
path
=
pathlib
.
Path
(
__file__
).
parent
.
parent
.
resolve
()
TEMPLATE
=
'
templates/bcd_request_template.j2
'
body
=
render_jinja_template
(
path
,
TEMPLATE
,
bcd_request
=
bcd_request
,
mgr
=
mgr
,
host_mode
=
host_mode
,
)
subject
=
f
'
BCD Request for
{
html
.
escape
(
bcd_request
.
oe
)
}
by
{
html
.
escape
(
mgr
.
first_name
)
}
{
html
.
escape
(
mgr
.
last_name
)
}
'
if
host_mode
:
subject
=
f
'
[
{
host_mode
}
]
{
subject
}
'
# hacky way to intercept mails for development. In production, the assignment should be used
if
settings
.
bcd_request_email_receivers
is
not
None
:
receiver
=
settings
.
bcd_request_email_receivers
send_email
(
to
=
receiver
,
sender
=
settings
.
patch_request_email_sender
,
reply_to
=
mgr
.
email
,
subject
=
subject
,
body
=
body
,
)
return
True
except
Exception
as
e
:
raise
e
def
send_bcd_request_confirmation
(
bcd_request
:
BCDRequestModel
,
mgr
:
Mgr
,
receiver
)
->
bool
:
try
:
host_mode
=
db
.
host_omdl
.
OP_ENV_MODE
.
upper
()
path
=
pathlib
.
Path
(
__file__
).
parent
.
parent
.
resolve
()
TEMPLATE
=
'
templates/bcd_request_template.j2
'
body
=
render_jinja_template
(
path
,
TEMPLATE
,
bcd_request
=
bcd_request
,
mgr
=
mgr
,
host_mode
=
host_mode
,
confirmation
=
True
)
subject
=
f
'
Confirmation for BCD Request for
{
html
.
escape
(
bcd_request
.
oe
)
}
'
if
host_mode
:
subject
=
f
'
[
{
host_mode
}
]
{
subject
}
'
# hacky way to intercept mails for development. In production, the assignment should be used
if
settings
.
patch_request_email_receivers
is
not
None
:
receiver
=
settings
.
patch_request_email_receivers
send_email
(
to
=
receiver
,
sender
=
settings
.
bcd_request_email_sender
,
reply_to
=
settings
.
bcd_request_email_sender
,
subject
=
subject
,
body
=
body
)
return
True
except
Exception
as
e
:
raise
e
This diff is collapsed.
Click to expand it.
model/settings.py
+
3
−
0
View file @
2e6cb5e5
...
...
@@ -49,6 +49,9 @@ class Settings(BaseSettings):
patch_request_email_sender
:
str
=
''
patch_request_assignment
:
dict
[
str
,
str
]
=
{}
bcd_request_email_receivers
:
Optional
[
str
]
=
None
bcd_request_email_sender
:
str
=
''
mail_smarthost
:
str
=
'
smarthost.kit.edu
'
ip_contact_send_mail
:
bool
=
True
...
...
This diff is collapsed.
Click to expand it.
templates/bcd_request_template.j2
0 → 100644
+
45
−
0
View file @
2e6cb5e5
<body>
<h1>BCD Request</h1>
{% if host_mode != 'PROD' %}
<h2 style="color: red">This BCD request was sent from a development or testing instance of NETVS and is probably
just a test!</h2>
{% endif %}
{% if confirmation is defined %}
{% else %}
<p>{{ mgr.first_name }} {{ mgr.last_name }} ({{ mgr.email|urlize }}) would like you to fulfill
the following BCD request:</p>
{% endif %}
<table style="width: 100%; border: 1px solid black; border-collapse: collapse;">
<tr>
<th style="border: 1px solid black; border-collapse: collapse;">Organizational unit</th>
<td style="border: 1px solid black; border-collapse: collapse;">{{ bcd_request.oe }}</td>
</tr>
<tr>
<th style="border: 1px solid black; border-collapse: collapse;">Group</th>
<td style="border: 1px solid black; border-collapse: collapse;">{{ bcd_request.group }}</td>
</tr>
<tr>
<th style="border: 1px solid black; border-collapse: collapse;">Protection Requirements</th>
<td style="border: 1px solid black; border-collapse: collapse;">{{ bcd_request.protection_requirement }}</td>
</tr>
{% if bcd_request.protection_requirement_note is not None %}
<tr>
<th style="border: 1px solid black; border-collapse: collapse;">Special Protection Requirements Note</th>
<td style="border: 1px solid black; border-collapse: collapse;">{{ bcd_request.protection_requirement_note }}</td>
</tr>
{% endif %}
<tr>
<th style="border: 1px solid black; border-collapse: collapse;">Type of Systems</th>
<td style="border: 1px solid black; border-collapse: collapse;">{{ bcd_request.type_of_system }}</td>
</tr>
{% if bcd_request.type_of_system_note is not None%}
<tr>
<th style="border: 1px solid black; border-collapse: collapse;">Special Type of Systems Note</th>
<td style="border: 1px solid black; border-collapse: collapse;">{{ bcd_request.type_of_system_note }}</td>
</tr>
{% endif %}
</table>
<p>Have a nice day!</p>
</body>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment