@@ -108,17 +108,37 @@ def _parse_atom_entry(entry):
108108 elink = elink if isinstance (elink , list ) else [elink ]
109109 links = record ((link .rel , link .href ) for link in elink )
110110
111- econtent = entry .get ('content' , {})
112- content = record ((k , v ) for k , v in econtent .iteritems ()
111+ # Retrieve entity content values
112+ content = entry .get ('content' , {})
113+
114+ # Host entry metadata
115+ metadata = _parse_atom_metadata (content )
116+
117+ # Filter some of the noise out of the content record
118+ content = record ((k , v ) for k , v in content .iteritems ()
113119 if k not in ['eai:acl' , 'eai:attributes' , 'type' ])
114- metadata = dict ((k , econtent .get (k , None ))
115- for k in ['eai:acl' , 'eai:attributes' ])
116120
117121 return record ({
118122 'title' : title ,
119123 'links' : links ,
120- 'content' : content ,
121- 'metadata' : metadata })
124+ 'access' : metadata .access ,
125+ 'fields' : metadata .fields ,
126+ 'content' : content
127+ })
128+
129+ # Parse the metadata fields out of the given atom entry content record
130+ def _parse_atom_metadata (content ):
131+ # Hoist access metadata
132+ access = content .get ('eai:acl' , None )
133+
134+ # Hoist content metadata (and cleanup some naming)
135+ attributes = content .get ('eai:attributes' , {})
136+ fields = record ({
137+ 'required' : attributes .get ('requiredFields' , []),
138+ 'optional' : attributes .get ('optionalFields' , []),
139+ 'wildcard' : attributes .get ('wildcardFields' , [])})
140+
141+ return record ({'access' : access , 'fields' : fields })
122142
123143# kwargs: scheme, host, port, app, owner, username, password
124144def connect (** kwargs ):
@@ -220,7 +240,7 @@ def jobs(self):
220240 def loggers (self ):
221241 """Returns a collection of service logging categories and their status.
222242 """
223- return Collection (self , PATH_LOGGER )
243+ return Loggers (self )
224244
225245 @property
226246 def messages (self ):
@@ -233,7 +253,7 @@ def parse(self, query, **kwargs):
233253
234254 :param `query`: The search query to parse.
235255 :param `kwargs`: Optional arguments to pass to the ``search/parser``
236- endpoint.
256+ endpoint.
237257 :return: A semantic map of the parsed search query.
238258 """
239259 return self .get ("search/parser" , q = query , ** kwargs )
@@ -302,17 +322,6 @@ def __call__(self, *args):
302322 def __getitem__ (self , key ):
303323 return self .content [key ]
304324
305- #
306- # Given that update doesn't automatically refresh the cached local state,
307- # this operation now violates the principle of least surprise, because it
308- # allows you to do what appears to be a local assignment, which is then
309- # not reflected in the value you see if you do a subsequent __getitem__
310- # without an explicit refresh.
311- #
312- # def __setitem__(self, key, value):
313- # self.update(**{ key: value })
314- #
315-
316325 # Load the Atom entry record from the given response - this is a method
317326 # because the "entry" record varies slightly by entity and this allows
318327 # for a subclass to override and handle any special cases.
@@ -331,6 +340,11 @@ def refresh(self, state=None):
331340 self ._state = state if state is not None else self .read ()
332341 return self
333342
343+ @property
344+ def access (self ):
345+ """Returns entity access metadata."""
346+ return self .state .access
347+
334348 @property
335349 def content (self ):
336350 """Returns the contents of the entity."""
@@ -346,16 +360,16 @@ def enable(self):
346360 self .post ("enable" )
347361 return self
348362
363+ @property
364+ def fields (self ):
365+ """Returns entity content metadata."""
366+ return self .state .fields
367+
349368 @property
350369 def links (self ):
351370 """Returns a dictionary of related resources."""
352371 return self .state .links
353372
354- @property
355- def metadata (self ):
356- """Returns the entity metadata."""
357- return self .state .metadata
358-
359373 @property
360374 def name (self ):
361375 """Returns the entity name."""
@@ -448,10 +462,7 @@ def itemmeta(self):
448462 """Returns metadata for members of the collection."""
449463 response = self .get ("_new" )
450464 content = _load_atom (response , MATCH_ENTRY_CONTENT )
451- return {
452- 'eai:acl' : content ['eai:acl' ],
453- 'eai:attributes' : content ['eai:attributes' ]
454- }
465+ return _parse_atom_metadata (content )
455466
456467 # kwargs: count, offset, search, sort_dir, sort_key, sort_mode
457468 def list (self , count = - 1 , ** kwargs ):
@@ -674,10 +685,7 @@ def itemmeta(self, kind):
674685 """Returns metadata for the members of a given kind."""
675686 response = self .get ("%s/_new" % self ._kindmap [kind ])
676687 content = _load_atom (response , MATCH_ENTRY_CONTENT )
677- return {
678- 'eai:acl' : content ['eai:acl' ],
679- 'eai:attributes' : content ['eai:attributes' ]
680- }
688+ return _parse_atom_metadata (content )
681689
682690 @property
683691 def kinds (self ):
@@ -884,9 +892,17 @@ def create(self, query, **kwargs):
884892 def list (self , count = 0 , ** kwargs ):
885893 return Collection .list (self , count , ** kwargs )
886894
895+ class Loggers (Collection ):
896+ """This class represents a collection of service logging categories."""
897+ def __init__ (self , service ):
898+ Collection .__init__ (self , service , PATH_LOGGER )
899+
900+ def itemmeta (self ):
901+ raise NotSupportedError
902+
887903class Message (Entity ):
888- def __init__ (self , service , name , ** kwargs ):
889- Entity .__init__ (self , service , _path ( PATH_MESSAGES , name ) , ** kwargs )
904+ def __init__ (self , service , path , ** kwargs ):
905+ Entity .__init__ (self , service , path , ** kwargs )
890906
891907 @property
892908 def value (self ):
0 commit comments