-
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: Add network rule to the sdk (#2526)
<!-- Feel free to delete comments as you fill this in --> Implements: #2514 Adds network rule to the sdk which is needed for #2482. <!-- summary of changes --> ## Test Plan * [x] unit and integration tests ## References <!-- issues documentation links, etc --> * [Create network rules](https://docs.snowflake.com/en/sql-reference/sql/create-network-rule)
- Loading branch information
1 parent
5e2dbf3
commit b379565
Showing
11 changed files
with
1,005 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package sdk | ||
|
||
import g "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/poc/generator" | ||
|
||
//go:generate go run ./poc/main.go | ||
|
||
type NetworkRuleType string | ||
|
||
const ( | ||
NetworkRuleTypeIpv4 NetworkRuleType = "IPV4" | ||
NetworkRuleTypeAwsVpcEndpointId NetworkRuleType = "AWSVPCEID" | ||
NetworkRuleTypeAzureLinkId NetworkRuleType = "AZURELINKID" | ||
NetworkRuleTypeHostPort NetworkRuleType = "HOST_PORT" | ||
) | ||
|
||
type NetworkRuleMode string | ||
|
||
const ( | ||
NetworkRuleModeIngress NetworkRuleMode = "INGRESS" | ||
NetworkRuleModeInternalStage NetworkRuleMode = "INTERNAL_STAGE" | ||
NetworkRuleModeEgress NetworkRuleMode = "EGRESS" | ||
) | ||
|
||
var NetworkRuleDef = g.NewInterface( | ||
"NetworkRules", | ||
"NetworkRule", | ||
g.KindOfT[SchemaObjectIdentifier](), | ||
). | ||
CreateOperation( | ||
"https://docs.snowflake.com/en/sql-reference/sql/create-network-rule", | ||
g.NewQueryStruct("CreateNetworkRule"). | ||
Create(). | ||
OrReplace(). | ||
SQL("NETWORK RULE"). | ||
Name(). | ||
Assignment("TYPE", g.KindOfT[NetworkRuleType](), g.ParameterOptions().Required().NoQuotes()). | ||
ListAssignment("VALUE_LIST", "NetworkRuleValue", g.ParameterOptions().Required().Parentheses()). | ||
Assignment("MODE", g.KindOfT[NetworkRuleMode](), g.ParameterOptions().Required().NoQuotes()). | ||
OptionalComment(). | ||
WithValidation(g.ValidIdentifier, "name"), | ||
g.NewQueryStruct("NetworkRuleValue"). | ||
Text("Value", g.KeywordOptions().SingleQuotes().Required()), | ||
). | ||
AlterOperation( | ||
"https://docs.snowflake.com/en/sql-reference/sql/alter-network-rule", | ||
g.NewQueryStruct("AlterNetworkRule"). | ||
Alter(). | ||
SQL("NETWORK RULE"). | ||
IfExists(). | ||
Name(). | ||
OptionalQueryStructField( | ||
"Set", | ||
g.NewQueryStruct("NetworkRuleSet"). | ||
ListAssignment("VALUE_LIST", "NetworkRuleValue", g.ParameterOptions().Required().Parentheses()). | ||
OptionalComment(). | ||
WithValidation(g.AtLeastOneValueSet, "ValueList", "Comment"), | ||
g.ListOptions().SQL("SET"), | ||
). | ||
OptionalQueryStructField( | ||
"Unset", | ||
g.NewQueryStruct("NetworkRuleUnset"). | ||
OptionalSQL("VALUE_LIST"). | ||
OptionalSQL("COMMENT"). | ||
WithValidation(g.AtLeastOneValueSet, "ValueList", "Comment"), | ||
g.ListOptions().SQL("UNSET"), | ||
). | ||
WithValidation(g.ValidIdentifier, "name"). | ||
WithValidation(g.AtLeastOneValueSet, "Set", "Unset"), | ||
). | ||
DropOperation( | ||
"https://docs.snowflake.com/en/sql-reference/sql/drop-network-rule", | ||
g.NewQueryStruct("DropNetworkRule"). | ||
Drop(). | ||
SQL("NETWORK RULE"). | ||
IfExists(). | ||
Name(). | ||
WithValidation(g.ValidIdentifier, "name"), | ||
). | ||
ShowOperation( | ||
"https://docs.snowflake.com/en/sql-reference/sql/show-network-rules", | ||
g.DbStruct("ShowNetworkRulesRow"). | ||
Time("created_on"). | ||
Text("name"). | ||
Text("database_name"). | ||
Text("schema_name"). | ||
Text("owner"). | ||
Text("comment"). | ||
Text("type"). | ||
Text("mode"). | ||
Number("entries_in_valuelist"). | ||
Text("owner_role_type"), | ||
g.PlainStruct("NetworkRule"). | ||
Time("CreatedOn"). | ||
Text("Name"). | ||
Text("DatabaseName"). | ||
Text("SchemaName"). | ||
Text("Owner"). | ||
Text("Comment"). | ||
Text("Type"). | ||
Text("Mode"). | ||
Number("EntriesInValueList"). | ||
Text("OwnerRoleType"), | ||
g.NewQueryStruct("ShowNetworkRules"). | ||
Show(). | ||
SQL("NETWORK RULES"). | ||
OptionalLike(). | ||
OptionalIn(). | ||
OptionalStartsWith(). | ||
OptionalLimitFrom(), | ||
). | ||
ShowByIdOperation(). | ||
DescribeOperation( | ||
g.DescriptionMappingKindSingleValue, | ||
"https://docs.snowflake.com/en/sql-reference/sql/desc-network-rule", | ||
g.DbStruct("DescNetworkRulesRow"). | ||
Time("created_on"). | ||
Text("name"). | ||
Text("database_name"). | ||
Text("schema_name"). | ||
Text("owner"). | ||
Text("comment"). | ||
Text("type"). | ||
Text("mode"). | ||
Text("value_list"), | ||
g.PlainStruct("NetworkRuleDetails"). | ||
Time("CreatedOn"). | ||
Text("Name"). | ||
Text("DatabaseName"). | ||
Text("SchemaName"). | ||
Text("Owner"). | ||
Text("Comment"). | ||
Text("Type"). | ||
Text("Mode"). | ||
Field("ValueList", "[]string"), | ||
g.NewQueryStruct("ShowNetworkRules"). | ||
Describe(). | ||
SQL("NETWORK RULE"). | ||
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,53 @@ | ||
package sdk | ||
|
||
//go:generate go run ./dto-builder-generator/main.go | ||
|
||
var ( | ||
_ optionsProvider[CreateNetworkRuleOptions] = new(CreateNetworkRuleRequest) | ||
_ optionsProvider[AlterNetworkRuleOptions] = new(AlterNetworkRuleRequest) | ||
_ optionsProvider[DropNetworkRuleOptions] = new(DropNetworkRuleRequest) | ||
_ optionsProvider[ShowNetworkRuleOptions] = new(ShowNetworkRuleRequest) | ||
_ optionsProvider[DescribeNetworkRuleOptions] = new(DescribeNetworkRuleRequest) | ||
) | ||
|
||
type CreateNetworkRuleRequest struct { | ||
OrReplace *bool | ||
name SchemaObjectIdentifier // required | ||
Type NetworkRuleType // required | ||
ValueList []NetworkRuleValue // required | ||
Mode NetworkRuleMode // required | ||
Comment *string | ||
} | ||
|
||
type AlterNetworkRuleRequest struct { | ||
IfExists *bool | ||
name SchemaObjectIdentifier // required | ||
Set *NetworkRuleSetRequest | ||
Unset *NetworkRuleUnsetRequest | ||
} | ||
|
||
type NetworkRuleSetRequest struct { | ||
ValueList []NetworkRuleValue // required | ||
Comment *string | ||
} | ||
|
||
type NetworkRuleUnsetRequest struct { | ||
ValueList *bool | ||
Comment *bool | ||
} | ||
|
||
type DropNetworkRuleRequest struct { | ||
IfExists *bool | ||
name SchemaObjectIdentifier // required | ||
} | ||
|
||
type ShowNetworkRuleRequest struct { | ||
Like *Like | ||
In *In | ||
StartsWith *string | ||
Limit *LimitFrom | ||
} | ||
|
||
type DescribeNetworkRuleRequest struct { | ||
name SchemaObjectIdentifier // required | ||
} |
Oops, something went wrong.