Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: devopsmakers/grafana-json-api-proxies
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.0.2
Choose a base ref
...
head repository: devopsmakers/grafana-json-api-proxies
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 10 commits
  • 5 files changed
  • 2 contributors

Commits on Aug 9, 2023

  1. Verified

    This commit was signed with the committer’s verified signature.
    portswigger-tim Tim Birkett
    Copy the full SHA
    9c45b89 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    portswigger-tim Tim Birkett
    Copy the full SHA
    998e5c2 View commit details
  3. version 0.0.3

    portswigger-tim committed Aug 9, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    portswigger-tim Tim Birkett
    Copy the full SHA
    4bdba8d View commit details

Commits on Oct 17, 2023

  1. enable recurrent events in ical-proxy

    portswigger-tim committed Oct 17, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    portswigger-tim Tim Birkett
    Copy the full SHA
    1d7780e View commit details
  2. enable recurrent events in ical-proxy

    portswigger-tim committed Oct 17, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    portswigger-tim Tim Birkett
    Copy the full SHA
    1a43892 View commit details
  3. update icalendar

    portswigger-tim committed Oct 17, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    portswigger-tim Tim Birkett
    Copy the full SHA
    bda1ad6 View commit details
  4. bump chart versions

    portswigger-tim committed Oct 17, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    portswigger-tim Tim Birkett
    Copy the full SHA
    35ea387 View commit details
  5. Update Chart.yaml

    portswigger-tim authored Oct 17, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    962e63f View commit details
  6. Update requirements.txt

    portswigger-tim authored Oct 17, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    64b0d7c View commit details
  7. Update Chart.yaml

    portswigger-tim authored Oct 17, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    23662eb View commit details
Showing with 72 additions and 33 deletions.
  1. +3 −3 helm-charts/json-api-proxy/Chart.yaml
  2. +1 −1 helm-charts/json-api-proxy/README.md
  3. +37 −26 ical-proxy/app.py
  4. +26 −0 ical-proxy/fixtures/calendar.ics
  5. +5 −3 ical-proxy/requirements.txt
6 changes: 3 additions & 3 deletions helm-charts/json-api-proxy/Chart.yaml
Original file line number Diff line number Diff line change
@@ -15,12 +15,12 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.0.1
version: 0.0.6

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
appVersion: 0.0.1
appVersion: 0.0.6

keywords:
- proxy
@@ -38,4 +38,4 @@ maintainers:

annotations:
artifacthub.io/changes: |
- version 0.0.1
- fix datetime handling
2 changes: 1 addition & 1 deletion helm-charts/json-api-proxy/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# json-api-proxy

![Version: 0.0.1](https://img.shields.io/badge/Version-0.0.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.0.1](https://img.shields.io/badge/AppVersion-0.0.1-informational?style=flat-square)
![Version: 0.0.4](https://img.shields.io/badge/Version-0.0.4-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.0.4](https://img.shields.io/badge/AppVersion-0.0.4-informational?style=flat-square)

A Helm chart for the JSON API Proxies

63 changes: 37 additions & 26 deletions ical-proxy/app.py
Original file line number Diff line number Diff line change
@@ -2,8 +2,10 @@
import os

import icalendar
import recurring_ical_events
import requests
from cachetools import TTLCache, cached
from dateutil.relativedelta import relativedelta
from flask import Flask, abort, request
from flask_cors import CORS
from requests_file import FileAdapter
@@ -12,6 +14,9 @@

CACHE = TTLCache(maxsize=1000, ttl=CACHE_TTL)

DATE_MIN = (1970, 1, 1)
LOOK_AHEAD_MONTHS = 6

app = Flask(__name__)

cors = CORS(app)
@@ -74,9 +79,10 @@ def _ical_annotations(url: str, tags: str):
return ical_as_annotations


def _millis_timestamp(dt: datetime.datetime):
if isinstance(dt, datetime.date):
def _millis_timestamp(dt):
if (not isinstance(dt, datetime.datetime)) and isinstance(dt, datetime.date):
dt = datetime.datetime(dt.year, dt.month, dt.day, tzinfo=datetime.timezone.utc)

return int(dt.timestamp() * 1000)


@@ -99,30 +105,35 @@ def _convert_ical_to_annotations(ical_data, tags):
ical_annotations = []
ical_calendar = icalendar.Calendar.from_ical(ical_data)

for component in ical_calendar.walk():
if component.name == "VEVENT":
try:
start_time = component.get("dtstart").dt

end_time = component.get("dtstart").dt
if "dtend" in component:
end_time = component.get("dtend").dt

ical_annotation = {
"time": _millis_timestamp(start_time),
"timeEnd": _millis_timestamp(end_time),
"title": component.get("summary"),
"tags": tags,
"text": component.get("description", ""),
"uid": component.get("uid"),
}

ical_annotations.append(ical_annotation)

except AttributeError as e:
print(
f'level=ERROR {e} msg="decoding event failed" event_summary="{component.get("summary")}" event_dtstart="{component.get("dtstart")}" event_dtstamp="{component.get("dtstamp")}" event_dtend="{component.get("dtend")}"'
)
date_max = datetime.date.today() + relativedelta(months=LOOK_AHEAD_MONTHS)

ical_events = recurring_ical_events.of(
ical_calendar, components=["VEVENT"]
).between(DATE_MIN, date_max)

for component in ical_events:
try:
start_time = component.get("dtstart").dt

end_time = component.get("dtstart").dt
if "dtend" in component:
end_time = component.get("dtend").dt

ical_annotation = {
"time": _millis_timestamp(start_time),
"timeEnd": _millis_timestamp(end_time),
"title": component.get("summary"),
"tags": tags,
"text": component.get("description", ""),
"uid": component.get("uid"),
}

ical_annotations.append(ical_annotation)

except AttributeError as e:
print(
f'level=ERROR {e} msg="decoding event failed" event_summary="{component.get("summary")}" event_dtstart="{component.get("dtstart")}" event_dtstamp="{component.get("dtstamp")}" event_dtend="{component.get("dtend")}"'
)
return ical_annotations


26 changes: 26 additions & 0 deletions ical-proxy/fixtures/calendar.ics
Original file line number Diff line number Diff line change
@@ -36,4 +36,30 @@ STATUS:CONFIRMED
SUMMARY:Test event
TRANSP:TRANSPARENT
END:VEVENT
BEGIN:VEVENT
DTSTART;VALUE=DATE:20230925
DTEND;VALUE=DATE:20230930
RRULE:FREQ=WEEKLY;WKST=SU;INTERVAL=3;BYDAY=MO
DTSTAMP:20231003T134624Z
UID:7bj4rgci9ukdvv9395b4jrck93@google.com
CREATED:20230911T092330Z
LAST-MODIFIED:20230925T092701Z
SEQUENCE:1
STATUS:CONFIRMED
SUMMARY:[Platform] Tim
TRANSP:TRANSPARENT
END:VEVENT
BEGIN:VEVENT
DTSTART;VALUE=DATE:20230918
DTEND;VALUE=DATE:20230923
RRULE:FREQ=WEEKLY;WKST=SU;INTERVAL=3;BYDAY=MO
DTSTAMP:20231003T134624Z
UID:18332sojjpf8tfhsh15skgaheu@google.com
CREATED:20230911T091947Z
LAST-MODIFIED:20230925T092728Z
SEQUENCE:1
STATUS:CONFIRMED
SUMMARY:[Platform] Ben
TRANSP:TRANSPARENT
END:VEVENT
END:VCALENDAR
8 changes: 5 additions & 3 deletions ical-proxy/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
Flask==2.2.2
Flask-Cors==3.0.10
Flask==3.0.0
Flask-Cors==4.0.0
requests==2.28.1
requests-file==1.5.1
uWSGI==2.0.20
icalendar==4.1.0
icalendar==5.0.10
cachetools==5.2.0
recurring-ical-events==2.1.0
python-dateutil==2.8.2