github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/models/access_key.go (about)

     1  package models
     2  
     3  import (
     4  	"database/sql/driver"
     5  
     6  	"github.com/machinefi/w3bstream/pkg/depends/base/types"
     7  	"github.com/machinefi/w3bstream/pkg/depends/kit/sqlx/datatypes"
     8  	"github.com/machinefi/w3bstream/pkg/enums"
     9  )
    10  
    11  // AccessKey api access key
    12  // @def primary ID
    13  // @def unique_index ui_name AccountID Name
    14  // @def unique_index ui_rand Rand
    15  //
    16  //go:generate toolkit gen model AccessKey --database DB
    17  type AccessKey struct {
    18  	datatypes.PrimaryID
    19  	RelAccount
    20  	AccessKeyInfo
    21  	datatypes.OperationTimesWithDeleted
    22  }
    23  
    24  type AccessKeyInfo struct {
    25  	IdentityID   types.SFID                  `db:"f_identity_id"`
    26  	IdentityType enums.AccessKeyIdentityType `db:"f_identity_type"`
    27  	Name         string                      `db:"f_name"`
    28  	Rand         string                      `db:"f_rand"`
    29  	ExpiredAt    types.Timestamp             `db:"f_expired_at,default='0'"`
    30  	LastUsed     types.Timestamp             `db:"f_last_used,default='0'"`
    31  	Description  string                      `db:"f_desc,default=''"`
    32  	Privileges   GroupAccessPrivileges       `db:"f_privileges,default='[]'"`
    33  }
    34  
    35  // GroupAccessPrivileges mapping group name and access permission
    36  type GroupAccessPrivileges map[string]enums.AccessPermission
    37  
    38  func (GroupAccessPrivileges) DataType(driver string) string { return "text" }
    39  
    40  func (m GroupAccessPrivileges) Value() (driver.Value, error) { return datatypes.JSONValue(m) }
    41  
    42  func (m *GroupAccessPrivileges) Scan(src interface{}) error { return datatypes.JSONScan(src, m) }