-
Notifications
You must be signed in to change notification settings - Fork 2
chore: load and prep dp validator #304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,128 @@ | ||||||||||||||||||||||||||||||||||||||||
| // Copyright 2025 Hedgehog | ||||||||||||||||||||||||||||||||||||||||
| // SPDX-License-Identifier: Apache-2.0 | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| package ctrl | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| import ( | ||||||||||||||||||||||||||||||||||||||||
| "context" | ||||||||||||||||||||||||||||||||||||||||
| "crypto/tls" | ||||||||||||||||||||||||||||||||||||||||
| "crypto/x509" | ||||||||||||||||||||||||||||||||||||||||
| "fmt" | ||||||||||||||||||||||||||||||||||||||||
| "log/slog" | ||||||||||||||||||||||||||||||||||||||||
| "net/http" | ||||||||||||||||||||||||||||||||||||||||
| "os" | ||||||||||||||||||||||||||||||||||||||||
| "path/filepath" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| "github.com/tetratelabs/wazero" | ||||||||||||||||||||||||||||||||||||||||
| "github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1" | ||||||||||||||||||||||||||||||||||||||||
| "oras.land/oras-go/v2" | ||||||||||||||||||||||||||||||||||||||||
| "oras.land/oras-go/v2/content/file" | ||||||||||||||||||||||||||||||||||||||||
| "oras.land/oras-go/v2/registry/remote" | ||||||||||||||||||||||||||||||||||||||||
| "oras.land/oras-go/v2/registry/remote/auth" | ||||||||||||||||||||||||||||||||||||||||
| "oras.land/oras-go/v2/registry/remote/credentials" | ||||||||||||||||||||||||||||||||||||||||
| "oras.land/oras-go/v2/registry/remote/retry" | ||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| type Validator struct { | ||||||||||||||||||||||||||||||||||||||||
| runtime wazero.Runtime | ||||||||||||||||||||||||||||||||||||||||
| compiled wazero.CompiledModule | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| func NewValidator(ctx context.Context, credsPath, caPath, ref, tag string) (*Validator, error) { | ||||||||||||||||||||||||||||||||||||||||
| v := &Validator{} | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| if ref == "" && tag == "" { | ||||||||||||||||||||||||||||||||||||||||
| slog.Info("Skipping Dataplane validator as it is not configured") | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| return nil, nil //nolint:nilnil | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| slog.Info("Loading dataplane validator", "version", tag) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| slog.Debug("Downloading dataplane validator", "ref", ref) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| storeOpts := credentials.StoreOptions{} | ||||||||||||||||||||||||||||||||||||||||
| credStore, err := credentials.NewStore(credsPath, storeOpts) | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+44
to
+45
|
||||||||||||||||||||||||||||||||||||||||
| storeOpts := credentials.StoreOptions{} | |
| credStore, err := credentials.NewStore(credsPath, storeOpts) | |
| credStore, err := credentials.NewStore(credsPath, credentials.StoreOptions{}) |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error variable err is being wrapped here, but it will always be nil at this point since it was only set on line 51 (the ReadFile call). If AppendCertsFromPEM fails, you should return a new error without wrapping, such as fmt.Errorf("failed to append CA cert to rootCAs\").
| return nil, fmt.Errorf("appending CA cert to rootCAs: %w", err) | |
| return nil, fmt.Errorf("failed to append CA cert %s to rootCAs", caPath) |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Close method doesn't check if v.compiled or v.runtime are nil before attempting to close them. If NewValidator returns early (lines 34-38), these fields will be nil and calling Close will panic. Add nil checks before calling Close on these fields.
| if err := v.compiled.Close(ctx); err != nil { | |
| slog.Warn("Error closing compiled validator module", "err", err.Error()) | |
| } | |
| if err := v.runtime.Close(ctx); err != nil { | |
| slog.Warn("Error closing validator runtime", "err", err.Error()) | |
| } | |
| if v == nil { | |
| return | |
| } | |
| if v.compiled != nil { | |
| if err := v.compiled.Close(ctx); err != nil { | |
| slog.Warn("Error closing compiled validator module", "err", err.Error()) | |
| } | |
| } | |
| if v.runtime != nil { | |
| if err := v.runtime.Close(ctx); err != nil { | |
| slog.Warn("Error closing validator runtime", "err", err.Error()) | |
| } | |
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable name
closeshadows the built-inclosefunction. Consider renaming it tocancelwhich is the conventional name for context cancellation functions.