Skip to content

Commit

Permalink
Return unimplemented error for objects containing collections or obje…
Browse files Browse the repository at this point in the history
…cts (#84)
  • Loading branch information
bendbennett committed Nov 6, 2023
1 parent bdc570e commit 6dafd8d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 10 deletions.
12 changes: 10 additions & 2 deletions internal/datasource_generate/object_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,17 @@ func (g GeneratorObjectAttribute) ToFromFunctions(name string) ([]byte, error) {
return nil, nil
}

attrTypesToFuncs := generatorschema.GetAttrTypesToFuncs(g.AttributeTypes)
attrTypesToFuncs, err := generatorschema.GetAttrTypesToFuncs(g.AttributeTypes)

attrTypesFromFuncs := generatorschema.GetAttrTypesFromFuncs(g.AttributeTypes)
if err != nil {
return nil, err
}

attrTypesFromFuncs, err := generatorschema.GetAttrTypesFromFuncs(g.AttributeTypes)

if err != nil {
return nil, err
}

toFrom := generatorschema.NewToFromObject(name, g.AssociatedExternalType, attrTypesToFuncs, attrTypesFromFuncs)

Expand Down
12 changes: 10 additions & 2 deletions internal/provider_generate/object_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,17 @@ func (g GeneratorObjectAttribute) ToFromFunctions(name string) ([]byte, error) {
return nil, nil
}

attrTypesToFuncs := generatorschema.GetAttrTypesToFuncs(g.AttributeTypes)
attrTypesToFuncs, err := generatorschema.GetAttrTypesToFuncs(g.AttributeTypes)

attrTypesFromFuncs := generatorschema.GetAttrTypesFromFuncs(g.AttributeTypes)
if err != nil {
return nil, err
}

attrTypesFromFuncs, err := generatorschema.GetAttrTypesFromFuncs(g.AttributeTypes)

if err != nil {
return nil, err
}

toFrom := generatorschema.NewToFromObject(name, g.AssociatedExternalType, attrTypesToFuncs, attrTypesFromFuncs)

Expand Down
12 changes: 10 additions & 2 deletions internal/resource_generate/object_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,17 @@ func (g GeneratorObjectAttribute) ToFromFunctions(name string) ([]byte, error) {
return nil, nil
}

attrTypesToFuncs := generatorschema.GetAttrTypesToFuncs(g.AttributeTypes)
attrTypesToFuncs, err := generatorschema.GetAttrTypesToFuncs(g.AttributeTypes)

attrTypesFromFuncs := generatorschema.GetAttrTypesFromFuncs(g.AttributeTypes)
if err != nil {
return nil, err
}

attrTypesFromFuncs, err := generatorschema.GetAttrTypesFromFuncs(g.AttributeTypes)

if err != nil {
return nil, err
}

toFrom := generatorschema.NewToFromObject(name, g.AssociatedExternalType, attrTypesToFuncs, attrTypesFromFuncs)

Expand Down
26 changes: 22 additions & 4 deletions internal/schema/attrtypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package schema

import (
"errors"
"fmt"
"strings"

Expand Down Expand Up @@ -93,7 +94,7 @@ type AttrTypesToFuncs struct {
// GetAttrTypesToFuncs returns string representations of the function that is used
// for converting to an API Go type from a framework type.
// TODO: Handle custom type, and types other than primitives.
func GetAttrTypesToFuncs(a specschema.ObjectAttributeTypes) map[string]AttrTypesToFuncs {
func GetAttrTypesToFuncs(a specschema.ObjectAttributeTypes) (map[string]AttrTypesToFuncs, error) {
attrTypesFuncs := make(map[string]AttrTypesToFuncs, len(a))

for _, v := range a {
Expand All @@ -113,11 +114,20 @@ func GetAttrTypesToFuncs(a specschema.ObjectAttributeTypes) map[string]AttrTypes
AttrValue: "types.Int64",
ToFunc: "ValueInt64Pointer",
}
case v.List != nil:
return nil, NewUnimplementedError(errors.New("list attribute type is not yet implemented"))
case v.Map != nil:
return nil, NewUnimplementedError(errors.New("map attribute type is not yet implemented"))

case v.Number != nil:
attrTypesFuncs[v.Name] = AttrTypesToFuncs{
AttrValue: "types.Number",
ToFunc: "ValueBigFloat",
}
case v.Object != nil:
return nil, NewUnimplementedError(errors.New("object attribute type is not yet implemented"))
case v.Set != nil:
return nil, NewUnimplementedError(errors.New("set attribute type is not yet implemented"))
case v.String != nil:
attrTypesFuncs[v.Name] = AttrTypesToFuncs{
AttrValue: "types.String",
Expand All @@ -126,13 +136,13 @@ func GetAttrTypesToFuncs(a specschema.ObjectAttributeTypes) map[string]AttrTypes
}
}

return attrTypesFuncs
return attrTypesFuncs, nil
}

// GetAttrTypesFromFuncs returns string representations of the function that is used
// for converting from an API Go type to a framework type.
// TODO: Handle custom type, and types other than primitives.
func GetAttrTypesFromFuncs(a specschema.ObjectAttributeTypes) map[string]string {
func GetAttrTypesFromFuncs(a specschema.ObjectAttributeTypes) (map[string]string, error) {
attrTypesFuncs := make(map[string]string, len(a))

for _, v := range a {
Expand All @@ -143,12 +153,20 @@ func GetAttrTypesFromFuncs(a specschema.ObjectAttributeTypes) map[string]string
attrTypesFuncs[v.Name] = "types.Float64PointerValue"
case v.Int64 != nil:
attrTypesFuncs[v.Name] = "types.Int64PointerValue"
case v.List != nil:
return nil, NewUnimplementedError(errors.New("list attribute type is not yet implemented"))
case v.Map != nil:
return nil, NewUnimplementedError(errors.New("map attribute type is not yet implemented"))
case v.Number != nil:
attrTypesFuncs[v.Name] = "types.NumberValue"
case v.Object != nil:
return nil, NewUnimplementedError(errors.New("object attribute type is not yet implemented"))
case v.Set != nil:
return nil, NewUnimplementedError(errors.New("set attribute type is not yet implemented"))
case v.String != nil:
attrTypesFuncs[v.Name] = "types.StringPointerValue"
}
}

return attrTypesFuncs
return attrTypesFuncs, nil
}

0 comments on commit 6dafd8d

Please sign in to comment.