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 notification integration to the SDK #2412

Merged
merged 30 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
88361d9
Start notification integration definitions
sfc-gh-asawicki Jan 24, 2024
18f553c
Define create for notification integration
sfc-gh-asawicki Jan 24, 2024
b64491f
Define alter for notification integration
sfc-gh-asawicki Jan 24, 2024
794d5d8
Define drop, show, and describe for notification integration
sfc-gh-asawicki Jan 24, 2024
c541bff
Generate files
sfc-gh-asawicki Jan 24, 2024
467af3b
Copied implementation of same methods from api integration
sfc-gh-asawicki Jan 24, 2024
cb2a13b
Unit test create notification integration
sfc-gh-asawicki Jan 24, 2024
fa2e499
Unit test drop, show, and describe notification integration
sfc-gh-asawicki Jan 24, 2024
82b5ed9
Unit test alter notification integration
sfc-gh-asawicki Jan 24, 2024
84f033c
Add TODO
sfc-gh-asawicki Jan 24, 2024
7f5cb8c
List integration tests to implement
sfc-gh-asawicki Jan 24, 2024
f9d3718
Implement create test for auto google (skipped)
sfc-gh-asawicki Jan 24, 2024
d9f9e18
Implement create test for auto azure (skipped)
sfc-gh-asawicki Jan 24, 2024
c2ded46
Add TODO for describe
sfc-gh-asawicki Jan 24, 2024
04062de
Test create for amazon push
sfc-gh-asawicki Jan 24, 2024
14c4697
Test create for auto google
sfc-gh-asawicki Jan 24, 2024
6657b76
Test create for auto azure
sfc-gh-asawicki Jan 24, 2024
0969683
Test create for push google (skipped)
sfc-gh-asawicki Jan 24, 2024
12e81d3
Update values in unit test
sfc-gh-asawicki Jan 24, 2024
92a24fb
Test create for push azure (skipped)
sfc-gh-asawicki Jan 24, 2024
399104b
Test create for email
sfc-gh-asawicki Jan 24, 2024
84ac5ae
Add tests for describe, drop, and show
sfc-gh-asawicki Jan 24, 2024
950c5f9
Test set and unset tags
sfc-gh-asawicki Jan 24, 2024
4756793
Skip tests that can't be implemented now
sfc-gh-asawicki Jan 24, 2024
fa38b36
Test alter for email
sfc-gh-asawicki Jan 24, 2024
c148455
Test alter for others
sfc-gh-asawicki Jan 24, 2024
211f670
Adjust TODOs
sfc-gh-asawicki Jan 24, 2024
3442d74
Limit unset only to email notifications
sfc-gh-asawicki Jan 24, 2024
9fef233
Fix after review (renames)
sfc-gh-asawicki Jan 25, 2024
a71877b
Merge branch 'main' into add-notification-integration-to-the-sdk
sfc-gh-asawicki Jan 25, 2024
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
84 changes: 43 additions & 41 deletions pkg/sdk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,47 +38,48 @@ type Client struct {
ReplicationFunctions ReplicationFunctions

// DDL Commands
Accounts Accounts
Alerts Alerts
ApiIntegrations ApiIntegrations
ApplicationPackages ApplicationPackages
ApplicationRoles ApplicationRoles
Applications Applications
Comments Comments
DatabaseRoles DatabaseRoles
Databases Databases
DynamicTables DynamicTables
ExternalTables ExternalTables
EventTables EventTables
FailoverGroups FailoverGroups
FileFormats FileFormats
Functions Functions
Grants Grants
ManagedAccounts ManagedAccounts
MaskingPolicies MaskingPolicies
MaterializedViews MaterializedViews
NetworkPolicies NetworkPolicies
Parameters Parameters
PasswordPolicies PasswordPolicies
Pipes Pipes
Procedures Procedures
ResourceMonitors ResourceMonitors
Roles Roles
RowAccessPolicies RowAccessPolicies
Schemas Schemas
Sequences Sequences
SessionPolicies SessionPolicies
Sessions Sessions
Shares Shares
Stages Stages
StorageIntegrations StorageIntegrations
Streams Streams
Tables Tables
Tags Tags
Tasks Tasks
Users Users
Views Views
Warehouses Warehouses
Accounts Accounts
Alerts Alerts
ApiIntegrations ApiIntegrations
ApplicationPackages ApplicationPackages
ApplicationRoles ApplicationRoles
Applications Applications
Comments Comments
DatabaseRoles DatabaseRoles
Databases Databases
DynamicTables DynamicTables
ExternalTables ExternalTables
EventTables EventTables
FailoverGroups FailoverGroups
FileFormats FileFormats
Functions Functions
Grants Grants
ManagedAccounts ManagedAccounts
MaskingPolicies MaskingPolicies
MaterializedViews MaterializedViews
NetworkPolicies NetworkPolicies
NotificationIntegrations NotificationIntegrations
Parameters Parameters
PasswordPolicies PasswordPolicies
Pipes Pipes
Procedures Procedures
ResourceMonitors ResourceMonitors
Roles Roles
RowAccessPolicies RowAccessPolicies
Schemas Schemas
Sequences Sequences
SessionPolicies SessionPolicies
Sessions Sessions
Shares Shares
Stages Stages
StorageIntegrations StorageIntegrations
Streams Streams
Tables Tables
Tags Tags
Tasks Tasks
Users Users
Views Views
Warehouses Warehouses
}

func (c *Client) GetAccountLocator() string {
Expand Down Expand Up @@ -207,6 +208,7 @@ func (c *Client) initialize() {
c.MaskingPolicies = &maskingPolicies{client: c}
c.MaterializedViews = &materializedViews{client: c}
c.NetworkPolicies = &networkPolicies{client: c}
c.NotificationIntegrations = &notificationIntegrations{client: c}
c.Parameters = &parameters{client: c}
c.PasswordPolicies = &passwordPolicies{client: c}
c.Pipes = &pipes{client: c}
Expand Down
203 changes: 203 additions & 0 deletions pkg/sdk/notification_integrations_def.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
package sdk

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

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

var NotificationIntegrationAllowedRecipientDef = g.NewQueryStruct("NotificationIntegrationAllowedRecipient").
Text("Email", g.KeywordOptions().SingleQuotes().Required())

// TODO [SNOW-1016561]: all integrations reuse almost the same show, drop, and describe. For now we are copying it. Consider reusing in linked issue.
var NotificationIntegrationsDef = g.NewInterface(
"NotificationIntegrations",
"NotificationIntegration",
g.KindOfT[AccountObjectIdentifier](),
).
CreateOperation(
"https://docs.snowflake.com/en/sql-reference/sql/create-notification-integration",
g.NewQueryStruct("CreateNotificationIntegration").
Create().
OrReplace().
SQL("NOTIFICATION INTEGRATION").
IfNotExists().
Name().
BooleanAssignment("ENABLED", g.ParameterOptions().Required()).
OptionalQueryStructField(
"AutomatedDataLoadsParams",
g.NewQueryStruct("AutomatedDataLoadsParams").
PredefinedQueryStructField("notificationType", "string", g.StaticOptions().SQL("TYPE = QUEUE")).
OptionalQueryStructField(
"GoogleAutoParams",
g.NewQueryStruct("GoogleAutoParams").
PredefinedQueryStructField("notificationProvider", "string", g.StaticOptions().SQL("NOTIFICATION_PROVIDER = GCP_PUBSUB")).
TextAssignment("GCP_PUBSUB_SUBSCRIPTION_NAME", g.ParameterOptions().SingleQuotes().Required()),
g.KeywordOptions(),
).
OptionalQueryStructField(
"AzureAutoParams",
g.NewQueryStruct("AzureAutoParams").
PredefinedQueryStructField("notificationProvider", "string", g.StaticOptions().SQL("NOTIFICATION_PROVIDER = AZURE_STORAGE_QUEUE")).
TextAssignment("AZURE_STORAGE_QUEUE_PRIMARY_URI", g.ParameterOptions().SingleQuotes().Required()).
TextAssignment("AZURE_TENANT_ID", g.ParameterOptions().SingleQuotes().Required()),
g.KeywordOptions(),
).
WithValidation(g.ExactlyOneValueSet, "GoogleAutoParams", "AzureAutoParams"),
g.KeywordOptions(),
).
OptionalQueryStructField(
"PushNotificationParams",
g.NewQueryStruct("PushNotificationParams").
PredefinedQueryStructField("direction", "string", g.StaticOptions().SQL("DIRECTION = OUTBOUND")).
PredefinedQueryStructField("notificationType", "string", g.StaticOptions().SQL("TYPE = QUEUE")).
OptionalQueryStructField(
"AmazonPushParams",
g.NewQueryStruct("AmazonPushParams").
PredefinedQueryStructField("notificationProvider", "string", g.StaticOptions().SQL("NOTIFICATION_PROVIDER = AWS_SNS")).
TextAssignment("AWS_SNS_TOPIC_ARN", g.ParameterOptions().SingleQuotes().Required()).
TextAssignment("AWS_SNS_ROLE_ARN", g.ParameterOptions().SingleQuotes().Required()),
g.KeywordOptions(),
).
OptionalQueryStructField(
"GooglePushParams",
g.NewQueryStruct("GooglePushParams").
PredefinedQueryStructField("notificationProvider", "string", g.StaticOptions().SQL("NOTIFICATION_PROVIDER = GCP_PUBSUB")).
TextAssignment("GCP_PUBSUB_TOPIC_NAME", g.ParameterOptions().SingleQuotes().Required()),
g.KeywordOptions(),
).
OptionalQueryStructField(
"AzurePushParams",
g.NewQueryStruct("AzurePushParams").
PredefinedQueryStructField("notificationProvider", "string", g.StaticOptions().SQL("NOTIFICATION_PROVIDER = AZURE_EVENT_GRID")).
TextAssignment("AZURE_EVENT_GRID_TOPIC_ENDPOINT", g.ParameterOptions().SingleQuotes().Required()).
TextAssignment("AZURE_TENANT_ID", g.ParameterOptions().SingleQuotes().Required()),
g.KeywordOptions(),
).
WithValidation(g.ExactlyOneValueSet, "AmazonPushParams", "GooglePushParams", "AzurePushParams"),
g.KeywordOptions(),
).
OptionalQueryStructField(
"EmailParams",
g.NewQueryStruct("EmailParams").
PredefinedQueryStructField("notificationType", "string", g.StaticOptions().SQL("TYPE = EMAIL")).
ListAssignment("ALLOWED_RECIPIENTS", "NotificationIntegrationAllowedRecipient", g.ParameterOptions().Parentheses()),
g.KeywordOptions(),
).
OptionalComment().
WithValidation(g.ValidIdentifier, "name").
WithValidation(g.ConflictingFields, "IfNotExists", "OrReplace").
WithValidation(g.ExactlyOneValueSet, "AutomatedDataLoadsParams", "PushNotificationParams", "EmailParams"),
NotificationIntegrationAllowedRecipientDef,
).
AlterOperation(
"https://docs.snowflake.com/en/sql-reference/sql/alter-notification-integration",
g.NewQueryStruct("AlterNotificationIntegration").
Alter().
SQL("NOTIFICATION INTEGRATION").
IfExists().
Name().
OptionalQueryStructField(
"Set",
g.NewQueryStruct("NotificationIntegrationSet").
OptionalBooleanAssignment("ENABLED", g.ParameterOptions()).
OptionalQueryStructField(
"SetPushParams",
g.NewQueryStruct("SetPushParams").
OptionalQueryStructField(
"SetAmazonPush",
g.NewQueryStruct("SetAmazonPush").
TextAssignment("AWS_SNS_TOPIC_ARN", g.ParameterOptions().SingleQuotes().Required()).
TextAssignment("AWS_SNS_ROLE_ARN", g.ParameterOptions().SingleQuotes().Required()),
g.KeywordOptions(),
).
OptionalQueryStructField(
"SetGooglePush",
g.NewQueryStruct("SetGooglePush").
TextAssignment("GCP_PUBSUB_SUBSCRIPTION_NAME", g.ParameterOptions().SingleQuotes().Required()),
g.KeywordOptions(),
).
OptionalQueryStructField(
"SetAzurePush",
g.NewQueryStruct("SetAzurePush").
TextAssignment("AZURE_STORAGE_QUEUE_PRIMARY_URI", g.ParameterOptions().SingleQuotes().Required()).
TextAssignment("AZURE_TENANT_ID", g.ParameterOptions().SingleQuotes().Required()),
g.KeywordOptions(),
).
WithValidation(g.ExactlyOneValueSet, "SetAmazonPush", "SetGooglePush", "SetAzurePush"),
g.KeywordOptions(),
).
OptionalQueryStructField(
"SetEmailParams",
g.NewQueryStruct("SetEmailParams").
ListAssignment("ALLOWED_RECIPIENTS", "NotificationIntegrationAllowedRecipient", g.ParameterOptions().Parentheses().Required()).
WithValidation(g.ValidateValueSet, "AllowedRecipients"),
g.KeywordOptions(),
).
OptionalComment().
WithValidation(g.ConflictingFields, "SetPushParams", "SetEmailParams").
WithValidation(g.AtLeastOneValueSet, "Enabled", "SetPushParams", "SetEmailParams", "Comment"),
g.KeywordOptions().SQL("SET"),
).
// UNSET is supported only for the email notifications
OptionalQueryStructField(
"UnsetEmailParams",
g.NewQueryStruct("NotificationIntegrationUnsetEmailParams").
OptionalSQL("ALLOWED_RECIPIENTS").
OptionalSQL("COMMENT").
WithValidation(g.AtLeastOneValueSet, "AllowedRecipients", "Comment"),
g.ListOptions().NoParentheses().SQL("UNSET"),
).
OptionalSetTags().
OptionalUnsetTags().
sfc-gh-jcieslak marked this conversation as resolved.
Show resolved Hide resolved
WithValidation(g.ValidIdentifier, "name").
WithValidation(g.ExactlyOneValueSet, "Set", "UnsetEmailParams", "SetTags", "UnsetTags"),
).
DropOperation(
"https://docs.snowflake.com/en/sql-reference/sql/drop-integration",
g.NewQueryStruct("DropNotificationIntegration").
Drop().
SQL("NOTIFICATION INTEGRATION").
IfExists().
Name().
WithValidation(g.ValidIdentifier, "name"),
).
ShowOperation(
"https://docs.snowflake.com/en/sql-reference/sql/show-integrations",
g.DbStruct("showNotificationIntegrationsDbRow").
Text("name").
Text("type").
Text("category").
Bool("enabled").
OptionalText("comment").
Time("created_on"),
g.PlainStruct("NotificationIntegration").
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the same for all integrations and there is no additional metadata?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Properties (from DESC) hold metadata for a given integration. SHOW's are the same

Text("Name").
Text("NotificationType").
Text("Category").
Bool("Enabled").
Text("Comment").
Time("CreatedOn"),
g.NewQueryStruct("ShowNotificationIntegrations").
Show().
SQL("NOTIFICATION INTEGRATIONS").
OptionalLike(),
).
ShowByIdOperation().
DescribeOperation(
g.DescriptionMappingKindSlice,
"https://docs.snowflake.com/en/sql-reference/sql/desc-integration",
g.DbStruct("descNotificationIntegrationsDbRow").
Text("property").
Text("property_type").
Text("property_value").
Text("property_default"),
g.PlainStruct("NotificationIntegrationProperty").
Text("Name").
Text("Type").
Text("Value").
Text("Default"),
g.NewQueryStruct("DescribeNotificationIntegration").
Describe().
SQL("NOTIFICATION INTEGRATION").
Name().
WithValidation(g.ValidIdentifier, "name"),
)
Loading
Loading