<commit_before>// Copyright 2018 The OpenPitrix Authors. All rights reserved.
// Use of this source code is governed by a Apache license
// that can be found in the LICENSE file.

package account

import (
	"context"

	pbam "openpitrix.io/iam/pkg/pb/am"
	"openpitrix.io/openpitrix/pkg/client/am"
	"openpitrix.io/openpitrix/pkg/gerr"
	"openpitrix.io/openpitrix/pkg/pb"
	"openpitrix.io/openpitrix/pkg/util/ctxutil"
)

var (
	_           pb.AccessManagerServer = (*Server)(nil)
	amClient, _                        = am.NewClient()
)

func pbRole(p *pbam.Role) *pb.Role {
	return &pb.Role{
		RoleId:      p.RoleId,
		RoleName:    p.RoleName,
		Description: p.Description,
		Portal:      p.Portal,
		Owner:       p.Owner,
		OwnerPath:   p.OwnerPath,
		Status:      p.Status,

		CreateTime: p.CreateTime,
		UpdateTime: p.UpdateTime,
		StatusTime: p.StatusTime,

		UserId: p.UserId,
	}
}
func pbamRole(p *pb.Role) *pbam.Role {
	return &pbam.Role{
		RoleId:      p.RoleId,
		RoleName:    p.RoleName,
		Description: p.Description,
		Portal:      p.Portal,
		Owner:       p.Owner,
		OwnerPath:   p.OwnerPath,
		Status:      p.Status,

		CreateTime: p.CreateTime,
		UpdateTime: p.UpdateTime,
		StatusTime: p.StatusTime,

		UserId: p.UserId,
	}
}

func pbRoleModule(p *pbam.RoleModule) *pb.RoleModule {
	return &pb.RoleModule{
		RoleId: p.RoleId,
		Module: pbRoleModuleElemList(p.Module),
	}
}
func pbamRoleModule(p *pb.RoleModule) *pbam.RoleModule {
	return &pbam.RoleModule{
		RoleId: p.RoleId,
		Module: pbamRoleModuleElemList(p.Module),
	}
}

func pbRoleModuleElemList(ps []*pbam.RoleModuleElem) []*pb.RoleModuleElem {
	var results []*pb.RoleModuleElem
	for _, p := range ps {
		results = append(results, &pb.RoleModuleElem{
			ModuleId:   p.ModuleId,
			ModuleName: p.ModuleName,
			Feature:    pbModuleFeatureList(p.Feature),
			Owner:      p.Owner,
			DataLevel:  p.DataLevel,
			IsCheckAll: p.IsCheckAll,
		})
	}
	return results
}
func pbamRoleModuleElemList(ps []*pb.RoleModuleElem) []*pbam.RoleModuleElem {
	var results []*pbam.RoleModuleElem
	for _, p := range ps {
		results = append(results, &pbam.RoleModuleElem{
			ModuleId:   p.ModuleId,
			ModuleName: p.ModuleName,
			Feature:    pbamModuleFeatureList(p.Feature),<commit_msg>account: fix nil pointer panic<commit_after>// Copyright 2018 The OpenPitrix Authors. All rights reserved.
// Use of this source code is governed by a Apache license
// that can be found in the LICENSE file.

package account

import (
	"context"

	pbam "openpitrix.io/iam/pkg/pb/am"
	"openpitrix.io/openpitrix/pkg/client/am"
	"openpitrix.io/openpitrix/pkg/gerr"
	"openpitrix.io/openpitrix/pkg/pb"
	"openpitrix.io/openpitrix/pkg/util/ctxutil"
)

var (
	_           pb.AccessManagerServer = (*Server)(nil)
	amClient, _                        = am.NewClient()
)

func pbRole(p *pbam.Role) *pb.Role {
	if p == nil {
		return new(pb.Role)
	}
	return &pb.Role{
		RoleId:      p.RoleId,
		RoleName:    p.RoleName,
		Description: p.Description,
		Portal:      p.Portal,
		Owner:       p.Owner,
		OwnerPath:   p.OwnerPath,
		Status:      p.Status,

		CreateTime: p.CreateTime,
		UpdateTime: p.UpdateTime,
		StatusTime: p.StatusTime,

		UserId: p.UserId,
	}
}
func pbamRole(p *pb.Role) *pbam.Role {
	if p == nil {
		return new(pbam.Role)
	}
	return &pbam.Role{
		RoleId:      p.RoleId,
		RoleName:    p.RoleName,
		Description: p.Description,
		Portal:      p.Portal,
		Owner:       p.Owner,
		OwnerPath:   p.OwnerPath,
		Status:      p.Status,

		CreateTime: p.CreateTime,
		UpdateTime: p.UpdateTime,
		StatusTime: p.StatusTime,

		UserId: p.UserId,
	}
}

func pbRoleModule(p *pbam.RoleModule) *pb.RoleModule {
	if p == nil {
		return new(pb.RoleModule)
	}
	return &pb.RoleModule{
		RoleId: p.RoleId,
		Module: pbRoleModuleElemList(p.Module),
	}
}
func pbamRoleModule(p *pb.RoleModule) *pbam.RoleModule {
	if p == nil {
		return new(pbam.RoleModule)
	}
	return &pbam.RoleModule{
		RoleId: p.RoleId,
		Module: pbamRoleModuleElemList(p.Module),
	}
}

func pbRoleModuleElemList(ps []*pbam.RoleModuleElem) []*pb.RoleModuleElem {
	var results []*pb.RoleModuleElem
	for _, p := range ps {
		results = append(results, &pb.RoleModuleElem{
			ModuleId:   p.ModuleId,
			ModuleName: p.ModuleName,
			Feature:    pbModuleFeatureList(p.Feature),
			Owner:      p.Owner,
			DataLevel:  p.DataLevel,
			IsCheckAll: p.IsCheckAll,
		})
	}
	return results
}
func pbamRoleModuleElemList(ps []*pb.RoleModuleElem) []*pbam.RoleModuleElem {
	var results []*pbam.RoleModuleElem
	for _, p := range ps {
		results = append(results, &pbam.RoleModuleElem{
			ModuleId:   p.ModuleId,
			ModuleName: p.ModuleName,
			Feature:    pbamModuleFeatureList(p.Feature),
{'fraction_non_alphanumeric': 0.12567132116004295, 'fraction_numerical': 0.0017185821697099893, 'mean_word_length': 3.3311627906976744, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5270379', 'n_tokens_mistral': 1860, 'n_tokens_neox': 1765, 'n_words': 357}