Help us shape the future of Go! Take the 2026 Go Developer Survey

service

package
v1.11.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EncryptedSvc

type EncryptedSvc = Service

type IResourceProtector added in v1.11.3

type IResourceProtector interface {
	// Encrypt 对单个资产的敏感属性执行加密
	Encrypt(ctx context.Context, res domain.Resource) (domain.Resource, error)

	// EncryptMany 批量对资产执行敏感属性加密(聚合查询属性以优化性能)
	EncryptMany(ctx context.Context, resources []domain.Resource) ([]domain.Resource, error)

	// Decrypt 对单个资产的敏感属性执行严格解密,并自动还原带有 ENC: 的历史密文
	Decrypt(ctx context.Context, res domain.Resource) (domain.Resource, error)

	// DecryptMany 批量对资产执行敏感属性解密
	DecryptMany(ctx context.Context, resources []domain.Resource) ([]domain.Resource, error)

	// DecryptFields 针对明确指定的字段列表执行解密(用于安全属性关闭时的存量数据异步清洗与还原)
	DecryptFields(ctx context.Context, resources []domain.Resource, fields []string) ([]domain.Resource, error)

	// Mask 将单个资产的敏感字段替换为 "[已脱敏]",用于展示与审计
	Mask(ctx context.Context, res domain.Resource) (domain.Resource, error)

	// MaskMany 批量对资产敏感属性置空脱敏(用于列表检索安全展示,支持前端解密查看)
	MaskMany(ctx context.Context, resources []domain.Resource) ([]domain.Resource, error)

	// DecryptValue 对单个密文字符串进行解密
	DecryptValue(encryptedText string) (string, error)

	// IsMasked 判断值是否为脱敏占位文本
	IsMasked(val any) bool
}

IResourceProtector 统管 ECMDB 资产在存储、运行和展示阶段的敏感属性保护

func NewResourceProtector added in v1.11.3

func NewResourceProtector(attrSvc attribute.Service, cipher cryptox.Crypto) IResourceProtector

NewResourceProtector 创建资产敏感属性保护器

type Service

type Service interface {
	// CreateResource 创建资产
	CreateResource(ctx context.Context, req domain.Resource) (int64, error)

	// BatchCreateOrUpdate 批量创建或修改资产
	BatchCreateOrUpdate(ctx context.Context, rs []domain.Resource) error

	// FindResourceById 根据 ID 获取资产详情(自动解密敏感数据)
	FindResourceById(ctx context.Context, fields []string, id int64) (domain.Resource, error)

	// ListResource 获取模型资产列表(自动解密)
	ListResource(ctx context.Context, fields []string, modelUid string, offset, limit int64) ([]domain.Resource, int64, error)

	// CountByModelUid 统计模型下的资产数量
	CountByModelUid(ctx context.Context, modelUid string) (int64, error)

	// SetCustomField 变更指定字段的数据
	SetCustomField(ctx context.Context, id int64, field string, data interface{}) (int64, error)

	// UnsetCustomField 抹除指定模型下所有资产的自定义字段
	UnsetCustomField(ctx context.Context, modelUid string, fieldUid string) (int64, error)

	// ListResourceByIds 按 ID 列表批量查询关联资源(自动解密)
	ListResourceByIds(ctx context.Context, fields []string, ids []int64) ([]domain.Resource, error)

	// ListExcludeAndFilterResourceByIds 排序以及复杂条件过滤
	ListExcludeAndFilterResourceByIds(ctx context.Context, fields []string, modelUid string, offset, limit int64,
		ids []int64, filter domain.Condition) ([]domain.Resource, int64, error)

	// DeleteResource 删除资产数据
	DeleteResource(ctx context.Context, id int64) (int64, error)

	// CountByModelUids 聚合查看各模型下的数量
	CountByModelUids(ctx context.Context, modelUids []string) (map[string]int, error)

	// SearchStructure 单租户检索模型 Tabs 统计(轻量元数据,支撑模型Tabs)
	SearchStructure(ctx context.Context, text string) (domain.SearchStructureResult, error)

	// SearchPagedResources 模型资产物理分页检索并执行敏感脱敏(支持指定租户或当前租户上下文)
	SearchPagedResources(ctx context.Context, tenantID int64, modelUid string, text string, offset, limit int64) ([]domain.Resource, int64, error)

	// AdminSearchStructure 跨租户检索大盘结构统计(轻量元数据,支撑左侧租户树与右侧模型Tabs)
	AdminSearchStructure(ctx context.Context, text string) (domain.AdminSearchStructureResult, error)

	// FindSecureData 查看指定资产加密字段明文数据
	FindSecureData(ctx context.Context, id int64, fieldUid string) (string, error)

	// UpdateResource 修改资产数据(支持脱敏占位符防覆盖与自动加密)
	UpdateResource(ctx context.Context, resource domain.Resource) (int64, error)

	// BatchUpdateResources 批量更新资产(支持敏感属性变更重加密)
	BatchUpdateResources(ctx context.Context, resources []domain.Resource) (int64, error)

	// ListBeforeUtime 获取指定时间前的资产列表
	ListBeforeUtime(ctx context.Context, utime int64, fields []string, modelUid string, offset, limit int64) ([]domain.Resource, error)

	// ListAndDecryptBeforeUtime 获取指定时间前的资产列表并精准解密传入字段
	ListAndDecryptBeforeUtime(ctx context.Context, utime int64, fields []string, modelUid string, offset, limit int64) ([]domain.Resource, error)

	// ListResourcesWithFilters 根据复杂筛选条件获取资产列表(自动解密)
	ListResourcesWithFilters(ctx context.Context, fields []string, modelUid string, ids []int64, offset, limit int64,
		filterGroups []domain.FilterGroup) ([]domain.Resource, int64, error)

	// CheckBeforeDelete 检查指定模型下是否还有资产实例,未清空时阻断删除
	CheckBeforeDelete(ctx context.Context, modelUid string) error
}

func NewService

func NewService(repo repository.ResourceRepository, attrSvc attribute.Service, crypto cryptox.Crypto) Service

NewService 创建资产领域服务实例

Directories

Path Synopsis
Package resourcemocks is a generated GoMock package.
Package resourcemocks is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL