Skip to content

Commit

Permalink
Support owner role type in other views
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jmichalak committed Apr 23, 2024
1 parent 9dc6423 commit f323623
Show file tree
Hide file tree
Showing 15 changed files with 116 additions and 48 deletions.
2 changes: 2 additions & 0 deletions pkg/sdk/masking_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ type MaskingPolicy struct {
Owner string
Comment string
ExemptOtherPolicies bool
OwnerRoleType string
}

func (v *MaskingPolicy) ID() SchemaObjectIdentifier {
Expand Down Expand Up @@ -268,6 +269,7 @@ func (row maskingPolicyDBRow) convert() *MaskingPolicy {
Owner: row.Owner,
Comment: row.Comment,
ExemptOtherPolicies: exemptOtherPolicies,
OwnerRoleType: row.OwnerRoleType,
}
}

Expand Down
30 changes: 16 additions & 14 deletions pkg/sdk/password_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
}
}

Expand Down
6 changes: 4 additions & 2 deletions pkg/sdk/session_policies_def.go
Original file line number Diff line number Diff line change
Expand Up @@ -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").
Expand All @@ -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"),
Expand Down
34 changes: 18 additions & 16 deletions pkg/sdk/session_policies_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 9 additions & 8 deletions pkg/sdk/session_policies_impl_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
16 changes: 8 additions & 8 deletions pkg/sdk/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type Tag struct {
Owner string
Comment string
AllowedValues []string
OwnerRole string
OwnerRoleType string
}

func (v *Tag) ID() SchemaObjectIdentifier {
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions pkg/sdk/testint/masking_policy_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
11 changes: 11 additions & 0 deletions pkg/sdk/testint/password_policy_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
11 changes: 11 additions & 0 deletions pkg/sdk/testint/pipes_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
1 change: 1 addition & 0 deletions pkg/sdk/testint/schemas_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

Expand Down
11 changes: 11 additions & 0 deletions pkg/sdk/testint/sequences_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
1 change: 1 addition & 0 deletions pkg/sdk/testint/session_policies_gen_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions pkg/sdk/testint/stages_gen_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

Expand Down
11 changes: 11 additions & 0 deletions pkg/sdk/testint/tables_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
1 change: 1 addition & 0 deletions pkg/sdk/testint/tags_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit f323623

Please sign in to comment.