@@ -33,10 +33,13 @@ const (
33
33
34
34
var sshOpLocker sync.Mutex
35
35
36
+ // KeyType specifies the key type
36
37
type KeyType int
37
38
38
39
const (
40
+ // KeyTypeUser specifies the user key
39
41
KeyTypeUser = iota + 1
42
+ // KeyTypeDeploy specifies the deploy key
40
43
KeyTypeDeploy
41
44
)
42
45
@@ -58,28 +61,31 @@ type PublicKey struct {
58
61
HasUsed bool `xorm:"-"`
59
62
}
60
63
61
- func (k * PublicKey ) BeforeInsert () {
62
- k .CreatedUnix = time .Now ().Unix ()
64
+ // BeforeInsert will be invoked by XORM before inserting a record
65
+ func (key * PublicKey ) BeforeInsert () {
66
+ key .CreatedUnix = time .Now ().Unix ()
63
67
}
64
68
65
- func (k * PublicKey ) BeforeUpdate () {
66
- k .UpdatedUnix = time .Now ().Unix ()
69
+ // BeforeUpdate is invoked from XORM before updating this object.
70
+ func (key * PublicKey ) BeforeUpdate () {
71
+ key .UpdatedUnix = time .Now ().Unix ()
67
72
}
68
73
69
- func (k * PublicKey ) AfterSet (colName string , _ xorm.Cell ) {
74
+ // AfterSet is invoked from XORM after setting the value of a field of this object.
75
+ func (key * PublicKey ) AfterSet (colName string , _ xorm.Cell ) {
70
76
switch colName {
71
77
case "created_unix" :
72
- k .Created = time .Unix (k .CreatedUnix , 0 ).Local ()
78
+ key .Created = time .Unix (key .CreatedUnix , 0 ).Local ()
73
79
case "updated_unix" :
74
- k .Updated = time .Unix (k .UpdatedUnix , 0 ).Local ()
75
- k .HasUsed = k .Updated .After (k .Created )
76
- k .HasRecentActivity = k .Updated .Add (7 * 24 * time .Hour ).After (time .Now ())
80
+ key .Updated = time .Unix (key .UpdatedUnix , 0 ).Local ()
81
+ key .HasUsed = key .Updated .After (key .Created )
82
+ key .HasRecentActivity = key .Updated .Add (7 * 24 * time .Hour ).After (time .Now ())
77
83
}
78
84
}
79
85
80
86
// OmitEmail returns content of public key without email address.
81
- func (k * PublicKey ) OmitEmail () string {
82
- return strings .Join (strings .Split (k .Content , " " )[:2 ], " " )
87
+ func (key * PublicKey ) OmitEmail () string {
88
+ return strings .Join (strings .Split (key .Content , " " )[:2 ], " " )
83
89
}
84
90
85
91
// AuthorizedString returns formatted public key string for authorized_keys file.
@@ -573,32 +579,35 @@ type DeployKey struct {
573
579
HasUsed bool `xorm:"-"`
574
580
}
575
581
576
- func (k * DeployKey ) BeforeInsert () {
577
- k .CreatedUnix = time .Now ().Unix ()
582
+ // BeforeInsert will be invoked by XORM before inserting a record
583
+ func (key * DeployKey ) BeforeInsert () {
584
+ key .CreatedUnix = time .Now ().Unix ()
578
585
}
579
586
580
- func (k * DeployKey ) BeforeUpdate () {
581
- k .UpdatedUnix = time .Now ().Unix ()
587
+ // BeforeUpdate is invoked from XORM before updating this object.
588
+ func (key * DeployKey ) BeforeUpdate () {
589
+ key .UpdatedUnix = time .Now ().Unix ()
582
590
}
583
591
584
- func (k * DeployKey ) AfterSet (colName string , _ xorm.Cell ) {
592
+ // AfterSet is invoked from XORM after setting the value of a field of this object.
593
+ func (key * DeployKey ) AfterSet (colName string , _ xorm.Cell ) {
585
594
switch colName {
586
595
case "created_unix" :
587
- k .Created = time .Unix (k .CreatedUnix , 0 ).Local ()
596
+ key .Created = time .Unix (key .CreatedUnix , 0 ).Local ()
588
597
case "updated_unix" :
589
- k .Updated = time .Unix (k .UpdatedUnix , 0 ).Local ()
590
- k .HasUsed = k .Updated .After (k .Created )
591
- k .HasRecentActivity = k .Updated .Add (7 * 24 * time .Hour ).After (time .Now ())
598
+ key .Updated = time .Unix (key .UpdatedUnix , 0 ).Local ()
599
+ key .HasUsed = key .Updated .After (key .Created )
600
+ key .HasRecentActivity = key .Updated .Add (7 * 24 * time .Hour ).After (time .Now ())
592
601
}
593
602
}
594
603
595
604
// GetContent gets associated public key content.
596
- func (k * DeployKey ) GetContent () error {
597
- pkey , err := GetPublicKeyByID (k .KeyID )
605
+ func (key * DeployKey ) GetContent () error {
606
+ pkey , err := GetPublicKeyByID (key .KeyID )
598
607
if err != nil {
599
608
return err
600
609
}
601
- k .Content = pkey .Content
610
+ key .Content = pkey .Content
602
611
return nil
603
612
}
604
613
0 commit comments