Skip to content

Commit

Permalink
Merge pull request #34 from whdalsrnt/master
Browse files Browse the repository at this point in the history
Refactor Resource Module
  • Loading branch information
whdalsrnt authored May 11, 2023
2 parents 97c04c3 + a2c7e73 commit 431f1bc
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions src/spacectl/modules/resource/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,23 +161,33 @@ def _load_parser(columns=None, template_path=None):

def _load_parser_from_metadata(self, metadata, use_name_alias):
cloud_service_type = self._get_cloud_service_type(metadata)
user_config = self._get_user_config(metadata)
show_optional = False
# user_config = self._get_user_config(metadata)
# show_optional = False
#
# if user_config:
# table_fields = user_config.get('data', {}).get('options', {}).get('fields', [])
# show_optional = True
# else:
# table_fields = cloud_service_type.get('metadata', {}).get('view', {}).get('table', {}).get('layout', {}).get(
# 'options', {}).get('fields', [])
#
# template = self._generate_template_from_metadata_table_fields(table_fields, show_optional)
#
# if not user_config:
# template['template']['list'] = ['project_id', 'provider|Provider',
# 'region_code|Region', 'name|Name'] \
# + template['template']['list'] \
# + ['reference.resource_id|Resource ID']

if user_config:
table_fields = user_config.get('data', {}).get('options', {}).get('fields', [])
show_optional = True
else:
table_fields = cloud_service_type.get('metadata', {}).get('view', {}).get('table', {}).get('layout', {}).get(
'options', {}).get('fields', [])
show_optional = False
table_fields = cloud_service_type.get('metadata', {}).get('view', {}).get('table', {}).get('layout', {}).get(
'options', {}).get('fields', [])

template = self._generate_template_from_metadata_table_fields(table_fields, show_optional)

if not user_config:
template['template']['list'] = ['project_id', 'provider|Provider',
'region_code|Region', 'name|Name'] \
+ template['template']['list'] \
+ ['reference.resource_id|Resource ID']
template['template']['list'] = ['project_id', 'provider|Provider', 'region_code|Region', 'name|Name']
template['template']['list'] += template['template']['list']
template['template']['list'] += ['reference.resource_id|Resource ID']

return load_parser(None, None, template, use_name_alias)

Expand All @@ -198,6 +208,9 @@ def _generate_template_from_metadata_table_fields(self, table_fields, show_optio
'launched_at']:
_list.append(self._set_field(_field))

if 'project_id' not in _list:
_list.append('project_id')

return {'template': {'list': _list}}

@staticmethod
Expand Down

0 comments on commit 431f1bc

Please sign in to comment.