From 7266fef59285c1ab6e25b3e957ec9239cc959ab8 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Tue, 23 Jan 2024 16:53:55 +0100 Subject: [PATCH 01/24] Define create for api integration --- pkg/sdk/api_integrations_def.go | 63 +++++++++++++++++++++++++++++++++ pkg/sdk/poc/main.go | 1 + 2 files changed, 64 insertions(+) create mode 100644 pkg/sdk/api_integrations_def.go diff --git a/pkg/sdk/api_integrations_def.go b/pkg/sdk/api_integrations_def.go new file mode 100644 index 0000000000..81c7123afb --- /dev/null +++ b/pkg/sdk/api_integrations_def.go @@ -0,0 +1,63 @@ +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()) + +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( + "S3ApiProviderParams", + g.NewQueryStruct("S3ApiParams"). + 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( + "GCSApiProviderParams", + g.NewQueryStruct("GCSApiParams"). + PredefinedQueryStructField("apiProvider", "string", g.StaticOptions().SQL("STORAGE_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, "S3ApiProviderParams", "AzureApiProviderParams", "GCSApiProviderParams"), + ApiIntegrationEndpointPrefixDef, + ) diff --git a/pkg/sdk/poc/main.go b/pkg/sdk/poc/main.go index 484c2adcf9..1880c38a00 100644 --- a/pkg/sdk/poc/main.go +++ b/pkg/sdk/poc/main.go @@ -34,6 +34,7 @@ var definitionMapping = map[string]*generator.Interface{ "applications_def.go": sdk.ApplicationsDef, "sequences_def.go": sdk.SequencesDef, "materialized_views_def.go": sdk.MaterializedViewsDef, + "api_integrations_def.go": sdk.ApiIntegrationsDef, } func main() { From 539600f091e932ae41bbca3d33a201b8d2b880f2 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Tue, 23 Jan 2024 17:14:09 +0100 Subject: [PATCH 02/24] Define alter for api integration --- pkg/sdk/api_integrations_def.go | 51 +++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/pkg/sdk/api_integrations_def.go b/pkg/sdk/api_integrations_def.go index 81c7123afb..6107993699 100644 --- a/pkg/sdk/api_integrations_def.go +++ b/pkg/sdk/api_integrations_def.go @@ -60,4 +60,55 @@ var ApiIntegrationsDef = g.NewInterface( WithValidation(g.ConflictingFields, "IfNotExists", "OrReplace"). WithValidation(g.ExactlyOneValueSet, "S3ApiProviderParams", "AzureApiProviderParams", "GCSApiProviderParams"), 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( + "S3Params", + g.NewQueryStruct("SetS3ApiParams"). + 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"). + TextAssignment("AZURE_AD_APPLICATION_ID", g.ParameterOptions().SingleQuotes().Required()). + 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, "S3Params", "AzureParams"). + WithValidation(g.AtLeastOneValueSet, "S3Params", "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"), ) From 72c43cb9ac25deb41369c5ae0aebdb7813c49344 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Tue, 23 Jan 2024 17:16:40 +0100 Subject: [PATCH 03/24] Define drop, show, and describe for api integration --- pkg/sdk/api_integrations_def.go | 52 ++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/pkg/sdk/api_integrations_def.go b/pkg/sdk/api_integrations_def.go index 6107993699..e6a8b6875f 100644 --- a/pkg/sdk/api_integrations_def.go +++ b/pkg/sdk/api_integrations_def.go @@ -48,7 +48,7 @@ var ApiIntegrationsDef = g.NewInterface( OptionalQueryStructField( "GCSApiProviderParams", g.NewQueryStruct("GCSApiParams"). - PredefinedQueryStructField("apiProvider", "string", g.StaticOptions().SQL("STORAGE_PROVIDER = google_api_gateway")). + PredefinedQueryStructField("apiProvider", "string", g.StaticOptions().SQL("API_PROVIDER = google_api_gateway")). TextAssignment("GOOGLE_AUDIENCE", g.ParameterOptions().SingleQuotes().Required()), g.KeywordOptions(), ). @@ -111,4 +111,54 @@ var ApiIntegrationsDef = g.NewInterface( 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"), ) From 9d2d1f95ee17fce806e1d6daaacdd127758f4efb Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Tue, 23 Jan 2024 17:29:17 +0100 Subject: [PATCH 04/24] Add TODO about possible implementation reuse --- pkg/sdk/api_integrations_def.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/sdk/api_integrations_def.go b/pkg/sdk/api_integrations_def.go index e6a8b6875f..a975b5a954 100644 --- a/pkg/sdk/api_integrations_def.go +++ b/pkg/sdk/api_integrations_def.go @@ -15,6 +15,7 @@ var ( 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", From b66e18c02dbe2f17672836f18cda9e7c7553f136 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Tue, 23 Jan 2024 17:30:41 +0100 Subject: [PATCH 05/24] Generate files --- pkg/sdk/api_integrations_dto_builders_gen.go | 238 ++++++++++++++++++ pkg/sdk/api_integrations_dto_gen.go | 88 +++++++ pkg/sdk/api_integrations_gen.go | 146 +++++++++++ pkg/sdk/api_integrations_gen_test.go | 227 +++++++++++++++++ pkg/sdk/api_integrations_impl_gen.go | 163 ++++++++++++ pkg/sdk/api_integrations_validations_gen.go | 99 ++++++++ .../api_integrations_gen_integration_test.go | 31 +++ 7 files changed, 992 insertions(+) create mode 100644 pkg/sdk/api_integrations_dto_builders_gen.go create mode 100644 pkg/sdk/api_integrations_dto_gen.go create mode 100644 pkg/sdk/api_integrations_gen.go create mode 100644 pkg/sdk/api_integrations_gen_test.go create mode 100644 pkg/sdk/api_integrations_impl_gen.go create mode 100644 pkg/sdk/api_integrations_validations_gen.go create mode 100644 pkg/sdk/testint/api_integrations_gen_integration_test.go diff --git a/pkg/sdk/api_integrations_dto_builders_gen.go b/pkg/sdk/api_integrations_dto_builders_gen.go new file mode 100644 index 0000000000..17d0093902 --- /dev/null +++ b/pkg/sdk/api_integrations_dto_builders_gen.go @@ -0,0 +1,238 @@ +// Code generated by dto builder generator; DO NOT EDIT. + +package sdk + +import () + +func NewCreateApiIntegrationRequest( + name AccountObjectIdentifier, + ApiAllowedPrefixes []ApiIntegrationEndpointPrefix, + Enabled bool, +) *CreateApiIntegrationRequest { + s := CreateApiIntegrationRequest{} + s.name = name + s.ApiAllowedPrefixes = ApiAllowedPrefixes + s.Enabled = Enabled + return &s +} + +func (s *CreateApiIntegrationRequest) WithOrReplace(OrReplace *bool) *CreateApiIntegrationRequest { + s.OrReplace = OrReplace + return s +} + +func (s *CreateApiIntegrationRequest) WithIfNotExists(IfNotExists *bool) *CreateApiIntegrationRequest { + s.IfNotExists = IfNotExists + return s +} + +func (s *CreateApiIntegrationRequest) WithS3ApiProviderParams(S3ApiProviderParams *S3ApiParamsRequest) *CreateApiIntegrationRequest { + s.S3ApiProviderParams = S3ApiProviderParams + return s +} + +func (s *CreateApiIntegrationRequest) WithAzureApiProviderParams(AzureApiProviderParams *AzureApiParamsRequest) *CreateApiIntegrationRequest { + s.AzureApiProviderParams = AzureApiProviderParams + return s +} + +func (s *CreateApiIntegrationRequest) WithGCSApiProviderParams(GCSApiProviderParams *GCSApiParamsRequest) *CreateApiIntegrationRequest { + s.GCSApiProviderParams = GCSApiProviderParams + return s +} + +func (s *CreateApiIntegrationRequest) WithApiBlockedPrefixes(ApiBlockedPrefixes []ApiIntegrationEndpointPrefix) *CreateApiIntegrationRequest { + s.ApiBlockedPrefixes = ApiBlockedPrefixes + return s +} + +func (s *CreateApiIntegrationRequest) WithComment(Comment *string) *CreateApiIntegrationRequest { + s.Comment = Comment + return s +} + +func NewS3ApiParamsRequest( + ApiProvider ApiIntegrationAwsApiProviderType, + ApiAwsRoleArn string, +) *S3ApiParamsRequest { + s := S3ApiParamsRequest{} + s.ApiProvider = ApiProvider + s.ApiAwsRoleArn = ApiAwsRoleArn + return &s +} + +func (s *S3ApiParamsRequest) WithApiKey(ApiKey *string) *S3ApiParamsRequest { + s.ApiKey = ApiKey + return s +} + +func NewAzureApiParamsRequest( + AzureTenantId string, + AzureAdApplicationId string, +) *AzureApiParamsRequest { + s := AzureApiParamsRequest{} + s.AzureTenantId = AzureTenantId + s.AzureAdApplicationId = AzureAdApplicationId + return &s +} + +func (s *AzureApiParamsRequest) WithApiKey(ApiKey *string) *AzureApiParamsRequest { + s.ApiKey = ApiKey + return s +} + +func NewGCSApiParamsRequest( + GoogleAudience string, +) *GCSApiParamsRequest { + s := GCSApiParamsRequest{} + s.GoogleAudience = GoogleAudience + return &s +} + +func NewAlterApiIntegrationRequest( + name AccountObjectIdentifier, +) *AlterApiIntegrationRequest { + s := AlterApiIntegrationRequest{} + s.name = name + return &s +} + +func (s *AlterApiIntegrationRequest) WithIfExists(IfExists *bool) *AlterApiIntegrationRequest { + s.IfExists = IfExists + return s +} + +func (s *AlterApiIntegrationRequest) WithSet(Set *ApiIntegrationSetRequest) *AlterApiIntegrationRequest { + s.Set = Set + return s +} + +func (s *AlterApiIntegrationRequest) WithUnset(Unset *ApiIntegrationUnsetRequest) *AlterApiIntegrationRequest { + s.Unset = Unset + return s +} + +func (s *AlterApiIntegrationRequest) WithSetTags(SetTags []TagAssociation) *AlterApiIntegrationRequest { + s.SetTags = SetTags + return s +} + +func (s *AlterApiIntegrationRequest) WithUnsetTags(UnsetTags []ObjectIdentifier) *AlterApiIntegrationRequest { + s.UnsetTags = UnsetTags + return s +} + +func NewApiIntegrationSetRequest() *ApiIntegrationSetRequest { + return &ApiIntegrationSetRequest{} +} + +func (s *ApiIntegrationSetRequest) WithS3Params(S3Params *SetS3ApiParamsRequest) *ApiIntegrationSetRequest { + s.S3Params = S3Params + return s +} + +func (s *ApiIntegrationSetRequest) WithAzureParams(AzureParams *SetAzureApiParamsRequest) *ApiIntegrationSetRequest { + s.AzureParams = AzureParams + return s +} + +func (s *ApiIntegrationSetRequest) WithEnabled(Enabled *bool) *ApiIntegrationSetRequest { + s.Enabled = Enabled + return s +} + +func (s *ApiIntegrationSetRequest) WithApiAllowedPrefixes(ApiAllowedPrefixes []ApiIntegrationEndpointPrefix) *ApiIntegrationSetRequest { + s.ApiAllowedPrefixes = ApiAllowedPrefixes + return s +} + +func (s *ApiIntegrationSetRequest) WithApiBlockedPrefixes(ApiBlockedPrefixes []ApiIntegrationEndpointPrefix) *ApiIntegrationSetRequest { + s.ApiBlockedPrefixes = ApiBlockedPrefixes + return s +} + +func (s *ApiIntegrationSetRequest) WithComment(Comment *string) *ApiIntegrationSetRequest { + s.Comment = Comment + return s +} + +func NewSetS3ApiParamsRequest() *SetS3ApiParamsRequest { + return &SetS3ApiParamsRequest{} +} + +func (s *SetS3ApiParamsRequest) WithApiAwsRoleArn(ApiAwsRoleArn *string) *SetS3ApiParamsRequest { + s.ApiAwsRoleArn = ApiAwsRoleArn + return s +} + +func (s *SetS3ApiParamsRequest) WithApiKey(ApiKey *string) *SetS3ApiParamsRequest { + s.ApiKey = ApiKey + return s +} + +func NewSetAzureApiParamsRequest( + AzureAdApplicationId string, +) *SetAzureApiParamsRequest { + s := SetAzureApiParamsRequest{} + s.AzureAdApplicationId = AzureAdApplicationId + return &s +} + +func (s *SetAzureApiParamsRequest) WithApiKey(ApiKey *string) *SetAzureApiParamsRequest { + s.ApiKey = ApiKey + return s +} + +func NewApiIntegrationUnsetRequest() *ApiIntegrationUnsetRequest { + return &ApiIntegrationUnsetRequest{} +} + +func (s *ApiIntegrationUnsetRequest) WithApiKey(ApiKey *bool) *ApiIntegrationUnsetRequest { + s.ApiKey = ApiKey + return s +} + +func (s *ApiIntegrationUnsetRequest) WithEnabled(Enabled *bool) *ApiIntegrationUnsetRequest { + s.Enabled = Enabled + return s +} + +func (s *ApiIntegrationUnsetRequest) WithApiBlockedPrefixes(ApiBlockedPrefixes *bool) *ApiIntegrationUnsetRequest { + s.ApiBlockedPrefixes = ApiBlockedPrefixes + return s +} + +func (s *ApiIntegrationUnsetRequest) WithComment(Comment *bool) *ApiIntegrationUnsetRequest { + s.Comment = Comment + return s +} + +func NewDropApiIntegrationRequest( + name AccountObjectIdentifier, +) *DropApiIntegrationRequest { + s := DropApiIntegrationRequest{} + s.name = name + return &s +} + +func (s *DropApiIntegrationRequest) WithIfExists(IfExists *bool) *DropApiIntegrationRequest { + s.IfExists = IfExists + return s +} + +func NewShowApiIntegrationRequest() *ShowApiIntegrationRequest { + return &ShowApiIntegrationRequest{} +} + +func (s *ShowApiIntegrationRequest) WithLike(Like *Like) *ShowApiIntegrationRequest { + s.Like = Like + return s +} + +func NewDescribeApiIntegrationRequest( + name AccountObjectIdentifier, +) *DescribeApiIntegrationRequest { + s := DescribeApiIntegrationRequest{} + s.name = name + return &s +} diff --git a/pkg/sdk/api_integrations_dto_gen.go b/pkg/sdk/api_integrations_dto_gen.go new file mode 100644 index 0000000000..0f74a8720c --- /dev/null +++ b/pkg/sdk/api_integrations_dto_gen.go @@ -0,0 +1,88 @@ +package sdk + +//go:generate go run ./dto-builder-generator/main.go + +var ( + _ optionsProvider[CreateApiIntegrationOptions] = new(CreateApiIntegrationRequest) + _ optionsProvider[AlterApiIntegrationOptions] = new(AlterApiIntegrationRequest) + _ optionsProvider[DropApiIntegrationOptions] = new(DropApiIntegrationRequest) + _ optionsProvider[ShowApiIntegrationOptions] = new(ShowApiIntegrationRequest) + _ optionsProvider[DescribeApiIntegrationOptions] = new(DescribeApiIntegrationRequest) +) + +type CreateApiIntegrationRequest struct { + OrReplace *bool + IfNotExists *bool + name AccountObjectIdentifier // required + S3ApiProviderParams *S3ApiParamsRequest + AzureApiProviderParams *AzureApiParamsRequest + GCSApiProviderParams *GCSApiParamsRequest + ApiAllowedPrefixes []ApiIntegrationEndpointPrefix // required + ApiBlockedPrefixes []ApiIntegrationEndpointPrefix + Enabled bool // required + Comment *string +} + +type S3ApiParamsRequest struct { + ApiProvider ApiIntegrationAwsApiProviderType // required + ApiAwsRoleArn string // required + ApiKey *string +} + +type AzureApiParamsRequest struct { + AzureTenantId string // required + AzureAdApplicationId string // required + ApiKey *string +} + +type GCSApiParamsRequest struct { + GoogleAudience string // required +} + +type AlterApiIntegrationRequest struct { + IfExists *bool + name AccountObjectIdentifier // required + Set *ApiIntegrationSetRequest + Unset *ApiIntegrationUnsetRequest + SetTags []TagAssociation + UnsetTags []ObjectIdentifier +} + +type ApiIntegrationSetRequest struct { + S3Params *SetS3ApiParamsRequest + AzureParams *SetAzureApiParamsRequest + Enabled *bool + ApiAllowedPrefixes []ApiIntegrationEndpointPrefix + ApiBlockedPrefixes []ApiIntegrationEndpointPrefix + Comment *string +} + +type SetS3ApiParamsRequest struct { + ApiAwsRoleArn *string + ApiKey *string +} + +type SetAzureApiParamsRequest struct { + AzureAdApplicationId string // required + ApiKey *string +} + +type ApiIntegrationUnsetRequest struct { + ApiKey *bool + Enabled *bool + ApiBlockedPrefixes *bool + Comment *bool +} + +type DropApiIntegrationRequest struct { + IfExists *bool + name AccountObjectIdentifier // required +} + +type ShowApiIntegrationRequest struct { + Like *Like +} + +type DescribeApiIntegrationRequest struct { + name AccountObjectIdentifier // required +} diff --git a/pkg/sdk/api_integrations_gen.go b/pkg/sdk/api_integrations_gen.go new file mode 100644 index 0000000000..397f8c9875 --- /dev/null +++ b/pkg/sdk/api_integrations_gen.go @@ -0,0 +1,146 @@ +package sdk + +import ( + "context" + "database/sql" + "time" +) + +type ApiIntegrations interface { + Create(ctx context.Context, request *CreateApiIntegrationRequest) error + Alter(ctx context.Context, request *AlterApiIntegrationRequest) error + Drop(ctx context.Context, request *DropApiIntegrationRequest) error + Show(ctx context.Context, request *ShowApiIntegrationRequest) ([]ApiIntegration, error) + ShowByID(ctx context.Context, id AccountObjectIdentifier) (*ApiIntegration, error) + Describe(ctx context.Context, id AccountObjectIdentifier) ([]ApiIntegrationProperty, error) +} + +// CreateApiIntegrationOptions is based on https://docs.snowflake.com/en/sql-reference/sql/create-api-integration. +type CreateApiIntegrationOptions struct { + create bool `ddl:"static" sql:"CREATE"` + OrReplace *bool `ddl:"keyword" sql:"OR REPLACE"` + apiIntegration bool `ddl:"static" sql:"API INTEGRATION"` + IfNotExists *bool `ddl:"keyword" sql:"IF NOT EXISTS"` + name AccountObjectIdentifier `ddl:"identifier"` + S3ApiProviderParams *S3ApiParams `ddl:"keyword"` + AzureApiProviderParams *AzureApiParams `ddl:"keyword"` + GCSApiProviderParams *GCSApiParams `ddl:"keyword"` + ApiAllowedPrefixes []ApiIntegrationEndpointPrefix `ddl:"parameter,parentheses" sql:"API_ALLOWED_PREFIXES"` + ApiBlockedPrefixes []ApiIntegrationEndpointPrefix `ddl:"parameter,parentheses" sql:"API_BLOCKED_PREFIXES"` + Enabled bool `ddl:"parameter" sql:"ENABLED"` + Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"` +} + +type ApiIntegrationEndpointPrefix struct { + Path string `ddl:"keyword,single_quotes"` +} + +type S3ApiParams struct { + ApiProvider ApiIntegrationAwsApiProviderType `ddl:"parameter,no_quotes" sql:"API_PROVIDER"` + ApiAwsRoleArn string `ddl:"parameter,single_quotes" sql:"API_AWS_ROLE_ARN"` + ApiKey *string `ddl:"parameter,single_quotes" sql:"API_KEY"` +} + +type AzureApiParams struct { + apiProvider string `ddl:"static" sql:"API_PROVIDER = azure_api_management"` + AzureTenantId string `ddl:"parameter,single_quotes" sql:"AZURE_TENANT_ID"` + AzureAdApplicationId string `ddl:"parameter,single_quotes" sql:"AZURE_AD_APPLICATION_ID"` + ApiKey *string `ddl:"parameter,single_quotes" sql:"API_KEY"` +} + +type GCSApiParams struct { + apiProvider string `ddl:"static" sql:"API_PROVIDER = google_api_gateway"` + GoogleAudience string `ddl:"parameter,single_quotes" sql:"GOOGLE_AUDIENCE"` +} + +// AlterApiIntegrationOptions is based on https://docs.snowflake.com/en/sql-reference/sql/alter-api-integration. +type AlterApiIntegrationOptions struct { + alter bool `ddl:"static" sql:"ALTER"` + apiIntegration bool `ddl:"static" sql:"API INTEGRATION"` + IfExists *bool `ddl:"keyword" sql:"IF EXISTS"` + name AccountObjectIdentifier `ddl:"identifier"` + Set *ApiIntegrationSet `ddl:"keyword" sql:"SET"` + Unset *ApiIntegrationUnset `ddl:"list,no_parentheses" sql:"UNSET"` + SetTags []TagAssociation `ddl:"keyword" sql:"SET TAG"` + UnsetTags []ObjectIdentifier `ddl:"keyword" sql:"UNSET TAG"` +} + +type ApiIntegrationSet struct { + S3Params *SetS3ApiParams `ddl:"keyword"` + AzureParams *SetAzureApiParams `ddl:"keyword"` + Enabled *bool `ddl:"parameter" sql:"ENABLED"` + ApiAllowedPrefixes []ApiIntegrationEndpointPrefix `ddl:"parameter,parentheses" sql:"API_ALLOWED_PREFIXES"` + ApiBlockedPrefixes []ApiIntegrationEndpointPrefix `ddl:"parameter,parentheses" sql:"API_BLOCKED_PREFIXES"` + Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"` +} + +type SetS3ApiParams struct { + ApiAwsRoleArn *string `ddl:"parameter,single_quotes" sql:"API_AWS_ROLE_ARN"` + ApiKey *string `ddl:"parameter,single_quotes" sql:"API_KEY"` +} + +type SetAzureApiParams struct { + AzureAdApplicationId string `ddl:"parameter,single_quotes" sql:"AZURE_AD_APPLICATION_ID"` + ApiKey *string `ddl:"parameter,single_quotes" sql:"API_KEY"` +} + +type ApiIntegrationUnset struct { + ApiKey *bool `ddl:"keyword" sql:"API_KEY"` + Enabled *bool `ddl:"keyword" sql:"ENABLED"` + ApiBlockedPrefixes *bool `ddl:"keyword" sql:"API_BLOCKED_PREFIXES"` + Comment *bool `ddl:"keyword" sql:"COMMENT"` +} + +// DropApiIntegrationOptions is based on https://docs.snowflake.com/en/sql-reference/sql/drop-integration. +type DropApiIntegrationOptions struct { + drop bool `ddl:"static" sql:"DROP"` + apiIntegration bool `ddl:"static" sql:"API INTEGRATION"` + IfExists *bool `ddl:"keyword" sql:"IF EXISTS"` + name AccountObjectIdentifier `ddl:"identifier"` +} + +// ShowApiIntegrationOptions is based on https://docs.snowflake.com/en/sql-reference/sql/show-integrations. +type ShowApiIntegrationOptions struct { + show bool `ddl:"static" sql:"SHOW"` + apiIntegrations bool `ddl:"static" sql:"API INTEGRATIONS"` + Like *Like `ddl:"keyword" sql:"LIKE"` +} + +type showApiIntegrationsDbRow struct { + Name string `db:"name"` + Type string `db:"type"` + Category string `db:"category"` + Enabled bool `db:"enabled"` + Comment sql.NullString `db:"comment"` + CreatedOn time.Time `db:"created_on"` +} + +type ApiIntegration struct { + Name string + ApiType string + Category string + Enabled bool + Comment string + CreatedOn time.Time +} + +// DescribeApiIntegrationOptions is based on https://docs.snowflake.com/en/sql-reference/sql/desc-integration. +type DescribeApiIntegrationOptions struct { + describe bool `ddl:"static" sql:"DESCRIBE"` + apiIntegration bool `ddl:"static" sql:"API INTEGRATION"` + name AccountObjectIdentifier `ddl:"identifier"` +} + +type descApiIntegrationsDbRow struct { + Property string `db:"property"` + PropertyType string `db:"property_type"` + PropertyValue string `db:"property_value"` + PropertyDefault string `db:"property_default"` +} + +type ApiIntegrationProperty struct { + Name string + Type string + Value string + Default string +} diff --git a/pkg/sdk/api_integrations_gen_test.go b/pkg/sdk/api_integrations_gen_test.go new file mode 100644 index 0000000000..d443b75b48 --- /dev/null +++ b/pkg/sdk/api_integrations_gen_test.go @@ -0,0 +1,227 @@ +package sdk + +import "testing" + +func TestApiIntegrations_Create(t *testing.T) { + id := RandomAccountObjectIdentifier() + + // Minimal valid CreateApiIntegrationOptions + defaultOpts := func() *CreateApiIntegrationOptions { + return &CreateApiIntegrationOptions{ + name: id, + } + } + + t.Run("validation: nil options", func(t *testing.T) { + var opts *CreateApiIntegrationOptions = nil + assertOptsInvalidJoinedErrors(t, opts, ErrNilOptions) + }) + + t.Run("validation: valid identifier for [opts.name]", func(t *testing.T) { + opts := defaultOpts() + // TODO: fill me + assertOptsInvalidJoinedErrors(t, opts, ErrInvalidObjectIdentifier) + }) + + t.Run("validation: conflicting fields for [opts.IfNotExists opts.OrReplace]", func(t *testing.T) { + opts := defaultOpts() + // TODO: fill me + assertOptsInvalidJoinedErrors(t, opts, errOneOf("CreateApiIntegrationOptions", "IfNotExists", "OrReplace")) + }) + + t.Run("validation: exactly one field from [opts.S3ApiProviderParams opts.AzureApiProviderParams opts.GCSApiProviderParams] should be present", func(t *testing.T) { + opts := defaultOpts() + // TODO: fill me + assertOptsInvalidJoinedErrors(t, opts, errExactlyOneOf("CreateApiIntegrationOptions", "S3ApiProviderParams", "AzureApiProviderParams", "GCSApiProviderParams")) + }) + + t.Run("basic", func(t *testing.T) { + opts := defaultOpts() + // TODO: fill me + assertOptsValidAndSQLEquals(t, opts, "TODO: fill me") + }) + + t.Run("all options", func(t *testing.T) { + opts := defaultOpts() + // TODO: fill me + assertOptsValidAndSQLEquals(t, opts, "TODO: fill me") + }) +} + +func TestApiIntegrations_Alter(t *testing.T) { + id := RandomAccountObjectIdentifier() + + // Minimal valid AlterApiIntegrationOptions + defaultOpts := func() *AlterApiIntegrationOptions { + return &AlterApiIntegrationOptions{ + name: id, + } + } + + t.Run("validation: nil options", func(t *testing.T) { + var opts *AlterApiIntegrationOptions = nil + assertOptsInvalidJoinedErrors(t, opts, ErrNilOptions) + }) + + t.Run("validation: valid identifier for [opts.name]", func(t *testing.T) { + opts := defaultOpts() + // TODO: fill me + assertOptsInvalidJoinedErrors(t, opts, ErrInvalidObjectIdentifier) + }) + + t.Run("validation: conflicting fields for [opts.IfExists opts.SetTags]", func(t *testing.T) { + opts := defaultOpts() + // TODO: fill me + assertOptsInvalidJoinedErrors(t, opts, errOneOf("AlterApiIntegrationOptions", "IfExists", "SetTags")) + }) + + t.Run("validation: conflicting fields for [opts.IfExists opts.UnsetTags]", func(t *testing.T) { + opts := defaultOpts() + // TODO: fill me + assertOptsInvalidJoinedErrors(t, opts, errOneOf("AlterApiIntegrationOptions", "IfExists", "UnsetTags")) + }) + + t.Run("validation: exactly one field from [opts.Set opts.Unset opts.SetTags opts.UnsetTags] should be present", func(t *testing.T) { + opts := defaultOpts() + // TODO: fill me + assertOptsInvalidJoinedErrors(t, opts, errExactlyOneOf("AlterApiIntegrationOptions", "Set", "Unset", "SetTags", "UnsetTags")) + }) + + t.Run("validation: conflicting fields for [opts.Set.S3Params opts.Set.AzureParams]", func(t *testing.T) { + opts := defaultOpts() + // TODO: fill me + assertOptsInvalidJoinedErrors(t, opts, errOneOf("AlterApiIntegrationOptions.Set", "S3Params", "AzureParams")) + }) + + t.Run("validation: at least one of the fields [opts.Set.S3Params opts.Set.AzureParams opts.Set.Enabled opts.Set.ApiAllowedPrefixes opts.Set.ApiBlockedPrefixes opts.Set.Comment] should be set", func(t *testing.T) { + opts := defaultOpts() + // TODO: fill me + assertOptsInvalidJoinedErrors(t, opts, errAtLeastOneOf("AlterApiIntegrationOptions.Set", "S3Params", "AzureParams", "Enabled", "ApiAllowedPrefixes", "ApiBlockedPrefixes", "Comment")) + }) + + t.Run("validation: at least one of the fields [opts.Set.S3Params.ApiAwsRoleArn opts.Set.S3Params.ApiKey] should be set", func(t *testing.T) { + opts := defaultOpts() + // TODO: fill me + assertOptsInvalidJoinedErrors(t, opts, errAtLeastOneOf("AlterApiIntegrationOptions.Set.S3Params", "ApiAwsRoleArn", "ApiKey")) + }) + + t.Run("validation: at least one of the fields [opts.Set.AzureParams.AzureAdApplicationId opts.Set.AzureParams.ApiKey] should be set", func(t *testing.T) { + opts := defaultOpts() + // TODO: fill me + assertOptsInvalidJoinedErrors(t, opts, errAtLeastOneOf("AlterApiIntegrationOptions.Set.AzureParams", "AzureAdApplicationId", "ApiKey")) + }) + + t.Run("validation: at least one of the fields [opts.Unset.ApiKey opts.Unset.Enabled opts.Unset.ApiBlockedPrefixes opts.Unset.Comment] should be set", func(t *testing.T) { + opts := defaultOpts() + // TODO: fill me + assertOptsInvalidJoinedErrors(t, opts, errAtLeastOneOf("AlterApiIntegrationOptions.Unset", "ApiKey", "Enabled", "ApiBlockedPrefixes", "Comment")) + }) + + t.Run("basic", func(t *testing.T) { + opts := defaultOpts() + // TODO: fill me + assertOptsValidAndSQLEquals(t, opts, "TODO: fill me") + }) + + t.Run("all options", func(t *testing.T) { + opts := defaultOpts() + // TODO: fill me + assertOptsValidAndSQLEquals(t, opts, "TODO: fill me") + }) +} + +func TestApiIntegrations_Drop(t *testing.T) { + id := RandomAccountObjectIdentifier() + + // Minimal valid DropApiIntegrationOptions + defaultOpts := func() *DropApiIntegrationOptions { + return &DropApiIntegrationOptions{ + name: id, + } + } + + t.Run("validation: nil options", func(t *testing.T) { + var opts *DropApiIntegrationOptions = nil + assertOptsInvalidJoinedErrors(t, opts, ErrNilOptions) + }) + + t.Run("validation: valid identifier for [opts.name]", func(t *testing.T) { + opts := defaultOpts() + // TODO: fill me + assertOptsInvalidJoinedErrors(t, opts, ErrInvalidObjectIdentifier) + }) + + t.Run("basic", func(t *testing.T) { + opts := defaultOpts() + // TODO: fill me + assertOptsValidAndSQLEquals(t, opts, "TODO: fill me") + }) + + t.Run("all options", func(t *testing.T) { + opts := defaultOpts() + // TODO: fill me + assertOptsValidAndSQLEquals(t, opts, "TODO: fill me") + }) +} + +func TestApiIntegrations_Show(t *testing.T) { + id := RandomAccountObjectIdentifier() + + // Minimal valid ShowApiIntegrationOptions + defaultOpts := func() *ShowApiIntegrationOptions { + return &ShowApiIntegrationOptions{ + name: id, + } + } + + t.Run("validation: nil options", func(t *testing.T) { + var opts *ShowApiIntegrationOptions = nil + assertOptsInvalidJoinedErrors(t, opts, ErrNilOptions) + }) + + t.Run("basic", func(t *testing.T) { + opts := defaultOpts() + // TODO: fill me + assertOptsValidAndSQLEquals(t, opts, "TODO: fill me") + }) + + t.Run("all options", func(t *testing.T) { + opts := defaultOpts() + // TODO: fill me + assertOptsValidAndSQLEquals(t, opts, "TODO: fill me") + }) +} + +func TestApiIntegrations_Describe(t *testing.T) { + id := RandomAccountObjectIdentifier() + + // Minimal valid DescribeApiIntegrationOptions + defaultOpts := func() *DescribeApiIntegrationOptions { + return &DescribeApiIntegrationOptions{ + name: id, + } + } + + t.Run("validation: nil options", func(t *testing.T) { + var opts *DescribeApiIntegrationOptions = nil + assertOptsInvalidJoinedErrors(t, opts, ErrNilOptions) + }) + + t.Run("validation: valid identifier for [opts.name]", func(t *testing.T) { + opts := defaultOpts() + // TODO: fill me + assertOptsInvalidJoinedErrors(t, opts, ErrInvalidObjectIdentifier) + }) + + t.Run("basic", func(t *testing.T) { + opts := defaultOpts() + // TODO: fill me + assertOptsValidAndSQLEquals(t, opts, "TODO: fill me") + }) + + t.Run("all options", func(t *testing.T) { + opts := defaultOpts() + // TODO: fill me + assertOptsValidAndSQLEquals(t, opts, "TODO: fill me") + }) +} diff --git a/pkg/sdk/api_integrations_impl_gen.go b/pkg/sdk/api_integrations_impl_gen.go new file mode 100644 index 0000000000..abc00a7746 --- /dev/null +++ b/pkg/sdk/api_integrations_impl_gen.go @@ -0,0 +1,163 @@ +package sdk + +import ( + "context" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/collections" +) + +var _ ApiIntegrations = (*apiIntegrations)(nil) + +type apiIntegrations struct { + client *Client +} + +func (v *apiIntegrations) Create(ctx context.Context, request *CreateApiIntegrationRequest) error { + opts := request.toOpts() + return validateAndExec(v.client, ctx, opts) +} + +func (v *apiIntegrations) Alter(ctx context.Context, request *AlterApiIntegrationRequest) error { + opts := request.toOpts() + return validateAndExec(v.client, ctx, opts) +} + +func (v *apiIntegrations) Drop(ctx context.Context, request *DropApiIntegrationRequest) error { + opts := request.toOpts() + return validateAndExec(v.client, ctx, opts) +} + +func (v *apiIntegrations) Show(ctx context.Context, request *ShowApiIntegrationRequest) ([]ApiIntegration, error) { + opts := request.toOpts() + dbRows, err := validateAndQuery[showApiIntegrationsDbRow](v.client, ctx, opts) + if err != nil { + return nil, err + } + resultList := convertRows[showApiIntegrationsDbRow, ApiIntegration](dbRows) + return resultList, nil +} + +func (v *apiIntegrations) ShowByID(ctx context.Context, id AccountObjectIdentifier) (*ApiIntegration, error) { + // TODO: adjust request if e.g. LIKE is supported for the resource + apiIntegrations, err := v.Show(ctx, NewShowApiIntegrationRequest()) + if err != nil { + return nil, err + } + return collections.FindOne(apiIntegrations, func(r ApiIntegration) bool { return r.Name == id.Name() }) +} + +func (v *apiIntegrations) Describe(ctx context.Context, id AccountObjectIdentifier) ([]ApiIntegrationProperty, error) { + opts := &DescribeApiIntegrationOptions{ + name: id, + } + rows, err := validateAndQuery[descApiIntegrationsDbRow](v.client, ctx, opts) + if err != nil { + return nil, err + } + return convertRows[descApiIntegrationsDbRow, ApiIntegrationProperty](rows), nil +} + +func (r *CreateApiIntegrationRequest) toOpts() *CreateApiIntegrationOptions { + opts := &CreateApiIntegrationOptions{ + OrReplace: r.OrReplace, + IfNotExists: r.IfNotExists, + name: r.name, + + ApiAllowedPrefixes: r.ApiAllowedPrefixes, + ApiBlockedPrefixes: r.ApiBlockedPrefixes, + Enabled: r.Enabled, + Comment: r.Comment, + } + if r.S3ApiProviderParams != nil { + opts.S3ApiProviderParams = &S3ApiParams{ + ApiProvider: r.S3ApiProviderParams.ApiProvider, + ApiAwsRoleArn: r.S3ApiProviderParams.ApiAwsRoleArn, + ApiKey: r.S3ApiProviderParams.ApiKey, + } + } + if r.AzureApiProviderParams != nil { + opts.AzureApiProviderParams = &AzureApiParams{ + AzureTenantId: r.AzureApiProviderParams.AzureTenantId, + AzureAdApplicationId: r.AzureApiProviderParams.AzureAdApplicationId, + ApiKey: r.AzureApiProviderParams.ApiKey, + } + } + if r.GCSApiProviderParams != nil { + opts.GCSApiProviderParams = &GCSApiParams{ + GoogleAudience: r.GCSApiProviderParams.GoogleAudience, + } + } + return opts +} + +func (r *AlterApiIntegrationRequest) toOpts() *AlterApiIntegrationOptions { + opts := &AlterApiIntegrationOptions{ + IfExists: r.IfExists, + name: r.name, + + SetTags: r.SetTags, + UnsetTags: r.UnsetTags, + } + if r.Set != nil { + opts.Set = &ApiIntegrationSet{ + + Enabled: r.Set.Enabled, + ApiAllowedPrefixes: r.Set.ApiAllowedPrefixes, + ApiBlockedPrefixes: r.Set.ApiBlockedPrefixes, + Comment: r.Set.Comment, + } + if r.Set.S3Params != nil { + opts.Set.S3Params = &SetS3ApiParams{ + ApiAwsRoleArn: r.Set.S3Params.ApiAwsRoleArn, + ApiKey: r.Set.S3Params.ApiKey, + } + } + if r.Set.AzureParams != nil { + opts.Set.AzureParams = &SetAzureApiParams{ + AzureAdApplicationId: r.Set.AzureParams.AzureAdApplicationId, + ApiKey: r.Set.AzureParams.ApiKey, + } + } + } + if r.Unset != nil { + opts.Unset = &ApiIntegrationUnset{ + ApiKey: r.Unset.ApiKey, + Enabled: r.Unset.Enabled, + ApiBlockedPrefixes: r.Unset.ApiBlockedPrefixes, + Comment: r.Unset.Comment, + } + } + return opts +} + +func (r *DropApiIntegrationRequest) toOpts() *DropApiIntegrationOptions { + opts := &DropApiIntegrationOptions{ + IfExists: r.IfExists, + name: r.name, + } + return opts +} + +func (r *ShowApiIntegrationRequest) toOpts() *ShowApiIntegrationOptions { + opts := &ShowApiIntegrationOptions{ + Like: r.Like, + } + return opts +} + +func (r showApiIntegrationsDbRow) convert() *ApiIntegration { + // TODO: Mapping + return &ApiIntegration{} +} + +func (r *DescribeApiIntegrationRequest) toOpts() *DescribeApiIntegrationOptions { + opts := &DescribeApiIntegrationOptions{ + name: r.name, + } + return opts +} + +func (r descApiIntegrationsDbRow) convert() *ApiIntegrationProperty { + // TODO: Mapping + return &ApiIntegrationProperty{} +} diff --git a/pkg/sdk/api_integrations_validations_gen.go b/pkg/sdk/api_integrations_validations_gen.go new file mode 100644 index 0000000000..e575da5bf5 --- /dev/null +++ b/pkg/sdk/api_integrations_validations_gen.go @@ -0,0 +1,99 @@ +package sdk + +var ( + _ validatable = new(CreateApiIntegrationOptions) + _ validatable = new(AlterApiIntegrationOptions) + _ validatable = new(DropApiIntegrationOptions) + _ validatable = new(ShowApiIntegrationOptions) + _ validatable = new(DescribeApiIntegrationOptions) +) + +func (opts *CreateApiIntegrationOptions) validate() error { + if opts == nil { + return ErrNilOptions + } + var errs []error + if !ValidObjectIdentifier(opts.name) { + errs = append(errs, ErrInvalidObjectIdentifier) + } + if everyValueSet(opts.IfNotExists, opts.OrReplace) { + errs = append(errs, errOneOf("CreateApiIntegrationOptions", "IfNotExists", "OrReplace")) + } + if !exactlyOneValueSet(opts.S3ApiProviderParams, opts.AzureApiProviderParams, opts.GCSApiProviderParams) { + errs = append(errs, errExactlyOneOf("CreateApiIntegrationOptions", "S3ApiProviderParams", "AzureApiProviderParams", "GCSApiProviderParams")) + } + return JoinErrors(errs...) +} + +func (opts *AlterApiIntegrationOptions) validate() error { + if opts == nil { + return ErrNilOptions + } + var errs []error + if !ValidObjectIdentifier(opts.name) { + errs = append(errs, ErrInvalidObjectIdentifier) + } + if everyValueSet(opts.IfExists, opts.SetTags) { + errs = append(errs, errOneOf("AlterApiIntegrationOptions", "IfExists", "SetTags")) + } + if everyValueSet(opts.IfExists, opts.UnsetTags) { + errs = append(errs, errOneOf("AlterApiIntegrationOptions", "IfExists", "UnsetTags")) + } + if !exactlyOneValueSet(opts.Set, opts.Unset, opts.SetTags, opts.UnsetTags) { + errs = append(errs, errExactlyOneOf("AlterApiIntegrationOptions", "Set", "Unset", "SetTags", "UnsetTags")) + } + if valueSet(opts.Set) { + if everyValueSet(opts.Set.S3Params, opts.Set.AzureParams) { + errs = append(errs, errOneOf("AlterApiIntegrationOptions.Set", "S3Params", "AzureParams")) + } + if !anyValueSet(opts.Set.S3Params, opts.Set.AzureParams, opts.Set.Enabled, opts.Set.ApiAllowedPrefixes, opts.Set.ApiBlockedPrefixes, opts.Set.Comment) { + errs = append(errs, errAtLeastOneOf("AlterApiIntegrationOptions.Set", "S3Params", "AzureParams", "Enabled", "ApiAllowedPrefixes", "ApiBlockedPrefixes", "Comment")) + } + if valueSet(opts.Set.S3Params) { + if !anyValueSet(opts.Set.S3Params.ApiAwsRoleArn, opts.Set.S3Params.ApiKey) { + errs = append(errs, errAtLeastOneOf("AlterApiIntegrationOptions.Set.S3Params", "ApiAwsRoleArn", "ApiKey")) + } + } + if valueSet(opts.Set.AzureParams) { + if !anyValueSet(opts.Set.AzureParams.AzureAdApplicationId, opts.Set.AzureParams.ApiKey) { + errs = append(errs, errAtLeastOneOf("AlterApiIntegrationOptions.Set.AzureParams", "AzureAdApplicationId", "ApiKey")) + } + } + } + if valueSet(opts.Unset) { + if !anyValueSet(opts.Unset.ApiKey, opts.Unset.Enabled, opts.Unset.ApiBlockedPrefixes, opts.Unset.Comment) { + errs = append(errs, errAtLeastOneOf("AlterApiIntegrationOptions.Unset", "ApiKey", "Enabled", "ApiBlockedPrefixes", "Comment")) + } + } + return JoinErrors(errs...) +} + +func (opts *DropApiIntegrationOptions) validate() error { + if opts == nil { + return ErrNilOptions + } + var errs []error + if !ValidObjectIdentifier(opts.name) { + errs = append(errs, ErrInvalidObjectIdentifier) + } + return JoinErrors(errs...) +} + +func (opts *ShowApiIntegrationOptions) validate() error { + if opts == nil { + return ErrNilOptions + } + var errs []error + return JoinErrors(errs...) +} + +func (opts *DescribeApiIntegrationOptions) validate() error { + if opts == nil { + return ErrNilOptions + } + var errs []error + if !ValidObjectIdentifier(opts.name) { + errs = append(errs, ErrInvalidObjectIdentifier) + } + return JoinErrors(errs...) +} diff --git a/pkg/sdk/testint/api_integrations_gen_integration_test.go b/pkg/sdk/testint/api_integrations_gen_integration_test.go new file mode 100644 index 0000000000..ec1f8b929d --- /dev/null +++ b/pkg/sdk/testint/api_integrations_gen_integration_test.go @@ -0,0 +1,31 @@ +package testint + +import "testing" + +func TestInt_ApiIntegrations(t *testing.T) { + // TODO: prepare common resources + + t.Run("Create", func(t *testing.T) { + // TODO: fill me + }) + + t.Run("Alter", func(t *testing.T) { + // TODO: fill me + }) + + t.Run("Drop", func(t *testing.T) { + // TODO: fill me + }) + + t.Run("Show", func(t *testing.T) { + // TODO: fill me + }) + + t.Run("ShowByID", func(t *testing.T) { + // TODO: fill me + }) + + t.Run("Describe", func(t *testing.T) { + // TODO: fill me + }) +} From 20ab165eff3bde6fe7693a9644849600709425fa Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Tue, 23 Jan 2024 17:33:27 +0100 Subject: [PATCH 06/24] Copied show by id impl and mappings from storage integration --- pkg/sdk/api_integrations_impl_gen.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/pkg/sdk/api_integrations_impl_gen.go b/pkg/sdk/api_integrations_impl_gen.go index abc00a7746..b493b4aa66 100644 --- a/pkg/sdk/api_integrations_impl_gen.go +++ b/pkg/sdk/api_integrations_impl_gen.go @@ -38,8 +38,9 @@ func (v *apiIntegrations) Show(ctx context.Context, request *ShowApiIntegrationR } func (v *apiIntegrations) ShowByID(ctx context.Context, id AccountObjectIdentifier) (*ApiIntegration, error) { - // TODO: adjust request if e.g. LIKE is supported for the resource - apiIntegrations, err := v.Show(ctx, NewShowApiIntegrationRequest()) + apiIntegrations, err := v.Show(ctx, NewShowApiIntegrationRequest().WithLike(&Like{ + Pattern: String(id.Name()), + })) if err != nil { return nil, err } @@ -146,8 +147,17 @@ func (r *ShowApiIntegrationRequest) toOpts() *ShowApiIntegrationOptions { } func (r showApiIntegrationsDbRow) convert() *ApiIntegration { - // TODO: Mapping - return &ApiIntegration{} + s := &ApiIntegration{ + Name: r.Name, + ApiType: r.Type, + Category: r.Category, + Enabled: r.Enabled, + CreatedOn: r.CreatedOn, + } + if r.Comment.Valid { + s.Comment = r.Comment.String + } + return s } func (r *DescribeApiIntegrationRequest) toOpts() *DescribeApiIntegrationOptions { @@ -158,6 +168,10 @@ func (r *DescribeApiIntegrationRequest) toOpts() *DescribeApiIntegrationOptions } func (r descApiIntegrationsDbRow) convert() *ApiIntegrationProperty { - // TODO: Mapping - return &ApiIntegrationProperty{} + return &ApiIntegrationProperty{ + Name: r.Property, + Type: r.PropertyType, + Value: r.PropertyValue, + Default: r.PropertyDefault, + } } From 85fdec30f0a2afc9bd0c7295b1387992881552bd Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Tue, 23 Jan 2024 17:48:46 +0100 Subject: [PATCH 07/24] Regenerate files after name changes --- pkg/sdk/api_integrations_def.go | 18 +++++------ pkg/sdk/api_integrations_dto_builders_gen.go | 34 ++++++++++---------- pkg/sdk/api_integrations_dto_gen.go | 28 ++++++++-------- pkg/sdk/api_integrations_gen.go | 32 +++++++++--------- pkg/sdk/api_integrations_impl_gen.go | 24 +++++++------- pkg/sdk/api_integrations_validations_gen.go | 18 +++++------ 6 files changed, 77 insertions(+), 77 deletions(-) diff --git a/pkg/sdk/api_integrations_def.go b/pkg/sdk/api_integrations_def.go index a975b5a954..28bb7ad83e 100644 --- a/pkg/sdk/api_integrations_def.go +++ b/pkg/sdk/api_integrations_def.go @@ -30,8 +30,8 @@ var ApiIntegrationsDef = g.NewInterface( IfNotExists(). Name(). OptionalQueryStructField( - "S3ApiProviderParams", - g.NewQueryStruct("S3ApiParams"). + "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()), @@ -47,8 +47,8 @@ var ApiIntegrationsDef = g.NewInterface( g.KeywordOptions(), ). OptionalQueryStructField( - "GCSApiProviderParams", - g.NewQueryStruct("GCSApiParams"). + "GoogleApiProviderParams", + g.NewQueryStruct("GoogleApiParams"). PredefinedQueryStructField("apiProvider", "string", g.StaticOptions().SQL("API_PROVIDER = google_api_gateway")). TextAssignment("GOOGLE_AUDIENCE", g.ParameterOptions().SingleQuotes().Required()), g.KeywordOptions(), @@ -59,7 +59,7 @@ var ApiIntegrationsDef = g.NewInterface( OptionalComment(). WithValidation(g.ValidIdentifier, "name"). WithValidation(g.ConflictingFields, "IfNotExists", "OrReplace"). - WithValidation(g.ExactlyOneValueSet, "S3ApiProviderParams", "AzureApiProviderParams", "GCSApiProviderParams"), + WithValidation(g.ExactlyOneValueSet, "AwsApiProviderParams", "AzureApiProviderParams", "GoogleApiProviderParams"), ApiIntegrationEndpointPrefixDef, ). AlterOperation( @@ -73,8 +73,8 @@ var ApiIntegrationsDef = g.NewInterface( "Set", g.NewQueryStruct("ApiIntegrationSet"). OptionalQueryStructField( - "S3Params", - g.NewQueryStruct("SetS3ApiParams"). + "AwsParams", + g.NewQueryStruct("SetAwsApiParams"). OptionalTextAssignment("API_AWS_ROLE_ARN", g.ParameterOptions().SingleQuotes()). OptionalTextAssignment("API_KEY", g.ParameterOptions().SingleQuotes()). WithValidation(g.AtLeastOneValueSet, "ApiAwsRoleArn", "ApiKey"), @@ -92,8 +92,8 @@ var ApiIntegrationsDef = g.NewInterface( ListAssignment("API_ALLOWED_PREFIXES", "ApiIntegrationEndpointPrefix", g.ParameterOptions().Parentheses()). ListAssignment("API_BLOCKED_PREFIXES", "ApiIntegrationEndpointPrefix", g.ParameterOptions().Parentheses()). OptionalComment(). - WithValidation(g.ConflictingFields, "S3Params", "AzureParams"). - WithValidation(g.AtLeastOneValueSet, "S3Params", "AzureParams", "Enabled", "ApiAllowedPrefixes", "ApiBlockedPrefixes", "Comment"), + WithValidation(g.ConflictingFields, "AwsParams", "AzureParams"). + WithValidation(g.AtLeastOneValueSet, "AwsParams", "AzureParams", "Enabled", "ApiAllowedPrefixes", "ApiBlockedPrefixes", "Comment"), g.KeywordOptions().SQL("SET"), ). OptionalQueryStructField( diff --git a/pkg/sdk/api_integrations_dto_builders_gen.go b/pkg/sdk/api_integrations_dto_builders_gen.go index 17d0093902..fb15b2ee0f 100644 --- a/pkg/sdk/api_integrations_dto_builders_gen.go +++ b/pkg/sdk/api_integrations_dto_builders_gen.go @@ -26,8 +26,8 @@ func (s *CreateApiIntegrationRequest) WithIfNotExists(IfNotExists *bool) *Create return s } -func (s *CreateApiIntegrationRequest) WithS3ApiProviderParams(S3ApiProviderParams *S3ApiParamsRequest) *CreateApiIntegrationRequest { - s.S3ApiProviderParams = S3ApiProviderParams +func (s *CreateApiIntegrationRequest) WithAwsApiProviderParams(AwsApiProviderParams *AwsApiParamsRequest) *CreateApiIntegrationRequest { + s.AwsApiProviderParams = AwsApiProviderParams return s } @@ -36,8 +36,8 @@ func (s *CreateApiIntegrationRequest) WithAzureApiProviderParams(AzureApiProvide return s } -func (s *CreateApiIntegrationRequest) WithGCSApiProviderParams(GCSApiProviderParams *GCSApiParamsRequest) *CreateApiIntegrationRequest { - s.GCSApiProviderParams = GCSApiProviderParams +func (s *CreateApiIntegrationRequest) WithGoogleApiProviderParams(GoogleApiProviderParams *GoogleApiParamsRequest) *CreateApiIntegrationRequest { + s.GoogleApiProviderParams = GoogleApiProviderParams return s } @@ -51,17 +51,17 @@ func (s *CreateApiIntegrationRequest) WithComment(Comment *string) *CreateApiInt return s } -func NewS3ApiParamsRequest( +func NewAwsApiParamsRequest( ApiProvider ApiIntegrationAwsApiProviderType, ApiAwsRoleArn string, -) *S3ApiParamsRequest { - s := S3ApiParamsRequest{} +) *AwsApiParamsRequest { + s := AwsApiParamsRequest{} s.ApiProvider = ApiProvider s.ApiAwsRoleArn = ApiAwsRoleArn return &s } -func (s *S3ApiParamsRequest) WithApiKey(ApiKey *string) *S3ApiParamsRequest { +func (s *AwsApiParamsRequest) WithApiKey(ApiKey *string) *AwsApiParamsRequest { s.ApiKey = ApiKey return s } @@ -81,10 +81,10 @@ func (s *AzureApiParamsRequest) WithApiKey(ApiKey *string) *AzureApiParamsReques return s } -func NewGCSApiParamsRequest( +func NewGoogleApiParamsRequest( GoogleAudience string, -) *GCSApiParamsRequest { - s := GCSApiParamsRequest{} +) *GoogleApiParamsRequest { + s := GoogleApiParamsRequest{} s.GoogleAudience = GoogleAudience return &s } @@ -126,8 +126,8 @@ func NewApiIntegrationSetRequest() *ApiIntegrationSetRequest { return &ApiIntegrationSetRequest{} } -func (s *ApiIntegrationSetRequest) WithS3Params(S3Params *SetS3ApiParamsRequest) *ApiIntegrationSetRequest { - s.S3Params = S3Params +func (s *ApiIntegrationSetRequest) WithAwsParams(AwsParams *SetAwsApiParamsRequest) *ApiIntegrationSetRequest { + s.AwsParams = AwsParams return s } @@ -156,16 +156,16 @@ func (s *ApiIntegrationSetRequest) WithComment(Comment *string) *ApiIntegrationS return s } -func NewSetS3ApiParamsRequest() *SetS3ApiParamsRequest { - return &SetS3ApiParamsRequest{} +func NewSetAwsApiParamsRequest() *SetAwsApiParamsRequest { + return &SetAwsApiParamsRequest{} } -func (s *SetS3ApiParamsRequest) WithApiAwsRoleArn(ApiAwsRoleArn *string) *SetS3ApiParamsRequest { +func (s *SetAwsApiParamsRequest) WithApiAwsRoleArn(ApiAwsRoleArn *string) *SetAwsApiParamsRequest { s.ApiAwsRoleArn = ApiAwsRoleArn return s } -func (s *SetS3ApiParamsRequest) WithApiKey(ApiKey *string) *SetS3ApiParamsRequest { +func (s *SetAwsApiParamsRequest) WithApiKey(ApiKey *string) *SetAwsApiParamsRequest { s.ApiKey = ApiKey return s } diff --git a/pkg/sdk/api_integrations_dto_gen.go b/pkg/sdk/api_integrations_dto_gen.go index 0f74a8720c..b63ca5dc17 100644 --- a/pkg/sdk/api_integrations_dto_gen.go +++ b/pkg/sdk/api_integrations_dto_gen.go @@ -11,19 +11,19 @@ var ( ) type CreateApiIntegrationRequest struct { - OrReplace *bool - IfNotExists *bool - name AccountObjectIdentifier // required - S3ApiProviderParams *S3ApiParamsRequest - AzureApiProviderParams *AzureApiParamsRequest - GCSApiProviderParams *GCSApiParamsRequest - ApiAllowedPrefixes []ApiIntegrationEndpointPrefix // required - ApiBlockedPrefixes []ApiIntegrationEndpointPrefix - Enabled bool // required - Comment *string + OrReplace *bool + IfNotExists *bool + name AccountObjectIdentifier // required + AwsApiProviderParams *AwsApiParamsRequest + AzureApiProviderParams *AzureApiParamsRequest + GoogleApiProviderParams *GoogleApiParamsRequest + ApiAllowedPrefixes []ApiIntegrationEndpointPrefix // required + ApiBlockedPrefixes []ApiIntegrationEndpointPrefix + Enabled bool // required + Comment *string } -type S3ApiParamsRequest struct { +type AwsApiParamsRequest struct { ApiProvider ApiIntegrationAwsApiProviderType // required ApiAwsRoleArn string // required ApiKey *string @@ -35,7 +35,7 @@ type AzureApiParamsRequest struct { ApiKey *string } -type GCSApiParamsRequest struct { +type GoogleApiParamsRequest struct { GoogleAudience string // required } @@ -49,7 +49,7 @@ type AlterApiIntegrationRequest struct { } type ApiIntegrationSetRequest struct { - S3Params *SetS3ApiParamsRequest + AwsParams *SetAwsApiParamsRequest AzureParams *SetAzureApiParamsRequest Enabled *bool ApiAllowedPrefixes []ApiIntegrationEndpointPrefix @@ -57,7 +57,7 @@ type ApiIntegrationSetRequest struct { Comment *string } -type SetS3ApiParamsRequest struct { +type SetAwsApiParamsRequest struct { ApiAwsRoleArn *string ApiKey *string } diff --git a/pkg/sdk/api_integrations_gen.go b/pkg/sdk/api_integrations_gen.go index 397f8c9875..017769c833 100644 --- a/pkg/sdk/api_integrations_gen.go +++ b/pkg/sdk/api_integrations_gen.go @@ -17,25 +17,25 @@ type ApiIntegrations interface { // CreateApiIntegrationOptions is based on https://docs.snowflake.com/en/sql-reference/sql/create-api-integration. type CreateApiIntegrationOptions struct { - create bool `ddl:"static" sql:"CREATE"` - OrReplace *bool `ddl:"keyword" sql:"OR REPLACE"` - apiIntegration bool `ddl:"static" sql:"API INTEGRATION"` - IfNotExists *bool `ddl:"keyword" sql:"IF NOT EXISTS"` - name AccountObjectIdentifier `ddl:"identifier"` - S3ApiProviderParams *S3ApiParams `ddl:"keyword"` - AzureApiProviderParams *AzureApiParams `ddl:"keyword"` - GCSApiProviderParams *GCSApiParams `ddl:"keyword"` - ApiAllowedPrefixes []ApiIntegrationEndpointPrefix `ddl:"parameter,parentheses" sql:"API_ALLOWED_PREFIXES"` - ApiBlockedPrefixes []ApiIntegrationEndpointPrefix `ddl:"parameter,parentheses" sql:"API_BLOCKED_PREFIXES"` - Enabled bool `ddl:"parameter" sql:"ENABLED"` - Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"` + create bool `ddl:"static" sql:"CREATE"` + OrReplace *bool `ddl:"keyword" sql:"OR REPLACE"` + apiIntegration bool `ddl:"static" sql:"API INTEGRATION"` + IfNotExists *bool `ddl:"keyword" sql:"IF NOT EXISTS"` + name AccountObjectIdentifier `ddl:"identifier"` + AwsApiProviderParams *AwsApiParams `ddl:"keyword"` + AzureApiProviderParams *AzureApiParams `ddl:"keyword"` + GoogleApiProviderParams *GoogleApiParams `ddl:"keyword"` + ApiAllowedPrefixes []ApiIntegrationEndpointPrefix `ddl:"parameter,parentheses" sql:"API_ALLOWED_PREFIXES"` + ApiBlockedPrefixes []ApiIntegrationEndpointPrefix `ddl:"parameter,parentheses" sql:"API_BLOCKED_PREFIXES"` + Enabled bool `ddl:"parameter" sql:"ENABLED"` + Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"` } type ApiIntegrationEndpointPrefix struct { Path string `ddl:"keyword,single_quotes"` } -type S3ApiParams struct { +type AwsApiParams struct { ApiProvider ApiIntegrationAwsApiProviderType `ddl:"parameter,no_quotes" sql:"API_PROVIDER"` ApiAwsRoleArn string `ddl:"parameter,single_quotes" sql:"API_AWS_ROLE_ARN"` ApiKey *string `ddl:"parameter,single_quotes" sql:"API_KEY"` @@ -48,7 +48,7 @@ type AzureApiParams struct { ApiKey *string `ddl:"parameter,single_quotes" sql:"API_KEY"` } -type GCSApiParams struct { +type GoogleApiParams struct { apiProvider string `ddl:"static" sql:"API_PROVIDER = google_api_gateway"` GoogleAudience string `ddl:"parameter,single_quotes" sql:"GOOGLE_AUDIENCE"` } @@ -66,7 +66,7 @@ type AlterApiIntegrationOptions struct { } type ApiIntegrationSet struct { - S3Params *SetS3ApiParams `ddl:"keyword"` + AwsParams *SetAwsApiParams `ddl:"keyword"` AzureParams *SetAzureApiParams `ddl:"keyword"` Enabled *bool `ddl:"parameter" sql:"ENABLED"` ApiAllowedPrefixes []ApiIntegrationEndpointPrefix `ddl:"parameter,parentheses" sql:"API_ALLOWED_PREFIXES"` @@ -74,7 +74,7 @@ type ApiIntegrationSet struct { Comment *string `ddl:"parameter,single_quotes" sql:"COMMENT"` } -type SetS3ApiParams struct { +type SetAwsApiParams struct { ApiAwsRoleArn *string `ddl:"parameter,single_quotes" sql:"API_AWS_ROLE_ARN"` ApiKey *string `ddl:"parameter,single_quotes" sql:"API_KEY"` } diff --git a/pkg/sdk/api_integrations_impl_gen.go b/pkg/sdk/api_integrations_impl_gen.go index b493b4aa66..99c564ae77 100644 --- a/pkg/sdk/api_integrations_impl_gen.go +++ b/pkg/sdk/api_integrations_impl_gen.go @@ -69,11 +69,11 @@ func (r *CreateApiIntegrationRequest) toOpts() *CreateApiIntegrationOptions { Enabled: r.Enabled, Comment: r.Comment, } - if r.S3ApiProviderParams != nil { - opts.S3ApiProviderParams = &S3ApiParams{ - ApiProvider: r.S3ApiProviderParams.ApiProvider, - ApiAwsRoleArn: r.S3ApiProviderParams.ApiAwsRoleArn, - ApiKey: r.S3ApiProviderParams.ApiKey, + if r.AwsApiProviderParams != nil { + opts.AwsApiProviderParams = &AwsApiParams{ + ApiProvider: r.AwsApiProviderParams.ApiProvider, + ApiAwsRoleArn: r.AwsApiProviderParams.ApiAwsRoleArn, + ApiKey: r.AwsApiProviderParams.ApiKey, } } if r.AzureApiProviderParams != nil { @@ -83,9 +83,9 @@ func (r *CreateApiIntegrationRequest) toOpts() *CreateApiIntegrationOptions { ApiKey: r.AzureApiProviderParams.ApiKey, } } - if r.GCSApiProviderParams != nil { - opts.GCSApiProviderParams = &GCSApiParams{ - GoogleAudience: r.GCSApiProviderParams.GoogleAudience, + if r.GoogleApiProviderParams != nil { + opts.GoogleApiProviderParams = &GoogleApiParams{ + GoogleAudience: r.GoogleApiProviderParams.GoogleAudience, } } return opts @@ -107,10 +107,10 @@ func (r *AlterApiIntegrationRequest) toOpts() *AlterApiIntegrationOptions { ApiBlockedPrefixes: r.Set.ApiBlockedPrefixes, Comment: r.Set.Comment, } - if r.Set.S3Params != nil { - opts.Set.S3Params = &SetS3ApiParams{ - ApiAwsRoleArn: r.Set.S3Params.ApiAwsRoleArn, - ApiKey: r.Set.S3Params.ApiKey, + if r.Set.AwsParams != nil { + opts.Set.AwsParams = &SetAwsApiParams{ + ApiAwsRoleArn: r.Set.AwsParams.ApiAwsRoleArn, + ApiKey: r.Set.AwsParams.ApiKey, } } if r.Set.AzureParams != nil { diff --git a/pkg/sdk/api_integrations_validations_gen.go b/pkg/sdk/api_integrations_validations_gen.go index e575da5bf5..092327f553 100644 --- a/pkg/sdk/api_integrations_validations_gen.go +++ b/pkg/sdk/api_integrations_validations_gen.go @@ -19,8 +19,8 @@ func (opts *CreateApiIntegrationOptions) validate() error { if everyValueSet(opts.IfNotExists, opts.OrReplace) { errs = append(errs, errOneOf("CreateApiIntegrationOptions", "IfNotExists", "OrReplace")) } - if !exactlyOneValueSet(opts.S3ApiProviderParams, opts.AzureApiProviderParams, opts.GCSApiProviderParams) { - errs = append(errs, errExactlyOneOf("CreateApiIntegrationOptions", "S3ApiProviderParams", "AzureApiProviderParams", "GCSApiProviderParams")) + if !exactlyOneValueSet(opts.AwsApiProviderParams, opts.AzureApiProviderParams, opts.GoogleApiProviderParams) { + errs = append(errs, errExactlyOneOf("CreateApiIntegrationOptions", "AwsApiProviderParams", "AzureApiProviderParams", "GoogleApiProviderParams")) } return JoinErrors(errs...) } @@ -43,15 +43,15 @@ func (opts *AlterApiIntegrationOptions) validate() error { errs = append(errs, errExactlyOneOf("AlterApiIntegrationOptions", "Set", "Unset", "SetTags", "UnsetTags")) } if valueSet(opts.Set) { - if everyValueSet(opts.Set.S3Params, opts.Set.AzureParams) { - errs = append(errs, errOneOf("AlterApiIntegrationOptions.Set", "S3Params", "AzureParams")) + if everyValueSet(opts.Set.AwsParams, opts.Set.AzureParams) { + errs = append(errs, errOneOf("AlterApiIntegrationOptions.Set", "AwsParams", "AzureParams")) } - if !anyValueSet(opts.Set.S3Params, opts.Set.AzureParams, opts.Set.Enabled, opts.Set.ApiAllowedPrefixes, opts.Set.ApiBlockedPrefixes, opts.Set.Comment) { - errs = append(errs, errAtLeastOneOf("AlterApiIntegrationOptions.Set", "S3Params", "AzureParams", "Enabled", "ApiAllowedPrefixes", "ApiBlockedPrefixes", "Comment")) + if !anyValueSet(opts.Set.AwsParams, opts.Set.AzureParams, opts.Set.Enabled, opts.Set.ApiAllowedPrefixes, opts.Set.ApiBlockedPrefixes, opts.Set.Comment) { + errs = append(errs, errAtLeastOneOf("AlterApiIntegrationOptions.Set", "AwsParams", "AzureParams", "Enabled", "ApiAllowedPrefixes", "ApiBlockedPrefixes", "Comment")) } - if valueSet(opts.Set.S3Params) { - if !anyValueSet(opts.Set.S3Params.ApiAwsRoleArn, opts.Set.S3Params.ApiKey) { - errs = append(errs, errAtLeastOneOf("AlterApiIntegrationOptions.Set.S3Params", "ApiAwsRoleArn", "ApiKey")) + if valueSet(opts.Set.AwsParams) { + if !anyValueSet(opts.Set.AwsParams.ApiAwsRoleArn, opts.Set.AwsParams.ApiKey) { + errs = append(errs, errAtLeastOneOf("AlterApiIntegrationOptions.Set.AwsParams", "ApiAwsRoleArn", "ApiKey")) } } if valueSet(opts.Set.AzureParams) { From b84e8bf9b0ee41b5879128f3655337685ce5634b Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Tue, 23 Jan 2024 18:03:28 +0100 Subject: [PATCH 08/24] Unit test create --- pkg/sdk/api_integrations_gen_test.go | 104 ++++++++++++++++++++++----- 1 file changed, 86 insertions(+), 18 deletions(-) diff --git a/pkg/sdk/api_integrations_gen_test.go b/pkg/sdk/api_integrations_gen_test.go index d443b75b48..5195a3793a 100644 --- a/pkg/sdk/api_integrations_gen_test.go +++ b/pkg/sdk/api_integrations_gen_test.go @@ -2,16 +2,58 @@ package sdk import "testing" +const AwsAllowedPrefix = "https://123456.execute-api.us-west-2.amazonaws.com/prod/" +const AzureAllowedPrefix = "https://apim-hello-world.azure-api.net/" +const GoogleAllowedPrefix = "https://gateway-id-123456.uc.gateway.dev/" + +const ApiAwsRoleArn = "arn:aws:iam::000000000001:/role/test" +const AzureTenantId = "00000000-0000-0000-0000-000000000000" +const AzureAdApplicationId = "11111111-1111-1111-1111-111111111111" +const GoogleAudience = "api-gateway-id-123456.apigateway.gcp-project.cloud.goog" + func TestApiIntegrations_Create(t *testing.T) { id := RandomAccountObjectIdentifier() - // Minimal valid CreateApiIntegrationOptions - defaultOpts := func() *CreateApiIntegrationOptions { + // Minimal valid CreateApiIntegrationOptions for AWS + defaultOptsAws := func() *CreateApiIntegrationOptions { return &CreateApiIntegrationOptions{ name: id, + AwsApiProviderParams: &AwsApiParams{ + ApiProvider: ApiIntegrationAwsApiGateway, + ApiAwsRoleArn: ApiAwsRoleArn, + }, + ApiAllowedPrefixes: []ApiIntegrationEndpointPrefix{{Path: AwsAllowedPrefix}}, + Enabled: true, } } + // Minimal valid CreateApiIntegrationOptions for Azure + defaultOptsAzure := func() *CreateApiIntegrationOptions { + return &CreateApiIntegrationOptions{ + name: id, + AzureApiProviderParams: &AzureApiParams{ + AzureTenantId: AzureTenantId, + AzureAdApplicationId: AzureAdApplicationId, + }, + ApiAllowedPrefixes: []ApiIntegrationEndpointPrefix{{Path: AzureAllowedPrefix}}, + Enabled: true, + } + } + + // Minimal valid CreateApiIntegrationOptions for Google + defaultOptsGoogle := func() *CreateApiIntegrationOptions { + return &CreateApiIntegrationOptions{ + name: id, + GoogleApiProviderParams: &GoogleApiParams{ + GoogleAudience: GoogleAudience, + }, + ApiAllowedPrefixes: []ApiIntegrationEndpointPrefix{{Path: GoogleAllowedPrefix}}, + Enabled: true, + } + } + + defaultOpts := defaultOptsAws + t.Run("validation: nil options", func(t *testing.T) { var opts *CreateApiIntegrationOptions = nil assertOptsInvalidJoinedErrors(t, opts, ErrNilOptions) @@ -19,32 +61,62 @@ func TestApiIntegrations_Create(t *testing.T) { t.Run("validation: valid identifier for [opts.name]", func(t *testing.T) { opts := defaultOpts() - // TODO: fill me + opts.name = NewAccountObjectIdentifier("") assertOptsInvalidJoinedErrors(t, opts, ErrInvalidObjectIdentifier) }) t.Run("validation: conflicting fields for [opts.IfNotExists opts.OrReplace]", func(t *testing.T) { opts := defaultOpts() - // TODO: fill me + opts.IfNotExists = Bool(true) + opts.OrReplace = Bool(true) assertOptsInvalidJoinedErrors(t, opts, errOneOf("CreateApiIntegrationOptions", "IfNotExists", "OrReplace")) }) - t.Run("validation: exactly one field from [opts.S3ApiProviderParams opts.AzureApiProviderParams opts.GCSApiProviderParams] should be present", func(t *testing.T) { + t.Run("validation: exactly one field from [opts.AwsApiProviderParams opts.AzureApiProviderParams opts.GoogleApiProviderParams] should be present", func(t *testing.T) { opts := defaultOpts() - // TODO: fill me - assertOptsInvalidJoinedErrors(t, opts, errExactlyOneOf("CreateApiIntegrationOptions", "S3ApiProviderParams", "AzureApiProviderParams", "GCSApiProviderParams")) + opts.AwsApiProviderParams = nil + assertOptsInvalidJoinedErrors(t, opts, errExactlyOneOf("CreateApiIntegrationOptions", "AwsApiProviderParams", "AzureApiProviderParams", "GoogleApiProviderParams")) }) - t.Run("basic", func(t *testing.T) { + t.Run("validation: exactly one field from [opts.AwsApiProviderParams opts.AzureApiProviderParams opts.GoogleApiProviderParams] should be present - more present", func(t *testing.T) { opts := defaultOpts() - // TODO: fill me - assertOptsValidAndSQLEquals(t, opts, "TODO: fill me") + opts.AzureApiProviderParams = new(AzureApiParams) + assertOptsInvalidJoinedErrors(t, opts, errExactlyOneOf("CreateApiIntegrationOptions", "AwsApiProviderParams", "AzureApiProviderParams", "GoogleApiProviderParams")) }) - t.Run("all options", func(t *testing.T) { + t.Run("basic", func(t *testing.T) { opts := defaultOpts() - // TODO: fill me - assertOptsValidAndSQLEquals(t, opts, "TODO: fill me") + assertOptsValidAndSQLEquals(t, opts, `CREATE API INTEGRATION %s API_PROVIDER = aws_api_gateway API_AWS_ROLE_ARN = '%s' API_ALLOWED_PREFIXES = ('%s') ENABLED = true`, id.FullyQualifiedName(), ApiAwsRoleArn, AwsAllowedPrefix) + }) + + t.Run("all options - aws", func(t *testing.T) { + opts := defaultOptsAws() + opts.IfNotExists = Bool(true) + opts.AwsApiProviderParams.ApiProvider = ApiIntegrationAwsPrivateApiGateway + opts.AwsApiProviderParams.ApiKey = String("key") + opts.ApiBlockedPrefixes = []ApiIntegrationEndpointPrefix{{Path: GoogleAllowedPrefix}, {Path: AzureAllowedPrefix}} + opts.Enabled = false + opts.Comment = String("some comment") + assertOptsValidAndSQLEquals(t, opts, `CREATE API INTEGRATION IF NOT EXISTS %s API_PROVIDER = aws_private_api_gateway API_AWS_ROLE_ARN = '%s' API_KEY = 'key' API_ALLOWED_PREFIXES = ('%s') API_BLOCKED_PREFIXES = ('%s', '%s') ENABLED = false COMMENT = 'some comment'`, id.FullyQualifiedName(), ApiAwsRoleArn, AwsAllowedPrefix, GoogleAllowedPrefix, AzureAllowedPrefix) + }) + + t.Run("all options - azure", func(t *testing.T) { + opts := defaultOptsAzure() + opts.IfNotExists = Bool(true) + opts.AzureApiProviderParams.ApiKey = String("key") + opts.ApiBlockedPrefixes = []ApiIntegrationEndpointPrefix{{Path: AwsAllowedPrefix}, {Path: GoogleAllowedPrefix}} + opts.Enabled = false + opts.Comment = String("some comment") + assertOptsValidAndSQLEquals(t, opts, `CREATE API INTEGRATION IF NOT EXISTS %s API_PROVIDER = azure_api_management AZURE_TENANT_ID = '%s' AZURE_AD_APPLICATION_ID = '%s' API_KEY = 'key' API_ALLOWED_PREFIXES = ('%s') API_BLOCKED_PREFIXES = ('%s', '%s') ENABLED = false COMMENT = 'some comment'`, id.FullyQualifiedName(), AzureTenantId, AzureAdApplicationId, AzureAllowedPrefix, AwsAllowedPrefix, GoogleAllowedPrefix) + }) + + t.Run("all options - google", func(t *testing.T) { + opts := defaultOptsGoogle() + opts.IfNotExists = Bool(true) + opts.ApiBlockedPrefixes = []ApiIntegrationEndpointPrefix{{Path: AwsAllowedPrefix}, {Path: AzureAllowedPrefix}} + opts.Enabled = false + opts.Comment = String("some comment") + assertOptsValidAndSQLEquals(t, opts, `CREATE API INTEGRATION IF NOT EXISTS %s API_PROVIDER = google_api_gateway GOOGLE_AUDIENCE = '%s' API_ALLOWED_PREFIXES = ('%s') API_BLOCKED_PREFIXES = ('%s', '%s') ENABLED = false COMMENT = 'some comment'`, id.FullyQualifiedName(), GoogleAudience, GoogleAllowedPrefix, AwsAllowedPrefix, AzureAllowedPrefix) }) } @@ -165,13 +237,9 @@ func TestApiIntegrations_Drop(t *testing.T) { } func TestApiIntegrations_Show(t *testing.T) { - id := RandomAccountObjectIdentifier() - // Minimal valid ShowApiIntegrationOptions defaultOpts := func() *ShowApiIntegrationOptions { - return &ShowApiIntegrationOptions{ - name: id, - } + return &ShowApiIntegrationOptions{} } t.Run("validation: nil options", func(t *testing.T) { From 0971c281b3760185032de015dfc07ab4ee8fd6a4 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Tue, 23 Jan 2024 18:04:20 +0100 Subject: [PATCH 09/24] Unit test describe --- pkg/sdk/api_integrations_gen_test.go | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/pkg/sdk/api_integrations_gen_test.go b/pkg/sdk/api_integrations_gen_test.go index 5195a3793a..08afa25adc 100644 --- a/pkg/sdk/api_integrations_gen_test.go +++ b/pkg/sdk/api_integrations_gen_test.go @@ -277,19 +277,12 @@ func TestApiIntegrations_Describe(t *testing.T) { t.Run("validation: valid identifier for [opts.name]", func(t *testing.T) { opts := defaultOpts() - // TODO: fill me + opts.name = NewAccountObjectIdentifier("") assertOptsInvalidJoinedErrors(t, opts, ErrInvalidObjectIdentifier) }) - t.Run("basic", func(t *testing.T) { - opts := defaultOpts() - // TODO: fill me - assertOptsValidAndSQLEquals(t, opts, "TODO: fill me") - }) - t.Run("all options", func(t *testing.T) { opts := defaultOpts() - // TODO: fill me - assertOptsValidAndSQLEquals(t, opts, "TODO: fill me") + assertOptsValidAndSQLEquals(t, opts, "DESCRIBE API INTEGRATION %s", id.FullyQualifiedName()) }) } From fa4c65255808ec2406278debf7685ce4ef05b51a Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Tue, 23 Jan 2024 18:05:22 +0100 Subject: [PATCH 10/24] Unit test show --- pkg/sdk/api_integrations_gen_test.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/sdk/api_integrations_gen_test.go b/pkg/sdk/api_integrations_gen_test.go index 08afa25adc..825e4dc8f0 100644 --- a/pkg/sdk/api_integrations_gen_test.go +++ b/pkg/sdk/api_integrations_gen_test.go @@ -237,6 +237,8 @@ func TestApiIntegrations_Drop(t *testing.T) { } func TestApiIntegrations_Show(t *testing.T) { + id := RandomAccountObjectIdentifier() + // Minimal valid ShowApiIntegrationOptions defaultOpts := func() *ShowApiIntegrationOptions { return &ShowApiIntegrationOptions{} @@ -249,14 +251,15 @@ func TestApiIntegrations_Show(t *testing.T) { t.Run("basic", func(t *testing.T) { opts := defaultOpts() - // TODO: fill me - assertOptsValidAndSQLEquals(t, opts, "TODO: fill me") + assertOptsValidAndSQLEquals(t, opts, "SHOW API INTEGRATIONS") }) t.Run("all options", func(t *testing.T) { opts := defaultOpts() - // TODO: fill me - assertOptsValidAndSQLEquals(t, opts, "TODO: fill me") + opts.Like = &Like{ + Pattern: String(id.Name()), + } + assertOptsValidAndSQLEquals(t, opts, "SHOW API INTEGRATIONS LIKE '%s'", id.Name()) }) } From 107534bd14a5d8a6051d49e3c3b98483a78a0466 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Tue, 23 Jan 2024 18:06:30 +0100 Subject: [PATCH 11/24] Unit test drop --- pkg/sdk/api_integrations_gen_test.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/pkg/sdk/api_integrations_gen_test.go b/pkg/sdk/api_integrations_gen_test.go index 825e4dc8f0..8f3edad6ca 100644 --- a/pkg/sdk/api_integrations_gen_test.go +++ b/pkg/sdk/api_integrations_gen_test.go @@ -219,20 +219,14 @@ func TestApiIntegrations_Drop(t *testing.T) { t.Run("validation: valid identifier for [opts.name]", func(t *testing.T) { opts := defaultOpts() - // TODO: fill me + opts.name = NewAccountObjectIdentifier("") assertOptsInvalidJoinedErrors(t, opts, ErrInvalidObjectIdentifier) }) - t.Run("basic", func(t *testing.T) { - opts := defaultOpts() - // TODO: fill me - assertOptsValidAndSQLEquals(t, opts, "TODO: fill me") - }) - t.Run("all options", func(t *testing.T) { opts := defaultOpts() - // TODO: fill me - assertOptsValidAndSQLEquals(t, opts, "TODO: fill me") + opts.IfExists = Bool(true) + assertOptsValidAndSQLEquals(t, opts, "DROP API INTEGRATION IF EXISTS %s", id.FullyQualifiedName()) }) } From 8978b16677dc0326be8895dc206d37fe4358390b Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Wed, 24 Jan 2024 09:49:32 +0100 Subject: [PATCH 12/24] Unit test alter (WIP) --- pkg/sdk/api_integrations_def.go | 2 +- pkg/sdk/api_integrations_gen.go | 2 +- pkg/sdk/api_integrations_gen_test.go | 140 +++++++++++++++++++++++---- 3 files changed, 121 insertions(+), 23 deletions(-) diff --git a/pkg/sdk/api_integrations_def.go b/pkg/sdk/api_integrations_def.go index 28bb7ad83e..312c38f76a 100644 --- a/pkg/sdk/api_integrations_def.go +++ b/pkg/sdk/api_integrations_def.go @@ -83,7 +83,7 @@ var ApiIntegrationsDef = g.NewInterface( OptionalQueryStructField( "AzureParams", g.NewQueryStruct("SetAzureApiParams"). - TextAssignment("AZURE_AD_APPLICATION_ID", g.ParameterOptions().SingleQuotes().Required()). + TextAssignment("AZURE_AD_APPLICATION_ID", g.ParameterOptions().SingleQuotes()). OptionalTextAssignment("API_KEY", g.ParameterOptions().SingleQuotes()). WithValidation(g.AtLeastOneValueSet, "AzureAdApplicationId", "ApiKey"), g.KeywordOptions(), diff --git a/pkg/sdk/api_integrations_gen.go b/pkg/sdk/api_integrations_gen.go index 017769c833..9a04922f02 100644 --- a/pkg/sdk/api_integrations_gen.go +++ b/pkg/sdk/api_integrations_gen.go @@ -80,7 +80,7 @@ type SetAwsApiParams struct { } type SetAzureApiParams struct { - AzureAdApplicationId string `ddl:"parameter,single_quotes" sql:"AZURE_AD_APPLICATION_ID"` + AzureAdApplicationId *string `ddl:"parameter,single_quotes" sql:"AZURE_AD_APPLICATION_ID"` ApiKey *string `ddl:"parameter,single_quotes" sql:"API_KEY"` } diff --git a/pkg/sdk/api_integrations_gen_test.go b/pkg/sdk/api_integrations_gen_test.go index 8f3edad6ca..bd6bcc5dc6 100644 --- a/pkg/sdk/api_integrations_gen_test.go +++ b/pkg/sdk/api_integrations_gen_test.go @@ -137,68 +137,166 @@ func TestApiIntegrations_Alter(t *testing.T) { t.Run("validation: valid identifier for [opts.name]", func(t *testing.T) { opts := defaultOpts() - // TODO: fill me + opts.name = NewAccountObjectIdentifier("") assertOptsInvalidJoinedErrors(t, opts, ErrInvalidObjectIdentifier) }) t.Run("validation: conflicting fields for [opts.IfExists opts.SetTags]", func(t *testing.T) { opts := defaultOpts() - // TODO: fill me + opts.IfExists = Bool(true) + opts.SetTags = []TagAssociation{ + { + Name: NewAccountObjectIdentifier("name"), + Value: "value", + }, + } assertOptsInvalidJoinedErrors(t, opts, errOneOf("AlterApiIntegrationOptions", "IfExists", "SetTags")) }) t.Run("validation: conflicting fields for [opts.IfExists opts.UnsetTags]", func(t *testing.T) { opts := defaultOpts() - // TODO: fill me + opts.IfExists = Bool(true) + opts.UnsetTags = []ObjectIdentifier{ + NewAccountObjectIdentifier("one"), + } assertOptsInvalidJoinedErrors(t, opts, errOneOf("AlterApiIntegrationOptions", "IfExists", "UnsetTags")) }) t.Run("validation: exactly one field from [opts.Set opts.Unset opts.SetTags opts.UnsetTags] should be present", func(t *testing.T) { opts := defaultOpts() - // TODO: fill me assertOptsInvalidJoinedErrors(t, opts, errExactlyOneOf("AlterApiIntegrationOptions", "Set", "Unset", "SetTags", "UnsetTags")) }) - t.Run("validation: conflicting fields for [opts.Set.S3Params opts.Set.AzureParams]", func(t *testing.T) { + t.Run("validation: exactly one field from [opts.Set opts.Unset opts.SetTags opts.UnsetTags] should be present - more present", func(t *testing.T) { + opts := defaultOpts() + opts.Set = &ApiIntegrationSet{ + Enabled: Bool(true), + } + opts.Unset = &ApiIntegrationUnset{ + Enabled: Bool(true), + } + assertOptsInvalidJoinedErrors(t, opts, errExactlyOneOf("AlterApiIntegrationOptions", "Set", "Unset", "SetTags", "UnsetTags")) + }) + + t.Run("validation: conflicting fields for [opts.Set.AwsParams opts.Set.AzureParams]", func(t *testing.T) { opts := defaultOpts() - // TODO: fill me - assertOptsInvalidJoinedErrors(t, opts, errOneOf("AlterApiIntegrationOptions.Set", "S3Params", "AzureParams")) + opts.Set = &ApiIntegrationSet{ + AwsParams: &SetAwsApiParams{ApiKey: String("key")}, + AzureParams: &SetAzureApiParams{ApiKey: String("key")}, + } + assertOptsInvalidJoinedErrors(t, opts, errOneOf("AlterApiIntegrationOptions.Set", "AwsParams", "AzureParams")) }) - t.Run("validation: at least one of the fields [opts.Set.S3Params opts.Set.AzureParams opts.Set.Enabled opts.Set.ApiAllowedPrefixes opts.Set.ApiBlockedPrefixes opts.Set.Comment] should be set", func(t *testing.T) { + t.Run("validation: at least one of the fields [opts.Set.AwsParams opts.Set.AzureParams opts.Set.Enabled opts.Set.ApiAllowedPrefixes opts.Set.ApiBlockedPrefixes opts.Set.Comment] should be set", func(t *testing.T) { opts := defaultOpts() - // TODO: fill me - assertOptsInvalidJoinedErrors(t, opts, errAtLeastOneOf("AlterApiIntegrationOptions.Set", "S3Params", "AzureParams", "Enabled", "ApiAllowedPrefixes", "ApiBlockedPrefixes", "Comment")) + assertOptsInvalidJoinedErrors(t, opts, errAtLeastOneOf("AlterApiIntegrationOptions.Set", "AwsParams", "AzureParams", "Enabled", "ApiAllowedPrefixes", "ApiBlockedPrefixes", "Comment")) }) - t.Run("validation: at least one of the fields [opts.Set.S3Params.ApiAwsRoleArn opts.Set.S3Params.ApiKey] should be set", func(t *testing.T) { + t.Run("validation: at least one of the fields [opts.Set.AwsParams.ApiAwsRoleArn opts.Set.AwsParams.ApiKey] should be set", func(t *testing.T) { opts := defaultOpts() - // TODO: fill me - assertOptsInvalidJoinedErrors(t, opts, errAtLeastOneOf("AlterApiIntegrationOptions.Set.S3Params", "ApiAwsRoleArn", "ApiKey")) + opts.Set = &ApiIntegrationSet{ + AwsParams: &SetAwsApiParams{}, + } + assertOptsInvalidJoinedErrors(t, opts, errAtLeastOneOf("AlterApiIntegrationOptions.Set.AwsParams", "ApiAwsRoleArn", "ApiKey")) }) t.Run("validation: at least one of the fields [opts.Set.AzureParams.AzureAdApplicationId opts.Set.AzureParams.ApiKey] should be set", func(t *testing.T) { opts := defaultOpts() - // TODO: fill me + opts.Set = &ApiIntegrationSet{ + AzureParams: &SetAzureApiParams{}, + } assertOptsInvalidJoinedErrors(t, opts, errAtLeastOneOf("AlterApiIntegrationOptions.Set.AzureParams", "AzureAdApplicationId", "ApiKey")) }) t.Run("validation: at least one of the fields [opts.Unset.ApiKey opts.Unset.Enabled opts.Unset.ApiBlockedPrefixes opts.Unset.Comment] should be set", func(t *testing.T) { opts := defaultOpts() - // TODO: fill me + opts.Unset = &ApiIntegrationUnset{} assertOptsInvalidJoinedErrors(t, opts, errAtLeastOneOf("AlterApiIntegrationOptions.Unset", "ApiKey", "Enabled", "ApiBlockedPrefixes", "Comment")) }) - t.Run("basic", func(t *testing.T) { + t.Run("set - aws", func(t *testing.T) { opts := defaultOpts() - // TODO: fill me - assertOptsValidAndSQLEquals(t, opts, "TODO: fill me") + opts.Set = &ApiIntegrationSet{ + AwsParams: &SetAwsApiParams{ + ApiAwsRoleArn: String("new-aws-role-arn"), + ApiKey: String("key"), + }, + Enabled: Bool(true), + ApiAllowedPrefixes: []ApiIntegrationEndpointPrefix{{Path: AwsAllowedPrefix}}, + ApiBlockedPrefixes: []ApiIntegrationEndpointPrefix{{Path: AzureAllowedPrefix}, {Path: GoogleAllowedPrefix}}, + Comment: String("comment"), + } + assertOptsValidAndSQLEquals(t, opts, "ALTER API INTEGRATION %s SET API_AWS_ROLE_ARN = 'new-aws-role-arn' API_KEY = 'key' ENABLED = true API_ALLOWED_PREFIXES = ('%s') API_BLOCKED_PREFIXES = ('%s', '%s') COMMENT = 'comment'", id.FullyQualifiedName(), AwsAllowedPrefix, AzureAllowedPrefix, GoogleAllowedPrefix) }) - t.Run("all options", func(t *testing.T) { + t.Run("set - azure", func(t *testing.T) { opts := defaultOpts() - // TODO: fill me - assertOptsValidAndSQLEquals(t, opts, "TODO: fill me") + opts.Set = &ApiIntegrationSet{ + AzureParams: &SetAzureApiParams{ + AzureAdApplicationId: String("new-azure-ad-application-id"), + ApiKey: String("key"), + }, + Enabled: Bool(true), + ApiAllowedPrefixes: []ApiIntegrationEndpointPrefix{{Path: AzureAllowedPrefix}}, + ApiBlockedPrefixes: []ApiIntegrationEndpointPrefix{{Path: AwsAllowedPrefix}, {Path: GoogleAllowedPrefix}}, + Comment: String("comment"), + } + assertOptsValidAndSQLEquals(t, opts, "ALTER API INTEGRATION %s SET AZURE_AD_APPLICATION_ID = 'new-azure-ad-application-id' API_KEY = 'key' ENABLED = true API_ALLOWED_PREFIXES = ('%s') API_BLOCKED_PREFIXES = ('%s', '%s') COMMENT = 'comment'", id.FullyQualifiedName(), AzureAllowedPrefix, AwsAllowedPrefix, GoogleAllowedPrefix) + }) + + t.Run("set - google", func(t *testing.T) { + opts := defaultOpts() + opts.Set = &ApiIntegrationSet{ + Enabled: Bool(true), + ApiAllowedPrefixes: []ApiIntegrationEndpointPrefix{{Path: GoogleAllowedPrefix}}, + ApiBlockedPrefixes: []ApiIntegrationEndpointPrefix{{Path: AwsAllowedPrefix}, {Path: AzureAllowedPrefix}}, + Comment: String("comment"), + } + assertOptsValidAndSQLEquals(t, opts, "ALTER API INTEGRATION %s SET ENABLED = true API_ALLOWED_PREFIXES = ('%s') API_BLOCKED_PREFIXES = ('%s', '%s') COMMENT = 'comment'", id.FullyQualifiedName(), GoogleAllowedPrefix, AwsAllowedPrefix, AzureAllowedPrefix) + }) + + t.Run("unset single", func(t *testing.T) { + opts := defaultOpts() + opts.Unset = &ApiIntegrationUnset{ + Comment: Bool(true), + } + assertOptsValidAndSQLEquals(t, opts, "ALTER API INTEGRATION %s UNSET COMMENT", id.FullyQualifiedName()) + }) + + t.Run("unset multiple", func(t *testing.T) { + opts := defaultOpts() + opts.Unset = &ApiIntegrationUnset{ + ApiKey: Bool(true), + Enabled: Bool(true), + ApiBlockedPrefixes: Bool(true), + Comment: Bool(true), + } + assertOptsValidAndSQLEquals(t, opts, "ALTER API INTEGRATION %s UNSET API_KEY, ENABLED, API_BLOCKED_PREFIXES, COMMENT", id.FullyQualifiedName()) + }) + + t.Run("set tags", func(t *testing.T) { + opts := defaultOpts() + opts.IfExists = Bool(true) + opts.SetTags = []TagAssociation{ + { + Name: NewAccountObjectIdentifier("name"), + Value: "value", + }, + { + Name: NewAccountObjectIdentifier("second-name"), + Value: "second-value", + }, + } + assertOptsValidAndSQLEquals(t, opts, `ALTER API INTEGRATION IF EXISTS %s SET TAG "name" = 'value', "second-name" = 'second-value'`, id.FullyQualifiedName()) + }) + + t.Run("unset tags", func(t *testing.T) { + opts := defaultOpts() + opts.UnsetTags = []ObjectIdentifier{ + NewAccountObjectIdentifier("name"), + NewAccountObjectIdentifier("second-name"), + } + assertOptsValidAndSQLEquals(t, opts, `ALTER API INTEGRATION %s UNSET TAG "name", "second-name"`, id.FullyQualifiedName()) }) } From 86c43da0588cd6c05dda6c8e1d69dcfdf94d986e Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Wed, 24 Jan 2024 09:51:11 +0100 Subject: [PATCH 13/24] Regenerate files --- pkg/sdk/api_integrations_def.go | 2 +- pkg/sdk/api_integrations_dto_builders_gen.go | 11 ++++++----- pkg/sdk/api_integrations_dto_gen.go | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/sdk/api_integrations_def.go b/pkg/sdk/api_integrations_def.go index 312c38f76a..043b96f11c 100644 --- a/pkg/sdk/api_integrations_def.go +++ b/pkg/sdk/api_integrations_def.go @@ -83,7 +83,7 @@ var ApiIntegrationsDef = g.NewInterface( OptionalQueryStructField( "AzureParams", g.NewQueryStruct("SetAzureApiParams"). - TextAssignment("AZURE_AD_APPLICATION_ID", g.ParameterOptions().SingleQuotes()). + OptionalTextAssignment("AZURE_AD_APPLICATION_ID", g.ParameterOptions().SingleQuotes()). OptionalTextAssignment("API_KEY", g.ParameterOptions().SingleQuotes()). WithValidation(g.AtLeastOneValueSet, "AzureAdApplicationId", "ApiKey"), g.KeywordOptions(), diff --git a/pkg/sdk/api_integrations_dto_builders_gen.go b/pkg/sdk/api_integrations_dto_builders_gen.go index fb15b2ee0f..90217bef3d 100644 --- a/pkg/sdk/api_integrations_dto_builders_gen.go +++ b/pkg/sdk/api_integrations_dto_builders_gen.go @@ -170,12 +170,13 @@ func (s *SetAwsApiParamsRequest) WithApiKey(ApiKey *string) *SetAwsApiParamsRequ return s } -func NewSetAzureApiParamsRequest( - AzureAdApplicationId string, -) *SetAzureApiParamsRequest { - s := SetAzureApiParamsRequest{} +func NewSetAzureApiParamsRequest() *SetAzureApiParamsRequest { + return &SetAzureApiParamsRequest{} +} + +func (s *SetAzureApiParamsRequest) WithAzureAdApplicationId(AzureAdApplicationId *string) *SetAzureApiParamsRequest { s.AzureAdApplicationId = AzureAdApplicationId - return &s + return s } func (s *SetAzureApiParamsRequest) WithApiKey(ApiKey *string) *SetAzureApiParamsRequest { diff --git a/pkg/sdk/api_integrations_dto_gen.go b/pkg/sdk/api_integrations_dto_gen.go index b63ca5dc17..46e5e196d3 100644 --- a/pkg/sdk/api_integrations_dto_gen.go +++ b/pkg/sdk/api_integrations_dto_gen.go @@ -63,7 +63,7 @@ type SetAwsApiParamsRequest struct { } type SetAzureApiParamsRequest struct { - AzureAdApplicationId string // required + AzureAdApplicationId *string ApiKey *string } From 465cd9b18ab4eb2160409e525ab9e15c4142d2ff Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Wed, 24 Jan 2024 09:52:51 +0100 Subject: [PATCH 14/24] Finish alter unit tests --- pkg/sdk/api_integrations_gen_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/sdk/api_integrations_gen_test.go b/pkg/sdk/api_integrations_gen_test.go index bd6bcc5dc6..181203ec0c 100644 --- a/pkg/sdk/api_integrations_gen_test.go +++ b/pkg/sdk/api_integrations_gen_test.go @@ -189,6 +189,7 @@ func TestApiIntegrations_Alter(t *testing.T) { t.Run("validation: at least one of the fields [opts.Set.AwsParams opts.Set.AzureParams opts.Set.Enabled opts.Set.ApiAllowedPrefixes opts.Set.ApiBlockedPrefixes opts.Set.Comment] should be set", func(t *testing.T) { opts := defaultOpts() + opts.Set = &ApiIntegrationSet{} assertOptsInvalidJoinedErrors(t, opts, errAtLeastOneOf("AlterApiIntegrationOptions.Set", "AwsParams", "AzureParams", "Enabled", "ApiAllowedPrefixes", "ApiBlockedPrefixes", "Comment")) }) @@ -276,7 +277,6 @@ func TestApiIntegrations_Alter(t *testing.T) { t.Run("set tags", func(t *testing.T) { opts := defaultOpts() - opts.IfExists = Bool(true) opts.SetTags = []TagAssociation{ { Name: NewAccountObjectIdentifier("name"), @@ -287,7 +287,7 @@ func TestApiIntegrations_Alter(t *testing.T) { Value: "second-value", }, } - assertOptsValidAndSQLEquals(t, opts, `ALTER API INTEGRATION IF EXISTS %s SET TAG "name" = 'value', "second-name" = 'second-value'`, id.FullyQualifiedName()) + assertOptsValidAndSQLEquals(t, opts, `ALTER API INTEGRATION %s SET TAG "name" = 'value', "second-name" = 'second-value'`, id.FullyQualifiedName()) }) t.Run("unset tags", func(t *testing.T) { From 4798a53b9daa7b281516f8cb7066724cff972ac2 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Wed, 24 Jan 2024 10:13:34 +0100 Subject: [PATCH 15/24] List integration tests to implement --- .../api_integrations_gen_integration_test.go | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/pkg/sdk/testint/api_integrations_gen_integration_test.go b/pkg/sdk/testint/api_integrations_gen_integration_test.go index ec1f8b929d..06a6f4e737 100644 --- a/pkg/sdk/testint/api_integrations_gen_integration_test.go +++ b/pkg/sdk/testint/api_integrations_gen_integration_test.go @@ -5,27 +5,55 @@ import "testing" func TestInt_ApiIntegrations(t *testing.T) { // TODO: prepare common resources - t.Run("Create", func(t *testing.T) { + t.Run("create api integration: aws", func(t *testing.T) { // TODO: fill me }) - t.Run("Alter", func(t *testing.T) { + t.Run("create api integration: azure", func(t *testing.T) { // TODO: fill me }) - t.Run("Drop", func(t *testing.T) { + t.Run("create api integration: google", func(t *testing.T) { // TODO: fill me }) - t.Run("Show", func(t *testing.T) { + t.Run("alter api integration: aws", func(t *testing.T) { // TODO: fill me }) - t.Run("ShowByID", func(t *testing.T) { + t.Run("alter api integration: azure", func(t *testing.T) { // TODO: fill me }) - t.Run("Describe", func(t *testing.T) { + t.Run("alter api integration: google", func(t *testing.T) { + // TODO: fill me + }) + + t.Run("drop view: existing", func(t *testing.T) { + // TODO: fill me + }) + + t.Run("drop view: non-existing", func(t *testing.T) { + // TODO: fill me + }) + + t.Run("show api integration: default", func(t *testing.T) { + // TODO: fill me + }) + + t.Run("show api integration: with options", func(t *testing.T) { + // TODO: fill me + }) + + t.Run("describe api integration: aws", func(t *testing.T) { + // TODO: fill me + }) + + t.Run("describe api integration: azure", func(t *testing.T) { + // TODO: fill me + }) + + t.Run("describe api integration: google", func(t *testing.T) { // TODO: fill me }) } From b2b139f29abec9eb121ef30dab6aa9655d3bf9de Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Wed, 24 Jan 2024 10:41:52 +0100 Subject: [PATCH 16/24] Test basic creation for each api provider --- pkg/sdk/api_integrations_dto_gen.go | 4 + pkg/sdk/client.go | 2 + .../api_integrations_gen_integration_test.go | 105 ++++++++++++++++-- 3 files changed, 103 insertions(+), 8 deletions(-) diff --git a/pkg/sdk/api_integrations_dto_gen.go b/pkg/sdk/api_integrations_dto_gen.go index 46e5e196d3..d0ca623dd8 100644 --- a/pkg/sdk/api_integrations_dto_gen.go +++ b/pkg/sdk/api_integrations_dto_gen.go @@ -23,6 +23,10 @@ type CreateApiIntegrationRequest struct { Comment *string } +func (r *CreateApiIntegrationRequest) GetName() AccountObjectIdentifier { + return r.name +} + type AwsApiParamsRequest struct { ApiProvider ApiIntegrationAwsApiProviderType // required ApiAwsRoleArn string // required diff --git a/pkg/sdk/client.go b/pkg/sdk/client.go index 3934cfb776..2a2939693c 100644 --- a/pkg/sdk/client.go +++ b/pkg/sdk/client.go @@ -40,6 +40,7 @@ type Client struct { // DDL Commands Accounts Accounts Alerts Alerts + ApiIntegrations ApiIntegrations ApplicationPackages ApplicationPackages ApplicationRoles ApplicationRoles Applications Applications @@ -186,6 +187,7 @@ func NewClientFromDB(db *sql.DB) *Client { func (c *Client) initialize() { c.Accounts = &accounts{client: c} c.Alerts = &alerts{client: c} + c.ApiIntegrations = &apiIntegrations{client: c} c.ApplicationPackages = &applicationPackages{client: c} c.ApplicationRoles = &applicationRoles{client: c} c.Applications = &applications{client: c} diff --git a/pkg/sdk/testint/api_integrations_gen_integration_test.go b/pkg/sdk/testint/api_integrations_gen_integration_test.go index 06a6f4e737..7d2d98dbea 100644 --- a/pkg/sdk/testint/api_integrations_gen_integration_test.go +++ b/pkg/sdk/testint/api_integrations_gen_integration_test.go @@ -1,20 +1,109 @@ package testint -import "testing" +import ( + "testing" + + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) func TestInt_ApiIntegrations(t *testing.T) { - // TODO: prepare common resources + client := testClient(t) + ctx := testContext(t) - t.Run("create api integration: aws", func(t *testing.T) { - // TODO: fill me + // TODO [JIRA]: replace with real values? + const awsAllowedPrefix = "https://123456.execute-api.us-west-2.amazonaws.com/prod/" + const azureAllowedPrefix = "https://apim-hello-world.azure-api.net/" + const googleAllowedPrefix = "https://gateway-id-123456.uc.gateway.dev/" + const apiAwsRoleArn = "arn:aws:iam::000000000001:/role/test" + const azureTenantId = "00000000-0000-0000-0000-000000000000" + const azureAdApplicationId = "11111111-1111-1111-1111-111111111111" + const googleAudience = "api-gateway-id-123456.apigateway.gcp-project.cloud.goog" + + prefixes := func(prefix string) []sdk.ApiIntegrationEndpointPrefix { + return []sdk.ApiIntegrationEndpointPrefix{{Path: prefix}} + } + awsAllowedPrefixes := prefixes(awsAllowedPrefix) + azureAllowedPrefixes := prefixes(azureAllowedPrefix) + googleAllowedPrefixes := prefixes(googleAllowedPrefix) + + assertApiIntegration := func(t *testing.T, s *sdk.ApiIntegration, name sdk.AccountObjectIdentifier, comment string) { + t.Helper() + assert.Equal(t, name.Name(), s.Name) + assert.Equal(t, true, s.Enabled) + assert.Equal(t, "EXTERNAL_API", s.ApiType) + assert.Equal(t, "API", s.Category) + assert.Equal(t, comment, s.Comment) + } + + cleanupApiIntegrationProvider := func(id sdk.AccountObjectIdentifier) func() { + return func() { + err := client.ApiIntegrations.Drop(ctx, sdk.NewDropApiIntegrationRequest(id)) + require.NoError(t, err) + } + } + + createApiIntegrationAwsRequest := func(t *testing.T) *sdk.CreateApiIntegrationRequest { + t.Helper() + id := sdk.RandomAccountObjectIdentifier() + + return sdk.NewCreateApiIntegrationRequest(id, awsAllowedPrefixes, true). + WithAwsApiProviderParams(sdk.NewAwsApiParamsRequest(sdk.ApiIntegrationAwsApiGateway, apiAwsRoleArn)) + } + + createApiIntegrationAzureRequest := func(t *testing.T) *sdk.CreateApiIntegrationRequest { + t.Helper() + id := sdk.RandomAccountObjectIdentifier() + + return sdk.NewCreateApiIntegrationRequest(id, azureAllowedPrefixes, true). + WithAzureApiProviderParams(sdk.NewAzureApiParamsRequest(azureTenantId, azureAdApplicationId)) + } + + createApiIntegrationGoogleRequest := func(t *testing.T) *sdk.CreateApiIntegrationRequest { + t.Helper() + id := sdk.RandomAccountObjectIdentifier() + + return sdk.NewCreateApiIntegrationRequest(id, googleAllowedPrefixes, true). + WithGoogleApiProviderParams(sdk.NewGoogleApiParamsRequest(googleAudience)) + } + + createApiIntegrationWithRequest := func(t *testing.T, request *sdk.CreateApiIntegrationRequest) *sdk.ApiIntegration { + t.Helper() + id := request.GetName() + + err := client.ApiIntegrations.Create(ctx, request) + require.NoError(t, err) + t.Cleanup(cleanupApiIntegrationProvider(id)) + + integration, err := client.ApiIntegrations.ShowByID(ctx, id) + require.NoError(t, err) + + return integration + } + + t.Run("create api integration: aws basic", func(t *testing.T) { + request := createApiIntegrationAwsRequest(t) + + integration := createApiIntegrationWithRequest(t, request) + + assertApiIntegration(t, integration, request.GetName(), "") }) - t.Run("create api integration: azure", func(t *testing.T) { - // TODO: fill me + t.Run("create api integration: azure basic", func(t *testing.T) { + request := createApiIntegrationAzureRequest(t) + + integration := createApiIntegrationWithRequest(t, request) + + assertApiIntegration(t, integration, request.GetName(), "") }) - t.Run("create api integration: google", func(t *testing.T) { - // TODO: fill me + t.Run("create api integration: google basic", func(t *testing.T) { + request := createApiIntegrationGoogleRequest(t) + + integration := createApiIntegrationWithRequest(t, request) + + assertApiIntegration(t, integration, request.GetName(), "") }) t.Run("alter api integration: aws", func(t *testing.T) { From d8472368a803c25a75ea587fbd5e79cd5ce49fc2 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Wed, 24 Jan 2024 10:56:57 +0100 Subject: [PATCH 17/24] Test creation with more params for each api provider --- .../api_integrations_gen_integration_test.go | 55 +++++++++++++++---- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/pkg/sdk/testint/api_integrations_gen_integration_test.go b/pkg/sdk/testint/api_integrations_gen_integration_test.go index 7d2d98dbea..d229342d22 100644 --- a/pkg/sdk/testint/api_integrations_gen_integration_test.go +++ b/pkg/sdk/testint/api_integrations_gen_integration_test.go @@ -13,9 +13,12 @@ func TestInt_ApiIntegrations(t *testing.T) { ctx := testContext(t) // TODO [JIRA]: replace with real values? - const awsAllowedPrefix = "https://123456.execute-api.us-west-2.amazonaws.com/prod/" - const azureAllowedPrefix = "https://apim-hello-world.azure-api.net/" - const googleAllowedPrefix = "https://gateway-id-123456.uc.gateway.dev/" + const awsAllowedPrefix = "https://123456.execute-api.us-west-2.amazonaws.com/dev/" + const awsBlockedPrefix = "https://123456.execute-api.us-west-2.amazonaws.com/prod/" + const azureAllowedPrefix = "https://apim-hello-world.azure-api.net/dev" + const azureBlockedPrefix = "https://apim-hello-world.azure-api.net/prod" + const googleAllowedPrefix = "https://gateway-id-123456.uc.gateway.dev/prod" + const googleBlockedPrefix = "https://gateway-id-123456.uc.gateway.dev/dev" const apiAwsRoleArn = "arn:aws:iam::000000000001:/role/test" const azureTenantId = "00000000-0000-0000-0000-000000000000" const azureAdApplicationId = "11111111-1111-1111-1111-111111111111" @@ -24,10 +27,6 @@ func TestInt_ApiIntegrations(t *testing.T) { prefixes := func(prefix string) []sdk.ApiIntegrationEndpointPrefix { return []sdk.ApiIntegrationEndpointPrefix{{Path: prefix}} } - awsAllowedPrefixes := prefixes(awsAllowedPrefix) - azureAllowedPrefixes := prefixes(azureAllowedPrefix) - googleAllowedPrefixes := prefixes(googleAllowedPrefix) - assertApiIntegration := func(t *testing.T, s *sdk.ApiIntegration, name sdk.AccountObjectIdentifier, comment string) { t.Helper() assert.Equal(t, name.Name(), s.Name) @@ -48,7 +47,7 @@ func TestInt_ApiIntegrations(t *testing.T) { t.Helper() id := sdk.RandomAccountObjectIdentifier() - return sdk.NewCreateApiIntegrationRequest(id, awsAllowedPrefixes, true). + return sdk.NewCreateApiIntegrationRequest(id, prefixes(awsAllowedPrefix), true). WithAwsApiProviderParams(sdk.NewAwsApiParamsRequest(sdk.ApiIntegrationAwsApiGateway, apiAwsRoleArn)) } @@ -56,7 +55,7 @@ func TestInt_ApiIntegrations(t *testing.T) { t.Helper() id := sdk.RandomAccountObjectIdentifier() - return sdk.NewCreateApiIntegrationRequest(id, azureAllowedPrefixes, true). + return sdk.NewCreateApiIntegrationRequest(id, prefixes(azureAllowedPrefix), true). WithAzureApiProviderParams(sdk.NewAzureApiParamsRequest(azureTenantId, azureAdApplicationId)) } @@ -64,7 +63,7 @@ func TestInt_ApiIntegrations(t *testing.T) { t.Helper() id := sdk.RandomAccountObjectIdentifier() - return sdk.NewCreateApiIntegrationRequest(id, googleAllowedPrefixes, true). + return sdk.NewCreateApiIntegrationRequest(id, prefixes(googleAllowedPrefix), true). WithGoogleApiProviderParams(sdk.NewGoogleApiParamsRequest(googleAudience)) } @@ -106,6 +105,42 @@ func TestInt_ApiIntegrations(t *testing.T) { assertApiIntegration(t, integration, request.GetName(), "") }) + t.Run("create api integration: aws more options", func(t *testing.T) { + request := createApiIntegrationAwsRequest(t) + + request = request. + WithAwsApiProviderParams(request.AwsApiProviderParams.WithApiKey(sdk.String("key"))). + WithApiBlockedPrefixes(prefixes(awsBlockedPrefix)). + WithComment(sdk.String("comment")) + + integration := createApiIntegrationWithRequest(t, request) + + assertApiIntegration(t, integration, request.GetName(), "comment") + }) + + t.Run("create api integration: azure more options", func(t *testing.T) { + request := createApiIntegrationAzureRequest(t) + + request = request. + WithAzureApiProviderParams(request.AzureApiProviderParams.WithApiKey(sdk.String("key"))). + WithApiBlockedPrefixes(prefixes(azureBlockedPrefix)). + WithComment(sdk.String("comment")) + + integration := createApiIntegrationWithRequest(t, request) + + assertApiIntegration(t, integration, request.GetName(), "comment") + }) + + t.Run("create api integration: google more options", func(t *testing.T) { + request := createApiIntegrationGoogleRequest(t). + WithApiBlockedPrefixes(prefixes(googleBlockedPrefix)). + WithComment(sdk.String("comment")) + + integration := createApiIntegrationWithRequest(t, request) + + assertApiIntegration(t, integration, request.GetName(), "comment") + }) + t.Run("alter api integration: aws", func(t *testing.T) { // TODO: fill me }) From 29df6cdcd7a7a719ef208b7cbc4488fabb0282e5 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Wed, 24 Jan 2024 10:59:05 +0100 Subject: [PATCH 18/24] Test drop --- .../api_integrations_gen_integration_test.go | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/pkg/sdk/testint/api_integrations_gen_integration_test.go b/pkg/sdk/testint/api_integrations_gen_integration_test.go index d229342d22..91ab65d349 100644 --- a/pkg/sdk/testint/api_integrations_gen_integration_test.go +++ b/pkg/sdk/testint/api_integrations_gen_integration_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" + "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/collections" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -153,12 +154,25 @@ func TestInt_ApiIntegrations(t *testing.T) { // TODO: fill me }) - t.Run("drop view: existing", func(t *testing.T) { - // TODO: fill me + t.Run("drop api integration: existing", func(t *testing.T) { + request := createApiIntegrationAwsRequest(t) + id := request.GetName() + + err := client.ApiIntegrations.Create(ctx, request) + require.NoError(t, err) + + err = client.ApiIntegrations.Drop(ctx, sdk.NewDropApiIntegrationRequest(id)) + require.NoError(t, err) + + _, err = client.ApiIntegrations.ShowByID(ctx, id) + assert.ErrorIs(t, err, collections.ErrObjectNotFound) }) - t.Run("drop view: non-existing", func(t *testing.T) { - // TODO: fill me + t.Run("drop api integration: non-existing", func(t *testing.T) { + id := sdk.NewAccountObjectIdentifier("does_not_exist") + + err := client.ApiIntegrations.Drop(ctx, sdk.NewDropApiIntegrationRequest(id)) + assert.ErrorIs(t, err, sdk.ErrObjectNotExistOrAuthorized) }) t.Run("show api integration: default", func(t *testing.T) { From 227a845bea33aa0c1e2f489ae8df8745ccc94175 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Wed, 24 Jan 2024 11:05:11 +0100 Subject: [PATCH 19/24] Test show --- .../api_integrations_gen_integration_test.go | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/pkg/sdk/testint/api_integrations_gen_integration_test.go b/pkg/sdk/testint/api_integrations_gen_integration_test.go index 91ab65d349..331d48fa18 100644 --- a/pkg/sdk/testint/api_integrations_gen_integration_test.go +++ b/pkg/sdk/testint/api_integrations_gen_integration_test.go @@ -82,6 +82,21 @@ func TestInt_ApiIntegrations(t *testing.T) { return integration } + createAwsApiIntegration := func(t *testing.T) *sdk.ApiIntegration { + t.Helper() + return createApiIntegrationWithRequest(t, createApiIntegrationAwsRequest(t)) + } + + createAzureApiIntegration := func(t *testing.T) *sdk.ApiIntegration { + t.Helper() + return createApiIntegrationWithRequest(t, createApiIntegrationAzureRequest(t)) + } + + createGoogleApiIntegration := func(t *testing.T) *sdk.ApiIntegration { + t.Helper() + return createApiIntegrationWithRequest(t, createApiIntegrationGoogleRequest(t)) + } + t.Run("create api integration: aws basic", func(t *testing.T) { request := createApiIntegrationAwsRequest(t) @@ -176,11 +191,30 @@ func TestInt_ApiIntegrations(t *testing.T) { }) t.Run("show api integration: default", func(t *testing.T) { - // TODO: fill me + integrationAws := createAwsApiIntegration(t) + integrationAzure := createAzureApiIntegration(t) + integrationGoogle := createGoogleApiIntegration(t) + + showRequest := sdk.NewShowApiIntegrationRequest() + returnedIntegrations, err := client.ApiIntegrations.Show(ctx, showRequest) + require.NoError(t, err) + + assert.Contains(t, returnedIntegrations, *integrationAws) + assert.Contains(t, returnedIntegrations, *integrationAzure) + assert.Contains(t, returnedIntegrations, *integrationGoogle) }) t.Run("show api integration: with options", func(t *testing.T) { - // TODO: fill me + integrationAws := createAwsApiIntegration(t) + integrationAzure := createAzureApiIntegration(t) + + showRequest := sdk.NewShowApiIntegrationRequest(). + WithLike(&sdk.Like{Pattern: &integrationAws.Name}) + returnedIntegrations, err := client.ApiIntegrations.Show(ctx, showRequest) + require.NoError(t, err) + + assert.Contains(t, returnedIntegrations, *integrationAws) + assert.NotContains(t, returnedIntegrations, *integrationAzure) }) t.Run("describe api integration: aws", func(t *testing.T) { From 848a20518d2a637f27f371b22ef1553d587c2d18 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Wed, 24 Jan 2024 11:27:35 +0100 Subject: [PATCH 20/24] Test describe --- pkg/sdk/api_integrations_gen.go | 4 ++ .../api_integrations_gen_integration_test.go | 49 +++++++++++++++++-- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/pkg/sdk/api_integrations_gen.go b/pkg/sdk/api_integrations_gen.go index 9a04922f02..69cda52d1d 100644 --- a/pkg/sdk/api_integrations_gen.go +++ b/pkg/sdk/api_integrations_gen.go @@ -124,6 +124,10 @@ type ApiIntegration struct { CreatedOn time.Time } +func (v *ApiIntegration) ID() AccountObjectIdentifier { + return NewAccountObjectIdentifier(v.Name) +} + // DescribeApiIntegrationOptions is based on https://docs.snowflake.com/en/sql-reference/sql/desc-integration. type DescribeApiIntegrationOptions struct { describe bool `ddl:"static" sql:"DESCRIBE"` diff --git a/pkg/sdk/testint/api_integrations_gen_integration_test.go b/pkg/sdk/testint/api_integrations_gen_integration_test.go index 331d48fa18..4a63366f37 100644 --- a/pkg/sdk/testint/api_integrations_gen_integration_test.go +++ b/pkg/sdk/testint/api_integrations_gen_integration_test.go @@ -1,6 +1,7 @@ package testint import ( + "strings" "testing" "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" @@ -28,6 +29,7 @@ func TestInt_ApiIntegrations(t *testing.T) { prefixes := func(prefix string) []sdk.ApiIntegrationEndpointPrefix { return []sdk.ApiIntegrationEndpointPrefix{{Path: prefix}} } + assertApiIntegration := func(t *testing.T, s *sdk.ApiIntegration, name sdk.AccountObjectIdentifier, comment string) { t.Helper() assert.Equal(t, name.Name(), s.Name) @@ -218,14 +220,55 @@ func TestInt_ApiIntegrations(t *testing.T) { }) t.Run("describe api integration: aws", func(t *testing.T) { - // TODO: fill me + integration := createAwsApiIntegration(t) + + details, err := client.ApiIntegrations.Describe(ctx, integration.ID()) + require.NoError(t, err) + + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "ENABLED", Type: "Boolean", Value: "true", Default: "false"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_KEY", Type: "String", Value: "", Default: ""}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_PROVIDER", Type: "String", Value: strings.ToUpper(string(sdk.ApiIntegrationAwsApiGateway)), Default: ""}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_AWS_ROLE_ARN", Type: "String", Value: apiAwsRoleArn, Default: ""}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_ALLOWED_PREFIXES", Type: "List", Value: awsAllowedPrefix, Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_BLOCKED_PREFIXES", Type: "List", Value: "", Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "COMMENT", Type: "String", Value: "", Default: ""}) }) t.Run("describe api integration: azure", func(t *testing.T) { - // TODO: fill me + integration := createAzureApiIntegration(t) + + details, err := client.ApiIntegrations.Describe(ctx, integration.ID()) + require.NoError(t, err) + + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "ENABLED", Type: "Boolean", Value: "true", Default: "false"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "AZURE_TENANT_ID", Type: "String", Value: azureTenantId, Default: ""}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "AZURE_AD_APPLICATION_ID", Type: "String", Value: azureAdApplicationId, Default: ""}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_KEY", Type: "String", Value: "", Default: ""}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_PROVIDER", Type: "String", Value: "AZURE_API_MANAGEMENT", Default: ""}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_ALLOWED_PREFIXES", Type: "List", Value: azureAllowedPrefix, Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_BLOCKED_PREFIXES", Type: "List", Value: "", Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "COMMENT", Type: "String", Value: "", Default: ""}) }) t.Run("describe api integration: google", func(t *testing.T) { - // TODO: fill me + integration := createGoogleApiIntegration(t) + + details, err := client.ApiIntegrations.Describe(ctx, integration.ID()) + require.NoError(t, err) + + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "ENABLED", Type: "Boolean", Value: "true", Default: "false"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_KEY", Type: "String", Value: "", Default: ""}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_PROVIDER", Type: "String", Value: "GOOGLE_API_GATEWAY", Default: ""}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "GOOGLE_AUDIENCE", Type: "String", Value: googleAudience, Default: ""}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_ALLOWED_PREFIXES", Type: "List", Value: googleAllowedPrefix, Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_BLOCKED_PREFIXES", Type: "List", Value: "", Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "COMMENT", Type: "String", Value: "", Default: ""}) + }) + + t.Run("describe api integration: non-existing", func(t *testing.T) { + id := sdk.NewAccountObjectIdentifier("does_not_exist") + + _, err := client.ApiIntegrations.Describe(ctx, id) + assert.ErrorIs(t, err, sdk.ErrObjectNotExistOrAuthorized) }) } From a5d7c15e599689e956f5a813e936ab954c5e1c4a Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Wed, 24 Jan 2024 11:50:36 +0100 Subject: [PATCH 21/24] Test alter --- .../api_integrations_gen_integration_test.go | 168 +++++++++++++++++- 1 file changed, 165 insertions(+), 3 deletions(-) diff --git a/pkg/sdk/testint/api_integrations_gen_integration_test.go b/pkg/sdk/testint/api_integrations_gen_integration_test.go index 4a63366f37..00e068f08e 100644 --- a/pkg/sdk/testint/api_integrations_gen_integration_test.go +++ b/pkg/sdk/testint/api_integrations_gen_integration_test.go @@ -160,15 +160,177 @@ func TestInt_ApiIntegrations(t *testing.T) { }) t.Run("alter api integration: aws", func(t *testing.T) { - // TODO: fill me + integration := createAwsApiIntegration(t) + + otherRoleArn := "arn:aws:iam::000000000001:/role/other" + setRequest := sdk.NewAlterApiIntegrationRequest(integration.ID()). + WithSet( + sdk.NewApiIntegrationSetRequest(). + WithAwsParams(sdk.NewSetAwsApiParamsRequest().WithApiAwsRoleArn(sdk.String(otherRoleArn)).WithApiKey(sdk.String("key"))). + WithEnabled(sdk.Bool(true)). + WithApiAllowedPrefixes(prefixes(awsBlockedPrefix)). + WithApiBlockedPrefixes(prefixes(awsAllowedPrefix)). + WithComment(sdk.String("changed comment")), + ) + err := client.ApiIntegrations.Alter(ctx, setRequest) + require.NoError(t, err) + + details, err := client.ApiIntegrations.Describe(ctx, integration.ID()) + require.NoError(t, err) + + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "ENABLED", Type: "Boolean", Value: "true", Default: "false"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_KEY", Type: "String", Value: "☺☺☺", Default: ""}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_AWS_ROLE_ARN", Type: "String", Value: otherRoleArn, Default: ""}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_ALLOWED_PREFIXES", Type: "List", Value: awsBlockedPrefix, Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_BLOCKED_PREFIXES", Type: "List", Value: awsAllowedPrefix, Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "COMMENT", Type: "String", Value: "changed comment", Default: ""}) + + unsetRequest := sdk.NewAlterApiIntegrationRequest(integration.ID()). + WithUnset( + sdk.NewApiIntegrationUnsetRequest(). + WithApiKey(sdk.Bool(true)). + WithEnabled(sdk.Bool(true)). + WithApiBlockedPrefixes(sdk.Bool(true)). + WithComment(sdk.Bool(true)), + ) + err = client.ApiIntegrations.Alter(ctx, unsetRequest) + require.NoError(t, err) + + details, err = client.ApiIntegrations.Describe(ctx, integration.ID()) + require.NoError(t, err) + + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "ENABLED", Type: "Boolean", Value: "false", Default: "false"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_KEY", Type: "String", Value: "", Default: ""}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_AWS_ROLE_ARN", Type: "String", Value: otherRoleArn, Default: ""}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_ALLOWED_PREFIXES", Type: "List", Value: awsBlockedPrefix, Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_BLOCKED_PREFIXES", Type: "List", Value: "", Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "COMMENT", Type: "String", Value: "", Default: ""}) }) t.Run("alter api integration: azure", func(t *testing.T) { - // TODO: fill me + integration := createAzureApiIntegration(t) + + otherAdApplicationId := "22222222-2222-2222-2222-222222222222" + setRequest := sdk.NewAlterApiIntegrationRequest(integration.ID()). + WithSet( + sdk.NewApiIntegrationSetRequest(). + WithAzureParams(sdk.NewSetAzureApiParamsRequest().WithAzureAdApplicationId(sdk.String(otherAdApplicationId)).WithApiKey(sdk.String("key"))). + WithEnabled(sdk.Bool(true)). + WithApiAllowedPrefixes(prefixes(azureBlockedPrefix)). + WithApiBlockedPrefixes(prefixes(azureAllowedPrefix)). + WithComment(sdk.String("changed comment")), + ) + err := client.ApiIntegrations.Alter(ctx, setRequest) + require.NoError(t, err) + + details, err := client.ApiIntegrations.Describe(ctx, integration.ID()) + require.NoError(t, err) + + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "ENABLED", Type: "Boolean", Value: "true", Default: "false"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_KEY", Type: "String", Value: "☺☺☺", Default: ""}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "AZURE_AD_APPLICATION_ID", Type: "String", Value: otherAdApplicationId, Default: ""}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_ALLOWED_PREFIXES", Type: "List", Value: azureBlockedPrefix, Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_BLOCKED_PREFIXES", Type: "List", Value: azureAllowedPrefix, Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "COMMENT", Type: "String", Value: "changed comment", Default: ""}) + + unsetRequest := sdk.NewAlterApiIntegrationRequest(integration.ID()). + WithUnset( + sdk.NewApiIntegrationUnsetRequest(). + WithApiKey(sdk.Bool(true)). + WithEnabled(sdk.Bool(true)). + WithApiBlockedPrefixes(sdk.Bool(true)). + WithComment(sdk.Bool(true)), + ) + err = client.ApiIntegrations.Alter(ctx, unsetRequest) + require.NoError(t, err) + + details, err = client.ApiIntegrations.Describe(ctx, integration.ID()) + require.NoError(t, err) + + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "ENABLED", Type: "Boolean", Value: "false", Default: "false"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_KEY", Type: "String", Value: "", Default: ""}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "AZURE_AD_APPLICATION_ID", Type: "String", Value: otherAdApplicationId, Default: ""}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_ALLOWED_PREFIXES", Type: "List", Value: azureBlockedPrefix, Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_BLOCKED_PREFIXES", Type: "List", Value: "", Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "COMMENT", Type: "String", Value: "", Default: ""}) }) t.Run("alter api integration: google", func(t *testing.T) { - // TODO: fill me + integration := createGoogleApiIntegration(t) + + setRequest := sdk.NewAlterApiIntegrationRequest(integration.ID()). + WithSet( + sdk.NewApiIntegrationSetRequest(). + WithEnabled(sdk.Bool(true)). + WithApiAllowedPrefixes(prefixes(googleBlockedPrefix)). + WithApiBlockedPrefixes(prefixes(googleAllowedPrefix)). + WithComment(sdk.String("changed comment")), + ) + err := client.ApiIntegrations.Alter(ctx, setRequest) + require.NoError(t, err) + + details, err := client.ApiIntegrations.Describe(ctx, integration.ID()) + require.NoError(t, err) + + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "ENABLED", Type: "Boolean", Value: "true", Default: "false"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_ALLOWED_PREFIXES", Type: "List", Value: googleBlockedPrefix, Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_BLOCKED_PREFIXES", Type: "List", Value: googleAllowedPrefix, Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "COMMENT", Type: "String", Value: "changed comment", Default: ""}) + + unsetRequest := sdk.NewAlterApiIntegrationRequest(integration.ID()). + WithUnset( + sdk.NewApiIntegrationUnsetRequest(). + WithApiKey(sdk.Bool(true)). + WithEnabled(sdk.Bool(true)). + WithApiBlockedPrefixes(sdk.Bool(true)). + WithComment(sdk.Bool(true)), + ) + err = client.ApiIntegrations.Alter(ctx, unsetRequest) + require.NoError(t, err) + + details, err = client.ApiIntegrations.Describe(ctx, integration.ID()) + require.NoError(t, err) + + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "ENABLED", Type: "Boolean", Value: "false", Default: "false"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_ALLOWED_PREFIXES", Type: "List", Value: googleBlockedPrefix, Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_BLOCKED_PREFIXES", Type: "List", Value: "", Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "COMMENT", Type: "String", Value: "", Default: ""}) + }) + + t.Run("alter api integration: set and unset tags", func(t *testing.T) { + tag, tagCleanup := createTag(t, client, testDb(t), testSchema(t)) + t.Cleanup(tagCleanup) + + integration := createAwsApiIntegration(t) + id := integration.ID() + + tagValue := "abc" + tags := []sdk.TagAssociation{ + { + Name: tag.ID(), + Value: tagValue, + }, + } + alterRequestSetTags := sdk.NewAlterApiIntegrationRequest(id).WithSetTags(tags) + + err := client.ApiIntegrations.Alter(ctx, alterRequestSetTags) + require.NoError(t, err) + + returnedTagValue, err := client.SystemFunctions.GetTag(ctx, tag.ID(), id, sdk.ObjectTypeIntegration) + require.NoError(t, err) + + assert.Equal(t, tagValue, returnedTagValue) + + unsetTags := []sdk.ObjectIdentifier{ + tag.ID(), + } + alterRequestUnsetTags := sdk.NewAlterApiIntegrationRequest(id).WithUnsetTags(unsetTags) + + err = client.ApiIntegrations.Alter(ctx, alterRequestUnsetTags) + require.NoError(t, err) + + _, err = client.SystemFunctions.GetTag(ctx, tag.ID(), id, sdk.ObjectTypeIntegration) + require.Error(t, err) }) t.Run("drop api integration: existing", func(t *testing.T) { From e9eca0e045bc1763272040a559e1daa3198f99ab Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Wed, 24 Jan 2024 11:54:08 +0100 Subject: [PATCH 22/24] Add ticket number to TODO --- pkg/sdk/testint/api_integrations_gen_integration_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/sdk/testint/api_integrations_gen_integration_test.go b/pkg/sdk/testint/api_integrations_gen_integration_test.go index 00e068f08e..a7c612f458 100644 --- a/pkg/sdk/testint/api_integrations_gen_integration_test.go +++ b/pkg/sdk/testint/api_integrations_gen_integration_test.go @@ -14,7 +14,7 @@ func TestInt_ApiIntegrations(t *testing.T) { client := testClient(t) ctx := testContext(t) - // TODO [JIRA]: replace with real values? + // TODO [SNOW-1017580]: replace with real values when testing with external function invocation. const awsAllowedPrefix = "https://123456.execute-api.us-west-2.amazonaws.com/dev/" const awsBlockedPrefix = "https://123456.execute-api.us-west-2.amazonaws.com/prod/" const azureAllowedPrefix = "https://apim-hello-world.azure-api.net/dev" From ae13d076cef3ec7c9945556fb7f45381e1e82223 Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Wed, 24 Jan 2024 11:57:46 +0100 Subject: [PATCH 23/24] Run make pre-push --- pkg/sdk/api_integrations_gen_test.go | 62 ++++++++++++++-------------- pkg/sdk/api_integrations_impl_gen.go | 1 - 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/pkg/sdk/api_integrations_gen_test.go b/pkg/sdk/api_integrations_gen_test.go index 181203ec0c..5e3be6e53a 100644 --- a/pkg/sdk/api_integrations_gen_test.go +++ b/pkg/sdk/api_integrations_gen_test.go @@ -2,14 +2,16 @@ package sdk import "testing" -const AwsAllowedPrefix = "https://123456.execute-api.us-west-2.amazonaws.com/prod/" -const AzureAllowedPrefix = "https://apim-hello-world.azure-api.net/" -const GoogleAllowedPrefix = "https://gateway-id-123456.uc.gateway.dev/" +const ( + awsAllowedPrefix = "https://123456.execute-api.us-west-2.amazonaws.com/prod/" + azureAllowedPrefix = "https://apim-hello-world.azure-api.net/" + googleAllowedPrefix = "https://gateway-id-123456.uc.gateway.dev/" -const ApiAwsRoleArn = "arn:aws:iam::000000000001:/role/test" -const AzureTenantId = "00000000-0000-0000-0000-000000000000" -const AzureAdApplicationId = "11111111-1111-1111-1111-111111111111" -const GoogleAudience = "api-gateway-id-123456.apigateway.gcp-project.cloud.goog" + apiAwsRoleArn = "arn:aws:iam::000000000001:/role/test" + azureTenantId = "00000000-0000-0000-0000-000000000000" + azureAdApplicationId = "11111111-1111-1111-1111-111111111111" + googleAudience = "api-gateway-id-123456.apigateway.gcp-project.cloud.goog" +) func TestApiIntegrations_Create(t *testing.T) { id := RandomAccountObjectIdentifier() @@ -20,9 +22,9 @@ func TestApiIntegrations_Create(t *testing.T) { name: id, AwsApiProviderParams: &AwsApiParams{ ApiProvider: ApiIntegrationAwsApiGateway, - ApiAwsRoleArn: ApiAwsRoleArn, + ApiAwsRoleArn: apiAwsRoleArn, }, - ApiAllowedPrefixes: []ApiIntegrationEndpointPrefix{{Path: AwsAllowedPrefix}}, + ApiAllowedPrefixes: []ApiIntegrationEndpointPrefix{{Path: awsAllowedPrefix}}, Enabled: true, } } @@ -32,10 +34,10 @@ func TestApiIntegrations_Create(t *testing.T) { return &CreateApiIntegrationOptions{ name: id, AzureApiProviderParams: &AzureApiParams{ - AzureTenantId: AzureTenantId, - AzureAdApplicationId: AzureAdApplicationId, + AzureTenantId: azureTenantId, + AzureAdApplicationId: azureAdApplicationId, }, - ApiAllowedPrefixes: []ApiIntegrationEndpointPrefix{{Path: AzureAllowedPrefix}}, + ApiAllowedPrefixes: []ApiIntegrationEndpointPrefix{{Path: azureAllowedPrefix}}, Enabled: true, } } @@ -45,9 +47,9 @@ func TestApiIntegrations_Create(t *testing.T) { return &CreateApiIntegrationOptions{ name: id, GoogleApiProviderParams: &GoogleApiParams{ - GoogleAudience: GoogleAudience, + GoogleAudience: googleAudience, }, - ApiAllowedPrefixes: []ApiIntegrationEndpointPrefix{{Path: GoogleAllowedPrefix}}, + ApiAllowedPrefixes: []ApiIntegrationEndpointPrefix{{Path: googleAllowedPrefix}}, Enabled: true, } } @@ -86,7 +88,7 @@ func TestApiIntegrations_Create(t *testing.T) { t.Run("basic", func(t *testing.T) { opts := defaultOpts() - assertOptsValidAndSQLEquals(t, opts, `CREATE API INTEGRATION %s API_PROVIDER = aws_api_gateway API_AWS_ROLE_ARN = '%s' API_ALLOWED_PREFIXES = ('%s') ENABLED = true`, id.FullyQualifiedName(), ApiAwsRoleArn, AwsAllowedPrefix) + assertOptsValidAndSQLEquals(t, opts, `CREATE API INTEGRATION %s API_PROVIDER = aws_api_gateway API_AWS_ROLE_ARN = '%s' API_ALLOWED_PREFIXES = ('%s') ENABLED = true`, id.FullyQualifiedName(), apiAwsRoleArn, awsAllowedPrefix) }) t.Run("all options - aws", func(t *testing.T) { @@ -94,29 +96,29 @@ func TestApiIntegrations_Create(t *testing.T) { opts.IfNotExists = Bool(true) opts.AwsApiProviderParams.ApiProvider = ApiIntegrationAwsPrivateApiGateway opts.AwsApiProviderParams.ApiKey = String("key") - opts.ApiBlockedPrefixes = []ApiIntegrationEndpointPrefix{{Path: GoogleAllowedPrefix}, {Path: AzureAllowedPrefix}} + opts.ApiBlockedPrefixes = []ApiIntegrationEndpointPrefix{{Path: googleAllowedPrefix}, {Path: azureAllowedPrefix}} opts.Enabled = false opts.Comment = String("some comment") - assertOptsValidAndSQLEquals(t, opts, `CREATE API INTEGRATION IF NOT EXISTS %s API_PROVIDER = aws_private_api_gateway API_AWS_ROLE_ARN = '%s' API_KEY = 'key' API_ALLOWED_PREFIXES = ('%s') API_BLOCKED_PREFIXES = ('%s', '%s') ENABLED = false COMMENT = 'some comment'`, id.FullyQualifiedName(), ApiAwsRoleArn, AwsAllowedPrefix, GoogleAllowedPrefix, AzureAllowedPrefix) + assertOptsValidAndSQLEquals(t, opts, `CREATE API INTEGRATION IF NOT EXISTS %s API_PROVIDER = aws_private_api_gateway API_AWS_ROLE_ARN = '%s' API_KEY = 'key' API_ALLOWED_PREFIXES = ('%s') API_BLOCKED_PREFIXES = ('%s', '%s') ENABLED = false COMMENT = 'some comment'`, id.FullyQualifiedName(), apiAwsRoleArn, awsAllowedPrefix, googleAllowedPrefix, azureAllowedPrefix) }) t.Run("all options - azure", func(t *testing.T) { opts := defaultOptsAzure() opts.IfNotExists = Bool(true) opts.AzureApiProviderParams.ApiKey = String("key") - opts.ApiBlockedPrefixes = []ApiIntegrationEndpointPrefix{{Path: AwsAllowedPrefix}, {Path: GoogleAllowedPrefix}} + opts.ApiBlockedPrefixes = []ApiIntegrationEndpointPrefix{{Path: awsAllowedPrefix}, {Path: googleAllowedPrefix}} opts.Enabled = false opts.Comment = String("some comment") - assertOptsValidAndSQLEquals(t, opts, `CREATE API INTEGRATION IF NOT EXISTS %s API_PROVIDER = azure_api_management AZURE_TENANT_ID = '%s' AZURE_AD_APPLICATION_ID = '%s' API_KEY = 'key' API_ALLOWED_PREFIXES = ('%s') API_BLOCKED_PREFIXES = ('%s', '%s') ENABLED = false COMMENT = 'some comment'`, id.FullyQualifiedName(), AzureTenantId, AzureAdApplicationId, AzureAllowedPrefix, AwsAllowedPrefix, GoogleAllowedPrefix) + assertOptsValidAndSQLEquals(t, opts, `CREATE API INTEGRATION IF NOT EXISTS %s API_PROVIDER = azure_api_management AZURE_TENANT_ID = '%s' AZURE_AD_APPLICATION_ID = '%s' API_KEY = 'key' API_ALLOWED_PREFIXES = ('%s') API_BLOCKED_PREFIXES = ('%s', '%s') ENABLED = false COMMENT = 'some comment'`, id.FullyQualifiedName(), azureTenantId, azureAdApplicationId, azureAllowedPrefix, awsAllowedPrefix, googleAllowedPrefix) }) t.Run("all options - google", func(t *testing.T) { opts := defaultOptsGoogle() opts.IfNotExists = Bool(true) - opts.ApiBlockedPrefixes = []ApiIntegrationEndpointPrefix{{Path: AwsAllowedPrefix}, {Path: AzureAllowedPrefix}} + opts.ApiBlockedPrefixes = []ApiIntegrationEndpointPrefix{{Path: awsAllowedPrefix}, {Path: azureAllowedPrefix}} opts.Enabled = false opts.Comment = String("some comment") - assertOptsValidAndSQLEquals(t, opts, `CREATE API INTEGRATION IF NOT EXISTS %s API_PROVIDER = google_api_gateway GOOGLE_AUDIENCE = '%s' API_ALLOWED_PREFIXES = ('%s') API_BLOCKED_PREFIXES = ('%s', '%s') ENABLED = false COMMENT = 'some comment'`, id.FullyQualifiedName(), GoogleAudience, GoogleAllowedPrefix, AwsAllowedPrefix, AzureAllowedPrefix) + assertOptsValidAndSQLEquals(t, opts, `CREATE API INTEGRATION IF NOT EXISTS %s API_PROVIDER = google_api_gateway GOOGLE_AUDIENCE = '%s' API_ALLOWED_PREFIXES = ('%s') API_BLOCKED_PREFIXES = ('%s', '%s') ENABLED = false COMMENT = 'some comment'`, id.FullyQualifiedName(), googleAudience, googleAllowedPrefix, awsAllowedPrefix, azureAllowedPrefix) }) } @@ -223,11 +225,11 @@ func TestApiIntegrations_Alter(t *testing.T) { ApiKey: String("key"), }, Enabled: Bool(true), - ApiAllowedPrefixes: []ApiIntegrationEndpointPrefix{{Path: AwsAllowedPrefix}}, - ApiBlockedPrefixes: []ApiIntegrationEndpointPrefix{{Path: AzureAllowedPrefix}, {Path: GoogleAllowedPrefix}}, + ApiAllowedPrefixes: []ApiIntegrationEndpointPrefix{{Path: awsAllowedPrefix}}, + ApiBlockedPrefixes: []ApiIntegrationEndpointPrefix{{Path: azureAllowedPrefix}, {Path: googleAllowedPrefix}}, Comment: String("comment"), } - assertOptsValidAndSQLEquals(t, opts, "ALTER API INTEGRATION %s SET API_AWS_ROLE_ARN = 'new-aws-role-arn' API_KEY = 'key' ENABLED = true API_ALLOWED_PREFIXES = ('%s') API_BLOCKED_PREFIXES = ('%s', '%s') COMMENT = 'comment'", id.FullyQualifiedName(), AwsAllowedPrefix, AzureAllowedPrefix, GoogleAllowedPrefix) + assertOptsValidAndSQLEquals(t, opts, "ALTER API INTEGRATION %s SET API_AWS_ROLE_ARN = 'new-aws-role-arn' API_KEY = 'key' ENABLED = true API_ALLOWED_PREFIXES = ('%s') API_BLOCKED_PREFIXES = ('%s', '%s') COMMENT = 'comment'", id.FullyQualifiedName(), awsAllowedPrefix, azureAllowedPrefix, googleAllowedPrefix) }) t.Run("set - azure", func(t *testing.T) { @@ -238,22 +240,22 @@ func TestApiIntegrations_Alter(t *testing.T) { ApiKey: String("key"), }, Enabled: Bool(true), - ApiAllowedPrefixes: []ApiIntegrationEndpointPrefix{{Path: AzureAllowedPrefix}}, - ApiBlockedPrefixes: []ApiIntegrationEndpointPrefix{{Path: AwsAllowedPrefix}, {Path: GoogleAllowedPrefix}}, + ApiAllowedPrefixes: []ApiIntegrationEndpointPrefix{{Path: azureAllowedPrefix}}, + ApiBlockedPrefixes: []ApiIntegrationEndpointPrefix{{Path: awsAllowedPrefix}, {Path: googleAllowedPrefix}}, Comment: String("comment"), } - assertOptsValidAndSQLEquals(t, opts, "ALTER API INTEGRATION %s SET AZURE_AD_APPLICATION_ID = 'new-azure-ad-application-id' API_KEY = 'key' ENABLED = true API_ALLOWED_PREFIXES = ('%s') API_BLOCKED_PREFIXES = ('%s', '%s') COMMENT = 'comment'", id.FullyQualifiedName(), AzureAllowedPrefix, AwsAllowedPrefix, GoogleAllowedPrefix) + assertOptsValidAndSQLEquals(t, opts, "ALTER API INTEGRATION %s SET AZURE_AD_APPLICATION_ID = 'new-azure-ad-application-id' API_KEY = 'key' ENABLED = true API_ALLOWED_PREFIXES = ('%s') API_BLOCKED_PREFIXES = ('%s', '%s') COMMENT = 'comment'", id.FullyQualifiedName(), azureAllowedPrefix, awsAllowedPrefix, googleAllowedPrefix) }) t.Run("set - google", func(t *testing.T) { opts := defaultOpts() opts.Set = &ApiIntegrationSet{ Enabled: Bool(true), - ApiAllowedPrefixes: []ApiIntegrationEndpointPrefix{{Path: GoogleAllowedPrefix}}, - ApiBlockedPrefixes: []ApiIntegrationEndpointPrefix{{Path: AwsAllowedPrefix}, {Path: AzureAllowedPrefix}}, + ApiAllowedPrefixes: []ApiIntegrationEndpointPrefix{{Path: googleAllowedPrefix}}, + ApiBlockedPrefixes: []ApiIntegrationEndpointPrefix{{Path: awsAllowedPrefix}, {Path: azureAllowedPrefix}}, Comment: String("comment"), } - assertOptsValidAndSQLEquals(t, opts, "ALTER API INTEGRATION %s SET ENABLED = true API_ALLOWED_PREFIXES = ('%s') API_BLOCKED_PREFIXES = ('%s', '%s') COMMENT = 'comment'", id.FullyQualifiedName(), GoogleAllowedPrefix, AwsAllowedPrefix, AzureAllowedPrefix) + assertOptsValidAndSQLEquals(t, opts, "ALTER API INTEGRATION %s SET ENABLED = true API_ALLOWED_PREFIXES = ('%s') API_BLOCKED_PREFIXES = ('%s', '%s') COMMENT = 'comment'", id.FullyQualifiedName(), googleAllowedPrefix, awsAllowedPrefix, azureAllowedPrefix) }) t.Run("unset single", func(t *testing.T) { diff --git a/pkg/sdk/api_integrations_impl_gen.go b/pkg/sdk/api_integrations_impl_gen.go index 99c564ae77..e93cdd9588 100644 --- a/pkg/sdk/api_integrations_impl_gen.go +++ b/pkg/sdk/api_integrations_impl_gen.go @@ -101,7 +101,6 @@ func (r *AlterApiIntegrationRequest) toOpts() *AlterApiIntegrationOptions { } if r.Set != nil { opts.Set = &ApiIntegrationSet{ - Enabled: r.Set.Enabled, ApiAllowedPrefixes: r.Set.ApiAllowedPrefixes, ApiBlockedPrefixes: r.Set.ApiBlockedPrefixes, From ff2f4ef7b22a6ca4668f587af18603140108c27d Mon Sep 17 00:00:00 2001 From: Artur Sawicki Date: Wed, 24 Jan 2024 13:46:03 +0100 Subject: [PATCH 24/24] Fix after review --- .../api_integrations_gen_integration_test.go | 80 ++++++++++++------- 1 file changed, 50 insertions(+), 30 deletions(-) diff --git a/pkg/sdk/testint/api_integrations_gen_integration_test.go b/pkg/sdk/testint/api_integrations_gen_integration_test.go index a7c612f458..39325f3580 100644 --- a/pkg/sdk/testint/api_integrations_gen_integration_test.go +++ b/pkg/sdk/testint/api_integrations_gen_integration_test.go @@ -15,12 +15,12 @@ func TestInt_ApiIntegrations(t *testing.T) { ctx := testContext(t) // TODO [SNOW-1017580]: replace with real values when testing with external function invocation. - const awsAllowedPrefix = "https://123456.execute-api.us-west-2.amazonaws.com/dev/" - const awsBlockedPrefix = "https://123456.execute-api.us-west-2.amazonaws.com/prod/" - const azureAllowedPrefix = "https://apim-hello-world.azure-api.net/dev" - const azureBlockedPrefix = "https://apim-hello-world.azure-api.net/prod" - const googleAllowedPrefix = "https://gateway-id-123456.uc.gateway.dev/prod" - const googleBlockedPrefix = "https://gateway-id-123456.uc.gateway.dev/dev" + const awsPrefix = "https://123456.execute-api.us-west-2.amazonaws.com/dev/" + const awsOtherPrefix = "https://123456.execute-api.us-west-2.amazonaws.com/prod/" + const azurePrefix = "https://apim-hello-world.azure-api.net/dev" + const azureOtherPrefix = "https://apim-hello-world.azure-api.net/prod" + const googlePrefix = "https://gateway-id-123456.uc.gateway.dev/prod" + const googleOtherPrefix = "https://gateway-id-123456.uc.gateway.dev/dev" const apiAwsRoleArn = "arn:aws:iam::000000000001:/role/test" const azureTenantId = "00000000-0000-0000-0000-000000000000" const azureAdApplicationId = "11111111-1111-1111-1111-111111111111" @@ -50,7 +50,7 @@ func TestInt_ApiIntegrations(t *testing.T) { t.Helper() id := sdk.RandomAccountObjectIdentifier() - return sdk.NewCreateApiIntegrationRequest(id, prefixes(awsAllowedPrefix), true). + return sdk.NewCreateApiIntegrationRequest(id, prefixes(awsPrefix), true). WithAwsApiProviderParams(sdk.NewAwsApiParamsRequest(sdk.ApiIntegrationAwsApiGateway, apiAwsRoleArn)) } @@ -58,7 +58,7 @@ func TestInt_ApiIntegrations(t *testing.T) { t.Helper() id := sdk.RandomAccountObjectIdentifier() - return sdk.NewCreateApiIntegrationRequest(id, prefixes(azureAllowedPrefix), true). + return sdk.NewCreateApiIntegrationRequest(id, prefixes(azurePrefix), true). WithAzureApiProviderParams(sdk.NewAzureApiParamsRequest(azureTenantId, azureAdApplicationId)) } @@ -66,7 +66,7 @@ func TestInt_ApiIntegrations(t *testing.T) { t.Helper() id := sdk.RandomAccountObjectIdentifier() - return sdk.NewCreateApiIntegrationRequest(id, prefixes(googleAllowedPrefix), true). + return sdk.NewCreateApiIntegrationRequest(id, prefixes(googlePrefix), true). WithGoogleApiProviderParams(sdk.NewGoogleApiParamsRequest(googleAudience)) } @@ -128,12 +128,19 @@ func TestInt_ApiIntegrations(t *testing.T) { request = request. WithAwsApiProviderParams(request.AwsApiProviderParams.WithApiKey(sdk.String("key"))). - WithApiBlockedPrefixes(prefixes(awsBlockedPrefix)). + WithApiBlockedPrefixes(prefixes(awsOtherPrefix)). WithComment(sdk.String("comment")) integration := createApiIntegrationWithRequest(t, request) assertApiIntegration(t, integration, request.GetName(), "comment") + + details, err := client.ApiIntegrations.Describe(ctx, integration.ID()) + require.NoError(t, err) + + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_KEY", Type: "String", Value: "☺☺☺", Default: ""}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_BLOCKED_PREFIXES", Type: "List", Value: awsOtherPrefix, Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "COMMENT", Type: "String", Value: "comment", Default: ""}) }) t.Run("create api integration: azure more options", func(t *testing.T) { @@ -141,22 +148,35 @@ func TestInt_ApiIntegrations(t *testing.T) { request = request. WithAzureApiProviderParams(request.AzureApiProviderParams.WithApiKey(sdk.String("key"))). - WithApiBlockedPrefixes(prefixes(azureBlockedPrefix)). + WithApiBlockedPrefixes(prefixes(azureOtherPrefix)). WithComment(sdk.String("comment")) integration := createApiIntegrationWithRequest(t, request) assertApiIntegration(t, integration, request.GetName(), "comment") + + details, err := client.ApiIntegrations.Describe(ctx, integration.ID()) + require.NoError(t, err) + + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_KEY", Type: "String", Value: "☺☺☺", Default: ""}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_BLOCKED_PREFIXES", Type: "List", Value: azureOtherPrefix, Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "COMMENT", Type: "String", Value: "comment", Default: ""}) }) t.Run("create api integration: google more options", func(t *testing.T) { request := createApiIntegrationGoogleRequest(t). - WithApiBlockedPrefixes(prefixes(googleBlockedPrefix)). + WithApiBlockedPrefixes(prefixes(googleOtherPrefix)). WithComment(sdk.String("comment")) integration := createApiIntegrationWithRequest(t, request) assertApiIntegration(t, integration, request.GetName(), "comment") + + details, err := client.ApiIntegrations.Describe(ctx, integration.ID()) + require.NoError(t, err) + + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_BLOCKED_PREFIXES", Type: "List", Value: googleOtherPrefix, Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "COMMENT", Type: "String", Value: "comment", Default: ""}) }) t.Run("alter api integration: aws", func(t *testing.T) { @@ -168,8 +188,8 @@ func TestInt_ApiIntegrations(t *testing.T) { sdk.NewApiIntegrationSetRequest(). WithAwsParams(sdk.NewSetAwsApiParamsRequest().WithApiAwsRoleArn(sdk.String(otherRoleArn)).WithApiKey(sdk.String("key"))). WithEnabled(sdk.Bool(true)). - WithApiAllowedPrefixes(prefixes(awsBlockedPrefix)). - WithApiBlockedPrefixes(prefixes(awsAllowedPrefix)). + WithApiAllowedPrefixes(prefixes(awsOtherPrefix)). + WithApiBlockedPrefixes(prefixes(awsPrefix)). WithComment(sdk.String("changed comment")), ) err := client.ApiIntegrations.Alter(ctx, setRequest) @@ -181,8 +201,8 @@ func TestInt_ApiIntegrations(t *testing.T) { assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "ENABLED", Type: "Boolean", Value: "true", Default: "false"}) assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_KEY", Type: "String", Value: "☺☺☺", Default: ""}) assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_AWS_ROLE_ARN", Type: "String", Value: otherRoleArn, Default: ""}) - assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_ALLOWED_PREFIXES", Type: "List", Value: awsBlockedPrefix, Default: "[]"}) - assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_BLOCKED_PREFIXES", Type: "List", Value: awsAllowedPrefix, Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_ALLOWED_PREFIXES", Type: "List", Value: awsOtherPrefix, Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_BLOCKED_PREFIXES", Type: "List", Value: awsPrefix, Default: "[]"}) assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "COMMENT", Type: "String", Value: "changed comment", Default: ""}) unsetRequest := sdk.NewAlterApiIntegrationRequest(integration.ID()). @@ -202,7 +222,7 @@ func TestInt_ApiIntegrations(t *testing.T) { assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "ENABLED", Type: "Boolean", Value: "false", Default: "false"}) assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_KEY", Type: "String", Value: "", Default: ""}) assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_AWS_ROLE_ARN", Type: "String", Value: otherRoleArn, Default: ""}) - assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_ALLOWED_PREFIXES", Type: "List", Value: awsBlockedPrefix, Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_ALLOWED_PREFIXES", Type: "List", Value: awsOtherPrefix, Default: "[]"}) assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_BLOCKED_PREFIXES", Type: "List", Value: "", Default: "[]"}) assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "COMMENT", Type: "String", Value: "", Default: ""}) }) @@ -216,8 +236,8 @@ func TestInt_ApiIntegrations(t *testing.T) { sdk.NewApiIntegrationSetRequest(). WithAzureParams(sdk.NewSetAzureApiParamsRequest().WithAzureAdApplicationId(sdk.String(otherAdApplicationId)).WithApiKey(sdk.String("key"))). WithEnabled(sdk.Bool(true)). - WithApiAllowedPrefixes(prefixes(azureBlockedPrefix)). - WithApiBlockedPrefixes(prefixes(azureAllowedPrefix)). + WithApiAllowedPrefixes(prefixes(azureOtherPrefix)). + WithApiBlockedPrefixes(prefixes(azurePrefix)). WithComment(sdk.String("changed comment")), ) err := client.ApiIntegrations.Alter(ctx, setRequest) @@ -229,8 +249,8 @@ func TestInt_ApiIntegrations(t *testing.T) { assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "ENABLED", Type: "Boolean", Value: "true", Default: "false"}) assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_KEY", Type: "String", Value: "☺☺☺", Default: ""}) assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "AZURE_AD_APPLICATION_ID", Type: "String", Value: otherAdApplicationId, Default: ""}) - assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_ALLOWED_PREFIXES", Type: "List", Value: azureBlockedPrefix, Default: "[]"}) - assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_BLOCKED_PREFIXES", Type: "List", Value: azureAllowedPrefix, Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_ALLOWED_PREFIXES", Type: "List", Value: azureOtherPrefix, Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_BLOCKED_PREFIXES", Type: "List", Value: azurePrefix, Default: "[]"}) assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "COMMENT", Type: "String", Value: "changed comment", Default: ""}) unsetRequest := sdk.NewAlterApiIntegrationRequest(integration.ID()). @@ -250,7 +270,7 @@ func TestInt_ApiIntegrations(t *testing.T) { assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "ENABLED", Type: "Boolean", Value: "false", Default: "false"}) assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_KEY", Type: "String", Value: "", Default: ""}) assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "AZURE_AD_APPLICATION_ID", Type: "String", Value: otherAdApplicationId, Default: ""}) - assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_ALLOWED_PREFIXES", Type: "List", Value: azureBlockedPrefix, Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_ALLOWED_PREFIXES", Type: "List", Value: azureOtherPrefix, Default: "[]"}) assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_BLOCKED_PREFIXES", Type: "List", Value: "", Default: "[]"}) assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "COMMENT", Type: "String", Value: "", Default: ""}) }) @@ -262,8 +282,8 @@ func TestInt_ApiIntegrations(t *testing.T) { WithSet( sdk.NewApiIntegrationSetRequest(). WithEnabled(sdk.Bool(true)). - WithApiAllowedPrefixes(prefixes(googleBlockedPrefix)). - WithApiBlockedPrefixes(prefixes(googleAllowedPrefix)). + WithApiAllowedPrefixes(prefixes(googleOtherPrefix)). + WithApiBlockedPrefixes(prefixes(googlePrefix)). WithComment(sdk.String("changed comment")), ) err := client.ApiIntegrations.Alter(ctx, setRequest) @@ -273,8 +293,8 @@ func TestInt_ApiIntegrations(t *testing.T) { require.NoError(t, err) assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "ENABLED", Type: "Boolean", Value: "true", Default: "false"}) - assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_ALLOWED_PREFIXES", Type: "List", Value: googleBlockedPrefix, Default: "[]"}) - assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_BLOCKED_PREFIXES", Type: "List", Value: googleAllowedPrefix, Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_ALLOWED_PREFIXES", Type: "List", Value: googleOtherPrefix, Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_BLOCKED_PREFIXES", Type: "List", Value: googlePrefix, Default: "[]"}) assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "COMMENT", Type: "String", Value: "changed comment", Default: ""}) unsetRequest := sdk.NewAlterApiIntegrationRequest(integration.ID()). @@ -292,7 +312,7 @@ func TestInt_ApiIntegrations(t *testing.T) { require.NoError(t, err) assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "ENABLED", Type: "Boolean", Value: "false", Default: "false"}) - assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_ALLOWED_PREFIXES", Type: "List", Value: googleBlockedPrefix, Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_ALLOWED_PREFIXES", Type: "List", Value: googleOtherPrefix, Default: "[]"}) assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_BLOCKED_PREFIXES", Type: "List", Value: "", Default: "[]"}) assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "COMMENT", Type: "String", Value: "", Default: ""}) }) @@ -391,7 +411,7 @@ func TestInt_ApiIntegrations(t *testing.T) { assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_KEY", Type: "String", Value: "", Default: ""}) assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_PROVIDER", Type: "String", Value: strings.ToUpper(string(sdk.ApiIntegrationAwsApiGateway)), Default: ""}) assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_AWS_ROLE_ARN", Type: "String", Value: apiAwsRoleArn, Default: ""}) - assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_ALLOWED_PREFIXES", Type: "List", Value: awsAllowedPrefix, Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_ALLOWED_PREFIXES", Type: "List", Value: awsPrefix, Default: "[]"}) assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_BLOCKED_PREFIXES", Type: "List", Value: "", Default: "[]"}) assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "COMMENT", Type: "String", Value: "", Default: ""}) }) @@ -407,7 +427,7 @@ func TestInt_ApiIntegrations(t *testing.T) { assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "AZURE_AD_APPLICATION_ID", Type: "String", Value: azureAdApplicationId, Default: ""}) assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_KEY", Type: "String", Value: "", Default: ""}) assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_PROVIDER", Type: "String", Value: "AZURE_API_MANAGEMENT", Default: ""}) - assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_ALLOWED_PREFIXES", Type: "List", Value: azureAllowedPrefix, Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_ALLOWED_PREFIXES", Type: "List", Value: azurePrefix, Default: "[]"}) assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_BLOCKED_PREFIXES", Type: "List", Value: "", Default: "[]"}) assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "COMMENT", Type: "String", Value: "", Default: ""}) }) @@ -422,7 +442,7 @@ func TestInt_ApiIntegrations(t *testing.T) { assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_KEY", Type: "String", Value: "", Default: ""}) assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_PROVIDER", Type: "String", Value: "GOOGLE_API_GATEWAY", Default: ""}) assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "GOOGLE_AUDIENCE", Type: "String", Value: googleAudience, Default: ""}) - assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_ALLOWED_PREFIXES", Type: "List", Value: googleAllowedPrefix, Default: "[]"}) + assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_ALLOWED_PREFIXES", Type: "List", Value: googlePrefix, Default: "[]"}) assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "API_BLOCKED_PREFIXES", Type: "List", Value: "", Default: "[]"}) assert.Contains(t, details, sdk.ApiIntegrationProperty{Name: "COMMENT", Type: "String", Value: "", Default: ""}) })