Skip to content

Commit

Permalink
Add support for oracle cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
0xdade committed Feb 16, 2020
1 parent dca8073 commit 730a914
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
1 change: 1 addition & 0 deletions providers/__init__.py
@@ -1,4 +1,5 @@
from .aws import AWS
from .azure import Azure
from .gcp import GCP
from .oci import OCI
from .provider import Provider
36 changes: 36 additions & 0 deletions providers/oci.py
@@ -0,0 +1,36 @@
import requests
from .base_provider import BaseProvider

class OCI(BaseProvider):

def __init__(self, excludeip6=False):
self.source_ranges = self._get_ranges()
self.processed_ranges = self._process_ranges(excludeip6)

def _get_ranges(self):
'''
Input: None
Output: Dict representation of ip-ranges.json
'''
aws_ip_ranges_url = "https://docs.cloud.oracle.com/en-us/iaas/tools/public_ip_ranges.json"
r = requests.get(aws_ip_ranges_url)
return r.json()

def _process_ranges(self, excludeip6=False):
'''
Input: Dict of ip-ranges.json, optionally exclude ip6 ranges
Output: Dict with header_comments and list of dicts for ip ranges
'''
header_comments = [
f"(oci) last_updated_timestamp: {self.source_ranges['last_updated_timestamp']}"
]
out_ranges = []

for r in self.source_ranges['regions']:
region = r["region"]
for cidr in r["cidrs"]:
item = {"range": cidr["cidr"], "comment": f"{region} {' '.join(cidr['tags'])}" }
out_ranges.append(item)

output = {"header_comments": header_comments, "ranges": out_ranges}
return output
5 changes: 3 additions & 2 deletions providers/provider.py
@@ -1,9 +1,10 @@
from . import AWS, Azure, GCP
from . import AWS, Azure, GCP, OCI

classmap = {
"aws": AWS,
"azure": Azure,
"gcp": GCP
"gcp": GCP,
"oci": OCI
}

class Provider():
Expand Down
3 changes: 2 additions & 1 deletion sephiroth.py
Expand Up @@ -22,7 +22,8 @@
supported_clouds = [
"aws",
"azure",
"gcp"
"gcp",
"oci"
]

base_dir = os.path.dirname(__file__)
Expand Down

0 comments on commit 730a914

Please sign in to comment.