-
Notifications
You must be signed in to change notification settings - Fork 279
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
Custom ResourceReader implementation in Golang fails to decode read data #656
Comments
The issue with returning an empty/nil byte slice is definitely a bug! The read contents are assumed to be non-null even though an empty byte slice on the go side is encoded as nil. A fix similar to #480 is needed for this, which should be pretty straightforward. I'll probably have a PR up for this later today or tomorrow. |
The other issue is not as clear. Can you share some of the exact code that produced that error? You definitely don't need to do the msgpack encoding yourself, just return the string produced by your resource directly, eg. PS: great bug report! ❤️ |
In messages "Read Resource Response" and "Read Module Response", if `contents` and `error` are both null, default to an empty byte array/string. This resolves one of the issues reported in apple#656
Thanks for the response. Here's the implementation of the resource and the code that gets the ssm parameter value. // wraps ssm call
func GetDecryptedParameter(ctx context.Context, name string) (*string, error) {
// do some service initialization
input := ssm.GetParameterInput{Name: aws.String(name), WithDecryption: aws.Bool(true)}
// call to aws sdk method
output, err := svc.GetParameter(ctx, &input)
if err != nil {
return nil, err
}
return output.Parameter.Value, nil
}
// pkl.ResourceReader implementation
type PklResourceReader struct{}
// Scheme: pkl.Reader implementation
func (r PklResourceReader) Scheme() string {
return "ssm"
}
// IsGlobbable: pkl.Reader implementation
func (r PklResourceReader) IsGlobbable() bool {
return false
}
// HasHierarchicalUris: pkl.Reader implementation
func (r PklResourceReader) HasHierarchicalUris() bool {
return false
}
// ListElements: pkl.Reader implementation
func (r PklResourceReader) ListElements(url url.URL) ([]pkl.PathElement, error) {
return nil, nil
}
// Read: pkl.Reader implementation
func (r PklResourceReader) Read(url url.URL) ([]byte, error) {
v, err := GetDecryptedParameter(context.Background(), url.Path)
if err != nil {
return nil, err
}
if v == nil {
return make([]byte, 0), nil
}
return []byte(*v), nil
} |
context
Hi all, first time submitting a bug report ever. Here's the info:
read("ssm:/foo/SomeParameterPath")
is assigned to a pkl resource.go1.23.0
outputs
pkl --version: Pkl 0.26.3 (macOS 14.3.1, native)
.pkl
file:Read
method returns a byte array as shown below:.Load()
method.b
do make a difference:[]byte(*v)
,[]byte("foo")
, the following error returns:Any pointers/insight on this would be appreciated. Thank you.
The text was updated successfully, but these errors were encountered: