@@ -10,6 +10,7 @@ import (
1010 "code.gitea.io/gitea/models/db"
1111 repo_model "code.gitea.io/gitea/models/repo"
1212 user_model "code.gitea.io/gitea/models/user"
13+ "code.gitea.io/gitea/modules/base"
1314 "code.gitea.io/gitea/modules/timeutil"
1415 "code.gitea.io/gitea/modules/util"
1516)
@@ -51,7 +52,7 @@ func GetRunnerToken(ctx context.Context, token string) (*ActionRunnerToken, erro
5152 if err != nil {
5253 return nil , err
5354 } else if ! has {
54- return nil , fmt .Errorf (" runner token %q : %w" , token , util .ErrNotExist )
55+ return nil , fmt .Errorf (` runner token "%s..." : %w` , base . TruncateString ( token , 3 ) , util .ErrNotExist )
5556 }
5657 return & runnerToken , nil
5758}
@@ -68,19 +69,15 @@ func UpdateRunnerToken(ctx context.Context, r *ActionRunnerToken, cols ...string
6869 return err
6970}
7071
71- // NewRunnerToken creates a new active runner token and invalidate all old tokens
72+ // NewRunnerTokenWithValue creates a new active runner token and invalidate all old tokens
7273// ownerID will be ignored and treated as 0 if repoID is non-zero.
73- func NewRunnerToken (ctx context.Context , ownerID , repoID int64 ) (* ActionRunnerToken , error ) {
74+ func NewRunnerTokenWithValue (ctx context.Context , ownerID , repoID int64 , token string ) (* ActionRunnerToken , error ) {
7475 if ownerID != 0 && repoID != 0 {
7576 // It's trying to create a runner token that belongs to a repository, but OwnerID has been set accidentally.
7677 // Remove OwnerID to avoid confusion; it's not worth returning an error here.
7778 ownerID = 0
7879 }
7980
80- token , err := util .CryptoRandomString (40 )
81- if err != nil {
82- return nil , err
83- }
8481 runnerToken := & ActionRunnerToken {
8582 OwnerID : ownerID ,
8683 RepoID : repoID ,
@@ -95,11 +92,19 @@ func NewRunnerToken(ctx context.Context, ownerID, repoID int64) (*ActionRunnerTo
9592 return err
9693 }
9794
98- _ , err = db .GetEngine (ctx ).Insert (runnerToken )
95+ _ , err : = db .GetEngine (ctx ).Insert (runnerToken )
9996 return err
10097 })
10198}
10299
100+ func NewRunnerToken (ctx context.Context , ownerID , repoID int64 ) (* ActionRunnerToken , error ) {
101+ token , err := util .CryptoRandomString (40 )
102+ if err != nil {
103+ return nil , err
104+ }
105+ return NewRunnerTokenWithValue (ctx , ownerID , repoID , token )
106+ }
107+
103108// GetLatestRunnerToken returns the latest runner token
104109func GetLatestRunnerToken (ctx context.Context , ownerID , repoID int64 ) (* ActionRunnerToken , error ) {
105110 if ownerID != 0 && repoID != 0 {
0 commit comments