mirror of
https://github.com/Luzifer/ots.git
synced 2025-12-21 11:05:45 -05:00
Fix linter errors
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
4aa5f14b3f
commit
a585adcd13
6 changed files with 23 additions and 14 deletions
11
api.go
11
api.go
|
|
@ -22,7 +22,7 @@ type apiResponse struct {
|
||||||
Error string `json:"error,omitempty"`
|
Error string `json:"error,omitempty"`
|
||||||
ExpiresAt *time.Time `json:"expires_at,omitempty"`
|
ExpiresAt *time.Time `json:"expires_at,omitempty"`
|
||||||
Secret string `json:"secret,omitempty"`
|
Secret string `json:"secret,omitempty"`
|
||||||
SecretId string `json:"secret_id,omitempty"`
|
SecretID string `json:"secret_id,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type apiRequest struct {
|
type apiRequest struct {
|
||||||
|
|
@ -83,7 +83,7 @@ func (a apiServer) handleCreate(res http.ResponseWriter, r *http.Request) {
|
||||||
a.jsonResponse(res, http.StatusCreated, apiResponse{
|
a.jsonResponse(res, http.StatusCreated, apiResponse{
|
||||||
ExpiresAt: expiresAt,
|
ExpiresAt: expiresAt,
|
||||||
Success: true,
|
Success: true,
|
||||||
SecretId: id,
|
SecretID: id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -124,10 +124,13 @@ func (a apiServer) errorResponse(res http.ResponseWriter, status int, err error,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a apiServer) jsonResponse(res http.ResponseWriter, status int, response apiResponse) {
|
func (apiServer) jsonResponse(res http.ResponseWriter, status int, response apiResponse) {
|
||||||
res.Header().Set("Content-Type", "application/json")
|
res.Header().Set("Content-Type", "application/json")
|
||||||
res.Header().Set("Cache-Control", "no-store, max-age=0")
|
res.Header().Set("Cache-Control", "no-store, max-age=0")
|
||||||
res.WriteHeader(status)
|
res.WriteHeader(status)
|
||||||
|
|
||||||
json.NewEncoder(res).Encode(response)
|
if err := json.NewEncoder(res).Encode(response); err != nil {
|
||||||
|
logrus.WithError(err).Error("encoding JSON response")
|
||||||
|
http.Error(res, `{"error":"could not encode response"}`, http.StatusInternalServerError)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ func loadCustomize(filename string) (cust customize, err error) {
|
||||||
return cust, nil
|
return cust, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
cf, err := os.Open(filename)
|
cf, err := os.Open(filename) //#nosec:G304 // Loading a custom file is the intention here
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, fs.ErrNotExist) {
|
if errors.Is(err, fs.ErrNotExist) {
|
||||||
logrus.Warn("customize file given but not found")
|
logrus.Warn("customize file given but not found")
|
||||||
|
|
@ -46,7 +46,11 @@ func loadCustomize(filename string) (cust customize, err error) {
|
||||||
}
|
}
|
||||||
return cust, errors.Wrap(err, "opening customize file")
|
return cust, errors.Wrap(err, "opening customize file")
|
||||||
}
|
}
|
||||||
defer cf.Close()
|
defer func() {
|
||||||
|
if err := cf.Close(); err != nil {
|
||||||
|
logrus.WithError(err).Error("closing customize file (leaked fd)")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
if err = yaml.NewDecoder(cf).Decode(&cust); err != nil {
|
if err = yaml.NewDecoder(cf).Decode(&cust); err != nil {
|
||||||
return cust, errors.Wrap(err, "decoding customize file")
|
return cust, errors.Wrap(err, "decoding customize file")
|
||||||
|
|
|
||||||
6
main.go
6
main.go
|
|
@ -155,10 +155,12 @@ func assetDelivery(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
w.Header().Set("Content-Type", mime.TypeByExtension(ext))
|
w.Header().Set("Content-Type", mime.TypeByExtension(ext))
|
||||||
w.Header().Set("X-Content-Type-Options", "nosniff")
|
w.Header().Set("X-Content-Type-Options", "nosniff")
|
||||||
w.Write(assetData)
|
if _, err = w.Write(assetData); err != nil {
|
||||||
|
logrus.WithError(err).Error("writing asset data")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleIndex(w http.ResponseWriter, r *http.Request) {
|
func handleIndex(w http.ResponseWriter, _ *http.Request) {
|
||||||
inlineContentNonce := make([]byte, scriptNonceSize)
|
inlineContentNonce := make([]byte, scriptNonceSize)
|
||||||
if _, err := rand.Read(inlineContentNonce); err != nil {
|
if _, err := rand.Read(inlineContentNonce); err != nil {
|
||||||
logrus.WithError(err).Error("generating script nonce")
|
logrus.WithError(err).Error("generating script nonce")
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var errSecretNotFound = errors.New("Secret not found")
|
var errSecretNotFound = errors.New("secret not found")
|
||||||
|
|
||||||
type storage interface {
|
type storage interface {
|
||||||
Create(secret string, expireIn time.Duration) (string, error)
|
Create(secret string, expireIn time.Duration) (string, error)
|
||||||
|
|
@ -20,6 +20,6 @@ func getStorageByType(t string) (storage, error) {
|
||||||
case "redis":
|
case "redis":
|
||||||
return newStorageRedis()
|
return newStorageRedis()
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("Storage type %q not found", t)
|
return nil, fmt.Errorf("storage type %q not found", t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,14 +53,14 @@ func (s storageRedis) ReadAndDestroy(id string) (string, error) {
|
||||||
if errors.Is(err, redis.Nil) {
|
if errors.Is(err, redis.Nil) {
|
||||||
return "", errSecretNotFound
|
return "", errSecretNotFound
|
||||||
}
|
}
|
||||||
return "", err
|
return "", errors.Wrap(err, "getting key")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.conn.Del(context.Background(), s.redisKey(id)).Err()
|
err = s.conn.Del(context.Background(), s.redisKey(id)).Err()
|
||||||
return string(secret), errors.Wrap(err, "deleting key")
|
return secret, errors.Wrap(err, "deleting key")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s storageRedis) redisKey(id string) string {
|
func (storageRedis) redisKey(id string) string {
|
||||||
prefix := redisDefaultPrefix
|
prefix := redisDefaultPrefix
|
||||||
if prfx := os.Getenv("REDIS_KEY"); prfx != "" {
|
if prfx := os.Getenv("REDIS_KEY"); prfx != "" {
|
||||||
prefix = prfx
|
prefix = prfx
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ func assetSRIHash(assetName string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
h := sha512.New384()
|
h := sha512.New384()
|
||||||
h.Write(data)
|
_, _ = h.Write(data)
|
||||||
sum := h.Sum(nil)
|
sum := h.Sum(nil)
|
||||||
|
|
||||||
sri := "sha384-" + base64.StdEncoding.EncodeToString(sum)
|
sri := "sha384-" + base64.StdEncoding.EncodeToString(sum)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue