Skip to content

Commit 5e908e9

Browse files
authored
Merge pull request #20 from softwareone-platform/MPT-9718
MPT-9718 Adopt FinOps Extension code to use Notification Module
2 parents 922f105 + 5d7b216 commit 5e908e9

File tree

18 files changed

+405
-271
lines changed

18 files changed

+405
-271
lines changed

.dockerignore

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
### Intellij
2+
.idea/
3+
.idea_modules/
4+
out/
5+
*.iml
6+
*.ipr
7+
8+
# CMake
9+
cmake-build-*/
10+
11+
# Mongo Explorer plugin
12+
.idea/**/mongoSettings.xml
13+
14+
# File-based project format
15+
*.iws
16+
17+
# JIRA plugin
18+
atlassian-ide-plugin.xml
19+
20+
### macOS template
21+
# General
22+
.DS_Store
23+
.AppleDouble
24+
.LSOverride
25+
26+
# Icon must end with two \r
27+
Icon
28+
29+
# Thumbnails
30+
._*
31+
32+
# Files that might appear in the root of a volume
33+
.DocumentRevisions-V100
34+
.fseventsd
35+
.Spotlight-V100
36+
.TemporaryItems
37+
.Trashes
38+
.VolumeIcon.icns
39+
.com.apple.timemachine.donotpresent
40+
41+
# Directories potentially created on remote AFP share
42+
.AppleDB
43+
.AppleDesktop
44+
Network Trash Folder
45+
Temporary Items
46+
.apdisk
47+
48+
### Python template
49+
# Byte-compiled / optimized / DLL files
50+
__pycache__/
51+
*.py[cod]
52+
*$py.class
53+
54+
# Distribution / packaging
55+
.Python
56+
build/
57+
develop-eggs/
58+
dist/
59+
downloads/
60+
eggs/
61+
.eggs/
62+
lib/
63+
lib64/
64+
parts/
65+
sdist/
66+
var/
67+
wheels/
68+
share/python-wheels/
69+
*.egg-info/
70+
.installed.cfg
71+
*.egg
72+
MANIFEST
73+
74+
# PyInstaller
75+
# Usually these files are written by a python script from a template
76+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
77+
*.manifest
78+
*.spec
79+
80+
# Installer logs
81+
pip-log.txt
82+
pip-delete-this-directory.txt
83+
84+
# Unit test / coverage reports
85+
htmlcov/
86+
.tox/
87+
.nox/
88+
.coverage
89+
.coverage.*
90+
.cache
91+
nosetests.xml
92+
coverage.xml
93+
*.cover
94+
*.py,cover
95+
.hypothesis/
96+
.pytest_cache/
97+
cover/
98+
99+
# Translations
100+
*.mo
101+
*.pot
102+
103+
# Django stuff:
104+
*.log
105+
local_settings.py
106+
db.sqlite3
107+
db.sqlite3-journal
108+
109+
# Flask stuff:
110+
instance/
111+
.webassets-cache
112+
113+
# Scrapy stuff:
114+
.scrapy
115+
116+
# Sphinx documentation
117+
docs/_build/
118+
119+
# PyBuilder
120+
.pybuilder/
121+
target/
122+
123+
# IPython
124+
profile_default/
125+
ipython_config.py
126+
127+
# pyenv
128+
# For a library or package, you might want to ignore these files since the code is
129+
# intended to run in multiple environments; otherwise, check them in:
130+
.python-version
131+
132+
# poetry
133+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
134+
# This is especially recommended for binary packages to ensure reproducibility, and is more
135+
# commonly ignored for libraries.
136+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
137+
#poetry.lock
138+
139+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
140+
__pypackages__/
141+
142+
# Celery stuff
143+
celerybeat-schedule
144+
celerybeat.pid
145+
146+
# SageMath parsed files
147+
*.sage.py
148+
149+
# Environments
150+
.env
151+
.venv
152+
env/
153+
venv/
154+
ENV/
155+
env.bak/
156+
venv.bak/
157+
158+
# Spyder project settings
159+
.spyderproject
160+
.spyproject
161+
162+
# Rope project settings
163+
.ropeproject
164+
165+
# mkdocs documentation
166+
/site
167+
168+
# mypy
169+
.mypy_cache/
170+
.dmypy.json
171+
dmypy.json
172+
173+
# Pyre type checker
174+
.pyre/
175+
176+
# pytype static type analyzer
177+
.pytype/
178+
179+
# Cython debug symbols
180+
cython_debug/
181+
182+
.ruff_cache
183+
.github
184+
.git
185+
.gitignore
186+
LICENSE

.env.sample

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ MPT_API_TOKEN=<vendor-api-token>
66
MPT_ORDERS_API_POLLING_INTERVAL_SECS=120
77
EXT_WEBHOOKS_SECRETS={"PRD-1111-1111": "<super-jwt-secret>"}
88
EXT_MSTEAMS_WEBHOOK_URL=https://whatever.webhook.office.com/webhookb2/<...>
9-
EXT_AWS_SES_CREDENTIALS=<access-key>:<secret-key>
10-
EXT_EMAIL_NOTIFICATIONS_SENDER=no-reply@domain.com
11-
EXT_EMAIL_NOTIFICATIONS_ENABLED=1
129
EXT_FFC_SUB=FTKN-1111-1111
1310
EXT_FFC_OPERATIONS_API_BASE_URL=https://api.finops.s1.show/ops
1411
EXT_FFC_OPERATIONS_SECRET=supersecret
12+
MPT_NOTIFY_CATEGORIES={"ORDERS": "NTC-0000-0006"}

README.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ MPT_API_TOKEN=<vendor-api-token>
2828
MPT_ORDERS_API_POLLING_INTERVAL_SECS=120
2929
EXT_WEBHOOKS_SECRETS={"PRD-1111-1111": "<super-jwt-secret>"}
3030
EXT_MSTEAMS_WEBHOOK_URL=https://whatever.webhook.office.com/webhookb2/<...>
31-
EXT_AWS_SES_CREDENTIALS=<access-key>:<secret-key>
32-
EXT_EMAIL_NOTIFICATIONS_SENDER=no-reply@domain.com
33-
EXT_EMAIL_NOTIFICATIONS_ENABLED=1
3431
EXT_FFC_SUB=FTKN-1111-1111
3532
EXT_FFC_OPERATIONS_API_BASE_URL=https://api.finops.s1.show/ops
3633
EXT_FFC_OPERATIONS_SECRET=supersecret
@@ -52,9 +49,6 @@ MPT_API_TOKEN=<vendor-api-token>
5249
MPT_ORDERS_API_POLLING_INTERVAL_SECS=120
5350
EXT_WEBHOOKS_SECRETS={"PRD-1111-1111": "<super-jwt-secret>"}
5451
EXT_MSTEAMS_WEBHOOK_URL=https://whatever.webhook.office.com/webhookb2/<...>
55-
EXT_AWS_SES_CREDENTIALS=<access-key>:<secret-key>
56-
EXT_EMAIL_NOTIFICATIONS_SENDER=no-reply@domain.com
57-
EXT_EMAIL_NOTIFICATIONS_ENABLED=1
5852
EXT_FFC_SUB=FTKN-1111-1111
5953
EXT_FFC_OPERATIONS_API_BASE_URL=https://api.finops.s1.show/ops
6054
EXT_FFC_OPERATIONS_SECRET=supersecret
@@ -81,8 +75,8 @@ $ docker-compose run --service-ports app
8175
| `EXT_FFC_SUB` | FTKN-1111-1111 | FTKN-1111-1111 | FinOps for Cloud Operation API Token ID |
8276
| `EXT_FFC_OPERATIONS_API_BASE_URL` | https://api.finops.s1.show/ops | https://api.finops.s1.show/ops | FinOps for Cloud Operation API URL |
8377
| `EXT_FFC_OPERATIONS_SECRET` | - | eyJhbGciOiJSUzI1N... | FinOps for CLoud Operation API Token |
84-
85-
78+
| `MPT_NOTIFY_CATEGORIES` | - | {"ORDERS": "NTC-0000-0006"} | SoftwareONE Marketplace Notification Categories |
79+
8680

8781
## Azure AppInsights
8882
| Environment Variable | Default | Example | Description |

ffc/flows/steps/due_date.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77

88
from ffc.flows.error import ERR_DUE_DATE_IS_REACHED
99
from ffc.flows.steps.utils import switch_order_to_failed
10-
from ffc.notifications import send_email_notification
10+
from ffc.notifications import send_mpt_notification
1111
from ffc.parameters import get_due_date, set_due_date
1212

1313
logger = logging.getLogger(__name__)
1414

1515

1616
class SetupDueDate(Step):
1717
"""
18-
Sets Due date for processing order and sends email
19-
if it is first attempt to process the order
18+
Sets Due date for processing order and sends a notification
19+
if it is the first attempt to process the order
2020
"""
2121

2222
def __call__(self, client, context, next_step):
@@ -43,8 +43,8 @@ def __call__(self, client, context, next_step):
4343
)
4444

4545
# means that's first attempt to process an order
46-
# send notification to the customer
47-
send_email_notification(client, context.order)
46+
# sends a notification to the customer
47+
send_mpt_notification(client, context)
4848

4949
next_step(client, context)
5050

ffc/flows/steps/order.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
set_template,
2323
)
2424
from ffc.flows.steps.utils import reset_order_error, switch_order_to_failed
25-
from ffc.notifications import send_email_notification
25+
from ffc.notifications import send_mpt_notification
2626
from ffc.parameters import (
2727
PARAM_ADMIN_CONTACT,
2828
PARAM_CURRENCY,
@@ -85,7 +85,7 @@ def __call__(self, client, context, next_step):
8585
parameters=context.order["parameters"],
8686
)
8787
context.order["agreement"] = agreement
88-
send_email_notification(client, context.order)
88+
send_mpt_notification(client, context)
8989
logger.info(f"{context}: order has been completed successfully")
9090
next_step(client, context)
9191

@@ -156,7 +156,7 @@ def __call__(self, client, context, next_step):
156156
logger.info(
157157
f"{context}: ordering parameters are invalid, move to querying",
158158
)
159-
send_email_notification(client, order)
159+
send_mpt_notification(client, context)
160160
return
161161

162162
next_step(client, context)
@@ -203,7 +203,7 @@ def __call__(self, client, context, next_step):
203203
logger.info(f"{context}: processing template is ok, continue")
204204

205205
if not get_due_date(context.order):
206-
send_email_notification(client, context.order)
206+
send_mpt_notification(client, context)
207207

208208
next_step(client, context)
209209

ffc/flows/steps/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
from mpt_extension_sdk.mpt_http.mpt import fail_order
44

5-
from ffc.notifications import send_email_notification
5+
from ffc.flows.order import OrderContext
6+
from ffc.notifications import send_mpt_notification
67
from ffc.parameters import set_due_date
78

89

@@ -22,7 +23,7 @@ def switch_order_to_failed(client, order, error):
2223
agreement = order["agreement"]
2324
order = fail_order(client, order["id"], error, parameters=order["parameters"])
2425
order["agreement"] = agreement
25-
send_email_notification(client, order)
26+
send_mpt_notification(client, OrderContext.from_order(order))
2627
return order
2728

2829

0 commit comments

Comments
 (0)