Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Commit

Permalink
Merge pull request #8 from RiotGames/dev
Browse files Browse the repository at this point in the history
adding support for exporting dns zones
  • Loading branch information
Zach authored Nov 20, 2018
2 parents 07e97d0 + 7126adf commit 388dbfb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
38 changes: 38 additions & 0 deletions cinq_collector_dns/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
from cloud_inquisitor.plugins.views import BaseView
from cloud_inquisitor.utils import MenuItem
from cloud_inquisitor.wrappers import check_auth, rollback
from cloud_inquisitor.json_utils import InquisitorJSONEncoder

from flask import Response
from base64 import b64encode
import json



class DNSZoneList(BaseView):
Expand Down Expand Up @@ -70,3 +76,35 @@ def get(self, zone_id):
'recordCount': len(zone.records),
'records': zone.records[start_offset:end_offset]
})


class DNSZonesExport(BaseView):
URLS = ['/api/v1/dns/zonesExport']

@rollback
@check_auth(ROLE_USER)
def get(self):
self.reqparse.add_argument('page', type=int, default=1, required=True)
self.reqparse.add_argument('count', type=int, default=99999, required=True)
self.reqparse.add_argument('fileFormat', type=str, default='json', choices=['json', 'xlsx'])

args = self.reqparse.parse_args()

total, zones = DNSZone.search(limit=99999, page=args['page'])
output = [{
'zones': [x.to_json(with_records=False) for x in zones],
'zoneCount': total
}]

response = Response(
response=b64encode(
bytes(
json.dumps(output, indent=4, cls=InquisitorJSONEncoder),
'utf-8'
)
)
)
response.content_type = 'application/octet-stream'
response.status_code = HTTP.OK

return response
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
'view_dns_zone_list = cinq_collector_dns.views:DNSZoneList',
'view_dns_zone_details = cinq_collector_dns.views:DNSZoneDetails',
'view_dns_zone_records = cinq_collector_dns.views:DNSZoneRecords',
'view_dns_zone_export = cinq_collector_dns.views:DNSZonesExport'
],
},

Expand Down

0 comments on commit 388dbfb

Please sign in to comment.