Skip to content
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

feat: Add network rule to the sdk #2526

Merged
merged 5 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/sdk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type Client struct {
MaskingPolicies MaskingPolicies
MaterializedViews MaterializedViews
NetworkPolicies NetworkPolicies
NetworkRules NetworkRules
NotificationIntegrations NotificationIntegrations
Parameters Parameters
PasswordPolicies PasswordPolicies
Expand Down Expand Up @@ -212,6 +213,7 @@ func (c *Client) initialize() {
c.MaskingPolicies = &maskingPolicies{client: c}
c.MaterializedViews = &materializedViews{client: c}
c.NetworkPolicies = &networkPolicies{client: c}
c.NetworkRules = &networkRules{client: c}
c.NotificationIntegrations = &notificationIntegrations{client: c}
c.Parameters = &parameters{client: c}
c.PasswordPolicies = &passwordPolicies{client: c}
Expand Down
140 changes: 140 additions & 0 deletions pkg/sdk/network_rule_def.go
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"),
)
124 changes: 124 additions & 0 deletions pkg/sdk/network_rule_dto_builders_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions pkg/sdk/network_rule_dto_gen.go
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
}
Loading
Loading