Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
53442a7
Adding timer and running formatting tools.
nharper285 Jul 7, 2021
30c88ca
Adding updated notification model
nharper285 Jul 7, 2021
9b4d784
Getting rid of long lines.
nharper285 Jul 7, 2021
f217c4a
Formatting.
nharper285 Jul 7, 2021
1cced9a
Checking var existing.
nharper285 Jul 7, 2021
9cbed29
Checking json existence.
nharper285 Jul 7, 2021
3c6d558
Retriggering build
nharper285 Jul 7, 2021
0107cca
Merge branch 'main' into user/noharper/pii-function-timer
nharper285 Jul 7, 2021
0b67992
Updating branch
nharper285 Jul 7, 2021
1f28d7f
Merge branch 'main' into user/noharper/pii-function-timer
bmc-msft Jul 8, 2021
25bcd88
Removing template-dependent query.
nharper285 Jul 8, 2021
568165b
Rerunning.
nharper285 Jul 8, 2021
5429443
Working function timer. Added notification and repro table scrubs.
nharper285 Jul 13, 2021
a5ec627
Formatting.
nharper285 Jul 13, 2021
7bcec51
Formatting.
nharper285 Jul 13, 2021
6634b44
Formatting.
nharper285 Jul 13, 2021
f39e08a
formatting.
nharper285 Jul 13, 2021
88e4671
formatting
nharper285 Jul 13, 2021
49f356f
Merge branch 'main' into user/noharper/pii-function-timer
bmc-msft Jul 14, 2021
d6e8de7
formatting
nharper285 Jul 14, 2021
d6c16ec
Adding logging.
nharper285 Jul 14, 2021
d4019be
Adding query for task search on notifcation loop.
nharper285 Jul 15, 2021
0b6f936
Adding additional state query
nharper285 Jul 15, 2021
06daa7e
Final draft.
nharper285 Jul 15, 2021
2af4172
Final draft.
nharper285 Jul 15, 2021
bbb1bec
Final final draft.
nharper285 Jul 15, 2021
2a91ffa
Formatted final draft.
nharper285 Jul 15, 2021
952a85d
Trying to resolve bug.
nharper285 Jul 15, 2021
658cffa
Still working to resolve bug.
nharper285 Jul 15, 2021
5c87fe0
Still bug finding.
nharper285 Jul 16, 2021
8e2ed6f
Still bug finding.
nharper285 Jul 16, 2021
da48ce6
Still bug finding.
nharper285 Jul 16, 2021
f3214f0
Addressing Brian comments.
nharper285 Jul 16, 2021
8928d97
Updated Draft. Ready for Review round #2.
nharper285 Jul 16, 2021
83719d6
Updated Draft. Ready for Review round #2.
nharper285 Jul 16, 2021
17841eb
Formatting.
nharper285 Jul 19, 2021
6ca8f30
Formatting.
nharper285 Jul 19, 2021
9350582
Formatting.
nharper285 Jul 19, 2021
9929409
Final Test Draft for manual deployment.
nharper285 Jul 19, 2021
959ddf3
Final Draft. Ready for Review Round 2.
nharper285 Jul 19, 2021
198ff2f
Delete .funcignore
nharper285 Jul 19, 2021
3564307
Delete __init__.py
nharper285 Jul 19, 2021
1eb57b6
Delete function.json
nharper285 Jul 19, 2021
d2ef1cd
Delete proxies.json
nharper285 Jul 19, 2021
80d21f6
Delete requirements.txt
nharper285 Jul 19, 2021
35c14d2
Delete sample.dat
nharper285 Jul 19, 2021
6529840
Delete function.json
nharper285 Jul 19, 2021
1727bb1
Delete readme.md
nharper285 Jul 19, 2021
39527b7
Changing time for timer.
nharper285 Jul 19, 2021
ea444a0
Removing unused files.
nharper285 Jul 19, 2021
2bdb6bf
Accidentely deleted reqs.txt.
nharper285 Jul 19, 2021
ba8ded3
Merge branch 'main' into user/noharper/pii-function-timer
nharper285 Jul 19, 2021
c5a9a33
Reverting requirements.txt
nharper285 Jul 20, 2021
e62983c
Merge branch 'user/noharper/pii-function-timer' of https://github.com…
nharper285 Jul 20, 2021
754a325
Update src/api-service/__app__/timer_retention/__init__.py
nharper285 Jul 20, 2021
da03ae6
Update src/api-service/__app__/timer_retention/__init__.py
nharper285 Jul 20, 2021
fba46e2
Formatting.
nharper285 Jul 20, 2021
27d2f18
Apply suggestions from code review
bmc-msft Jul 22, 2021
159ab52
Merge branch 'main' into user/noharper/pii-function-timer
bmc-msft Jul 22, 2021
23406b7
Delete sample.dat
bmc-msft Jul 22, 2021
7823a83
test
nharper285 Aug 10, 2021
8e68016
Removing env
nharper285 Aug 12, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/api-service/__app__/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jsonpatch==1.32
semver==2.13.0
base58==2.1.0
# onefuzz types version is set during build
onefuzztypes==0.0.0
onefuzztypes==2.30.0
79 changes: 79 additions & 0 deletions src/api-service/__app__/timer_retention/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env python
#
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

import datetime
import logging

import azure.functions as func
from onefuzztypes.enums import JobState, TaskState

from ..onefuzzlib.events import get_events
from ..onefuzzlib.jobs import Job
from ..onefuzzlib.notifications.main import Notification
from ..onefuzzlib.repro import Repro
from ..onefuzzlib.tasks.main import Task

RETENTION_POLICY = datetime.timedelta(minutes=(20))
SEARCH_EXTENT = datetime.timedelta(minutes=(120))


def main(mytimer: func.TimerRequest, dashboard: func.Out[str]) -> None: # noqa: F841

now = datetime.datetime.now(tz=datetime.timezone.utc)

time_retained_older = now - RETENTION_POLICY
time_retained_newer = now - SEARCH_EXTENT

time_filter = (
f"Timestamp lt datetime'{time_retained_older.isoformat()}' "
f"and Timestamp gt datetime'{time_retained_newer.isoformat()}'"
)
time_filter_newer = f"Timestamp gt datetime'{time_retained_older.isoformat()}'"

# Collecting 'still relevant' task containers.
# NOTE: This must be done before potentially modifying tasks otherwise
# the task timestamps will not be useful.
used_containers = set()
for task in Task.search(raw_unchecked_filter=time_filter_newer):
task_containers = {x.name for x in task.config.containers}
used_containers.update(task_containers)

for notification in Notification.search(raw_unchecked_filter=time_filter):
logging.debug(
"checking expired notification for removal: %s",
notification.notification_id,
)
container = notification.container
if container not in used_containers:
logging.info(
"deleting expired notification: %s", notification.notification_id
)
notification.delete()

for job in Job.search(
query={"state": [JobState.stopped]}, raw_unchecked_filter=time_filter
):
if job.user_info is not None and job.user_info.upn is not None:
logging.info("removing PII from job: %s", job.job_id)
job.user_info.upn = None
job.save()

for task in Task.search(
query={"state": [TaskState.stopped]}, raw_unchecked_filter=time_filter
):
if task.user_info is not None and task.user_info.upn is not None:
logging.info("removing PII from task: %s", task.task_id)
task.user_info.upn = None
task.save()

for repro in Repro.search(raw_unchecked_filter=time_filter):
if repro.user_info is not None and repro.user_info.upn is not None:
logging.info("removing PII from repro: %s", repro.vm_id)
repro.user_info.upn = None
repro.save()

events = get_events()
if events:
dashboard.set(events)
17 changes: 17 additions & 0 deletions src/api-service/__app__/timer_retention/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"bindings": [
{
"direction": "in",
"name": "mytimer",
"schedule": "20:00:00",
"type": "timerTrigger"
},
{
"type": "signalR",
"direction": "out",
"name": "dashboard",
"hubName": "dashboard"
}
],
"scriptFile": "__init__.py"
}