-
Notifications
You must be signed in to change notification settings - Fork 427
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
chore: Generate ID and ObjectType Show Object Methods #3292
Open
sfc-gh-fbudzynski
wants to merge
45
commits into
dev
Choose a base branch
from
sdk-helper-methods
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
cea5dd3
init for interface helper methods
sfc-gh-fbudzynski d47db72
Merge branch 'main' of github.com:Snowflake-Labs/terraform-provider-s…
sfc-gh-fbudzynski 4750632
enum
sfc-gh-fbudzynski e051890
refactor
sfc-gh-fbudzynski 86d55bd
doc to helper methods
sfc-gh-fbudzynski cf927ef
generated for streamlits
sfc-gh-fbudzynski 495e236
generated for notification integrations
sfc-gh-fbudzynski c9cb8d7
checks for missing fields to create ID() method
sfc-gh-fbudzynski 8fdc1dd
small fix
sfc-gh-fbudzynski a3784c0
slight refactor and generated some examples
sfc-gh-fbudzynski a1d1067
Merge branch 'main' of github.com:Snowflake-Labs/terraform-provider-s…
sfc-gh-fbudzynski 1c5c00d
Merge branch 'main' of github.com:Snowflake-Labs/terraform-provider-s…
sfc-gh-fbudzynski 590cb48
ff
sfc-gh-fbudzynski b0725ae
Merge branch 'main' of github.com:Snowflake-Labs/terraform-provider-s…
sfc-gh-fbudzynski 78a01e3
log change
sfc-gh-fbudzynski d5d1aa6
ref
sfc-gh-fbudzynski 6b4be76
Merge branch 'main' of github.com:Snowflake-Labs/terraform-provider-s…
sfc-gh-fbudzynski e1a27df
ref
sfc-gh-fbudzynski 38b8a3e
Merge branch 'main' of github.com:Snowflake-Labs/terraform-provider-s…
sfc-gh-fbudzynski 9f29c42
ref
sfc-gh-fbudzynski 1310f63
Merge branch 'dev' of github.com:Snowflake-Labs/terraform-provider-sn…
sfc-gh-fbudzynski d610978
refacotred to be on Operatin level
sfc-gh-fbudzynski 72fc399
rename
sfc-gh-fbudzynski 475a570
small ref
sfc-gh-fbudzynski 388abfc
rename
sfc-gh-fbudzynski 546e125
self rev
sfc-gh-fbudzynski 64fea51
self rev
sfc-gh-fbudzynski 3f44299
self rev
sfc-gh-fbudzynski 8987603
self rev
sfc-gh-fbudzynski 05914c3
self rev
sfc-gh-fbudzynski 3954232
rev
sfc-gh-fbudzynski 05c44e5
def fixes
sfc-gh-fbudzynski 9e757be
order fixed
sfc-gh-fbudzynski 8183ff7
rename...
sfc-gh-fbudzynski 268e2d8
lint
sfc-gh-fbudzynski c60dec5
ref
sfc-gh-fbudzynski df0563b
ref
sfc-gh-fbudzynski a8ff21d
ref
sfc-gh-fbudzynski a9d50cb
ref
sfc-gh-fbudzynski 57ebbc3
ref
sfc-gh-fbudzynski 560cc8b
small ref
sfc-gh-fbudzynski 891ce2b
removed methods from operation
sfc-gh-fbudzynski 2d9930e
Merge branch 'dev' of github.com:Snowflake-Labs/terraform-provider-sn…
sfc-gh-fbudzynski 5f5e263
merge
sfc-gh-fbudzynski cae24f6
Merge branch 'dev' into sdk-helper-methods
sfc-gh-fbudzynski 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 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 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 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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package generator | ||
|
||
import ( | ||
"log" | ||
"slices" | ||
) | ||
|
||
type ShowObjectIdMethod struct { | ||
StructName string | ||
IdentifierKind objectIdentifierKind | ||
Args []string | ||
} | ||
|
||
func newShowObjectIDMethod(structName string, idType objectIdentifierKind) *ShowObjectIdMethod { | ||
return &ShowObjectIdMethod{ | ||
StructName: structName, | ||
IdentifierKind: idType, | ||
Args: idTypeParts[idType], | ||
} | ||
} | ||
|
||
var idTypeParts map[objectIdentifierKind][]string = map[objectIdentifierKind][]string{ | ||
AccountObjectIdentifier: {"Name"}, | ||
DatabaseObjectIdentifier: {"DatabaseName", "Name"}, | ||
SchemaObjectIdentifier: {"DatabaseName", "SchemaName", "Name"}, | ||
} | ||
|
||
func checkRequiredFieldsForIdMethod(structName string, helperStructs []*Field, idKind objectIdentifierKind) bool { | ||
if requiredFields, ok := idTypeParts[idKind]; ok { | ||
for _, field := range helperStructs { | ||
if field.Name == structName { | ||
return containsFieldNames(field.Fields, requiredFields...) | ||
} | ||
} | ||
} | ||
log.Printf("[WARN] no required fields mapping defined for identifier %s", idKind) | ||
return false | ||
} | ||
|
||
func containsFieldNames(fields []*Field, names ...string) bool { | ||
fieldNames := []string{} | ||
for _, field := range fields { | ||
fieldNames = append(fieldNames, field.Name) | ||
} | ||
|
||
for _, name := range names { | ||
if !slices.Contains(fieldNames, name) { | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
|
||
type ShowObjectTypeMethod struct { | ||
StructName string | ||
} | ||
|
||
func newShowObjectTypeMethod(structName string) *ShowObjectTypeMethod { | ||
return &ShowObjectTypeMethod{StructName: structName} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package generator | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestIdentifierStringToObjectIdentifier(t *testing.T) { | ||
tests := []struct { | ||
input string | ||
expected objectIdentifierKind | ||
}{ | ||
{"AccountObjectIdentifier", AccountObjectIdentifier}, | ||
{"DatabaseObjectIdentifier", DatabaseObjectIdentifier}, | ||
{"SchemaObjectIdentifier", SchemaObjectIdentifier}, | ||
{"SchemaObjectIdentifierWithArguments", SchemaObjectIdentifierWithArguments}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.input, func(t *testing.T) { | ||
result, err := toObjectIdentifierKind(test.input) | ||
require.NoError(t, err) | ||
require.Equal(t, test.expected, result) | ||
}) | ||
} | ||
} | ||
|
||
func TestIdentifierStringToObjectIdentifier_Invalid(t *testing.T) { | ||
tests := []struct { | ||
input string | ||
err string | ||
}{ | ||
{"accountobjectidentifier", "invalid string identifier type: accountobjectidentifier"}, | ||
{"Account", "invalid string identifier type: Account"}, | ||
{"databaseobjectidentifier", "invalid string identifier type: databaseobjectidentifier"}, | ||
{"Database", "invalid string identifier type: Database"}, | ||
{"schemaobjectidentifier", "invalid string identifier type: schemaobjectidentifier"}, | ||
{"Schema", "invalid string identifier type: Schema"}, | ||
{"schemaobjectidentifierwitharguments", "invalid string identifier type: schemaobjectidentifierwitharguments"}, | ||
{"schemawitharguemnts", "invalid string identifier type: schemawitharguemnts"}, | ||
} | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.input, func(t *testing.T) { | ||
_, err := toObjectIdentifierKind(tc.input) | ||
require.ErrorContains(t, err, tc.err) | ||
}) | ||
} | ||
} |
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/poc/generator.ShowObjectIdMethod*/ -}} | ||
|
||
func (v *{{ .StructName }}) ID() {{ .IdentifierKind }} { | ||
return New{{ .IdentifierKind }}({{ range .Args }}v.{{ . }}, {{ end }}) | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/poc/generator.ShowObjectMethod*/ -}} | ||
|
||
func (v *{{ .StructName }}) ObjectType() ObjectType { | ||
return ObjectType{{ .StructName }} | ||
} | ||
|
This file contains 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/poc/generator.ShowObjectTypeMethod*/ -}} | ||
|
||
func (v *{{ .StructName }}) ObjectType() ObjectType { | ||
return ObjectType{{ .StructName }} | ||
} |
This file contains 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 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
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.
👍