-
Notifications
You must be signed in to change notification settings - Fork 97
types: Add Typable and Valuable Interfaces #536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f6c3071
Adding ValueFromFramework and ToFrameworkValue interface functions to…
bendbennett 467f056
Adding ValueFromFramework and ToFrameworkValue interface functions to…
bendbennett 94d03e6
Adding ValueFromFramework and ToFrameworkValue interface functions to…
bendbennett a042afc
Adding ValueFromFramework and ToFrameworkValue interface functions to…
bendbennett 69b5b10
Adding ValueFromFramework and ToFrameworkValue interface functions to…
bendbennett ddaa77b
Refactoring interface names to use -able suffix (#535)
bendbennett 1c2c246
Merge branch 'main' into bendbennett/issues-535
bendbennett 23bfa1a
Adding Go documentation and refactoring to return type-specific inter…
bendbennett 59d7778
Adding further Go documentation (#535)
bendbennett c14cc92
Apply suggestions from code review
bendbennett e117313
Amending Go documentation (#535)
bendbennett a548180
Adding changelog, amending Go documentation and adding unit tests for…
bendbennett File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,19 +140,26 @@ func AttributeValidateNestedAttributes(ctx context.Context, a fwschema.Attribute | |
nm := a.GetAttributes().GetNestingMode() | ||
switch nm { | ||
case fwschema.NestingModeList: | ||
l, ok := req.AttributeConfig.(types.List) | ||
listVal, ok := req.AttributeConfig.(types.ListValuable) | ||
|
||
if !ok { | ||
err := fmt.Errorf("unknown attribute value type (%T) for nesting mode (%T) at path: %s", req.AttributeConfig, nm, req.AttributePath) | ||
resp.Diagnostics.AddAttributeError( | ||
req.AttributePath, | ||
"Attribute Validation Error", | ||
"Attribute validation cannot walk schema. Report this to the provider developer:\n\n"+err.Error(), | ||
"Attribute Validation Error Invalid Value Type", | ||
"A type from which a types.List can be obtained is expected here. Report this to the provider developer:\n\n"+err.Error(), | ||
) | ||
|
||
return | ||
} | ||
|
||
l, diags := listVal.ToListValue(ctx) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we're ready for unit testing these! Maybe some additional types in |
||
|
||
resp.Diagnostics.Append(diags...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
for idx := range l.Elements() { | ||
for nestedName, nestedAttr := range a.GetAttributes().GetAttributes() { | ||
nestedAttrReq := tfsdk.ValidateAttributeRequest{ | ||
|
@@ -170,19 +177,26 @@ func AttributeValidateNestedAttributes(ctx context.Context, a fwschema.Attribute | |
} | ||
} | ||
case fwschema.NestingModeSet: | ||
s, ok := req.AttributeConfig.(types.Set) | ||
setVal, ok := req.AttributeConfig.(types.SetValuable) | ||
|
||
if !ok { | ||
err := fmt.Errorf("unknown attribute value type (%T) for nesting mode (%T) at path: %s", req.AttributeConfig, nm, req.AttributePath) | ||
resp.Diagnostics.AddAttributeError( | ||
req.AttributePath, | ||
"Attribute Validation Error", | ||
"Attribute validation cannot walk schema. Report this to the provider developer:\n\n"+err.Error(), | ||
"Attribute Validation Error Invalid Value Type", | ||
"A type from which a types.Set can be obtained is expected here. Report this to the provider developer:\n\n"+err.Error(), | ||
) | ||
|
||
return | ||
} | ||
|
||
s, diags := setVal.ToSetValue(ctx) | ||
|
||
resp.Diagnostics.Append(diags...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
for _, value := range s.Elements() { | ||
for nestedName, nestedAttr := range a.GetAttributes().GetAttributes() { | ||
nestedAttrReq := tfsdk.ValidateAttributeRequest{ | ||
|
@@ -200,19 +214,26 @@ func AttributeValidateNestedAttributes(ctx context.Context, a fwschema.Attribute | |
} | ||
} | ||
case fwschema.NestingModeMap: | ||
m, ok := req.AttributeConfig.(types.Map) | ||
mapVal, ok := req.AttributeConfig.(types.MapValuable) | ||
|
||
if !ok { | ||
err := fmt.Errorf("unknown attribute value type (%T) for nesting mode (%T) at path: %s", req.AttributeConfig, nm, req.AttributePath) | ||
resp.Diagnostics.AddAttributeError( | ||
req.AttributePath, | ||
"Attribute Validation Error", | ||
"Attribute validation cannot walk schema. Report this to the provider developer:\n\n"+err.Error(), | ||
"Attribute Validation Error Invalid Value Type", | ||
"A type from which a types.Map can be obtained is expected here. Report this to the provider developer:\n\n"+err.Error(), | ||
) | ||
|
||
return | ||
} | ||
|
||
m, diags := mapVal.ToMapValue(ctx) | ||
|
||
resp.Diagnostics.Append(diags...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
for key := range m.Elements() { | ||
for nestedName, nestedAttr := range a.GetAttributes().GetAttributes() { | ||
nestedAttrReq := tfsdk.ValidateAttributeRequest{ | ||
|
@@ -230,19 +251,26 @@ func AttributeValidateNestedAttributes(ctx context.Context, a fwschema.Attribute | |
} | ||
} | ||
case fwschema.NestingModeSingle: | ||
o, ok := req.AttributeConfig.(types.Object) | ||
objectVal, ok := req.AttributeConfig.(types.ObjectValuable) | ||
|
||
if !ok { | ||
err := fmt.Errorf("unknown attribute value type (%T) for nesting mode (%T) at path: %s", req.AttributeConfig, nm, req.AttributePath) | ||
resp.Diagnostics.AddAttributeError( | ||
req.AttributePath, | ||
"Attribute Validation Error", | ||
"Attribute validation cannot walk schema. Report this to the provider developer:\n\n"+err.Error(), | ||
"Attribute Validation Error Invalid Value Type", | ||
"A type from which a types.Object can be obtained is expected here. Report this to the provider developer:\n\n"+err.Error(), | ||
) | ||
|
||
return | ||
} | ||
|
||
o, diags := objectVal.ToObjectValue(ctx) | ||
|
||
resp.Diagnostics.Append(diags...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
if o.IsNull() || o.IsUnknown() { | ||
return | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Should we give the direct hint about the
types.ListValuable
interface for these?