-
Notifications
You must be signed in to change notification settings - Fork 427
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Go Generator + Network Policy migration to the new SDK (#2061)
- Loading branch information
1 parent
21f069a
commit 231b081
Showing
42 changed files
with
2,450 additions
and
525 deletions.
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
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,92 @@ | ||
package sdk | ||
|
||
import g "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/poc/generator" | ||
|
||
//go:generate go run ./poc/main.go | ||
|
||
var ( | ||
ip = g.QueryStruct("IP"). | ||
Text("IP", g.KeywordOptions().SingleQuotes().Required()) | ||
|
||
NetworkPoliciesDef = g.NewInterface( | ||
"NetworkPolicies", | ||
"NetworkPolicy", | ||
g.KindOfT[AccountObjectIdentifier](), | ||
). | ||
CreateOperation( | ||
"https://docs.snowflake.com/en/sql-reference/sql/create-network-policy", | ||
g.QueryStruct("CreateNetworkPolicies"). | ||
Create(). | ||
OrReplace(). | ||
SQL("NETWORK POLICY"). | ||
Name(). | ||
ListQueryStructField("AllowedIpList", ip, g.ParameterOptions().SQL("ALLOWED_IP_LIST").Parentheses()). | ||
ListQueryStructField("BlockedIpList", ip, g.ParameterOptions().SQL("BLOCKED_IP_LIST").Parentheses()). | ||
OptionalTextAssignment("COMMENT", g.ParameterOptions().SingleQuotes()). | ||
WithValidation(g.ValidIdentifier, "name"), | ||
). | ||
AlterOperation( | ||
"https://docs.snowflake.com/en/sql-reference/sql/alter-network-policy", | ||
g.QueryStruct("AlterNetworkPolicy"). | ||
Alter(). | ||
SQL("NETWORK POLICY"). | ||
IfExists(). | ||
Name(). | ||
OptionalQueryStructField( | ||
"Set", | ||
g.QueryStruct("NetworkPolicySet"). | ||
ListQueryStructField("AllowedIpList", ip, g.ParameterOptions().SQL("ALLOWED_IP_LIST").Parentheses()). | ||
ListQueryStructField("BlockedIpList", ip, g.ParameterOptions().SQL("BLOCKED_IP_LIST").Parentheses()). | ||
OptionalTextAssignment("COMMENT", g.ParameterOptions().SingleQuotes()). | ||
WithValidation(g.AtLeastOneValueSet, "AllowedIpList", "BlockedIpList", "Comment"), | ||
g.KeywordOptions().SQL("SET"), | ||
). | ||
OptionalSQL("UNSET COMMENT"). | ||
Identifier("RenameTo", g.KindOfTPointer[AccountObjectIdentifier](), g.IdentifierOptions().SQL("RENAME TO")). | ||
WithValidation(g.ValidIdentifier, "name"). | ||
WithValidation(g.AtLeastOneValueSet, "Set", "UnsetComment", "RenameTo"). | ||
WithValidation(g.ValidIdentifierIfSet, "RenameTo"), | ||
). | ||
DropOperation( | ||
"https://docs.snowflake.com/en/sql-reference/sql/drop-network-policy", | ||
g.QueryStruct("DropNetworkPolicy"). | ||
Drop(). | ||
SQL("NETWORK POLICY"). | ||
IfExists(). | ||
Name(). | ||
WithValidation(g.ValidIdentifier, "name"), | ||
). | ||
ShowOperation( | ||
"https://docs.snowflake.com/en/sql-reference/sql/show-network-policies", | ||
g.DbStruct("showNetworkPolicyDBRow"). | ||
Field("created_on", "string"). | ||
Field("name", "string"). | ||
Field("comment", "string"). | ||
Field("entries_in_allowed_ip_list", "int"). | ||
Field("entries_in_blocked_ip_list", "int"), | ||
g.PlainStruct("NetworkPolicy"). | ||
Field("CreatedOn", "string"). | ||
Field("Name", "string"). | ||
Field("Comment", "string"). | ||
Field("EntriesInAllowedIpList", "int"). | ||
Field("EntriesInBlockedIpList", "int"), | ||
g.QueryStruct("ShowNetworkPolicies"). | ||
Show(). | ||
SQL("NETWORK POLICIES"), | ||
). | ||
DescribeOperation( | ||
g.DescriptionMappingKindSlice, | ||
"https://docs.snowflake.com/en/sql-reference/sql/desc-network-policy", | ||
g.DbStruct("describeNetworkPolicyDBRow"). | ||
Field("name", "string"). | ||
Field("value", "string"), | ||
g.PlainStruct("NetworkPolicyDescription"). | ||
Field("Name", "string"). | ||
Field("Value", "string"), | ||
g.QueryStruct("DescribeNetworkPolicy"). | ||
Describe(). | ||
SQL("NETWORK POLICY"). | ||
Name(). | ||
WithValidation(g.ValidIdentifier, "name"), | ||
) | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,48 @@ | ||
package sdk | ||
|
||
//go:generate go run ./dto-builder-generator/main.go | ||
|
||
var ( | ||
_ optionsProvider[CreateNetworkPolicyOptions] = new(CreateNetworkPolicyRequest) | ||
_ optionsProvider[AlterNetworkPolicyOptions] = new(AlterNetworkPolicyRequest) | ||
_ optionsProvider[DropNetworkPolicyOptions] = new(DropNetworkPolicyRequest) | ||
_ optionsProvider[ShowNetworkPolicyOptions] = new(ShowNetworkPolicyRequest) | ||
_ optionsProvider[DescribeNetworkPolicyOptions] = new(DescribeNetworkPolicyRequest) | ||
) | ||
|
||
type CreateNetworkPolicyRequest struct { | ||
OrReplace *bool | ||
name AccountObjectIdentifier // required | ||
AllowedIpList []IPRequest | ||
BlockedIpList []IPRequest | ||
Comment *string | ||
} | ||
|
||
type IPRequest struct { | ||
IP string // required | ||
} | ||
|
||
type AlterNetworkPolicyRequest struct { | ||
IfExists *bool | ||
name AccountObjectIdentifier // required | ||
Set *NetworkPolicySetRequest | ||
UnsetComment *bool | ||
RenameTo *AccountObjectIdentifier | ||
} | ||
|
||
type NetworkPolicySetRequest struct { | ||
AllowedIpList []IPRequest | ||
BlockedIpList []IPRequest | ||
Comment *string | ||
} | ||
|
||
type DropNetworkPolicyRequest struct { | ||
IfExists *bool | ||
name AccountObjectIdentifier // required | ||
} | ||
|
||
type ShowNetworkPolicyRequest struct{} | ||
|
||
type DescribeNetworkPolicyRequest struct { | ||
name AccountObjectIdentifier // required | ||
} |
Oops, something went wrong.