Skip to content

Commit

Permalink
Merge pull request #23 from whdalsrnt/master
Browse files Browse the repository at this point in the history
refactor: add USER scope for authorization
  • Loading branch information
whdalsrnt authored Dec 26, 2021
2 parents 3e0a6c1 + 817fb52 commit cb1b9ba
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 17 deletions.
1 change: 0 additions & 1 deletion src/spaceone/config/info/domain_config_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def DomainConfigInfo(domain_config_vo: DomainConfig, minimal=False):
info.update({
'data': change_struct_type(domain_config_vo.data),
'tags': change_struct_type(utils.tags_to_dict(domain_config_vo.tags)),
'schema': domain_config_vo.schema,
'domain_id': domain_config_vo.domain_id,
'created_at': utils.datetime_to_iso8601(domain_config_vo.created_at)
})
Expand Down
4 changes: 1 addition & 3 deletions src/spaceone/config/model/domain_config_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@ class DomainConfigTag(EmbeddedDocument):
class DomainConfig(MongoModel):
name = StringField(max_length=255, unique_with='domain_id')
data = DictField()
schema = StringField(max_length=64)
tags = ListField(EmbeddedDocumentField(DomainConfigTag))
domain_id = StringField(max_length=255)
domain_id = StringField(max_length=40)
created_at = DateTimeField(auto_now_add=True)

meta = {
'updatable_fields': [
'name',
'data',
'schema',
'tags'
],
'minimal_fields': [
Expand Down
7 changes: 6 additions & 1 deletion src/spaceone/config/model/user_config_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class UserConfig(MongoModel):
name = StringField(max_length=255, unique_with='domain_id')
data = DictField()
tags = ListField(EmbeddedDocumentField(UserConfigTag))
domain_id = StringField(max_length=255)
user_id = StringField(max_length=40, default=None, null=True)
domain_id = StringField(max_length=40)
created_at = DateTimeField(auto_now_add=True)

meta = {
Expand All @@ -24,11 +25,15 @@ class UserConfig(MongoModel):
'minimal_fields': [
'name'
],
'change_query_keys': {
'user_self': 'user_id'
},
'ordering': [
'name'
],
'indexes': [
'name',
'user_id',
'domain_id',
('tags.key', 'tags.value')
]
Expand Down
2 changes: 0 additions & 2 deletions src/spaceone/config/service/domain_config_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def create(self, params):
params (dict): {
'name': 'str',
'data': 'dict',
'schema': 'str',
'tags': 'dict',
'domain_id': 'str'
}
Expand All @@ -49,7 +48,6 @@ def update(self, params):
params (dict): {
'name': 'str',
'data': 'dict',
'schema': 'str',
'tags': 'dict',
'domain_id': 'str'
}
Expand Down
32 changes: 22 additions & 10 deletions src/spaceone/config/service/user_config_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.user_config_mgr: UserConfigManager = self.locator.get_manager('UserConfigManager')

@transaction(append_meta={'authorization.scope': 'DOMAIN'})
@transaction(append_meta={'authorization.scope': 'USER'})
@check_required(['name', 'data', 'domain_id'])
def create(self, params):
"""Create config map
Expand All @@ -34,12 +34,16 @@ def create(self, params):
user_config_vo (object)
"""

user_type = self.transaction.get_meta('authorization.user_type')
if user_type != 'DOMAIN_OWNER':
params['user_id'] = self.transaction.get_meta('user_id')

if 'tags' in params:
params['tags'] = utils.dict_to_tags(params['tags'])

return self.user_config_mgr.create_user_config(params)

@transaction(append_meta={'authorization.scope': 'DOMAIN'})
@transaction(append_meta={'authorization.scope': 'USER'})
@check_required(['name', 'domain_id'])
def update(self, params):
"""Update config map
Expand All @@ -61,7 +65,7 @@ def update(self, params):

return self.user_config_mgr.update_user_config(params)

@transaction(append_meta={'authorization.scope': 'DOMAIN'})
@transaction(append_meta={'authorization.scope': 'USER'})
@check_required(['name', 'domain_id'])
def delete(self, params):
"""Delete config map
Expand All @@ -78,7 +82,7 @@ def delete(self, params):

self.user_config_mgr.delete_user_config(params['name'], params['domain_id'])

@transaction(append_meta={'authorization.scope': 'DOMAIN'})
@transaction(append_meta={'authorization.scope': 'USER'})
@check_required(['name', 'domain_id'])
def get(self, params):
"""Get config map
Expand All @@ -96,9 +100,12 @@ def get(self, params):

return self.user_config_mgr.get_user_config(params['name'], params['domain_id'], params.get('only'))

@transaction(append_meta={'authorization.scope': 'DOMAIN'})
@transaction(append_meta={
'authorization.scope': 'USER',
'mutation.append_parameter': {'user_self': {'meta': 'user_id', 'data': [None]}}
})
@check_required(['domain_id'])
@append_query_filter(['name', 'domain_id'])
@append_query_filter(['name', 'user_id', 'domain_id', 'user_self'])
@change_tag_filter('tags')
@append_keyword_filter(['name'])
def list(self, params):
Expand All @@ -108,7 +115,8 @@ def list(self, params):
params (dict): {
'name': 'str',
'domain_id': 'str',
'query': 'dict (spaceone.api.core.v1.Query)'
'query': 'dict (spaceone.api.core.v1.Query)',
'user_self': 'list', // from meta
}
Returns:
Expand All @@ -119,17 +127,21 @@ def list(self, params):
query = params.get('query', {})
return self.user_config_mgr.list_user_configs(query)

@transaction(append_meta={'authorization.scope': 'DOMAIN'})
@transaction(append_meta={
'authorization.scope': 'USER',
'mutation.append_parameter': {'user_self': {'meta': 'user_id', 'data': [None]}}
})
@check_required(['query', 'domain_id'])
@append_query_filter(['domain_id'])
@append_query_filter(['domain_id', 'user_self'])
@change_tag_filter('tags')
@append_keyword_filter(['name'])
def stat(self, params):
"""
Args:
params (dict): {
'domain_id': 'str',
'query': 'dict (spaceone.api.core.v1.StatisticsQuery)'
'query': 'dict (spaceone.api.core.v1.StatisticsQuery)',
'user_self': 'list', // from meta
}
Returns:
Expand Down

0 comments on commit cb1b9ba

Please sign in to comment.