Open barahona42 opened 1 month ago
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 https://github.com/apple/pkl/pull/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. return []byte("foo"), nil
PS: great bug report! ❤️
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)
complete error message:
.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.