Ported utils.remove_private_keys() from Pillar
This commit is contained in:
@@ -41,13 +41,7 @@ class Node(List, Find, Create, Post, Update, Delete, Replace):
|
||||
api = api or self.api
|
||||
attributes = attributes or self.to_dict()
|
||||
etag = attributes['_etag']
|
||||
attributes.pop('_id')
|
||||
attributes.pop('_etag')
|
||||
attributes.pop('_created')
|
||||
attributes.pop('_updated')
|
||||
attributes.pop('_links', None)
|
||||
attributes.pop('_deleted', None)
|
||||
attributes.pop('allowed_methods')
|
||||
attributes = utils.remove_private_keys(attributes)
|
||||
attributes = utils.remove_none_attributes(attributes)
|
||||
|
||||
url = utils.join_url(self.path, str(self['_id']))
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import copy
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
@@ -162,6 +163,24 @@ def remove_none_attributes(attributes):
|
||||
return attributes
|
||||
|
||||
|
||||
def remove_private_keys(document):
|
||||
"""Removes any key that starts with an underscore, returns result as new
|
||||
dictionary.
|
||||
"""
|
||||
|
||||
doc_copy = copy.deepcopy(document)
|
||||
for key in list(doc_copy.keys()):
|
||||
if key.startswith('_'):
|
||||
del doc_copy[key]
|
||||
|
||||
try:
|
||||
del doc_copy['allowed_methods']
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
return doc_copy
|
||||
|
||||
|
||||
def download_to_file(url, filename, chunk_size=10 * 1024):
|
||||
"""Downloads a file via HTTP(S) directly to the filesystem."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user