2626def _flatten_vault (obj ):
2727 """Flatten the structure of the vault into a single dict
2828 """
29+ bind_rules = []
30+ if obj .bind_rules and "tags" in obj .bind_rules :
31+ bind_rules = obj .bind_rules ["tags" ]
2932 data = {
3033 'id' : obj .id ,
3134 'name' : obj .name ,
@@ -46,7 +49,7 @@ def _flatten_vault(obj):
4649 'charging_mode' : obj .billing .charging_mode ,
4750 'is_auto_pay' : obj .billing .is_auto_pay ,
4851 'is_auto_renew' : obj .billing .is_auto_renew ,
49- 'bind_rules' : obj . bind_rules [ "tags" ] ,
52+ 'bind_rules' : bind_rules ,
5053 'resources' : obj .resources ,
5154 'tags' : obj .tags ,
5255 }
@@ -201,11 +204,32 @@ def take_action(self, parsed_args):
201204 if parsed_args .status :
202205 args ['status' ] = parsed_args .status
203206
204- data = client .vaults (** args )
205- table = (self .columns ,
206- (utils .get_dict_properties (
207- _flatten_vault (s ), self .columns ,
208- ) for s in data ))
207+ data = list (client .vaults (** args )) # Force evaluation once
208+
209+ def row_generator ():
210+ for s in data :
211+ row_columns = list (self .columns )
212+ row_data = utils .get_dict_properties (
213+ _flatten_vault (s ), row_columns
214+ )
215+ if s .resources :
216+ row_data , row_columns = _add_resources_to_vault_obj (
217+ s , row_data , tuple (row_columns )
218+ )
219+ if s .tags :
220+ row_data , row_columns = _add_tags_to_vault_obj (
221+ s , row_data , tuple (row_columns )
222+ )
223+ yield row_data
224+
225+ columns = list (self .columns )
226+ for s in data :
227+ if s .resources or s .tags :
228+ _ , columns = _add_tags_to_vault_obj (s , (), tuple (columns ))
229+ _ , columns = _add_resources_to_vault_obj (s , (), tuple (columns ))
230+ break
231+
232+ table = (columns , row_generator ())
209233 return table
210234
211235
0 commit comments