0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2024-11-22 01:01:13 +01:00

Lint models/ssh_key.go

This commit is contained in:
Bwko 2016-11-26 01:36:03 +01:00
parent 0a76d260fa
commit 6cde041080

View file

@ -33,10 +33,13 @@ const (
var sshOpLocker sync.Mutex var sshOpLocker sync.Mutex
// KeyType specifies the key type
type KeyType int type KeyType int
const ( const (
// KeyTypeUser specifies the user key
KeyTypeUser = iota + 1 KeyTypeUser = iota + 1
// KeyTypeDeploy specifies the deploy key
KeyTypeDeploy KeyTypeDeploy
) )
@ -58,28 +61,31 @@ type PublicKey struct {
HasUsed bool `xorm:"-"` HasUsed bool `xorm:"-"`
} }
func (k *PublicKey) BeforeInsert() { // BeforeInsert will be invoked by XORM before inserting a record
k.CreatedUnix = time.Now().Unix() func (key *PublicKey) BeforeInsert() {
key.CreatedUnix = time.Now().Unix()
} }
func (k *PublicKey) BeforeUpdate() { // BeforeUpdate is invoked from XORM before updating this object.
k.UpdatedUnix = time.Now().Unix() func (key *PublicKey) BeforeUpdate() {
key.UpdatedUnix = time.Now().Unix()
} }
func (k *PublicKey) AfterSet(colName string, _ xorm.Cell) { // AfterSet is invoked from XORM after setting the value of a field of this object.
func (key *PublicKey) AfterSet(colName string, _ xorm.Cell) {
switch colName { switch colName {
case "created_unix": case "created_unix":
k.Created = time.Unix(k.CreatedUnix, 0).Local() key.Created = time.Unix(key.CreatedUnix, 0).Local()
case "updated_unix": case "updated_unix":
k.Updated = time.Unix(k.UpdatedUnix, 0).Local() key.Updated = time.Unix(key.UpdatedUnix, 0).Local()
k.HasUsed = k.Updated.After(k.Created) key.HasUsed = key.Updated.After(key.Created)
k.HasRecentActivity = k.Updated.Add(7 * 24 * time.Hour).After(time.Now()) key.HasRecentActivity = key.Updated.Add(7 * 24 * time.Hour).After(time.Now())
} }
} }
// OmitEmail returns content of public key without email address. // OmitEmail returns content of public key without email address.
func (k *PublicKey) OmitEmail() string { func (key *PublicKey) OmitEmail() string {
return strings.Join(strings.Split(k.Content, " ")[:2], " ") return strings.Join(strings.Split(key.Content, " ")[:2], " ")
} }
// AuthorizedString returns formatted public key string for authorized_keys file. // AuthorizedString returns formatted public key string for authorized_keys file.
@ -573,32 +579,35 @@ type DeployKey struct {
HasUsed bool `xorm:"-"` HasUsed bool `xorm:"-"`
} }
func (k *DeployKey) BeforeInsert() { // BeforeInsert will be invoked by XORM before inserting a record
k.CreatedUnix = time.Now().Unix() func (key *DeployKey) BeforeInsert() {
key.CreatedUnix = time.Now().Unix()
} }
func (k *DeployKey) BeforeUpdate() { // BeforeUpdate is invoked from XORM before updating this object.
k.UpdatedUnix = time.Now().Unix() func (key *DeployKey) BeforeUpdate() {
key.UpdatedUnix = time.Now().Unix()
} }
func (k *DeployKey) AfterSet(colName string, _ xorm.Cell) { // AfterSet is invoked from XORM after setting the value of a field of this object.
func (key *DeployKey) AfterSet(colName string, _ xorm.Cell) {
switch colName { switch colName {
case "created_unix": case "created_unix":
k.Created = time.Unix(k.CreatedUnix, 0).Local() key.Created = time.Unix(key.CreatedUnix, 0).Local()
case "updated_unix": case "updated_unix":
k.Updated = time.Unix(k.UpdatedUnix, 0).Local() key.Updated = time.Unix(key.UpdatedUnix, 0).Local()
k.HasUsed = k.Updated.After(k.Created) key.HasUsed = key.Updated.After(key.Created)
k.HasRecentActivity = k.Updated.Add(7 * 24 * time.Hour).After(time.Now()) key.HasRecentActivity = key.Updated.Add(7 * 24 * time.Hour).After(time.Now())
} }
} }
// GetContent gets associated public key content. // GetContent gets associated public key content.
func (k *DeployKey) GetContent() error { func (key *DeployKey) GetContent() error {
pkey, err := GetPublicKeyByID(k.KeyID) pkey, err := GetPublicKeyByID(key.KeyID)
if err != nil { if err != nil {
return err return err
} }
k.Content = pkey.Content key.Content = pkey.Content
return nil return nil
} }