-
Notifications
You must be signed in to change notification settings - Fork 427
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 authentication policies to SDK #2937
Merged
sfc-gh-jcieslak
merged 15 commits into
Snowflake-Labs:main
from
cmonty-paypal:add_authentication_policies
Sep 10, 2024
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
461ed5c
Adds authentiation_policies_def
cmonty-paypal 03e0268
codegen and test for Authentication Policy
cmonty-paypal 7f0b0d1
more tests
cmonty-paypal df67697
finish unit tests
cmonty-paypal 7894c64
basic int test
cmonty-paypal 548fa11
more int tests
cmonty-paypal fbbc3b3
more int tests
cmonty-paypal 57b259b
Adds ALTER {ACCOUNT,USER} DDL
cmonty-paypal bd09910
add conversion functions
cmonty-paypal 2622636
passing int tests
cmonty-paypal 2b966a3
remove unused def types
cmonty-paypal f01f7d3
Merge branch 'main' into add_authentication_policies
sfc-gh-jcieslak 1a9773d
Update accounts_integration_test.go
sfc-gh-jcieslak 2b60080
Update authentication_policies_impl_gen.go
sfc-gh-jcieslak cd6889d
Update authentication_policies_impl_gen.go
sfc-gh-jcieslak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 AuthenticationPolicyClient struct { | ||
context *TestClientContext | ||
ids *IdsGenerator | ||
} | ||
|
||
func NewAuthenticationPolicyClient(context *TestClientContext, idsGenerator *IdsGenerator) *AuthenticationPolicyClient { | ||
return &AuthenticationPolicyClient{ | ||
context: context, | ||
ids: idsGenerator, | ||
} | ||
} | ||
|
||
func (c *AuthenticationPolicyClient) client() sdk.AuthenticationPolicies { | ||
return c.context.client.AuthenticationPolicies | ||
} | ||
|
||
func (c *AuthenticationPolicyClient) CreateAuthenticationPolicy(t *testing.T) (*sdk.AuthenticationPolicy, func()) { | ||
t.Helper() | ||
id := c.ids.RandomSchemaObjectIdentifier() | ||
return c.CreateAuthenticationPolicyWithOptions(t, id, sdk.NewCreateAuthenticationPolicyRequest(id)) | ||
} | ||
|
||
func (c *AuthenticationPolicyClient) CreateAuthenticationPolicyWithOptions(t *testing.T, id sdk.SchemaObjectIdentifier, request *sdk.CreateAuthenticationPolicyRequest) (*sdk.AuthenticationPolicy, func()) { | ||
t.Helper() | ||
ctx := context.Background() | ||
|
||
err := c.client().Create(ctx, request) | ||
require.NoError(t, err) | ||
|
||
sessionPolicy, err := c.client().ShowByID(ctx, id) | ||
require.NoError(t, err) | ||
|
||
return sessionPolicy, c.DropAuthenticationPolicyFunc(t, id) | ||
} | ||
|
||
func (c *AuthenticationPolicyClient) DropAuthenticationPolicyFunc(t *testing.T, id sdk.SchemaObjectIdentifier) func() { | ||
t.Helper() | ||
ctx := context.Background() | ||
|
||
return func() { | ||
err := c.client().Drop(ctx, sdk.NewDropAuthenticationPolicyRequest(id).WithIfExists(true)) | ||
require.NoError(t, err) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package sdk | ||
|
||
import g "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/poc/generator" | ||
|
||
//go:generate go run ./poc/main.go | ||
|
||
var AuthenticationMethodsOptionDef = g.NewQueryStruct("AuthenticationMethods").Text("Method", g.KeywordOptions().SingleQuotes()) | ||
var MfaAuthenticationMethodsOptionDef = g.NewQueryStruct("MfaAuthenticationMethods").Text("Method", g.KeywordOptions().SingleQuotes()) | ||
var ClientTypesOptionDef = g.NewQueryStruct("ClientTypes").Text("ClientType", g.KeywordOptions().SingleQuotes()) | ||
var SecurityIntegrationsOptionDef = g.NewQueryStruct("SecurityIntegrationsOption").Text("Name", g.KeywordOptions().SingleQuotes()) | ||
|
||
var ( | ||
AuthenticationPoliciesDef = g.NewInterface( | ||
"AuthenticationPolicies", | ||
"AuthenticationPolicy", | ||
g.KindOfT[SchemaObjectIdentifier](), | ||
). | ||
CreateOperation( | ||
"https://docs.snowflake.com/en/sql-reference/sql/create-authentication-policy", | ||
g.NewQueryStruct("CreateAuthenticationPolicy"). | ||
Create(). | ||
OrReplace(). | ||
SQL("AUTHENTICATION POLICY"). | ||
sfc-gh-jcieslak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Name(). | ||
ListAssignment("AUTHENTICATION_METHODS", "AuthenticationMethods", g.ParameterOptions().Parentheses()). | ||
ListAssignment("MFA_AUTHENTICATION_METHODS", "MfaAuthenticationMethods", g.ParameterOptions().Parentheses()). | ||
OptionalTextAssignment("MFA_ENROLLMENT", g.ParameterOptions()). | ||
ListAssignment("CLIENT_TYPES", "ClientTypes", g.ParameterOptions().Parentheses()). | ||
ListAssignment("SECURITY_INTEGRATIONS", "SecurityIntegrationsOption", g.ParameterOptions().Parentheses()). | ||
OptionalTextAssignment("COMMENT", g.ParameterOptions().SingleQuotes()). | ||
WithValidation(g.ValidIdentifier, "name"), | ||
AuthenticationMethodsOptionDef, | ||
MfaAuthenticationMethodsOptionDef, | ||
ClientTypesOptionDef, | ||
SecurityIntegrationsOptionDef, | ||
). | ||
AlterOperation( | ||
"https://docs.snowflake.com/en/sql-reference/sql/alter-authentication-policy", | ||
g.NewQueryStruct("AlterAuthenticationPolicy"). | ||
Alter(). | ||
SQL("AUTHENTICATION POLICY"). | ||
IfExists(). | ||
Name(). | ||
OptionalQueryStructField( | ||
"Set", | ||
g.NewQueryStruct("AuthenticationPolicySet"). | ||
ListAssignment("AUTHENTICATION_METHODS", "AuthenticationMethods", g.ParameterOptions().Parentheses()). | ||
ListAssignment("MFA_AUTHENTICATION_METHODS", "MfaAuthenticationMethods", g.ParameterOptions().Parentheses()). | ||
OptionalTextAssignment("MFA_ENROLLMENT", g.ParameterOptions().SingleQuotes()). | ||
ListAssignment("CLIENT_TYPES", "ClientTypes", g.ParameterOptions().Parentheses()). | ||
ListAssignment("SECURITY_INTEGRATIONS", "SecurityIntegrationsOption", g.ParameterOptions().Parentheses()). | ||
OptionalTextAssignment("COMMENT", g.ParameterOptions().SingleQuotes()). | ||
WithValidation(g.AtLeastOneValueSet, "AuthenticationMethods", "MfaAuthenticationMethods", "MfaEnrollment", "ClientTypes", "SecurityIntegrations", "Comment"), | ||
g.KeywordOptions().SQL("SET"), | ||
). | ||
OptionalQueryStructField( | ||
"Unset", | ||
g.NewQueryStruct("AuthenticationPolicyUnset"). | ||
OptionalSQL("CLIENT_TYPES"). | ||
OptionalSQL("AUTHENTICATION_METHODS"). | ||
OptionalSQL("SECURITY_INTEGRATIONS"). | ||
OptionalSQL("MFA_AUTHENTICATION_METHODS"). | ||
OptionalSQL("MFA_ENROLLMENT"). | ||
OptionalSQL("COMMENT"). | ||
WithValidation(g.AtLeastOneValueSet, "ClientTypes", "AuthenticationMethods", "Comment", "SecurityIntegrations", "MfaAuthenticationMethods", "MfaEnrollment"), | ||
g.ListOptions().NoParentheses().SQL("UNSET"), | ||
). | ||
Identifier("RenameTo", g.KindOfTPointer[SchemaObjectIdentifier](), g.IdentifierOptions().SQL("RENAME TO")). | ||
WithValidation(g.ValidIdentifier, "name"). | ||
WithValidation(g.ExactlyOneValueSet, "Set", "Unset", "RenameTo"). | ||
WithValidation(g.ValidIdentifierIfSet, "RenameTo"), | ||
). | ||
DropOperation( | ||
"https://docs.snowflake.com/en/sql-reference/sql/drop-authentication-policy", | ||
g.NewQueryStruct("DropAuthenticationPolicy"). | ||
Drop(). | ||
SQL("AUTHENTICATION POLICY"). | ||
IfExists(). | ||
Name(). | ||
WithValidation(g.ValidIdentifier, "name"), | ||
). | ||
ShowOperation( | ||
"https://docs.snowflake.com/en/sql-reference/sql/show-authentication-policies", | ||
g.DbStruct("showAuthenticationPolicyDBRow"). | ||
Field("created_on", "string"). | ||
Field("name", "string"). | ||
Field("comment", "string"). | ||
Field("database_name", "string"). | ||
Field("schema_name", "string"). | ||
Field("owner", "string"). | ||
Field("owner_role_type", "string"). | ||
Field("options", "string"), | ||
g.PlainStruct("AuthenticationPolicy"). | ||
Field("CreatedOn", "string"). | ||
Field("Name", "string"). | ||
Field("Comment", "string"). | ||
Field("DatabaseName", "string"). | ||
Field("SchemaName", "string"). | ||
Field("Owner", "string"). | ||
Field("OwnerRoleType", "string"). | ||
Field("Options", "string"), | ||
g.NewQueryStruct("ShowAuthenticationPolicies"). | ||
Show(). | ||
SQL("AUTHENTICATION POLICIES"). | ||
OptionalLike(). | ||
OptionalIn(). | ||
OptionalStartsWith(). | ||
OptionalLimit(), | ||
sfc-gh-jcieslak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
). | ||
ShowByIdOperation(). | ||
DescribeOperation( | ||
g.DescriptionMappingKindSlice, | ||
"https://docs.snowflake.com/en/sql-reference/sql/desc-authentication-policy", | ||
g.DbStruct("describeAuthenticationPolicyDBRow"). | ||
Field("property", "string"). | ||
Field("value", "string"), | ||
sfc-gh-jcieslak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
g.PlainStruct("AuthenticationPolicyDescription"). | ||
Field("Property", "string"). | ||
Field("Value", "string"), | ||
g.NewQueryStruct("DescribeAuthenticationPolicy"). | ||
Describe(). | ||
SQL("AUTHENTICATION POLICY"). | ||
Name(). | ||
WithValidation(g.ValidIdentifier, "name"), | ||
) | ||
) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the validation tests are missing (validations were updated but no test failed here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in #3068