Skip to content

Commit

Permalink
Merge pull request #26 from hashicorp/paddy_discourage_marshaling
Browse files Browse the repository at this point in the history
Discourage the use of our marshaling types.
  • Loading branch information
paddycarver committed Oct 29, 2020
2 parents 3e511da + 54654da commit 958fd96
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 5 deletions.
4 changes: 3 additions & 1 deletion tfprotov5/dynamic_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ var ErrUnknownDynamicValueType = errors.New("DynamicValue had no JSON or msgpack
// that is compatible with the Type of the Value. Usually it should just be the
// Type of the Value, but it can also be the DynamicPseudoType.
func NewDynamicValue(t tftypes.Type, v tftypes.Value) (DynamicValue, error) {
b, err := v.MarshalMsgPack(t)
b, err := v.MarshalMsgPack(t) //nolint:staticcheck
//
// Deprecated: this is not meant to be called by third-party code.
if err != nil {
return DynamicValue{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion tfprotov5/dynamic_value_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func jsonUnmarshalDynamicPseudoType(buf []byte, typ tftypes.Type, p tftypes.Attr
}
switch key {
case "type":
t, err = tftypes.ParseJSONType(rawVal)
t, err = tftypes.ParseJSONType(rawVal) //nolint:staticcheck
if err != nil {
return tftypes.Value{}, p.NewErrorf("error decoding type information: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion tfprotov5/dynamic_value_msgpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func msgpackUnmarshalDynamic(dec *msgpack.Decoder, path tftypes.AttributePath) (
if err != nil {
return tftypes.Value{}, path.NewErrorf("error decoding bytes: %w", err)
}
typ, err := tftypes.ParseJSONType(typeJSON)
typ, err := tftypes.ParseJSONType(typeJSON) //nolint:staticcheck
if err != nil {
return tftypes.Value{}, path.NewErrorf("error parsing type information: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion tfprotov5/internal/fromproto/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func SchemaAttribute(in *tfplugin5.Schema_Attribute) (*tfprotov5.SchemaAttribute
DescriptionKind: StringKind(in.DescriptionKind),
Deprecated: in.Deprecated,
}
typ, err := tftypes.ParseJSONType(in.Type)
typ, err := tftypes.ParseJSONType(in.Type) //nolint:staticcheck
if err != nil {
return resp, err
}
Expand Down
2 changes: 1 addition & 1 deletion tfprotov5/internal/toproto/dynamic_value.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions tfprotov5/tftypes/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func (l List) private() {}

// MarshalJSON returns a JSON representation of the full type signature of `l`,
// including its ElementType.
//
// Deprecated: this is not meant to be called by third-party code.
func (l List) MarshalJSON() ([]byte, error) {
elementType, err := l.ElementType.MarshalJSON()
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions tfprotov5/tftypes/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ func (m Map) private() {}

// MarshalJSON returns a JSON representation of the full type signature of `m`,
// including its AttributeType.
//
// Deprecated: this is not meant to be called by third-party code.
func (m Map) MarshalJSON() ([]byte, error) {
attributeType, err := m.AttributeType.MarshalJSON()
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions tfprotov5/tftypes/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func (o Object) private() {}

// MarshalJSON returns a JSON representation of the full type signature of `o`,
// including the AttributeTypes.
//
// Deprecated: this is not meant to be called by third-party code.
func (o Object) MarshalJSON() ([]byte, error) {
attrs, err := json.Marshal(o.AttributeTypes)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions tfprotov5/tftypes/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func (s Set) private() {}

// MarshalJSON returns a JSON representation of the full type signature of `s`,
// including its ElementType.
//
// Deprecated: this is not meant to be called by third-party code.
func (s Set) MarshalJSON() ([]byte, error) {
elementType, err := s.ElementType.MarshalJSON()
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions tfprotov5/tftypes/tuple.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ func (tu Tuple) private() {}

// MarshalJSON returns a JSON representation of the full type signature of
// `tu`, including the ElementTypes.
//
// Deprecated: this is not meant to be called by third-party code.
func (tu Tuple) MarshalJSON() ([]byte, error) {
elements, err := json.Marshal(tu.ElementTypes)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions tfprotov5/tftypes/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type Type interface {
// It is modeled based on Terraform's requirements for type signature
// JSON representations, and may change over time to match Terraform's
// formatting.
//
// Deprecated: this is not meant to be called by third-party code.
MarshalJSON() ([]byte, error)

// private is meant to keep this interface from being implemented by
Expand All @@ -36,6 +38,8 @@ type jsonType struct {
// ParseJSONType returns a Type from its JSON representation. The JSON
// representation should come from Terraform or from MarshalJSON as the format
// is not part of this package's API guarantees.
//
// Deprecated: this is not meant to be called by third-party code.
func ParseJSONType(buf []byte) (Type, error) {
var t jsonType
err := json.Unmarshal(buf, &t)
Expand Down
2 changes: 2 additions & 0 deletions tfprotov5/tftypes/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ func (val Value) IsNull() bool {

// MarshalMsgPack returns a msgpack representation of the Value. This is used
// for constructing tfprotov5.DynamicValues.
//
// Deprecated: this is not meant to be called by third parties. Don't use it.
func (val Value) MarshalMsgPack(t Type) ([]byte, error) {
var buf bytes.Buffer
enc := msgpack.NewEncoder(&buf)
Expand Down

0 comments on commit 958fd96

Please sign in to comment.