@@ -40,9 +40,15 @@ type Secret struct {
40
40
RepoID int64 `xorm:"INDEX UNIQUE(owner_repo_name) NOT NULL DEFAULT 0"`
41
41
Name string `xorm:"UNIQUE(owner_repo_name) NOT NULL"`
42
42
Data string `xorm:"LONGTEXT"` // encrypted data
43
+ Description string `xorm:"TEXT"`
43
44
CreatedUnix timeutil.TimeStamp `xorm:"created NOT NULL"`
44
45
}
45
46
47
+ const (
48
+ SecretDataMaxLength = 65536
49
+ SecretDescriptionMaxLength = 4096
50
+ )
51
+
46
52
// ErrSecretNotFound represents a "secret not found" error.
47
53
type ErrSecretNotFound struct {
48
54
Name string
@@ -57,7 +63,7 @@ func (err ErrSecretNotFound) Unwrap() error {
57
63
}
58
64
59
65
// InsertEncryptedSecret Creates, encrypts, and validates a new secret with yet unencrypted data and insert into database
60
- func InsertEncryptedSecret (ctx context.Context , ownerID , repoID int64 , name , data string ) (* Secret , error ) {
66
+ func InsertEncryptedSecret (ctx context.Context , ownerID , repoID int64 , name , data , description string ) (* Secret , error ) {
61
67
if ownerID != 0 && repoID != 0 {
62
68
// It's trying to create a secret that belongs to a repository, but OwnerID has been set accidentally.
63
69
// Remove OwnerID to avoid confusion; it's not worth returning an error here.
@@ -67,15 +73,23 @@ func InsertEncryptedSecret(ctx context.Context, ownerID, repoID int64, name, dat
67
73
return nil , fmt .Errorf ("%w: ownerID and repoID cannot be both zero, global secrets are not supported" , util .ErrInvalidArgument )
68
74
}
69
75
76
+ if len (data ) > SecretDataMaxLength {
77
+ return nil , util .NewInvalidArgumentErrorf ("data too long" )
78
+ }
79
+
80
+ description = util .TruncateRunes (description , SecretDescriptionMaxLength )
81
+
70
82
encrypted , err := secret_module .EncryptSecret (setting .SecretKey , data )
71
83
if err != nil {
72
84
return nil , err
73
85
}
86
+
74
87
secret := & Secret {
75
- OwnerID : ownerID ,
76
- RepoID : repoID ,
77
- Name : strings .ToUpper (name ),
78
- Data : encrypted ,
88
+ OwnerID : ownerID ,
89
+ RepoID : repoID ,
90
+ Name : strings .ToUpper (name ),
91
+ Data : encrypted ,
92
+ Description : description ,
79
93
}
80
94
return secret , db .Insert (ctx , secret )
81
95
}
@@ -114,16 +128,23 @@ func (opts FindSecretsOptions) ToConds() builder.Cond {
114
128
}
115
129
116
130
// UpdateSecret changes org or user reop secret.
117
- func UpdateSecret (ctx context.Context , secretID int64 , data string ) error {
131
+ func UpdateSecret (ctx context.Context , secretID int64 , data , description string ) error {
132
+ if len (data ) > SecretDataMaxLength {
133
+ return util .NewInvalidArgumentErrorf ("data too long" )
134
+ }
135
+
136
+ description = util .TruncateRunes (description , SecretDescriptionMaxLength )
137
+
118
138
encrypted , err := secret_module .EncryptSecret (setting .SecretKey , data )
119
139
if err != nil {
120
140
return err
121
141
}
122
142
123
143
s := & Secret {
124
- Data : encrypted ,
144
+ Data : encrypted ,
145
+ Description : description ,
125
146
}
126
- affected , err := db .GetEngine (ctx ).ID (secretID ).Cols ("data" ).Update (s )
147
+ affected , err := db .GetEngine (ctx ).ID (secretID ).Cols ("data" , "description" ).Update (s )
127
148
if affected != 1 {
128
149
return ErrSecretNotFound {}
129
150
}
0 commit comments