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 application to sdk #2350

Merged
merged 10 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
150 changes: 150 additions & 0 deletions pkg/sdk/applications_def.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
package sdk

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

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

/*
* todo: add definition for `CREATE APPLICATION <name> FROM LISTING <listing_name> [ COMMENT = '<string_literal>' ] [ WITH TAG ( <tag_name> = '<tag_value>' [ , ... ] ) ]`
sfc-gh-asawicki marked this conversation as resolved.
Show resolved Hide resolved
*/

var versionAndPatch = g.NewQueryStruct("VersionAndPatch").
TextAssignment("VERSION", g.ParameterOptions().NoEquals().NoQuotes().Required()).
OptionalNumberAssignment("PATCH", g.ParameterOptions().NoEquals().Required())

var applicationVersion = g.NewQueryStruct("ApplicationVersion").
OptionalText("VersionDirectory", g.KeywordOptions().SingleQuotes()).
OptionalQueryStructField("VersionAndPatch", versionAndPatch, g.KeywordOptions().NoQuotes()).
WithValidation(g.ExactlyOneValueSet, "VersionDirectory", "VersionAndPatch")

var applicationSet = g.NewQueryStruct("ApplicationSet").
OptionalTextAssignment("COMMENT", g.ParameterOptions().SingleQuotes()).
OptionalBooleanAssignment("SHARE_EVENTS_WITH_PROVIDER", g.ParameterOptions()).
OptionalBooleanAssignment("DEBUG_MODE", g.ParameterOptions())

var applicationUnset = g.NewQueryStruct("ApplicationUnset").
OptionalSQL("COMMENT").
OptionalSQL("SHARE_EVENTS_WITH_PROVIDER").
OptionalSQL("DEBUG_MODE").
WithValidation(g.ExactlyOneValueSet, "Comment", "ShareEventsWithProvider", "DebugMode")

var applicationReferences = g.NewQueryStruct("ApplicationReferences").ListQueryStructField(
"References",
g.NewQueryStruct("ApplicationReference").Text("Reference", g.KeywordOptions().SingleQuotes()),
g.ParameterOptions().Parentheses().NoEquals(),
)

var ApplicationsDef = g.NewInterface(
"Applications",
"Application",
g.KindOfT[AccountObjectIdentifier](),
).CreateOperation(
"https://docs.snowflake.com/en/sql-reference/sql/create-application",
g.NewQueryStruct("CreateApplication").
sfc-gh-jcieslak marked this conversation as resolved.
Show resolved Hide resolved
Create().
SQL("APPLICATION").
Name().
SQL("FROM APPLICATION PACKAGE").
Identifier("PackageName", g.KindOfT[AccountObjectIdentifier](), g.IdentifierOptions().Required()).
OptionalQueryStructField(
"Version",
applicationVersion,
g.KeywordOptions().SQL("USING"),
).
OptionalBooleanAssignment("DEBUG_MODE", g.ParameterOptions()).
OptionalTextAssignment("COMMENT", g.ParameterOptions().SingleQuotes()).
OptionalTags().
WithValidation(g.ValidIdentifier, "name").
WithValidation(g.ValidIdentifier, "PackageName"),
).DropOperation(
"https://docs.snowflake.com/en/sql-reference/sql/drop-application",
g.NewQueryStruct("DropApplication").
Drop().
SQL("APPLICATION").
IfExists().
Name().
OptionalSQL("CASCADE").
WithValidation(g.ValidIdentifier, "name"),
).AlterOperation(
"https://docs.snowflake.com/en/sql-reference/sql/alter-application",
g.NewQueryStruct("AlterApplication").
Alter().
SQL("APPLICATION").
IfExists().
Name().
OptionalQueryStructField(
"Set",
applicationSet,
g.KeywordOptions().SQL("SET"),
).
OptionalQueryStructField(
"Unset",
applicationUnset,
g.KeywordOptions().SQL("UNSET"),
).
OptionalSQL("UPGRADE").
OptionalQueryStructField(
"UpgradeVersion",
applicationVersion,
g.KeywordOptions().SQL("UPGRADE USING"),
).
OptionalQueryStructField(
"UnsetReferences",
applicationReferences,
g.KeywordOptions().SQL("UNSET REFERENCES"),
).
OptionalSetTags().
OptionalUnsetTags().
WithValidation(g.ValidIdentifier, "name").
sfc-gh-jcieslak marked this conversation as resolved.
Show resolved Hide resolved
WithValidation(g.ExactlyOneValueSet, "Set", "Unset", "Upgrade", "UpgradeVersion", "UnsetReferences", "SetTags", "UnsetTags"),
).ShowOperation(
"https://docs.snowflake.com/en/sql-reference/sql/show-applications",
g.DbStruct("applicationRow").
Field("created_on", "string").
Field("name", "string").
Field("is_default", "string").
Field("is_current", "string").
Field("source_type", "string").
Field("source", "string").
Field("owner", "string").
Field("comment", "string").
Field("version", "string").
Field("label", "string").
Field("patch", "int").
Field("options", "string").
Field("retention_time", "int"),
g.PlainStruct("Application").
Field("CreatedOn", "string").
Field("Name", "string").
Field("IsDefault", "bool").
Field("IsCurrent", "bool").
Field("SourceType", "string").
Field("Source", "string").
Field("Owner", "string").
Field("Comment", "string").
Field("Version", "string").
Field("Label", "string").
Field("Patch", "int").
Field("Options", "string").
Field("RetentionTime", "int"),
g.NewQueryStruct("ShowApplications").
Show().
SQL("APPLICATIONS").
OptionalLike().
OptionalStartsWith().
OptionalLimit(),
).ShowByIdOperation().DescribeOperation(
g.DescriptionMappingKindSlice,
"https://docs.snowflake.com/en/sql-reference/sql/desc-application",
g.DbStruct("applicationPropertyRow").
Field("property", "string").
Field("value", "sql.NullString"),
g.PlainStruct("ApplicationProperty").
Field("Property", "string").
Field("Value", "string"),
g.NewQueryStruct("DescribeApplication").
Describe().
SQL("APPLICATION").
Name().
WithValidation(g.ValidIdentifier, "name"),
)
208 changes: 208 additions & 0 deletions pkg/sdk/applications_dto_builders_gen.go

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

Loading
Loading