2017-06-26 21:46:34 +00:00
|
|
|
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
|
2017-03-03 20:13:19 +00:00
|
|
|
|
Overhaul resources, planning, and environments
This change, part of pulumi/lumi#90, overhauls quite a bit of the
core resource, planning, environments, and related areas.
The biggest amount of movement comes from the splitting of pkg/resource
into multiple sub-packages. This results in:
- pkg/resource: just the core resource data structures.
- pkg/resource/deployment: all planning and deployment logic.
- pkg/resource/environment: all environment, configuration, and
serialized checkpoint structures and logic.
- pkg/resource/plugin: all dynamically loaded analyzer and
provider logic, including the actual loading and RPC mechanisms.
This also splits the resource abstraction up. We now have:
- resource.Resource: a shared interface.
- resource.Object: a resource that is connected to a live object
that will periodically observe mutations due to ongoing
evaluation of computations. Snapshots of its state may be
taken; however, this is purely a "pre-planning" abstraction.
- resource.State: a snapshot of a resource's state that is frozen.
In other words, it is no longer connected to a live object.
This is what will store provider outputs (ID and properties),
and is what may be serialized into a deployment record.
The branch is in a half-baked state as of this change; more changes
are to come...
2017-06-08 23:37:40 +00:00
|
|
|
package plugin
|
2017-03-03 20:13:19 +00:00
|
|
|
|
|
|
|
import (
|
2017-09-22 02:18:21 +00:00
|
|
|
"github.com/pulumi/pulumi/pkg/util/mapper"
|
|
|
|
lumirpc "github.com/pulumi/pulumi/sdk/proto/go"
|
2017-03-03 20:13:19 +00:00
|
|
|
)
|
|
|
|
|
2017-03-12 21:13:44 +00:00
|
|
|
// NewCheckResponse produces a response with property validation failures from the given array of mapper failures.
|
Implement mapper.Encode "for real"
This change implements `mapper.Encode` "for real" (that is, in a way
that isn't a complete embarrassment). It uses the obvious reflection
trickery to encode a tagged struct and its values as a JSON-like
in-memory map and collection of keyed values.
During this, I took the opportunity to also clean up a few other things
that had been bugging me. Namely, the presence of `mapper.Object` was
always error prone, since it isn't a true "typedef" in the sence that
it carries extra RTTI. Instead of doing that, let's just use the real
`map[string]interface{}` "JSON-map-like" object type. Even better, we
no longer require resource providers to deal with the mapper
infrastructure. Instead, the `Check` function can simply return an
array of errors. It's still best practice to return field-specific errors
to facilitate better diagnostics, but it's no longer required; and I've
added `resource.NewFieldError` to eliminate the need to import mapper.
As of this change, we can also consistently emit RPC structs with `lumi`
tags, rather than `lumi` tags on the way in and `json` on the way out.
This completes pulumi/lumi#183.
2017-06-06 00:43:52 +00:00
|
|
|
func NewCheckResponse(err error) *lumirpc.CheckResponse {
|
|
|
|
var failures []*lumirpc.CheckFailure
|
2017-03-12 21:13:44 +00:00
|
|
|
if err != nil {
|
Implement mapper.Encode "for real"
This change implements `mapper.Encode` "for real" (that is, in a way
that isn't a complete embarrassment). It uses the obvious reflection
trickery to encode a tagged struct and its values as a JSON-like
in-memory map and collection of keyed values.
During this, I took the opportunity to also clean up a few other things
that had been bugging me. Namely, the presence of `mapper.Object` was
always error prone, since it isn't a true "typedef" in the sence that
it carries extra RTTI. Instead of doing that, let's just use the real
`map[string]interface{}` "JSON-map-like" object type. Even better, we
no longer require resource providers to deal with the mapper
infrastructure. Instead, the `Check` function can simply return an
array of errors. It's still best practice to return field-specific errors
to facilitate better diagnostics, but it's no longer required; and I've
added `resource.NewFieldError` to eliminate the need to import mapper.
As of this change, we can also consistently emit RPC structs with `lumi`
tags, rather than `lumi` tags on the way in and `json` on the way out.
This completes pulumi/lumi#183.
2017-06-06 00:43:52 +00:00
|
|
|
switch e := err.(type) {
|
|
|
|
case mapper.MappingError:
|
|
|
|
for _, failure := range e.Failures() {
|
|
|
|
switch f := failure.(type) {
|
|
|
|
case mapper.FieldError:
|
|
|
|
failures = append(failures, &lumirpc.CheckFailure{
|
|
|
|
Property: f.Field(),
|
|
|
|
Reason: f.Reason(),
|
|
|
|
})
|
|
|
|
default:
|
|
|
|
failures = append(failures, &lumirpc.CheckFailure{Reason: f.Error()})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
failures = append(failures, &lumirpc.CheckFailure{Reason: e.Error()})
|
2017-03-12 21:13:44 +00:00
|
|
|
}
|
2017-03-03 20:13:19 +00:00
|
|
|
}
|
Implement mapper.Encode "for real"
This change implements `mapper.Encode` "for real" (that is, in a way
that isn't a complete embarrassment). It uses the obvious reflection
trickery to encode a tagged struct and its values as a JSON-like
in-memory map and collection of keyed values.
During this, I took the opportunity to also clean up a few other things
that had been bugging me. Namely, the presence of `mapper.Object` was
always error prone, since it isn't a true "typedef" in the sence that
it carries extra RTTI. Instead of doing that, let's just use the real
`map[string]interface{}` "JSON-map-like" object type. Even better, we
no longer require resource providers to deal with the mapper
infrastructure. Instead, the `Check` function can simply return an
array of errors. It's still best practice to return field-specific errors
to facilitate better diagnostics, but it's no longer required; and I've
added `resource.NewFieldError` to eliminate the need to import mapper.
As of this change, we can also consistently emit RPC structs with `lumi`
tags, rather than `lumi` tags on the way in and `json` on the way out.
This completes pulumi/lumi#183.
2017-06-06 00:43:52 +00:00
|
|
|
return &lumirpc.CheckResponse{Failures: failures}
|
2017-03-03 20:13:19 +00:00
|
|
|
}
|