-
Notifications
You must be signed in to change notification settings - Fork 427
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Changes - Changed name of Secret struct in common_types.go due to naming clash - Added Secret Object to SDK - Generated validators for Secret - Unit and integration tests ## References * [CREATE SECRET](https://docs.snowflake.com/en/sql-reference/sql/create-secret)
- Loading branch information
1 parent
ad5fa11
commit 7430aee
Showing
28 changed files
with
2,520 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
pkg/acceptance/bettertestspoc/assert/objectassert/secret_snowflake_gen.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package helpers | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type SecretClient struct { | ||
context *TestClientContext | ||
ids *IdsGenerator | ||
} | ||
|
||
func NewSecretClient(context *TestClientContext, idsGenerator *IdsGenerator) *SecretClient { | ||
return &SecretClient{ | ||
context: context, | ||
ids: idsGenerator, | ||
} | ||
} | ||
|
||
func (c *SecretClient) client() sdk.Secrets { | ||
return c.context.client.Secrets | ||
} | ||
|
||
func (c *SecretClient) CreateWithOAuthClientCredentialsFlow(t *testing.T, id sdk.SchemaObjectIdentifier, apiIntegration sdk.AccountObjectIdentifier, oauthScopes []sdk.ApiIntegrationScope) (*sdk.Secret, func()) { | ||
t.Helper() | ||
ctx := context.Background() | ||
request := sdk.NewCreateWithOAuthClientCredentialsFlowSecretRequest(id, apiIntegration). | ||
WithOauthScopes(sdk.OauthScopesListRequest{OauthScopesList: oauthScopes}) | ||
|
||
err := c.client().CreateWithOAuthClientCredentialsFlow(ctx, request) | ||
require.NoError(t, err) | ||
|
||
secret, err := c.client().ShowByID(ctx, id) | ||
require.NoError(t, err) | ||
|
||
return secret, c.DropFunc(t, id) | ||
} | ||
|
||
func (c *SecretClient) CreateWithOAuthAuthorizationCodeFlow(t *testing.T, id sdk.SchemaObjectIdentifier, apiIntegration sdk.AccountObjectIdentifier, refreshToken, refreshTokenExpiryTime string) (*sdk.Secret, func()) { | ||
t.Helper() | ||
ctx := context.Background() | ||
request := sdk.NewCreateWithOAuthAuthorizationCodeFlowSecretRequest(id, refreshToken, refreshTokenExpiryTime, apiIntegration) | ||
|
||
err := c.client().CreateWithOAuthAuthorizationCodeFlow(ctx, request) | ||
require.NoError(t, err) | ||
|
||
secret, err := c.client().ShowByID(ctx, id) | ||
require.NoError(t, err) | ||
|
||
return secret, c.DropFunc(t, id) | ||
} | ||
|
||
func (c *SecretClient) CreateWithBasicAuthenticationFlow(t *testing.T, id sdk.SchemaObjectIdentifier, username, password string) (*sdk.Secret, func()) { | ||
t.Helper() | ||
ctx := context.Background() | ||
request := sdk.NewCreateWithBasicAuthenticationSecretRequest(id, username, password) | ||
|
||
err := c.client().CreateWithBasicAuthentication(ctx, request) | ||
require.NoError(t, err) | ||
|
||
secret, err := c.client().ShowByID(ctx, id) | ||
require.NoError(t, err) | ||
|
||
return secret, c.DropFunc(t, id) | ||
} | ||
|
||
func (c *SecretClient) CreateWithGenericString(t *testing.T, id sdk.SchemaObjectIdentifier, secretString string) (*sdk.Secret, func()) { | ||
t.Helper() | ||
ctx := context.Background() | ||
request := sdk.NewCreateWithGenericStringSecretRequest(id, secretString) | ||
|
||
err := c.client().CreateWithGenericString(ctx, request) | ||
require.NoError(t, err) | ||
|
||
secret, err := c.client().ShowByID(ctx, id) | ||
require.NoError(t, err) | ||
|
||
return secret, c.DropFunc(t, id) | ||
} | ||
|
||
func (c *SecretClient) DropFunc(t *testing.T, id sdk.SchemaObjectIdentifier) func() { | ||
t.Helper() | ||
ctx := context.Background() | ||
|
||
return func() { | ||
err := c.client().Drop(ctx, sdk.NewDropSecretRequest(id).WithIfExists(true)) | ||
assert.NoError(t, err) | ||
} | ||
} | ||
|
||
func (c *SecretClient) Show(t *testing.T, id sdk.SchemaObjectIdentifier) (*sdk.Secret, error) { | ||
t.Helper() | ||
ctx := context.Background() | ||
|
||
return c.client().ShowByID(ctx, id) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.