package models

import (
	"github.com/beego/beego/v2/client/orm"
	"time"
)

type OssSTSToken struct {
	Id              int       `orm:"column(id);pk" json:"id"`
	AccessKeyId     string    `json:"access_key_id" description:"临时AccessKeyId"`
	AccessKeySecret string    `json:"access_key_secret" description:"临时AccessKeySecret"`
	SecurityToken   string    `json:"security_token" description:"安全令牌"`
	ExpiredTime     time.Time `json:"expired_time" description:"过期时间"`
}

// TableName 表名变更
func (item *OssSTSToken) TableName() string {
	return "oss_sts_token"
}

// Insert 新增
func (item *OssSTSToken) Insert() (lastId int64, err error) {
	o := orm.NewOrm()
	lastId, err = o.Insert(item)
	return
}

// GetRecentOssSTSToken 获取最新的STSToken
func GetRecentOssSTSToken() (item *OssSTSToken, err error) {
	o := orm.NewOrm()
	sql := ` SELECT * FROM oss_sts_token ORDER BY expired_time DESC LIMIT 1 `
	err = o.Raw(sql).QueryRow(&item)
	return
}
