utils

package
v1.12.1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinCost     int = 4  // the minimum allowable cost as passed in to GenerateFromPassword
	MaxCost     int = 31 // the maximum allowable cost as passed in to GenerateFromPassword
	DefaultCost int = 10 // the cost that will actually be set if a cost below MinCost is passed into GenerateFromPassword
)
View Source
const (
	PlatformName     = "CloudSecPlatform"
	ManagementTenant = "systemTenant"
	DefaultTenant    = "defaultTenant"
	Account          = "systemAccount"
	UserName         = "SuperAdmin"
)
View Source
const (
	UserResourceType     = "user"
	ConfigResourceType   = "config"
	TenantResourceType   = "tenant"
	AccountResourceType  = "account"
	ProjectResourceType  = "project"
	AuditLogResourceType = "audit-log"
	RoleResourceType     = "role"
	PolicyResourceType   = "policy"
)
View Source
const (
	// ActionConfigRead ActionConfig
	ActionConfigRead           = "config:read"
	ActionConfigUpdateDatabase = "config:update:database"
	ActionConfigUpdateNetwork  = "config:update:network"

	// ActionTenantCreate Tenant Actions
	ActionTenantCreate = "tenant:create"
	ActionTenantRead   = "tenant:read"
	ActionTenantUpdate = "tenant:update"
	ActionTenantDelete = "tenant:delete"

	// ActionUserCreate User Actions
	ActionUserCreate = "user:create"
	ActionUserRead   = "user:read"
	ActionUserUpdate = "user:update"
	ActionUserDelete = "user:delete"

	// ActionRoleCreate ActionUserCreate User Actions
	ActionRoleCreate = "role:create"
	ActionRoleRead   = "role:read"
	ActionRoleUpdate = "role:update"
	ActionRoleDelete = "role:delete"

	// ActionProjectCreate Project Actions
	ActionProjectCreate = "project:create"
	ActionProjectRead   = "project:read"
	ActionProjectUpdate = "project:update"
	ActionProjectDelete = "project:delete"

	// ActionAuditLogRead Audit Log Actions
	ActionAuditLogRead   = "audit-log:read"
	ActionAuditLogExport = "audit-log:export"
)
View Source
const (
	ResourceUserAll        = "rrn:" + PlatformName + ":*:*:user:*"    // 匹配所有租户和账户的用户
	ResourceUserSpecific   = "rrn:" + PlatformName + ":%s:%s:user:%s" // 匹配特定租户和账户的用户
	ResourceConfigAll      = "rrn:" + PlatformName + ":*:*:config:*"
	ResourceConfigSpecific = "rrn:" + PlatformName + ":%s:%s:config:%s"
	ResourceTenantAll      = "rrn:" + PlatformName + ":*:*:tenant:*"
	ResourceAccountAll     = "rrn:" + PlatformName + ":*:*:account:*"
	ResourceProjectAll     = "rrn:" + PlatformName + ":*:*:project:*"
	ResourceAuditLogAll    = "rrn:" + PlatformName + ":*:*:audit-log:*"
	ResourceRoleAll        = "rrn:" + PlatformName + ":*:*:role:*"
	ResourcePolicyAll      = "rrn:" + PlatformName + ":*:*:policy:*"
)

Variables

View Source
var (
	AccessTokenSecret  string
	RefreshTokenSecret string
)

在代码中直接定义密钥(使用随机密钥)

View Source
var ErrMismatchedHashAndPassword = errors.New("crypto/bcrypt: hashedPassword is not the hash of the given password")

Log zapLog对象

Functions

func CasbinMiddleware

func CasbinMiddleware(enforcer *casbin.Enforcer) echo.MiddlewareFunc

func Check

func Check(content, encrypted string) bool

func CheckAccessToken

func CheckAccessToken(next echo.HandlerFunc) echo.HandlerFunc

CheckAccessToken 中间件用于检查访问令牌

func CompareHashAndPassword

func CompareHashAndPassword(hashedPassword, password []byte) error

func CreateAccessToken

func CreateAccessToken(userID, tenantID, accountID uuid.UUID, email, username, roleName string) (string, error)

CreateAccessToken 创建JWT访问令牌

func CreateRefreshToken

func CreateRefreshToken(userID, tenantID, accountID uuid.UUID, email, username, roleName string) (string, error)

CreateRefreshToken 创建刷新令牌

func Encode

func Encode(data string) string

func GenerateFromPassword

func GenerateFromPassword(password []byte, cost int) ([]byte, error)

func GenerateRandomKey

func GenerateRandomKey(length int) (string, error)

GenerateRandomKey 生成随机密钥的函数

func GenerateUsername

func GenerateUsername() string

GenerateUsername 生成唯一用户名

func InitLogger

func InitLogger()

InitLogger 初始化Logger

func SessionMiddleware

func SessionMiddleware(next echo.HandlerFunc) echo.HandlerFunc

func SetCSRFToken

func SetCSRFToken(next echo.HandlerFunc) echo.HandlerFunc

func UUID

func UUID() string

func ValidAccessTokenConfig

func ValidAccessTokenConfig() echojwt.Config

ValidAccessTokenConfig 配置有效的访问令牌

func ValidateRefreshTokenConfig

func ValidateRefreshTokenConfig() echojwt.Config

ValidateRefreshTokenConfig 验证刷新令牌

Types

type JwtCustomClaims

type JwtCustomClaims struct {
	UserID    uuid.UUID `json:"user_id"`
	Email     string    `json:"email"`
	Username  string    `json:"username"`
	TenantID  uuid.UUID `json:"tenant_id"`
	RoleName  string    `json:"role_name"` // 存储单个角色的名称
	AccountID uuid.UUID `json:"account_id"`

	jwt.RegisteredClaims
}

JwtCustomClaims 在全局范围内定义你的jwtCustomClaims类型

Jump to

Keyboard shortcuts

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