fix(): lint code

This commit is contained in:
Nicolas Carlier 2023-10-03 21:12:37 +00:00
parent 01f54adf28
commit af39ad75c6
7 changed files with 14 additions and 5 deletions

View File

@ -27,6 +27,7 @@ type Config struct {
TrustStoreFile string `flag:"trust-store-file" desc:"Trust store used by HTTP signature verifier (.pem or .p12)"` TrustStoreFile string `flag:"trust-store-file" desc:"Trust store used by HTTP signature verifier (.pem or .p12)"`
} }
// Validate configuration
func (c *Config) Validate() error { func (c *Config) Validate() error {
if matched, _ := regexp.MatchString(`^/\w+$`, c.StaticPath); !matched { if matched, _ := regexp.MatchString(`^/\w+$`, c.StaticPath); !matched {
return fmt.Errorf("invalid static path: %s", c.StaticPath) return fmt.Errorf("invalid static path: %s", c.StaticPath)

View File

@ -60,19 +60,22 @@ func NewHookJob(request *Request) (*Job, error) {
return job, nil return job, nil
} }
// ID returns job ID
func (job *Job) ID() uint64 { func (job *Job) ID() uint64 {
return job.id return job.id
} }
// Name returns job name
func (job *Job) Name() string { func (job *Job) Name() string {
return job.name return job.name
} }
// Err returns job error
func (job *Job) Err() error { func (job *Job) Err() error {
return job.err return job.err
} }
// Meta return job meta // Meta returns job meta
func (job *Job) Meta() []string { func (job *Job) Meta() []string {
return []string{ return []string{
"hook_id=" + strconv.FormatUint(job.id, 10), "hook_id=" + strconv.FormatUint(job.id, 10),

View File

@ -7,7 +7,9 @@ import (
) )
var ( var (
// HookOutputEnabled writes hook output into logs if true
HookOutputEnabled = false HookOutputEnabled = false
// RequestOutputEnabled writes HTTP request into logs if true
RequestOutputEnabled = false RequestOutputEnabled = false
) )

View File

@ -13,7 +13,7 @@ import (
) )
const ( const (
defaultKeyId = "default" defaultKeyID = "default"
xSignatureEd25519 = "X-Signature-Ed25519" xSignatureEd25519 = "X-Signature-Ed25519"
xSignatureTimestamp = "X-Signature-Timestamp" xSignatureTimestamp = "X-Signature-Timestamp"
) )
@ -25,9 +25,9 @@ func IsEd25519SignatureRequest(headers http.Header) bool {
// Ed25519SignatureHandler validate request HTTP signature // Ed25519SignatureHandler validate request HTTP signature
func Ed25519SignatureHandler(r *http.Request, ts truststore.TrustStore) error { func Ed25519SignatureHandler(r *http.Request, ts truststore.TrustStore) error {
pubkey := ts.GetPublicKey(defaultKeyId) pubkey := ts.GetPublicKey(defaultKeyID)
if pubkey == nil { if pubkey == nil {
return fmt.Errorf("public key not found: %s", defaultKeyId) return fmt.Errorf("public key not found: %s", defaultKeyID)
} }
key, ok := pubkey.(ed25519.PublicKey) key, ok := pubkey.(ed25519.PublicKey)

View File

@ -1,5 +1,6 @@
package notification package notification
// HookResult is the result of a hook execution
type HookResult interface { type HookResult interface {
ID() uint64 ID() uint64
Name() string Name() string

View File

@ -17,6 +17,7 @@ type InMemoryTrustStore struct {
Keys map[string]crypto.PublicKey Keys map[string]crypto.PublicKey
} }
// GetPublicKey returns the public key with this key ID
func (ts *InMemoryTrustStore) GetPublicKey(keyID string) crypto.PublicKey { func (ts *InMemoryTrustStore) GetPublicKey(keyID string) crypto.PublicKey {
if key, ok := ts.Keys[keyID]; ok { if key, ok := ts.Keys[keyID]; ok {
return key return key

View File

@ -10,6 +10,7 @@ func (c *ChanWriter) Write(p []byte) (int, error) {
return len(p), nil return len(p), nil
} }
// Work is a dispatched work given to a worker
type Work interface { type Work interface {
ID() uint64 ID() uint64
Name() string Name() string