Skip to content

Commit

Permalink
chore: rename the webhook password fields to be token (#608)
Browse files Browse the repository at this point in the history
Signed-off-by: Donnie Adams <[email protected]>
  • Loading branch information
thedadams authored Nov 15, 2024
1 parent 2df7a4a commit 5301986
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions pkg/api/handlers/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
)

const (
PasswordHTTPHeader = "X-Otto8-Webhook-Password"
PasswordQueryParam = "webhookPassword"
WebhookTokenHTTPHeader = "X-Otto8-Webhook-Token"
WebhookTokenQueryParam = "token"
)

type WebhookHandler struct{}
Expand Down Expand Up @@ -61,7 +61,7 @@ func (a *WebhookHandler) Update(req api.Context) error {
if err != nil {
return fmt.Errorf("failed to hash password: %w", err)
}
wh.Spec.PasswordHash = hash
wh.Spec.TokenHash = hash
webhookReq.Password = ""
}

Expand Down Expand Up @@ -116,7 +116,7 @@ func (a *WebhookHandler) Create(req api.Context) error {
return fmt.Errorf("failed to hash password: %w", err)
}
webhookReq.Password = ""
wh.Spec.PasswordHash = hash
wh.Spec.TokenHash = hash
}

for i, h := range wh.Spec.Headers {
Expand Down Expand Up @@ -196,13 +196,13 @@ func (a *WebhookHandler) Execute(req api.Context) error {
}
}

if webhook.Spec.PasswordHash != nil {
password := req.Request.Header.Get(PasswordHTTPHeader)
if webhook.Spec.TokenHash != nil {
password := req.Request.Header.Get(WebhookTokenHTTPHeader)
if password == "" {
password = req.Request.URL.Query().Get(PasswordQueryParam)
password = req.Request.URL.Query().Get(WebhookTokenQueryParam)
}

if err := bcrypt.CompareHashAndPassword(webhook.Spec.PasswordHash, []byte(password)); err != nil {
if err := bcrypt.CompareHashAndPassword(webhook.Spec.TokenHash, []byte(password)); err != nil {
req.WriteHeader(http.StatusForbidden)
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/apis/otto.otto8.ai/v1/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (w *Webhook) DeleteRefs() []Ref {

type WebhookSpec struct {
types.WebhookManifest `json:",inline"`
PasswordHash []byte `json:"passwordHash,omitempty"`
TokenHash []byte `json:"tokenHash,omitempty"`
}

type WebhookStatus struct {
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/apis/otto.otto8.ai/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5301986

Please sign in to comment.