Skip to content

Commit

Permalink
Bug fix: list and get policy apis
Browse files Browse the repository at this point in the history
add updated_at field to plugin, schema and policy resources

Signed-off-by: Jongmin Kim <[email protected]>
  • Loading branch information
whdalsrnt committed Dec 16, 2020
1 parent 7095b01 commit c7402bd
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 25 deletions.
18 changes: 0 additions & 18 deletions src/spaceone/repository/api/v1/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,6 @@ def delete(self, request, context):
policy_svc.delete(params)
return self.locator.get_info('EmptyInfo')

def enable(self, request, context):
params, metadata = self.parse_request(request, context)
with self.locator.get_service('PolicyService', metadata) as policy_svc:
policy_data = policy_svc.enable(params)
return self.locator.get_info('PolicyInfo', policy_data)

def disable(self, request, context):
params, metadata = self.parse_request(request, context)
with self.locator.get_service('PolicyService', metadata) as policy_svc:
policy_data = policy_svc.disable(params)
return self.locator.get_info('PolicyInfo', policy_data)

def get_versions(self, request, context):
params, metadata = self.parse_request(request, context)
with self.locator.get_service('PolicyService', metadata) as policy_svc:
version_list = policy_svc.get_versions(params)
return self.locator.get_info('VersionsInfo', version_list)

def get(self, request, context):
params, metadata = self.parse_request(request, context)
with self.locator.get_service('PolicyService', metadata) as policy_svc:
Expand Down
5 changes: 2 additions & 3 deletions src/spaceone/repository/connector/repository_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def get_local_repository(self, domain_id):
# if count > 1:
# for repo in repositories:
# _LOGGER.debug(f'[get_repository] name: {repo.name}')
print(response)
return response.results[0]

def get_policy(self, name, only=None):
Expand All @@ -87,7 +86,7 @@ def get_policy(self, name, only=None):
"""
param = {'name': name, 'domain_id': self.domain_id, 'only': only}
_LOGGER.debug("param: %s" % param)
return self.client.Schema.get(param, metadata=self.meta)
return self.client.Policy.get(param, metadata=self.meta)

def list_policies(self, query):
_LOGGER.debug(f'[list_schemas] query: {query}')
Expand All @@ -102,7 +101,7 @@ def list_policies(self, query):
'query': updated_query
}
_LOGGER.debug("params: %s" % params)
return self.client.Schema.list(params, metadata=self.meta)
return self.client.Policy.list(params, metadata=self.meta)

def get_schema(self, name, only=None):
""" get schema from repository
Expand Down
3 changes: 2 additions & 1 deletion src/spaceone/repository/info/plugin_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def PluginInfo(plugin_vo: Plugin, minimal=False):
'tags': [tag_pb2.Tag(key=tag.key, value=tag.value) for tag in plugin_vo.tags],
'project_id': plugin_vo.project_id,
'domain_id': plugin_vo.domain_id,
'created_at': change_timestamp_type(plugin_vo.created_at)
'created_at': change_timestamp_type(plugin_vo.created_at),
'updated_at': change_timestamp_type(plugin_vo.updated_at)
})
# WARNING
# Based on local_plugin or remote_plugin
Expand Down
3 changes: 2 additions & 1 deletion src/spaceone/repository/info/policy_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def PolicyInfo(policy_vo: Policy, minimal=False):
'tags': [tag_pb2.Tag(key=tag.key, value=tag.value) for tag in policy_vo.tags],
'project_id': policy_vo.project_id,
'domain_id': policy_vo.domain_id,
'created_at': change_timestamp_type(policy_vo.created_at)
'created_at': change_timestamp_type(policy_vo.created_at),
'updated_at': change_timestamp_type(policy_vo.updated_at)
})
# WARNING
# Based on local_policy or remote_policy
Expand Down
3 changes: 2 additions & 1 deletion src/spaceone/repository/info/schema_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def SchemaInfo(schema_vo: Schema, minimal=False):
'tags': [tag_pb2.Tag(key=tag.key, value=tag.value) for tag in schema_vo.tags],
'project_id': schema_vo.project_id,
'domain_id': schema_vo.domain_id,
'created_at': change_timestamp_type(schema_vo.created_at)
'created_at': change_timestamp_type(schema_vo.created_at),
'updated_at': change_timestamp_type(schema_vo.updated_at)
})
# WARNING
# Based on local_schema or remote_schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ def list_policies(self, query, domain_id):
# query should be JSON style query, not gRPC
#

response = connector.list_policys(query)
response = connector.list_policies(query)
_LOGGER.debug(f'[remote list_policy] count: {response.total_count}')

for policy_info in response.results:
# Warning:
# This is side effect coding, since policy_vo is protobuf message
self._get_updated_policy_info(policy_info)

return response.results, response.total_count

def stat_policies(self, query, domain_id):
Expand Down
1 change: 1 addition & 0 deletions src/spaceone/repository/model/plugin_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Plugin(MongoModel):
project_id = StringField(max_length=255, default=None, null=True)
domain_id = StringField(max_length=255)
created_at = DateTimeField(auto_now_add=True)
updated_at = DateTimeField(auto_now=True)
deleted_at = DateTimeField(default=None, null=True)

meta = {
Expand Down
1 change: 1 addition & 0 deletions src/spaceone/repository/model/policy_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Policy(MongoModel):
project_id = StringField(max_length=255, default=None, null=True)
domain_id = StringField(max_length=255)
created_at = DateTimeField(auto_now_add=True)
updated_at = DateTimeField(auto_now=True)

meta = {
'updatable_fields': [
Expand Down
1 change: 1 addition & 0 deletions src/spaceone/repository/model/schema_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Schema(MongoModel):
project_id = StringField(max_length=255, default=None, null=True)
domain_id = StringField(max_length=255)
created_at = DateTimeField(auto_now_add=True)
updated_at = DateTimeField(auto_now=True)

meta = {
'updatable_fields': [
Expand Down
1 change: 1 addition & 0 deletions test/factory/plugin_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ class Meta:
project_id = None
domain_id = utils.generate_id('domain')
created_at = factory.Faker('date_time')
updated_at = factory.Faker('date_time')
deleted_at = None
1 change: 1 addition & 0 deletions test/factory/policy_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ class Meta:
project_id = None
domain_id = utils.generate_id('domain')
created_at = factory.Faker('date_time')
updated_at = factory.Faker('date_time')
1 change: 1 addition & 0 deletions test/factory/schema_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ class Meta:
project_id = None
domain_id = utils.generate_id('domain')
created_at = factory.Faker('date_time')
updated_at = factory.Faker('date_time')

0 comments on commit c7402bd

Please sign in to comment.