Skip to content

Commit

Permalink
review: propagate context
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Wiesner committed May 12, 2023
1 parent 6d51f35 commit a9a37db
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pkg/handler/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func (h *Handler) Validate(c *gin.Context) {
err := h.sealer.Validate(c.Request.Body)
err := h.sealer.Validate(c, c.Request.Body)
if err != nil {
log.Printf("Error in %s: %v\n", Sanitize(c.Request.URL.Path), err)
c.Data(http.StatusBadRequest, "text/plain", []byte(err.Error()))
Expand Down
4 changes: 2 additions & 2 deletions pkg/handler/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var _ = Describe("Handler ", func() {
c.Request, _ = http.NewRequest("POST", "/v1/validate", bytes.NewReader([]byte(stringDataAsYAML)))
c.Request.Header.Set("Content-Type", "application/x-yaml")

sealer.EXPECT().Validate(gomock.Any()).Return(nil)
sealer.EXPECT().Validate(gomock.Any(), gomock.Any()).Return(nil)

h.Validate(c)

Expand All @@ -50,7 +50,7 @@ var _ = Describe("Handler ", func() {
c.Request, _ = http.NewRequest("POST", "/v1/validate", bytes.NewReader([]byte(stringDataAsYAML)))
c.Request.Header.Set("Content-Type", "application/x-yaml")

sealer.EXPECT().Validate(gomock.Any()).Return(errors.New("Validation failed"))
sealer.EXPECT().Validate(gomock.Any(), gomock.Any()).Return(errors.New("Validation failed"))

h.Validate(c)

Expand Down
8 changes: 4 additions & 4 deletions pkg/mocks/seal/mock.go

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

6 changes: 3 additions & 3 deletions pkg/seal/seal.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Sealer interface {
Raw(data Raw) ([]byte, error)
Certificate(ctx context.Context) ([]byte, error)
Seal(outputFormat string, secret io.Reader) ([]byte, error)
Validate(secret io.Reader) error
Validate(ctx context.Context, secret io.Reader) error
}

var _ Sealer = &apiSealer{}
Expand Down Expand Up @@ -101,9 +101,9 @@ func (a *apiSealer) Raw(data Raw) ([]byte, error) {
return buf.Bytes(), nil
}

func (a *apiSealer) Validate(secret io.Reader) error {
func (a *apiSealer) Validate(ctx context.Context, secret io.Reader) error {
return kubeseal.ValidateSealedSecret(
context.TODO(),
ctx,
a.clientConfig,
a.ss.Namespace,
a.ss.Service,
Expand Down

0 comments on commit a9a37db

Please sign in to comment.