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

fix: authentication policies #3061

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions pkg/acceptance/helpers/test_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type TestClient struct {
ApiIntegration *ApiIntegrationClient
Application *ApplicationClient
ApplicationPackage *ApplicationPackageClient
AuthenticationPolicy *AuthenticationPolicyClient
AuthenticationPolicy *AuthenticationPolicyClient
BcrBundles *BcrBundlesClient
Context *ContextClient
CortexSearchService *CortexSearchServiceClient
Expand Down Expand Up @@ -80,7 +80,7 @@ func NewTestClient(c *sdk.Client, database string, schema string, warehouse stri
ApiIntegration: NewApiIntegrationClient(context, idsGenerator),
Application: NewApplicationClient(context, idsGenerator),
ApplicationPackage: NewApplicationPackageClient(context, idsGenerator),
AuthenticationPolicy: NewAuthenticationPolicyClient(context, idsGenerator),
AuthenticationPolicy: NewAuthenticationPolicyClient(context, idsGenerator),
BcrBundles: NewBcrBundlesClient(context),
Context: NewContextClient(context),
CortexSearchService: NewCortexSearchServiceClient(context, idsGenerator),
Expand Down
236 changes: 118 additions & 118 deletions pkg/sdk/authentication_policies_def.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,123 +4,123 @@ import g "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/poc/gen

//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").
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(),
).
ShowByIdOperation().
DescribeOperation(
g.DescriptionMappingKindSlice,
"https://docs.snowflake.com/en/sql-reference/sql/desc-authentication-policy",
g.DbStruct("describeAuthenticationPolicyDBRow").
Field("property", "string").
Field("value", "string"),
g.PlainStruct("AuthenticationPolicyDescription").
Field("Property", "string").
Field("Value", "string"),
g.NewQueryStruct("DescribeAuthenticationPolicy").
Describe().
SQL("AUTHENTICATION POLICY").
Name().
WithValidation(g.ValidIdentifier, "name"),
)
AuthenticationMethodsOptionDef = g.NewQueryStruct("AuthenticationMethods").Text("Method", g.KeywordOptions().SingleQuotes())
MfaAuthenticationMethodsOptionDef = g.NewQueryStruct("MfaAuthenticationMethods").Text("Method", g.KeywordOptions().SingleQuotes())
ClientTypesOptionDef = g.NewQueryStruct("ClientTypes").Text("ClientType", g.KeywordOptions().SingleQuotes())
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").
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(),
).
ShowByIdOperation().
DescribeOperation(
g.DescriptionMappingKindSlice,
"https://docs.snowflake.com/en/sql-reference/sql/desc-authentication-policy",
g.DbStruct("describeAuthenticationPolicyDBRow").
Field("property", "string").
Field("value", "string"),
g.PlainStruct("AuthenticationPolicyDescription").
Field("Property", "string").
Field("Value", "string"),
g.NewQueryStruct("DescribeAuthenticationPolicy").
Describe().
SQL("AUTHENTICATION POLICY").
Name().
WithValidation(g.ValidIdentifier, "name"),
)
8 changes: 4 additions & 4 deletions pkg/sdk/authentication_policies_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ type DescribeAuthenticationPolicyOptions struct {
name SchemaObjectIdentifier `ddl:"identifier"`
}
type describeAuthenticationPolicyDBRow struct {
Property string `db:"property"`
Value string `db:"value"`
Property string `db:"property"`
Value string `db:"value"`
}
type AuthenticationPolicyDescription struct {
Property string
Value string
Property string
Value string
}

func (v *AuthenticationPolicy) ID() SchemaObjectIdentifier {
Expand Down
9 changes: 0 additions & 9 deletions pkg/sdk/authentication_policies_gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ package sdk
import "testing"

func TestAuthenticationPolicies_Create(t *testing.T) {

id := randomSchemaObjectIdentifier()
// Minimal valid CreateAuthenticationPolicyOptions
defaultOpts := func() *CreateAuthenticationPolicyOptions {
return &CreateAuthenticationPolicyOptions{

name: id,
}
}
Expand Down Expand Up @@ -44,12 +42,10 @@ func TestAuthenticationPolicies_Create(t *testing.T) {
}

func TestAuthenticationPolicies_Alter(t *testing.T) {

id := randomSchemaObjectIdentifier()
// Minimal valid AlterAuthenticationPolicyOptions
defaultOpts := func() *AlterAuthenticationPolicyOptions {
return &AlterAuthenticationPolicyOptions{

name: id,
}
}
Expand Down Expand Up @@ -137,16 +133,13 @@ func TestAuthenticationPolicies_Alter(t *testing.T) {
opts.RenameTo = &target
assertOptsValidAndSQLEquals(t, opts, "ALTER AUTHENTICATION POLICY %s RENAME TO %s", id.FullyQualifiedName(), opts.RenameTo.FullyQualifiedName())
})

}

func TestAuthenticationPolicies_Drop(t *testing.T) {

id := randomSchemaObjectIdentifier()
// Minimal valid DropAuthenticationPolicyOptions
defaultOpts := func() *DropAuthenticationPolicyOptions {
return &DropAuthenticationPolicyOptions{

name: id,
}
}
Expand Down Expand Up @@ -186,12 +179,10 @@ func TestAuthenticationPolicies_Show(t *testing.T) {
}

func TestAuthenticationPolicies_Describe(t *testing.T) {

id := randomSchemaObjectIdentifier()
// Minimal valid DescribeAuthenticationPolicyOptions
defaultOpts := func() *DescribeAuthenticationPolicyOptions {
return &DescribeAuthenticationPolicyOptions{

name: id,
}
}
Expand Down
8 changes: 2 additions & 6 deletions pkg/sdk/authentication_policies_impl_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func (r *AlterAuthenticationPolicyRequest) toOpts() *AlterAuthenticationPolicyOp
}

if r.Set != nil {

opts.Set = &AuthenticationPolicySet{
AuthenticationMethods: r.Set.AuthenticationMethods,
MfaAuthenticationMethods: r.Set.MfaAuthenticationMethods,
Expand All @@ -88,11 +87,9 @@ func (r *AlterAuthenticationPolicyRequest) toOpts() *AlterAuthenticationPolicyOp
SecurityIntegrations: r.Set.SecurityIntegrations,
Comment: r.Set.Comment,
}

}

if r.Unset != nil {

opts.Unset = &AuthenticationPolicyUnset{
ClientTypes: r.Unset.ClientTypes,
AuthenticationMethods: r.Unset.AuthenticationMethods,
Expand All @@ -101,7 +98,6 @@ func (r *AlterAuthenticationPolicyRequest) toOpts() *AlterAuthenticationPolicyOp
MfaEnrollment: r.Unset.MfaEnrollment,
Comment: r.Unset.Comment,
}

}

return opts
Expand Down Expand Up @@ -147,7 +143,7 @@ func (r *DescribeAuthenticationPolicyRequest) toOpts() *DescribeAuthenticationPo

func (r describeAuthenticationPolicyDBRow) convert() *AuthenticationPolicyDescription {
return &AuthenticationPolicyDescription{
Property: r.Property,
Value: r.Value,
Property: r.Property,
Value: r.Value,
}
}
2 changes: 1 addition & 1 deletion pkg/sdk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type Client struct {
ApplicationPackages ApplicationPackages
ApplicationRoles ApplicationRoles
Applications Applications
AuthenticationPolicies AuthenticationPolicies
AuthenticationPolicies AuthenticationPolicies
Comments Comments
CortexSearchServices CortexSearchServices
DatabaseRoles DatabaseRoles
Expand Down
2 changes: 1 addition & 1 deletion pkg/sdk/poc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var definitionMapping = map[string]*generator.Interface{
"cortex_search_services_def.go": sdk.CortexSearchServiceDef,
"data_metric_function_references_def.go": sdk.DataMetricFunctionReferenceDef,
"external_volumes_def.go": sdk.ExternalVolumesDef,
"authentication_policies_def.go": sdk.AuthenticationPoliciesDef,
"authentication_policies_def.go": sdk.AuthenticationPoliciesDef,
}

func main() {
Expand Down
Loading
Loading