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 row access policy to the SDK #2363

Merged
merged 18 commits into from
Jan 18, 2024
Merged
Changes from 1 commit
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
Next Next commit
Add row access policy definition (WIP)
sfc-gh-asawicki committed Jan 17, 2024
commit e5a383c69a18b4324d1cab696bf31b2be961b8a5
1 change: 1 addition & 0 deletions pkg/sdk/poc/main.go
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@ var definitionMapping = map[string]*generator.Interface{
"event_tables_def.go": sdk.EventTablesDef,
"storage_integration_def.go": sdk.StorageIntegrationDef,
"managed_accounts_def.go": sdk.ManagedAccountsDef,
"row_access_policies_def.go": sdk.RowAccessPoliciesDef,
}

func main() {
87 changes: 87 additions & 0 deletions pkg/sdk/row_access_policies_def.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package sdk

import g "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/poc/generator"

//go:generate go run ./poc/main.go

var rowAccessPolicyDbRow = g.DbStruct("rowAccessPolicyDBRow").
Text("created_on").
Text("name").
Text("database_name").
Text("schema_name").
Text("kind").
Text("owner").
OptionalText("comment").
Text("options").
Bool("owner_role_type")

var rowAccessPolicy = g.PlainStruct("RowAccessPolicy").
Text("CreatedOn").
Text("Name").
Text("DatabaseName").
Text("SchemaName").
Text("Kind").
Text("Owner").
OptionalText("Comment").
Text("Options").
Bool("OwnerRoleType")

var RowAccessPoliciesDef = g.NewInterface(
"RowAccessPolicies",
"RowAccessPolicy",
g.KindOfT[SchemaObjectIdentifier](),
).
CreateOperation(
"https://docs.snowflake.com/en/sql-reference/sql/create-row-access-policy",
g.NewQueryStruct("CreateRowAccessPolicy").
Create().
SQL("ROW ACCESS POLICY").
Name().
WithValidation(g.ValidIdentifier, "name"),
).
AlterOperation(
"https://docs.snowflake.com/en/sql-reference/sql/alter-row-access-policy",
g.NewQueryStruct("AlterRowAccessPolicy").
Drop().
SQL("ROW ACCESS POLICY").
Name().
WithValidation(g.ValidIdentifier, "name"),
).
DropOperation(
"https://docs.snowflake.com/en/sql-reference/sql/drop-row-access-policy",
g.NewQueryStruct("DropRowAccessPolicy").
Drop().
SQL("ROW ACCESS POLICY").
Name().
WithValidation(g.ValidIdentifier, "name"),
).
ShowOperation(
"https://docs.snowflake.com/en/sql-reference/sql/show-row-access-policies",
rowAccessPolicyDbRow,
rowAccessPolicy,
g.NewQueryStruct("ShowRowAccessPolicies").
Show().
SQL("ROW ACCESS POLICIES").
OptionalLike().
OptionalIn(),
).
ShowByIdOperation().
DescribeOperation(
g.DescriptionMappingKindSingleValue,
"https://docs.snowflake.com/en/sql-reference/sql/desc-row-access-policy",
g.DbStruct("describeRowAccessPolicyDBRow").
Field("name", "string").
Field("signature", "string").
Field("return_type", "string").
Field("body", "string"),
g.PlainStruct("RowAccessPolicyDescription").
Field("Name", "string").
Field("Signature", "string").
Field("ReturnType", "string").
Field("Body", "string"),
g.NewQueryStruct("DescribeRowAccessPolicy").
Describe().
SQL("ROW ACCESS POLICY").
Name().
WithValidation(g.ValidIdentifier, "name"),
)