示例#1
0
def ProjectGroupRoleBindingInfo(role_binding_vo):
    info = {
        'role_binding_id':
        role_binding_vo.role_binding_id,
        'resource_type':
        role_binding_vo.resource_type,
        'resource_id':
        role_binding_vo.resource_id,
        'role_info':
        RoleInfo(role_binding_vo.role, minimal=True),
        'project_group_info':
        ProjectGroupInfo(role_binding_vo.project_group, minimal=True),
        'labels':
        role_binding_vo.labels,
        'tags': [
            tag_pb2.Tag(key=tag.key, value=tag.value)
            for tag in role_binding_vo.tags
        ],
        'domain_id':
        role_binding_vo.domain_id,
        'created_at':
        change_timestamp_type(role_binding_vo.created_at)
    }

    return project_group_pb2.ProjectGroupRoleBindingInfo(**info)
示例#2
0
def ProjectGroupRoleBindingInfo(role_binding_vo, minimal=False):
    info = {
        'role_binding_id':
        role_binding_vo.role_binding_id,
        'resource_type':
        role_binding_vo.resource_type,
        'resource_id':
        role_binding_vo.resource_id,
        'role_info':
        RoleInfo(role_binding_vo.role, minimal=True)
        if role_binding_vo.role else None
    }

    if not minimal:
        info.update({
            'project_group_info':
            ProjectGroupInfo(role_binding_vo.project_group, minimal=True)
            if role_binding_vo.project_group else None,
            'labels':
            change_list_value_type(role_binding_vo.labels),
            'tags':
            change_struct_type(utils.tags_to_dict(role_binding_vo.tags)),
            'domain_id':
            role_binding_vo.domain_id,
            'created_at':
            utils.datetime_to_iso8601(role_binding_vo.created_at)
        })

    return project_group_pb2.ProjectGroupRoleBindingInfo(**info)
示例#3
0
def UserInfo(user_vo: User, minimal=False):
    info = {
        'user_id': user_vo.user_id,
        'name': user_vo.name,
        'state': user_vo.state,
        'domain_id': user_vo.domain_id
    }

    if not minimal:
        info.update({
            'email':
            user_vo.email,
            'mobile':
            user_vo.mobile,
            'group':
            user_vo.group,
            'language':
            user_vo.language,
            'timezone':
            user_vo.timezone,
            'roles':
            list(map(lambda role: RoleInfo(role, minimal=True),
                     user_vo.roles)),
            'tags':
            change_struct_type(user_vo.tags),
            'last_accessed_at':
            change_timestamp_type(user_vo.last_accessed_at),
            'created_at':
            change_timestamp_type(user_vo.created_at)
        })

    return user_pb2.UserInfo(**info)
示例#4
0
def ProjectMemberInfo(project_member_vo):
    info = {
        'project_info': ProjectInfo(project_member_vo.project, minimal=True),
        'user_info': UserInfo(project_member_vo.user),
        'roles': list(map(lambda role: RoleInfo(role, minimal=True), project_member_vo.roles)),
        'labels': change_list_value_type(project_member_vo.labels)
    }

    return project_pb2.ProjectMemberInfo(**info)
示例#5
0
def RoleBindingInfo(role_binding_vo: RoleBinding, minimal=False):
    info = {
        'role_binding_id':
        role_binding_vo.role_binding_id,
        'resource_type':
        role_binding_vo.resource_type,
        'resource_id':
        role_binding_vo.resource_id,
        'role_info':
        RoleInfo(role_binding_vo.role, minimal=True)
        if role_binding_vo.role else None
    }

    if not minimal:
        info.update({
            'project_info':
            ProjectInfo(role_binding_vo.project, minimal=True)
            if role_binding_vo.project else None,
            'project_group_info':
            ProjectGroupInfo(role_binding_vo.project_group, minimal=True)
            if role_binding_vo.project_group else None,
            'labels':
            role_binding_vo.labels,
            'tags': [
                tag_pb2.Tag(key=tag.key, value=tag.value)
                for tag in role_binding_vo.tags
            ],
            'domain_id':
            role_binding_vo.domain_id,
            'created_at':
            change_timestamp_type(role_binding_vo.created_at)
        })

        if not role_binding_vo.project_id and role_binding_vo.project:
            role_binding_vo.update(
                {'project_id': role_binding_vo.project.project_id})

        if not role_binding_vo.project_group_id and role_binding_vo.project_group:
            role_binding_vo.update({
                'project_group_id':
                role_binding_vo.project_group.project_group_id
            })

    # Temporary code for DB migration
    if not role_binding_vo.role_id and role_binding_vo.role:
        role_binding_vo.update({'role_id': role_binding_vo.role.role_id})

    return role_binding_pb2.RoleBindingInfo(**info)