Skip to content

Commit

Permalink
Fix panic in Check function (#462)
Browse files Browse the repository at this point in the history
* Fix panic in Check function

When the `build` field is unset entirely, the Check function was
panicking attempting to set the implicit `contextDigest` field.
This PR properly constructs the `inputs["build"]` field as a
`resource.NewObjectProperty`.

* remove comment

* use null check to avoid overwriting the inpust object
  • Loading branch information
guineveresaenger authored Jan 20, 2023
1 parent a359430 commit 842da37
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,13 @@ func (p *dockerNativeProvider) Check(ctx context.Context, req *rpc.CheckRequest)
}

// add implicit resource to provider
inputs["build"].ObjectValue()["contextDigest"] = resource.NewStringProperty(contextDigest)
if inputs["build"].IsNull() {
inputs["build"] = resource.NewObjectProperty(resource.PropertyMap{
"contextDigest": resource.NewStringProperty(contextDigest),
})
} else {
inputs["build"].ObjectValue()["contextDigest"] = resource.NewStringProperty(contextDigest)
}

inputStruct, err := plugin.MarshalProperties(inputs, plugin.MarshalOptions{
KeepUnknowns: true,
Expand Down

0 comments on commit 842da37

Please sign in to comment.