From f32362332f7a45938cad6788f2bd1bb98ad6cea6 Mon Sep 17 00:00:00 2001 From: Jakub Michalak Date: Tue, 23 Apr 2024 16:16:23 +0200 Subject: [PATCH] Support owner role type in other views --- pkg/sdk/masking_policy.go | 2 ++ pkg/sdk/password_policy.go | 30 ++++++++-------- pkg/sdk/session_policies_def.go | 6 ++-- pkg/sdk/session_policies_gen.go | 34 ++++++++++--------- pkg/sdk/session_policies_impl_gen.go | 17 +++++----- pkg/sdk/tags.go | 16 ++++----- .../masking_policy_integration_test.go | 11 ++++++ .../password_policy_integration_test.go | 11 ++++++ pkg/sdk/testint/pipes_integration_test.go | 11 ++++++ pkg/sdk/testint/schemas_integration_test.go | 1 + pkg/sdk/testint/sequences_integration_test.go | 11 ++++++ .../session_policies_gen_integration_test.go | 1 + .../testint/stages_gen_integration_test.go | 1 + pkg/sdk/testint/tables_integration_test.go | 11 ++++++ pkg/sdk/testint/tags_integration_test.go | 1 + 15 files changed, 116 insertions(+), 48 deletions(-) diff --git a/pkg/sdk/masking_policy.go b/pkg/sdk/masking_policy.go index 40d7f34656b..93916ca46fc 100644 --- a/pkg/sdk/masking_policy.go +++ b/pkg/sdk/masking_policy.go @@ -231,6 +231,7 @@ type MaskingPolicy struct { Owner string Comment string ExemptOtherPolicies bool + OwnerRoleType string } func (v *MaskingPolicy) ID() SchemaObjectIdentifier { @@ -268,6 +269,7 @@ func (row maskingPolicyDBRow) convert() *MaskingPolicy { Owner: row.Owner, Comment: row.Comment, ExemptOtherPolicies: exemptOtherPolicies, + OwnerRoleType: row.OwnerRoleType, } } diff --git a/pkg/sdk/password_policy.go b/pkg/sdk/password_policy.go index a77dad0bec8..16af471c642 100644 --- a/pkg/sdk/password_policy.go +++ b/pkg/sdk/password_policy.go @@ -251,13 +251,14 @@ func (opts *ShowPasswordPolicyOptions) validate() error { // PasswordPolicy is a user-friendly result for a CREATE PASSWORD POLICY query. type PasswordPolicy struct { - CreatedOn time.Time - Name string - DatabaseName string - SchemaName string - Kind string - Owner string - Comment string + CreatedOn time.Time + Name string + DatabaseName string + SchemaName string + Kind string + Owner string + Comment string + OwnerRoleType string } func (v *PasswordPolicy) ID() SchemaObjectIdentifier { @@ -283,13 +284,14 @@ type passwordPolicyDBRow struct { func (row passwordPolicyDBRow) convert() PasswordPolicy { return PasswordPolicy{ - CreatedOn: row.CreatedOn, - Name: row.Name, - DatabaseName: row.DatabaseName, - SchemaName: row.SchemaName, - Kind: row.Kind, - Owner: row.Owner, - Comment: row.Comment, + CreatedOn: row.CreatedOn, + Name: row.Name, + DatabaseName: row.DatabaseName, + SchemaName: row.SchemaName, + Kind: row.Kind, + Owner: row.Owner, + Comment: row.Comment, + OwnerRoleType: row.OwnerRoleType, } } diff --git a/pkg/sdk/session_policies_def.go b/pkg/sdk/session_policies_def.go index 2053e48d227..65f8870cf4c 100644 --- a/pkg/sdk/session_policies_def.go +++ b/pkg/sdk/session_policies_def.go @@ -73,7 +73,8 @@ var SessionPoliciesDef = g.NewInterface( Field("kind", "string"). Field("owner", "string"). Field("comment", "string"). - Field("options", "string"), + Field("options", "string"). + Field("owner_role_type", "string"), g.PlainStruct("SessionPolicy"). Field("CreatedOn", "string"). Field("Name", "string"). @@ -82,7 +83,8 @@ var SessionPoliciesDef = g.NewInterface( Field("Kind", "string"). Field("Owner", "string"). Field("Comment", "string"). - Field("Options", "string"), + Field("Options", "string"). + Field("OwnerRoleType", "string"), g.NewQueryStruct("ShowSessionPolicies"). Show(). SQL("SESSION POLICIES"), diff --git a/pkg/sdk/session_policies_gen.go b/pkg/sdk/session_policies_gen.go index 00c0480541e..461a14b5e57 100644 --- a/pkg/sdk/session_policies_gen.go +++ b/pkg/sdk/session_policies_gen.go @@ -66,25 +66,27 @@ type ShowSessionPolicyOptions struct { } type showSessionPolicyDBRow struct { - CreatedOn string `db:"created_on"` - Name string `db:"name"` - DatabaseName string `db:"database_name"` - SchemaName string `db:"schema_name"` - Kind string `db:"kind"` - Owner string `db:"owner"` - Comment string `db:"comment"` - Options string `db:"options"` + CreatedOn string `db:"created_on"` + Name string `db:"name"` + DatabaseName string `db:"database_name"` + SchemaName string `db:"schema_name"` + Kind string `db:"kind"` + Owner string `db:"owner"` + Comment string `db:"comment"` + Options string `db:"options"` + OwnerRoleType string `db:"owner_role_type"` } type SessionPolicy struct { - CreatedOn string - Name string - DatabaseName string - SchemaName string - Kind string - Owner string - Comment string - Options string + CreatedOn string + Name string + DatabaseName string + SchemaName string + Kind string + Owner string + Comment string + Options string + OwnerRoleType string } // DescribeSessionPolicyOptions is based on https://docs.snowflake.com/en/sql-reference/sql/desc-session-policy. diff --git a/pkg/sdk/session_policies_impl_gen.go b/pkg/sdk/session_policies_impl_gen.go index 1d48dadff7a..7d6284f0f39 100644 --- a/pkg/sdk/session_policies_impl_gen.go +++ b/pkg/sdk/session_policies_impl_gen.go @@ -110,14 +110,15 @@ func (r *ShowSessionPolicyRequest) toOpts() *ShowSessionPolicyOptions { func (r showSessionPolicyDBRow) convert() *SessionPolicy { return &SessionPolicy{ - CreatedOn: r.CreatedOn, - Name: r.Name, - DatabaseName: r.DatabaseName, - SchemaName: r.SchemaName, - Kind: r.Kind, - Owner: r.Owner, - Comment: r.Comment, - Options: r.Options, + CreatedOn: r.CreatedOn, + Name: r.Name, + DatabaseName: r.DatabaseName, + SchemaName: r.SchemaName, + Kind: r.Kind, + Owner: r.Owner, + Comment: r.Comment, + Options: r.Options, + OwnerRoleType: r.OwnerRoleType, } } diff --git a/pkg/sdk/tags.go b/pkg/sdk/tags.go index 1ef6f1e0a71..78f90e755a2 100644 --- a/pkg/sdk/tags.go +++ b/pkg/sdk/tags.go @@ -70,7 +70,7 @@ type Tag struct { Owner string Comment string AllowedValues []string - OwnerRole string + OwnerRoleType string } func (v *Tag) ID() SchemaObjectIdentifier { @@ -90,13 +90,13 @@ type tagRow struct { func (tr tagRow) convert() *Tag { t := &Tag{ - CreatedOn: tr.CreatedOn, - Name: tr.Name, - DatabaseName: tr.DatabaseName, - SchemaName: tr.SchemaName, - Owner: tr.Owner, - Comment: tr.Comment, - OwnerRole: tr.OwnerRoleType, + CreatedOn: tr.CreatedOn, + Name: tr.Name, + DatabaseName: tr.DatabaseName, + SchemaName: tr.SchemaName, + Owner: tr.Owner, + Comment: tr.Comment, + OwnerRoleType: tr.OwnerRoleType, } if tr.AllowedValues.Valid { // remove brackets diff --git a/pkg/sdk/testint/masking_policy_integration_test.go b/pkg/sdk/testint/masking_policy_integration_test.go index bfde3fab4ab..fa13eecae58 100644 --- a/pkg/sdk/testint/masking_policy_integration_test.go +++ b/pkg/sdk/testint/masking_policy_integration_test.go @@ -436,4 +436,15 @@ func TestInt_MaskingPoliciesShowByID(t *testing.T) { require.NoError(t, err) require.Equal(t, id2, e2.ID()) }) + + t.Run("show by id: check fields", func(t *testing.T) { + name := random.AlphaN(4) + id1 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + + createMaskingPolicyHandle(t, id1) + + sl, err := client.MaskingPolicies.ShowByID(ctx, id1) + require.NoError(t, err) + assert.Equal(t, "ROLE", sl.OwnerRoleType) + }) } diff --git a/pkg/sdk/testint/password_policy_integration_test.go b/pkg/sdk/testint/password_policy_integration_test.go index d503dc15015..082a931716c 100644 --- a/pkg/sdk/testint/password_policy_integration_test.go +++ b/pkg/sdk/testint/password_policy_integration_test.go @@ -354,4 +354,15 @@ func TestInt_PasswordPoliciesShowByID(t *testing.T) { require.NoError(t, err) require.Equal(t, id2, e2.ID()) }) + + t.Run("show by id: check fields", func(t *testing.T) { + name := random.AlphaN(4) + id1 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + + createPasswordPolicyHandle(t, id1) + + sl, err := client.PasswordPolicies.ShowByID(ctx, id1) + require.NoError(t, err) + assert.Equal(t, "ROLE", sl.OwnerRoleType) + }) } diff --git a/pkg/sdk/testint/pipes_integration_test.go b/pkg/sdk/testint/pipes_integration_test.go index e2221740cbb..c92b5327d93 100644 --- a/pkg/sdk/testint/pipes_integration_test.go +++ b/pkg/sdk/testint/pipes_integration_test.go @@ -402,4 +402,15 @@ func TestInt_PipesShowByID(t *testing.T) { require.NoError(t, err) require.Equal(t, id2, e2.ID()) }) + + t.Run("show by id: check fields", func(t *testing.T) { + name := random.AlphaN(4) + id1 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + + createPipeHandle(t, id1) + + sl, err := client.Pipes.ShowByID(ctx, id1) + require.NoError(t, err) + assert.Equal(t, "ROLE", sl.OwnerRoleType) + }) } diff --git a/pkg/sdk/testint/schemas_integration_test.go b/pkg/sdk/testint/schemas_integration_test.go index 2fd4e5f1aa8..278ea8c0788 100644 --- a/pkg/sdk/testint/schemas_integration_test.go +++ b/pkg/sdk/testint/schemas_integration_test.go @@ -333,6 +333,7 @@ func TestInt_SchemasShow(t *testing.T) { schemaNames[i] = s.Name } assert.Contains(t, schemaNames, schema.Name) + assert.Equal(t, "ROLE", schema.OwnerRoleType) }) } diff --git a/pkg/sdk/testint/sequences_integration_test.go b/pkg/sdk/testint/sequences_integration_test.go index 33140ece7f2..935c3e8b6e1 100644 --- a/pkg/sdk/testint/sequences_integration_test.go +++ b/pkg/sdk/testint/sequences_integration_test.go @@ -215,4 +215,15 @@ func TestInt_SequencesShowByID(t *testing.T) { require.NoError(t, err) require.Equal(t, id2, e2.ID()) }) + + t.Run("show by id: check fields", func(t *testing.T) { + name := random.AlphaN(4) + id1 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + + createSequenceHandle(t, id1) + + sl, err := client.Sequences.ShowByID(ctx, id1) + require.NoError(t, err) + assert.Equal(t, "ROLE", sl.OwnerRoleType) + }) } diff --git a/pkg/sdk/testint/session_policies_gen_integration_test.go b/pkg/sdk/testint/session_policies_gen_integration_test.go index 61b1174d1d4..e9ea72f3748 100644 --- a/pkg/sdk/testint/session_policies_gen_integration_test.go +++ b/pkg/sdk/testint/session_policies_gen_integration_test.go @@ -24,6 +24,7 @@ func TestInt_SessionPolicies(t *testing.T) { assert.Equal(t, expectedComment, sessionPolicy.Comment) assert.Equal(t, "SESSION_POLICY", sessionPolicy.Kind) assert.Equal(t, "", sessionPolicy.Options) + assert.Equal(t, "ROLE", sessionPolicy.OwnerRoleType) } assertSessionPolicyDescription := func( diff --git a/pkg/sdk/testint/stages_gen_integration_test.go b/pkg/sdk/testint/stages_gen_integration_test.go index 3d4a488c63d..a33cd52c336 100644 --- a/pkg/sdk/testint/stages_gen_integration_test.go +++ b/pkg/sdk/testint/stages_gen_integration_test.go @@ -553,6 +553,7 @@ func TestInt_Stages(t *testing.T) { assert.Nil(t, stage.StorageIntegration) assert.Nil(t, stage.Endpoint) assert.True(t, stage.DirectoryEnabled) + assert.Equal(t, "ROLE", stage.OwnerRoleType) }) } diff --git a/pkg/sdk/testint/tables_integration_test.go b/pkg/sdk/testint/tables_integration_test.go index dbff93f42e6..a5781d7aa2e 100644 --- a/pkg/sdk/testint/tables_integration_test.go +++ b/pkg/sdk/testint/tables_integration_test.go @@ -1047,4 +1047,15 @@ func TestInt_TablesShowByID(t *testing.T) { require.NoError(t, err) require.Equal(t, id2, e2.ID()) }) + + t.Run("show by id: check fields", func(t *testing.T) { + name := random.AlphaN(4) + id1 := sdk.NewSchemaObjectIdentifier(databaseTest.Name, schemaTest.Name, name) + + createTableHandle(t, id1) + + sl, err := client.Tables.ShowByID(ctx, id1) + require.NoError(t, err) + assert.Equal(t, "ROLE", sl.OwnerRoleType) + }) } diff --git a/pkg/sdk/testint/tags_integration_test.go b/pkg/sdk/testint/tags_integration_test.go index 01f52658c1f..f684e2ceaef 100644 --- a/pkg/sdk/testint/tags_integration_test.go +++ b/pkg/sdk/testint/tags_integration_test.go @@ -28,6 +28,7 @@ func TestInt_Tags(t *testing.T) { assert.Equal(t, "ACCOUNTADMIN", tag.Owner) assert.Equal(t, expectedComment, tag.Comment) assert.Equal(t, expectedAllowedValues, tag.AllowedValues) + assert.Equal(t, "ROLE", tag.OwnerRoleType) } cleanupTagHandle := func(id sdk.SchemaObjectIdentifier) func() { return func() {