#!/usr/bin/env python
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# Copyright (c) 2015 Mozilla Corporation
# Author: ameihm@mozilla.com

import requests
import json
import search
import config as cfg

def get_rra(rraid):
    u = cfg.config.apiurl() + '/rra/id'
    payload = { 'id': rraid }
    r = requests.get(u, params=payload, verify=cfg.config.sslverify)
    if r.status_code != requests.codes.ok:
        err = 'Request error: response {}'.format(r.status_code)
        raise search.SLIBException(err)
    return json.loads(r.text)

def get_rras():
    u = cfg.config.apiurl() + '/rras'
    r = requests.get(u, verify=cfg.config.sslverify)
    if r.status_code != requests.codes.ok:
        err = 'Request error: response {}'.format(r.status_code)
        raise search.SLIBException(err)
    return json.loads(r.text)

def get_risks():
    u = cfg.config.apiurl() + '/risks'
    r = requests.get(u, verify=cfg.config.sslverify)
    if r.status_code != requests.codes.ok:
        err = 'Request error: response {}'.format(r.status_code)
        raise search.SLIBException(err)
    return json.loads(r.text)

@@ -1240,28 +1240,627 @@
   return json.loads(r.text)%0A
+%0A# Submits an RRA to be updated via the API, rradict should be a dict%0A# representation of the RRA; the RRA information itself should be stored%0A# in a 'details' struct there, and it should also have a lastmodified%0A# element that is the lastmodified timestamp from the RRA%0Adef update_rra(rradict):%0A    u = cfg.config.apiurl() + '/rra/update'%0A    payload = %7B'rra': json.dumps(rradict)%7D%0A    r = requests.post(u, data=payload, verify=cfg.config.sslverify)%0A    if r.status_code != requests.codes.ok:%0A        err = 'Request error: response %7B%7D'.format(r.status_code)%0A        raise search.SLIBException(err)%0A

add rra update function to pyservicelib