forked from CincyPy/LibraryWebsite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublisher.py
More file actions
25 lines (19 loc) · 839 Bytes
/
publisher.py
File metadata and controls
25 lines (19 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import requests
from ipaddress import ip_address, ip_network
from itertools import chain
class Publisher:
@staticmethod
def __fetchgithubips():
jsonResponse = requests.get("https://api.github.com/meta", auth=("KentonCountyLibrary-Cincypy", "CincyPyCoders2000"))
ipranges = jsonResponse.json()["hooks"]
ipranges = [list(ip_network(ip).hosts()) for ip in ipranges]
# Flatten the matrix to an array
flat_range = list(chain.from_iterable(ipranges))
return flat_range
def in_ip_address_range(self):
return self.ip in Publisher.__fetchgithubips()
def __init__(self, ip, sourcebranch, payload):
# use https://api.github.com/meta to get github ipaddresses
self.sourcebranch = sourcebranch
self.payload = payload
self.ip = ip_address(ip)