如何编写Firebase规则,我的可信服务器可以存储不到2分钟的对象字典?

时间:2016-03-17 12:30:41

标签: python-2.7 firebase-security

这是我在python中所做的。

import json
from google.appengine.api import urlfetch
from firebase_token_generator import create_token

#FIREBASE EXTRACT
#Using urlfetch because Appengine does not use requests to talk to firebase.
def firebase_leads():
    leads_str = urlfetch.fetch(FIREBASE_URL + 'leads/.json?auth=' +\
                               token,\
                               method=urlfetch.GET)
    leads = json.loads(leads_str.content)
    return leads


def get_pipedrive_person_id(leads):
    person = {
                'name' : leads['FIRST_NAME'] + ' ' + leads['LAST_NAME'],
                'email': [leads['EMAIL']],
                'phone': [leads['PHONE']]
             }
    person_send = urlfetch.fetch(PIPEDRIVE_URL + '/persons?api_token=' +\
                                 PIPEDRIVE_SECRET,\
                                 payload=json.dumps(person),\
                                 method=urlfetch.POST,
                                 headers={'Content-Type': 'application/json'})
    if person_send.status_code > 210:
        print 'something is not right with the Pipedrive API. Status code: '
        print person_send.status_code
    else:
        person_content = json.loads(person_send.content)
        return person_content['data']['id']

@app.route('/leads')
def check_for_leads():
    """Get leads dictionary and send it to Pipedrive."""
    leads = firebase_leads()
    import pdb; pdb.set_trace()
    print leads
    for i in leads:
      person_id = get_pipedrive_person_id(leads[i])
      update = pipedrive_deals(leads[i], person_id)
      if 400 < update.status_code > 600:
        return str(update.status_code)
    return str(update.status_code)

以下是支持leads提取的Firebase规则。

{
"rules": {
    "leads": {
        ".write": true,
        ".read": "auth.uid === 'lead_checker'",
        "$lead_id": {
           ".read": "data.child('CREATED').val() > (now - 120000)",
           ".validate": "root.child('leads'+'/'+$lead_id).exists() && root.child('leads'+'/'+$lead_id).hasChildren(['CREATED','EMAIL', 'FIRST_NAME', 'LAST_NAME', 'LEAD_DESCRIPTION', 'PHONE'])"
        }
    }
  }
}

当我运行模拟器时,我无法对.read的{​​{1}}进行身份验证,因为它会在$lead_id中对auth.uid==='lead_checker'进行更高级验证。

如何使用leads验证leads的孙子?

.val('CREATED') > (now - 120000) .validate $lead_id时,.write: true下的leads规则是否有效?

0 个答案:

没有答案