next-terminal/pkg/model/credential.go
dushixiang bc9daf2b01 修改docker默认时区为上海
修复了记住登录无效的问题
修复了ssh下载文件名称不正确的问题
授权凭证增加了密钥类型
2021-01-08 23:01:41 +08:00

72 lines
1.6 KiB
Go

package model
import (
"next-terminal/pkg/global"
"next-terminal/pkg/utils"
)
// 密码
const Custom = "custom"
// 密钥
const PrivateKey = "private-key"
type Credential struct {
ID string `gorm:"primary_key" json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Username string `json:"username"`
Password string `json:"password"`
PrivateKey string `json:"privateKey"`
Passphrase string `json:"passphrase"`
Created utils.JsonTime `json:"created"`
}
func (r *Credential) TableName() string {
return "credentials"
}
func FindAllCredential() (o []Credential, err error) {
err = global.DB.Find(&o).Error
return
}
func FindPageCredential(pageIndex, pageSize int, name string) (o []Credential, total int64, err error) {
db := global.DB
if len(name) > 0 {
db = db.Where("name like ?", "%"+name+"%")
}
err = db.Order("created desc").Find(&o).Offset((pageIndex - 1) * pageSize).Limit(pageSize).Count(&total).Error
if o == nil {
o = make([]Credential, 0)
}
return
}
func CreateNewCredential(o *Credential) (err error) {
if err = global.DB.Create(o).Error; err != nil {
return err
}
return nil
}
func FindCredentialById(id string) (o Credential, err error) {
err = global.DB.Where("id = ?", id).First(&o).Error
return
}
func UpdateCredentialById(o *Credential, id string) {
o.ID = id
global.DB.Updates(o)
}
func DeleteCredentialById(id string) {
global.DB.Where("id = ?", id).Delete(&Credential{})
}
func CountCredential() (total int64, err error) {
err = global.DB.Find(&Credential{}).Count(&total).Error
return
}