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 API integration to the SDK #2409

Merged
merged 24 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7266fef
Define create for api integration
sfc-gh-asawicki Jan 23, 2024
539600f
Define alter for api integration
sfc-gh-asawicki Jan 23, 2024
72c43cb
Define drop, show, and describe for api integration
sfc-gh-asawicki Jan 23, 2024
9d2d1f9
Add TODO about possible implementation reuse
sfc-gh-asawicki Jan 23, 2024
b66e18c
Generate files
sfc-gh-asawicki Jan 23, 2024
20ab165
Copied show by id impl and mappings from storage integration
sfc-gh-asawicki Jan 23, 2024
85fdec3
Regenerate files after name changes
sfc-gh-asawicki Jan 23, 2024
b84e8bf
Unit test create
sfc-gh-asawicki Jan 23, 2024
0971c28
Unit test describe
sfc-gh-asawicki Jan 23, 2024
fa4c652
Unit test show
sfc-gh-asawicki Jan 23, 2024
107534b
Unit test drop
sfc-gh-asawicki Jan 23, 2024
8978b16
Unit test alter (WIP)
sfc-gh-asawicki Jan 24, 2024
86c43da
Regenerate files
sfc-gh-asawicki Jan 24, 2024
465cd9b
Finish alter unit tests
sfc-gh-asawicki Jan 24, 2024
4798a53
List integration tests to implement
sfc-gh-asawicki Jan 24, 2024
b2b139f
Test basic creation for each api provider
sfc-gh-asawicki Jan 24, 2024
d847236
Test creation with more params for each api provider
sfc-gh-asawicki Jan 24, 2024
29df6cd
Test drop
sfc-gh-asawicki Jan 24, 2024
227a845
Test show
sfc-gh-asawicki Jan 24, 2024
848a205
Test describe
sfc-gh-asawicki Jan 24, 2024
a5d7c15
Test alter
sfc-gh-asawicki Jan 24, 2024
e9eca0e
Add ticket number to TODO
sfc-gh-asawicki Jan 24, 2024
ae13d07
Run make pre-push
sfc-gh-asawicki Jan 24, 2024
ff2f4ef
Fix after review
sfc-gh-asawicki Jan 24, 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
165 changes: 165 additions & 0 deletions pkg/sdk/api_integrations_def.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
package sdk

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

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

type ApiIntegrationAwsApiProviderType string

var (
ApiIntegrationAwsApiGateway ApiIntegrationAwsApiProviderType = "aws_api_gateway"
ApiIntegrationAwsPrivateApiGateway ApiIntegrationAwsApiProviderType = "aws_private_api_gateway"
ApiIntegrationAwsGovApiGateway ApiIntegrationAwsApiProviderType = "aws_gov_api_gateway"
ApiIntegrationAwsGovPrivateApiGateway ApiIntegrationAwsApiProviderType = "aws_gov_private_api_gateway"
)

var ApiIntegrationEndpointPrefixDef = g.NewQueryStruct("ApiIntegrationEndpointPrefix").Text("Path", 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 ApiIntegrationsDef = g.NewInterface(
"ApiIntegrations",
"ApiIntegration",
g.KindOfT[AccountObjectIdentifier](),
).
CreateOperation(
"https://docs.snowflake.com/en/sql-reference/sql/create-api-integration",
g.NewQueryStruct("CreateApiIntegration").
Create().
OrReplace().
SQL("API INTEGRATION").
IfNotExists().
Name().
OptionalQueryStructField(
"AwsApiProviderParams",
g.NewQueryStruct("AwsApiParams").
Assignment("API_PROVIDER", g.KindOfT[ApiIntegrationAwsApiProviderType](), g.ParameterOptions().NoQuotes().Required()).
TextAssignment("API_AWS_ROLE_ARN", g.ParameterOptions().SingleQuotes().Required()).
OptionalTextAssignment("API_KEY", g.ParameterOptions().SingleQuotes()),
g.KeywordOptions(),
).
OptionalQueryStructField(
"AzureApiProviderParams",
g.NewQueryStruct("AzureApiParams").
PredefinedQueryStructField("apiProvider", "string", g.StaticOptions().SQL("API_PROVIDER = azure_api_management")).
TextAssignment("AZURE_TENANT_ID", g.ParameterOptions().SingleQuotes().Required()).
TextAssignment("AZURE_AD_APPLICATION_ID", g.ParameterOptions().SingleQuotes().Required()).
OptionalTextAssignment("API_KEY", g.ParameterOptions().SingleQuotes()),
g.KeywordOptions(),
).
OptionalQueryStructField(
"GoogleApiProviderParams",
g.NewQueryStruct("GoogleApiParams").
PredefinedQueryStructField("apiProvider", "string", g.StaticOptions().SQL("API_PROVIDER = google_api_gateway")).
TextAssignment("GOOGLE_AUDIENCE", g.ParameterOptions().SingleQuotes().Required()),
g.KeywordOptions(),
).
ListAssignment("API_ALLOWED_PREFIXES", "ApiIntegrationEndpointPrefix", g.ParameterOptions().Parentheses().Required()).
ListAssignment("API_BLOCKED_PREFIXES", "ApiIntegrationEndpointPrefix", g.ParameterOptions().Parentheses()).
BooleanAssignment("ENABLED", g.ParameterOptions().Required()).
OptionalComment().
WithValidation(g.ValidIdentifier, "name").
WithValidation(g.ConflictingFields, "IfNotExists", "OrReplace").
WithValidation(g.ExactlyOneValueSet, "AwsApiProviderParams", "AzureApiProviderParams", "GoogleApiProviderParams"),
ApiIntegrationEndpointPrefixDef,
).
AlterOperation(
"https://docs.snowflake.com/en/sql-reference/sql/alter-api-integration",
g.NewQueryStruct("AlterApiIntegration").
Alter().
SQL("API INTEGRATION").
IfExists().
Name().
OptionalQueryStructField(
"Set",
g.NewQueryStruct("ApiIntegrationSet").
OptionalQueryStructField(
"AwsParams",
g.NewQueryStruct("SetAwsApiParams").
OptionalTextAssignment("API_AWS_ROLE_ARN", g.ParameterOptions().SingleQuotes()).
OptionalTextAssignment("API_KEY", g.ParameterOptions().SingleQuotes()).
WithValidation(g.AtLeastOneValueSet, "ApiAwsRoleArn", "ApiKey"),
g.KeywordOptions(),
).
OptionalQueryStructField(
"AzureParams",
g.NewQueryStruct("SetAzureApiParams").
OptionalTextAssignment("AZURE_AD_APPLICATION_ID", g.ParameterOptions().SingleQuotes()).
OptionalTextAssignment("API_KEY", g.ParameterOptions().SingleQuotes()).
WithValidation(g.AtLeastOneValueSet, "AzureAdApplicationId", "ApiKey"),
g.KeywordOptions(),
).
OptionalBooleanAssignment("ENABLED", g.ParameterOptions()).
ListAssignment("API_ALLOWED_PREFIXES", "ApiIntegrationEndpointPrefix", g.ParameterOptions().Parentheses()).
ListAssignment("API_BLOCKED_PREFIXES", "ApiIntegrationEndpointPrefix", g.ParameterOptions().Parentheses()).
OptionalComment().
WithValidation(g.ConflictingFields, "AwsParams", "AzureParams").
WithValidation(g.AtLeastOneValueSet, "AwsParams", "AzureParams", "Enabled", "ApiAllowedPrefixes", "ApiBlockedPrefixes", "Comment"),
g.KeywordOptions().SQL("SET"),
).
OptionalQueryStructField(
"Unset",
g.NewQueryStruct("ApiIntegrationUnset").
OptionalSQL("API_KEY").
OptionalSQL("ENABLED").
OptionalSQL("API_BLOCKED_PREFIXES").
OptionalSQL("COMMENT").
WithValidation(g.AtLeastOneValueSet, "ApiKey", "Enabled", "ApiBlockedPrefixes", "Comment"),
g.ListOptions().NoParentheses().SQL("UNSET"),
).
OptionalSetTags().
OptionalUnsetTags().
WithValidation(g.ValidIdentifier, "name").
WithValidation(g.ConflictingFields, "IfExists", "SetTags").
WithValidation(g.ConflictingFields, "IfExists", "UnsetTags").
WithValidation(g.ExactlyOneValueSet, "Set", "Unset", "SetTags", "UnsetTags"),
).
DropOperation(
"https://docs.snowflake.com/en/sql-reference/sql/drop-integration",
g.NewQueryStruct("DropApiIntegration").
Drop().
SQL("API INTEGRATION").
IfExists().
Name().
WithValidation(g.ValidIdentifier, "name"),
).
ShowOperation(
"https://docs.snowflake.com/en/sql-reference/sql/show-integrations",
g.DbStruct("showApiIntegrationsDbRow").
Text("name").
Text("type").
Text("category").
Bool("enabled").
OptionalText("comment").
Time("created_on"),
g.PlainStruct("ApiIntegration").
Text("Name").
Text("ApiType").
Text("Category").
Bool("Enabled").
Text("Comment").
Time("CreatedOn"),
g.NewQueryStruct("ShowApiIntegrations").
Show().
SQL("API INTEGRATIONS").
OptionalLike(),
).
ShowByIdOperation().
DescribeOperation(
g.DescriptionMappingKindSlice,
"https://docs.snowflake.com/en/sql-reference/sql/desc-integration",
g.DbStruct("descApiIntegrationsDbRow").
Text("property").
Text("property_type").
Text("property_value").
Text("property_default"),
g.PlainStruct("ApiIntegrationProperty").
Text("Name").
Text("Type").
Text("Value").
Text("Default"),
g.NewQueryStruct("DescribeApiIntegration").
Describe().
SQL("API INTEGRATION").
Name().
WithValidation(g.ValidIdentifier, "name"),
)
Loading
Loading