Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into unskip-config-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jmichalak committed Nov 18, 2024
2 parents 4736dc6 + 7736e0a commit 81bd6c0
Show file tree
Hide file tree
Showing 48 changed files with 1,366 additions and 1,579 deletions.
49 changes: 49 additions & 0 deletions pkg/acceptance/helpers/event_table_client..go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package helpers

import (
"context"
"testing"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"github.com/stretchr/testify/require"
)

type EventTableClient struct {
context *TestClientContext
ids *IdsGenerator
}

func NewEventTableClient(context *TestClientContext, idsGenerator *IdsGenerator) *EventTableClient {
return &EventTableClient{
context: context,
ids: idsGenerator,
}
}

func (c *EventTableClient) client() sdk.EventTables {
return c.context.client.EventTables
}

func (c *EventTableClient) Create(t *testing.T) (*sdk.EventTable, func()) {
t.Helper()
ctx := context.Background()

id := c.ids.RandomSchemaObjectIdentifier()
err := c.client().Create(ctx, sdk.NewCreateEventTableRequest(id))
require.NoError(t, err)

integration, err := c.client().ShowByID(ctx, id)
require.NoError(t, err)

return integration, c.DropFunc(t, id)
}

func (c *EventTableClient) DropFunc(t *testing.T, id sdk.SchemaObjectIdentifier) func() {
t.Helper()
ctx := context.Background()

return func() {
err := c.client().Drop(ctx, sdk.NewDropEventTableRequest(id).WithIfExists(sdk.Bool(true)))
require.NoError(t, err)
}
}
54 changes: 54 additions & 0 deletions pkg/acceptance/helpers/notification_integration_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package helpers

import (
"context"
"testing"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"github.com/stretchr/testify/require"
)

type NotificationIntegrationClient struct {
context *TestClientContext
ids *IdsGenerator
}

func NewNotificationIntegrationClient(context *TestClientContext, idsGenerator *IdsGenerator) *NotificationIntegrationClient {
return &NotificationIntegrationClient{
context: context,
ids: idsGenerator,
}
}

func (c *NotificationIntegrationClient) client() sdk.NotificationIntegrations {
return c.context.client.NotificationIntegrations
}

func (c *NotificationIntegrationClient) Create(t *testing.T) (*sdk.NotificationIntegration, func()) {
t.Helper()
ctx := context.Background()

id := c.ids.RandomAccountObjectIdentifier()

// TODO [SNOW-1007539]: use email of our service user
request := sdk.NewCreateNotificationIntegrationRequest(id, true).
WithEmailParams(sdk.NewEmailParamsRequest().WithAllowedRecipients([]sdk.NotificationIntegrationAllowedRecipient{{Email: "[email protected]"}}))

err := c.client().Create(ctx, request)
require.NoError(t, err)

integration, err := c.client().ShowByID(ctx, id)
require.NoError(t, err)

return integration, c.DropFunc(t, id)
}

func (c *NotificationIntegrationClient) DropFunc(t *testing.T, id sdk.AccountObjectIdentifier) func() {
t.Helper()
ctx := context.Background()

return func() {
err := c.client().Drop(ctx, sdk.NewDropNotificationIntegrationRequest(id).WithIfExists(sdk.Bool(true)))
require.NoError(t, err)
}
}
112 changes: 96 additions & 16 deletions pkg/acceptance/helpers/security_integration_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,46 @@ func (c *SecurityIntegrationClient) client() sdk.SecurityIntegrations {
return c.context.client.SecurityIntegrations
}

func (c *SecurityIntegrationClient) UpdateExternalOauth(t *testing.T, request *sdk.AlterExternalOauthSecurityIntegrationRequest) {
func (c *SecurityIntegrationClient) CreateApiAuthenticationWithClientCredentialsFlow(t *testing.T) (*sdk.SecurityIntegration, func()) {
t.Helper()
ctx := context.Background()

err := c.client().AlterExternalOauth(ctx, request)
id := c.ids.RandomAccountObjectIdentifier()
request := sdk.NewCreateApiAuthenticationWithClientCredentialsFlowSecurityIntegrationRequest(id, false, "foo", "foo")
err := c.client().CreateApiAuthenticationWithClientCredentialsFlow(ctx, request)
require.NoError(t, err)

si, err := c.client().ShowByID(ctx, request.GetName())
require.NoError(t, err)

return si, c.DropSecurityIntegrationFunc(t, request.GetName())
}

func (c *SecurityIntegrationClient) CreateSaml2(t *testing.T, id sdk.AccountObjectIdentifier) (*sdk.SecurityIntegration, func()) {
func (c *SecurityIntegrationClient) CreateApiAuthenticationWithAuthorizationCodeGrantFlow(t *testing.T) (*sdk.SecurityIntegration, func()) {
t.Helper()
return c.CreateSaml2WithRequest(t, sdk.NewCreateSaml2SecurityIntegrationRequest(id, c.ids.Alpha(), "https://example.com", "Custom", random.GenerateX509(t)))
ctx := context.Background()

id := c.ids.RandomAccountObjectIdentifier()
request := sdk.NewCreateApiAuthenticationWithAuthorizationCodeGrantFlowSecurityIntegrationRequest(id, false, "foo", "foo")
err := c.client().CreateApiAuthenticationWithAuthorizationCodeGrantFlow(ctx, request)
require.NoError(t, err)

si, err := c.client().ShowByID(ctx, request.GetName())
require.NoError(t, err)

return si, c.DropSecurityIntegrationFunc(t, request.GetName())
}

func (c *SecurityIntegrationClient) CreateSaml2WithRequest(t *testing.T, request *sdk.CreateSaml2SecurityIntegrationRequest) (*sdk.SecurityIntegration, func()) {
func (c *SecurityIntegrationClient) CreateExternalOauth(t *testing.T) (*sdk.SecurityIntegration, func()) {
t.Helper()
ctx := context.Background()

err := c.client().CreateSaml2(ctx, request)
id := c.ids.RandomAccountObjectIdentifier()
issuer := random.String()
request := sdk.NewCreateExternalOauthSecurityIntegrationRequest(id, false, sdk.ExternalOauthSecurityIntegrationTypeCustom,
issuer, []sdk.TokenUserMappingClaim{{Claim: "foo"}}, sdk.ExternalOauthSecurityIntegrationSnowflakeUserMappingAttributeLoginName,
).WithExternalOauthJwsKeysUrl([]sdk.JwsKeysUrl{{JwsKeyUrl: "http://example.com"}})
err := c.client().CreateExternalOauth(ctx, request)
require.NoError(t, err)

si, err := c.client().ShowByID(ctx, request.GetName())
Expand All @@ -51,16 +73,29 @@ func (c *SecurityIntegrationClient) CreateSaml2WithRequest(t *testing.T, request
return si, c.DropSecurityIntegrationFunc(t, request.GetName())
}

func (c *SecurityIntegrationClient) CreateScim(t *testing.T) (*sdk.SecurityIntegration, func()) {
func (c *SecurityIntegrationClient) CreateOauthForPartnerApplications(t *testing.T) (*sdk.SecurityIntegration, func()) {
t.Helper()
return c.CreateScimWithRequest(t, sdk.NewCreateScimSecurityIntegrationRequest(c.ids.RandomAccountObjectIdentifier(), sdk.ScimSecurityIntegrationScimClientGeneric, sdk.ScimSecurityIntegrationRunAsRoleGenericScimProvisioner))
ctx := context.Background()

id := c.ids.RandomAccountObjectIdentifier()
request := sdk.NewCreateOauthForPartnerApplicationsSecurityIntegrationRequest(id, sdk.OauthSecurityIntegrationClientLooker).
WithOauthRedirectUri("http://example.com")
err := c.client().CreateOauthForPartnerApplications(ctx, request)
require.NoError(t, err)

si, err := c.client().ShowByID(ctx, request.GetName())
require.NoError(t, err)

return si, c.DropSecurityIntegrationFunc(t, request.GetName())
}

func (c *SecurityIntegrationClient) CreateApiAuthenticationClientCredentialsWithRequest(t *testing.T, request *sdk.CreateApiAuthenticationWithClientCredentialsFlowSecurityIntegrationRequest) (*sdk.SecurityIntegration, func()) {
func (c *SecurityIntegrationClient) CreateOauthForCustomClients(t *testing.T) (*sdk.SecurityIntegration, func()) {
t.Helper()
ctx := context.Background()

err := c.client().CreateApiAuthenticationWithClientCredentialsFlow(ctx, request)
id := c.ids.RandomAccountObjectIdentifier()
request := sdk.NewCreateOauthForCustomClientsSecurityIntegrationRequest(id, sdk.OauthSecurityIntegrationClientTypePublic, "https://example.com")
err := c.client().CreateOauthForCustomClients(ctx, request)
require.NoError(t, err)

si, err := c.client().ShowByID(ctx, request.GetName())
Expand All @@ -69,25 +104,41 @@ func (c *SecurityIntegrationClient) CreateApiAuthenticationClientCredentialsWith
return si, c.DropSecurityIntegrationFunc(t, request.GetName())
}

func (c *SecurityIntegrationClient) UpdateSaml2(t *testing.T, request *sdk.AlterSaml2SecurityIntegrationRequest) {
func (c *SecurityIntegrationClient) CreateSaml2(t *testing.T) (*sdk.SecurityIntegration, func()) {
t.Helper()
id := c.ids.RandomAccountObjectIdentifier()
return c.CreateSaml2WithRequest(t, sdk.NewCreateSaml2SecurityIntegrationRequest(id, c.ids.Alpha(), "https://example.com", "Custom", random.GenerateX509(t)))
}

func (c *SecurityIntegrationClient) CreateSaml2WithRequest(t *testing.T, request *sdk.CreateSaml2SecurityIntegrationRequest) (*sdk.SecurityIntegration, func()) {
t.Helper()
ctx := context.Background()

err := c.client().AlterSaml2(ctx, request)
err := c.client().CreateSaml2(ctx, request)
require.NoError(t, err)

si, err := c.client().ShowByID(ctx, request.GetName())
require.NoError(t, err)

return si, c.DropSecurityIntegrationFunc(t, request.GetName())
}

func (c *SecurityIntegrationClient) UpdateSaml2ForceAuthn(t *testing.T, id sdk.AccountObjectIdentifier, forceAuthn bool) {
func (c *SecurityIntegrationClient) CreateScim(t *testing.T) (*sdk.SecurityIntegration, func()) {
t.Helper()
c.UpdateSaml2(t, sdk.NewAlterSaml2SecurityIntegrationRequest(id).WithSet(*sdk.NewSaml2IntegrationSetRequest().WithSaml2ForceAuthn(forceAuthn)))
return c.CreateScimWithRequest(t, sdk.NewCreateScimSecurityIntegrationRequest(c.ids.RandomAccountObjectIdentifier(), sdk.ScimSecurityIntegrationScimClientGeneric, sdk.ScimSecurityIntegrationRunAsRoleGenericScimProvisioner))
}

func (c *SecurityIntegrationClient) UpdateOauthForPartnerApplications(t *testing.T, request *sdk.AlterOauthForPartnerApplicationsSecurityIntegrationRequest) {
func (c *SecurityIntegrationClient) CreateApiAuthenticationClientCredentialsWithRequest(t *testing.T, request *sdk.CreateApiAuthenticationWithClientCredentialsFlowSecurityIntegrationRequest) (*sdk.SecurityIntegration, func()) {
t.Helper()
ctx := context.Background()

err := c.client().AlterOauthForPartnerApplications(ctx, request)
err := c.client().CreateApiAuthenticationWithClientCredentialsFlow(ctx, request)
require.NoError(t, err)

si, err := c.client().ShowByID(ctx, request.GetName())
require.NoError(t, err)

return si, c.DropSecurityIntegrationFunc(t, request.GetName())
}

func (c *SecurityIntegrationClient) CreateScimWithRequest(t *testing.T, request *sdk.CreateScimSecurityIntegrationRequest) (*sdk.SecurityIntegration, func()) {
Expand All @@ -103,6 +154,35 @@ func (c *SecurityIntegrationClient) CreateScimWithRequest(t *testing.T, request
return si, c.DropSecurityIntegrationFunc(t, request.GetName())
}

func (c *SecurityIntegrationClient) UpdateExternalOauth(t *testing.T, request *sdk.AlterExternalOauthSecurityIntegrationRequest) {
t.Helper()
ctx := context.Background()

err := c.client().AlterExternalOauth(ctx, request)
require.NoError(t, err)
}

func (c *SecurityIntegrationClient) UpdateSaml2(t *testing.T, request *sdk.AlterSaml2SecurityIntegrationRequest) {
t.Helper()
ctx := context.Background()

err := c.client().AlterSaml2(ctx, request)
require.NoError(t, err)
}

func (c *SecurityIntegrationClient) UpdateSaml2ForceAuthn(t *testing.T, id sdk.AccountObjectIdentifier, forceAuthn bool) {
t.Helper()
c.UpdateSaml2(t, sdk.NewAlterSaml2SecurityIntegrationRequest(id).WithSet(*sdk.NewSaml2IntegrationSetRequest().WithSaml2ForceAuthn(forceAuthn)))
}

func (c *SecurityIntegrationClient) UpdateOauthForPartnerApplications(t *testing.T, request *sdk.AlterOauthForPartnerApplicationsSecurityIntegrationRequest) {
t.Helper()
ctx := context.Background()

err := c.client().AlterOauthForPartnerApplications(ctx, request)
require.NoError(t, err)
}

func (c *SecurityIntegrationClient) UpdateOauthForClients(t *testing.T, request *sdk.AlterOauthForCustomClientsSecurityIntegrationRequest) {
t.Helper()
ctx := context.Background()
Expand Down
79 changes: 79 additions & 0 deletions pkg/acceptance/helpers/storage_integration_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package helpers

import (
"context"
"testing"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"github.com/stretchr/testify/require"
)

type StorageIntegrationClient struct {
context *TestClientContext
ids *IdsGenerator
}

func NewStorageIntegrationClient(context *TestClientContext, idsGenerator *IdsGenerator) *StorageIntegrationClient {
return &StorageIntegrationClient{
context: context,
ids: idsGenerator,
}
}

func (c *StorageIntegrationClient) client() sdk.StorageIntegrations {
return c.context.client.StorageIntegrations
}

func (c *StorageIntegrationClient) CreateS3(t *testing.T, awsBucketUrl, awsRoleArn string) (*sdk.StorageIntegration, func()) {
t.Helper()
ctx := context.Background()

allowedLocations := func(prefix string) []sdk.StorageLocation {
return []sdk.StorageLocation{
{
Path: prefix + "/allowed-location",
},
{
Path: prefix + "/allowed-location2",
},
}
}
s3AllowedLocations := allowedLocations(awsBucketUrl)

blockedLocations := func(prefix string) []sdk.StorageLocation {
return []sdk.StorageLocation{
{
Path: prefix + "/blocked-location",
},
{
Path: prefix + "/blocked-location2",
},
}
}
s3BlockedLocations := blockedLocations(awsBucketUrl)

id := c.ids.RandomAccountObjectIdentifier()
req := sdk.NewCreateStorageIntegrationRequest(id, true, s3AllowedLocations).
WithIfNotExists(sdk.Bool(true)).
WithS3StorageProviderParams(sdk.NewS3StorageParamsRequest(awsRoleArn)).
WithStorageBlockedLocations(s3BlockedLocations).
WithComment(sdk.String("some comment"))

err := c.client().Create(ctx, req)
require.NoError(t, err)

integration, err := c.client().ShowByID(ctx, id)
require.NoError(t, err)

return integration, c.DropFunc(t, id)
}

func (c *StorageIntegrationClient) DropFunc(t *testing.T, id sdk.AccountObjectIdentifier) func() {
t.Helper()
ctx := context.Background()

return func() {
err := c.client().Drop(ctx, sdk.NewDropStorageIntegrationRequest(id).WithIfExists(sdk.Bool(true)))
require.NoError(t, err)
}
}
Loading

0 comments on commit 81bd6c0

Please sign in to comment.