@@ -3,6 +3,11 @@ package api
33import (
44 "encoding/json"
55 "errors"
6+ "io"
7+ "net/http"
8+ "strings"
9+ "time"
10+
611 "github.com/forceu/gokapi/internal/configuration"
712 "github.com/forceu/gokapi/internal/configuration/database"
813 "github.com/forceu/gokapi/internal/encryption"
@@ -11,14 +16,10 @@ import (
1116 "github.com/forceu/gokapi/internal/models"
1217 "github.com/forceu/gokapi/internal/storage"
1318 "github.com/forceu/gokapi/internal/webserver/fileupload"
14- "io"
15- "net/http"
16- "strings"
17- "time"
1819)
1920
20- const lengthPublicId = 35
21- const lengthApiKey = 30
21+ const LengthPublicId = 35
22+ const LengthApiKey = 30
2223const minLengthUser = 2
2324
2425// Process parses the request and executes the API call or returns an error message to the sender
@@ -109,8 +110,8 @@ func generateNewKey(defaultPermissions bool, userId int, friendlyName string) mo
109110 friendlyName = "Unnamed key"
110111 }
111112 newKey := models.ApiKey {
112- Id : helper .GenerateRandomString (lengthApiKey ),
113- PublicId : helper .GenerateRandomString (lengthPublicId ),
113+ Id : helper .GenerateRandomString (LengthApiKey ),
114+ PublicId : helper .GenerateRandomString (LengthPublicId ),
114115 FriendlyName : friendlyName ,
115116 Permissions : models .ApiPermDefault ,
116117 IsSystemKey : false ,
@@ -144,8 +145,8 @@ func newSystemKey(userId int) string {
144145 }
145146
146147 newKey := models.ApiKey {
147- Id : helper .GenerateRandomString (lengthApiKey ),
148- PublicId : helper .GenerateRandomString (lengthPublicId ),
148+ Id : helper .GenerateRandomString (LengthApiKey ),
149+ PublicId : helper .GenerateRandomString (LengthPublicId ),
149150 FriendlyName : "Internal System Key" ,
150151 Permissions : tempKey .Permissions ,
151152 Expiry : time .Now ().Add (time .Hour * 48 ).Unix (),
@@ -812,7 +813,7 @@ func sendError(w http.ResponseWriter, errorInt int, errorMessage string) {
812813// publicKeyToApiKey tries to convert a (possible) public key to a private key
813814// If not a public key or if invalid, the original value is returned
814815func publicKeyToApiKey (publicKey string ) string {
815- if len (publicKey ) == lengthPublicId {
816+ if len (publicKey ) == LengthPublicId {
816817 privateApiKey , ok := database .GetApiKeyByPublicKey (publicKey )
817818 if ok {
818819 return privateApiKey
0 commit comments