Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add secret to sdk #3091

Merged
merged 35 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
58d5794
initial secret_def file for sdk
sfc-gh-fbudzynski Sep 12, 2024
f1488ca
naming changes to secret create options
sfc-gh-fbudzynski Sep 12, 2024
752f924
create secrets and alter with two basic tests
sfc-gh-fbudzynski Sep 13, 2024
d7ae12f
unit tests for alter
sfc-gh-fbudzynski Sep 13, 2024
57ca19a
add tests for all four create types
sfc-gh-fbudzynski Sep 13, 2024
8d55a63
rename previous secret to secretReference in common_types.go due to n…
sfc-gh-fbudzynski Sep 16, 2024
9894799
secrets gen with drop, show and desc
sfc-gh-fbudzynski Sep 16, 2024
e4a0827
all unit tests
sfc-gh-fbudzynski Sep 16, 2024
3bb8c85
init for integration tests
sfc-gh-fbudzynski Sep 16, 2024
4130618
added secret to client.go and created secret_client
sfc-gh-fbudzynski Sep 17, 2024
fc85c66
added like and in to showByID for secret
sfc-gh-fbudzynski Sep 17, 2024
aa64511
init for integration tests
sfc-gh-fbudzynski Sep 17, 2024
ab8bee1
secret_def changes
sfc-gh-fbudzynski Sep 17, 2024
3541c70
tests for two methods of creating secret
sfc-gh-fbudzynski Sep 17, 2024
180a7ce
changed refresh token expiry time from string to time.Time
sfc-gh-fbudzynski Sep 18, 2024
7a9ad92
added remaining integration tests
sfc-gh-fbudzynski Sep 19, 2024
0e9cf94
linter
sfc-gh-fbudzynski Sep 19, 2024
deadc65
linting
sfc-gh-fbudzynski Sep 19, 2024
235fbe5
removing comment
sfc-gh-fbudzynski Sep 19, 2024
73eeb63
mid review commit before generating assertions
sfc-gh-fbudzynski Sep 20, 2024
bd0b64f
rebase conflict resolved
sfc-gh-fbudzynski Sep 23, 2024
2050b85
tests pass after changing to []string for oauthScopes
sfc-gh-fbudzynski Sep 23, 2024
59c7b14
readded unit tests
sfc-gh-fbudzynski Sep 23, 2024
df7a8ff
added CreateApiAuthenticationWithRequest to security integration client
sfc-gh-fbudzynski Sep 24, 2024
eed310a
changes to secret after review, all tests pass
sfc-gh-fbudzynski Sep 24, 2024
af2e030
added assert for details
sfc-gh-fbudzynski Sep 24, 2024
4ccc4e7
linter hints applied
sfc-gh-fbudzynski Sep 24, 2024
34983af
updated generator README with validation issue for ConflictingFields …
sfc-gh-fbudzynski Sep 24, 2024
bdf2585
updated after re-review
sfc-gh-fbudzynski Sep 24, 2024
7791f33
test changed to use errMoreThanOneOf
sfc-gh-fbudzynski Sep 25, 2024
d3e54db
Wrapped OAuth Scopes in separate queryStructField to allow empty list…
sfc-gh-fbudzynski Sep 30, 2024
0e18136
Linter adjustments
sfc-gh-fbudzynski Sep 30, 2024
a18b8f5
errMoreThanOneOf change to be proper errOneOf
sfc-gh-fbudzynski Sep 30, 2024
bbd7b7a
readme known issues more verbose description of the issue
sfc-gh-fbudzynski Oct 1, 2024
22e809e
Merge branch 'main' into add-secret-to-sdk
sfc-gh-fbudzynski Oct 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ var allStructs = []SdkObjectDef{
ObjectType: sdk.ObjectTypeTask,
ObjectStruct: sdk.Task{},
},
{
IdType: "sdk.SchemaObjectIdentifier",
ObjectType: sdk.ObjectTypeSecret,
ObjectStruct: sdk.Secret{},
},
{
IdType: "sdk.SchemaObjectIdentifier",
ObjectType: sdk.ObjectTypeStream,
Expand Down

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

100 changes: 100 additions & 0 deletions pkg/acceptance/helpers/secret_client.go
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)
}
13 changes: 13 additions & 0 deletions pkg/acceptance/helpers/security_integration_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ func (c *SecurityIntegrationClient) CreateScim(t *testing.T) (*sdk.SecurityInteg
return c.CreateScimWithRequest(t, sdk.NewCreateScimSecurityIntegrationRequest(c.ids.RandomAccountObjectIdentifier(), sdk.ScimSecurityIntegrationScimClientGeneric, sdk.ScimSecurityIntegrationRunAsRoleGenericScimProvisioner))
}

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

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) UpdateSaml2(t *testing.T, request *sdk.AlterSaml2SecurityIntegrationRequest) {
t.Helper()
ctx := context.Background()
Expand Down
2 changes: 2 additions & 0 deletions pkg/acceptance/helpers/test_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type TestClient struct {
Role *RoleClient
RowAccessPolicy *RowAccessPolicyClient
Schema *SchemaClient
Secret *SecretClient
SecurityIntegration *SecurityIntegrationClient
SessionPolicy *SessionPolicyClient
Share *ShareClient
Expand Down Expand Up @@ -113,6 +114,7 @@ func NewTestClient(c *sdk.Client, database string, schema string, warehouse stri
Role: NewRoleClient(context, idsGenerator),
RowAccessPolicy: NewRowAccessPolicyClient(context, idsGenerator),
Schema: NewSchemaClient(context, idsGenerator),
Secret: NewSecretClient(context, idsGenerator),
SecurityIntegration: NewSecurityIntegrationClient(context, idsGenerator),
SessionPolicy: NewSessionPolicyClient(context, idsGenerator),
Share: NewShareClient(context, idsGenerator),
Expand Down
2 changes: 2 additions & 0 deletions pkg/sdk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type Client struct {
Roles Roles
RowAccessPolicies RowAccessPolicies
Schemas Schemas
Secrets Secrets
SecurityIntegrations SecurityIntegrations
Sequences Sequences
SessionPolicies SessionPolicies
Expand Down Expand Up @@ -235,6 +236,7 @@ func (c *Client) initialize() {
c.Roles = &roles{client: c}
c.RowAccessPolicies = &rowAccessPolicies{client: c}
c.Schemas = &schemas{client: c}
c.Secrets = &secrets{client: c}
c.SecurityIntegrations = &securityIntegrations{client: c}
c.Sequences = &sequences{client: c}
c.SessionPolicies = &sessionPolicies{client: c}
Expand Down
2 changes: 1 addition & 1 deletion pkg/sdk/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func ReturnNullValuesPointer(v ReturnNullValues) *ReturnNullValues {
return &v
}

type Secret struct {
type SecretReference struct {
VariableName string `ddl:"keyword,single_quotes"`
Name string `ddl:"parameter,no_quotes"`
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/sdk/functions_def.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ var FunctionsDef = g.NewInterface(
).
TextAssignment("HANDLER", g.ParameterOptions().SingleQuotes().Required()).
ListAssignment("EXTERNAL_ACCESS_INTEGRATIONS", "AccountObjectIdentifier", g.ParameterOptions().Parentheses()).
ListAssignment("SECRETS", "Secret", g.ParameterOptions().Parentheses()).
ListAssignment("SECRETS", "SecretReference", g.ParameterOptions().Parentheses()).
OptionalTextAssignment("TARGET_PATH", g.ParameterOptions().SingleQuotes()).
PredefinedQueryStructField("FunctionDefinition", "*string", g.ParameterOptions().NoEquals().SingleQuotes().SQL("AS")).
WithValidation(g.ValidIdentifier, "name").
Expand Down Expand Up @@ -152,7 +152,7 @@ var FunctionsDef = g.NewInterface(
).
TextAssignment("HANDLER", g.ParameterOptions().SingleQuotes().Required()).
ListAssignment("EXTERNAL_ACCESS_INTEGRATIONS", "AccountObjectIdentifier", g.ParameterOptions().Parentheses()).
ListAssignment("SECRETS", "Secret", g.ParameterOptions().Parentheses()).
ListAssignment("SECRETS", "SecretReference", g.ParameterOptions().Parentheses()).
PredefinedQueryStructField("FunctionDefinition", "*string", g.ParameterOptions().NoEquals().SingleQuotes().SQL("AS")).
WithValidation(g.ValidIdentifier, "name").
WithValidation(g.ValidateValueSet, "RuntimeVersion").
Expand Down
4 changes: 2 additions & 2 deletions pkg/sdk/functions_dto_builders_gen.go

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

4 changes: 2 additions & 2 deletions pkg/sdk/functions_dto_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type CreateForJavaFunctionRequest struct {
Packages []FunctionPackageRequest
Handler string // required
ExternalAccessIntegrations []AccountObjectIdentifier
Secrets []Secret
Secrets []SecretReference
TargetPath *string
FunctionDefinition *string
}
Expand Down Expand Up @@ -102,7 +102,7 @@ type CreateForPythonFunctionRequest struct {
Packages []FunctionPackageRequest
Handler string // required
ExternalAccessIntegrations []AccountObjectIdentifier
Secrets []Secret
Secrets []SecretReference
FunctionDefinition *string
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/sdk/functions_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type CreateForJavaFunctionOptions struct {
Packages []FunctionPackage `ddl:"parameter,parentheses" sql:"PACKAGES"`
Handler string `ddl:"parameter,single_quotes" sql:"HANDLER"`
ExternalAccessIntegrations []AccountObjectIdentifier `ddl:"parameter,parentheses" sql:"EXTERNAL_ACCESS_INTEGRATIONS"`
Secrets []Secret `ddl:"parameter,parentheses" sql:"SECRETS"`
Secrets []SecretReference `ddl:"parameter,parentheses" sql:"SECRETS"`
TargetPath *string `ddl:"parameter,single_quotes" sql:"TARGET_PATH"`
FunctionDefinition *string `ddl:"parameter,single_quotes,no_equals" sql:"AS"`
}
Expand Down Expand Up @@ -118,7 +118,7 @@ type CreateForPythonFunctionOptions struct {
Packages []FunctionPackage `ddl:"parameter,parentheses" sql:"PACKAGES"`
Handler string `ddl:"parameter,single_quotes" sql:"HANDLER"`
ExternalAccessIntegrations []AccountObjectIdentifier `ddl:"parameter,parentheses" sql:"EXTERNAL_ACCESS_INTEGRATIONS"`
Secrets []Secret `ddl:"parameter,parentheses" sql:"SECRETS"`
Secrets []SecretReference `ddl:"parameter,parentheses" sql:"SECRETS"`
FunctionDefinition *string `ddl:"parameter,single_quotes,no_equals" sql:"AS"`
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/sdk/functions_gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestFunctions_CreateForJava(t *testing.T) {
opts.ExternalAccessIntegrations = []AccountObjectIdentifier{
NewAccountObjectIdentifier("ext_integration"),
}
opts.Secrets = []Secret{
opts.Secrets = []SecretReference{
{
VariableName: "variable1",
Name: "name1",
Expand Down Expand Up @@ -272,7 +272,7 @@ func TestFunctions_CreateForPython(t *testing.T) {
opts.ExternalAccessIntegrations = []AccountObjectIdentifier{
NewAccountObjectIdentifier("ext_integration"),
}
opts.Secrets = []Secret{
opts.Secrets = []SecretReference{
{
VariableName: "variable1",
Name: "name1",
Expand Down
Loading
Loading