Skip to content

Commit

Permalink
fix: 0.59 release fixes (#1636)
Browse files Browse the repository at this point in the history
* fix stream error

* fix 5 part id read

* fix role grants read

* fix linting error

* update docs

* update docs

* fix stage acceptance tests

* fix stage acceptance tests

* fix stream acceptance tests

* fix stream acceptance tests

* fix stream acceptance tests

* fix stream acceptance tests
  • Loading branch information
sfc-gh-swinkler authored Mar 21, 2023
1 parent 711ac0c commit 0a0256e
Show file tree
Hide file tree
Showing 49 changed files with 512 additions and 121 deletions.
1 change: 1 addition & 0 deletions docs/resources/stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ resource "snowflake_stream" "stream" {
- `append_only` (Boolean) Type of the stream that will be created.
- `comment` (String) Specifies a comment for the stream.
- `insert_only` (Boolean) Create an insert only stream type.
- `on_stage` (String) Name of the stage the stream will monitor.
- `on_table` (String) Name of the table the stream will monitor.
- `on_view` (String) Name of the view the stream will monitor.
- `show_initial_rows` (Boolean) Specifies whether to return all existing rows in the source table as row inserts the first time the stream is consumed.
Expand Down
12 changes: 10 additions & 2 deletions pkg/resources/account_grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,18 @@ func (v *AccountGrantID) String() string {
func ParseAccountGrantID(s string) (*AccountGrantID, error) {
if IsOldGrantID(s) {
idParts := strings.Split(s, "|")
var roles []string
var withGrantOption bool
if len(idParts) == 6 {
withGrantOption = idParts[5] == "true"
roles = helpers.SplitStringToSlice(idParts[4], ",")
} else {
withGrantOption = idParts[4] == "true"
}
return &AccountGrantID{
Privilege: idParts[3],
Roles: helpers.SplitStringToSlice(idParts[4], ","),
WithGrantOption: idParts[5] == "true",
Roles: roles,
WithGrantOption: withGrantOption,
IsOldID: true,
}, nil
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/resources/account_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,13 @@ func TestParseAccountGrantOldID(t *testing.T) {
r.Equal("role1", grantID.Roles[0])
r.Equal("role2", grantID.Roles[1])
}

func TestParseAccountGrantReallyOldID(t *testing.T) {
r := require.New(t)

grantID, err := resources.ParseAccountGrantID("ACCOUNT|||MONITOR EXECUTION|true")
r.NoError(err)
r.Equal("MONITOR EXECUTION", grantID.Privilege)
r.Equal(true, grantID.WithGrantOption)
r.Equal(0, len(grantID.Roles))
}
12 changes: 10 additions & 2 deletions pkg/resources/database_grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,20 @@ func (v *DatabaseGrantID) String() string {
func ParseDatabaseGrantID(s string) (*DatabaseGrantID, error) {
if IsOldGrantID(s) {
idParts := strings.Split(s, "|")
var roles []string
var withGrantOption bool
if len(idParts) == 6 {
withGrantOption = idParts[5] == "true"
roles = helpers.SplitStringToSlice(idParts[4], ",")
} else {
withGrantOption = idParts[4] == "true"
}
return &DatabaseGrantID{
DatabaseName: idParts[0],
Privilege: idParts[3],
Roles: helpers.SplitStringToSlice(idParts[4], ","),
Roles: roles,
Shares: []string{},
WithGrantOption: idParts[5] == "true",
WithGrantOption: withGrantOption,
IsOldID: true,
}, nil
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/resources/database_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,14 @@ func TestParseDatabaseGrantOldID(t *testing.T) {
r.Equal("role1", grantID.Roles[0])
r.Equal("role2", grantID.Roles[1])
}

func TestParseDatabaseGrantReallyOldID(t *testing.T) {
r := require.New(t)

grantID, err := resources.ParseDatabaseGrantID("test-database|||USAGE|true")
r.NoError(err)
r.Equal("test-database", grantID.DatabaseName)
r.Equal("USAGE", grantID.Privilege)
r.Equal(true, grantID.WithGrantOption)
r.Equal(0, len(grantID.Roles))
}
12 changes: 10 additions & 2 deletions pkg/resources/external_table_grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,22 @@ func (v *ExternalTableGrantID) String() string {
func ParseExternalTableGrantID(s string) (*ExternalTableGrantID, error) {
if IsOldGrantID(s) {
idParts := strings.Split(s, "|")
var roles []string
var withGrantOption bool
if len(idParts) == 6 {
withGrantOption = idParts[5] == "true"
roles = helpers.SplitStringToSlice(idParts[4], ",")
} else {
withGrantOption = idParts[4] == "true"
}
return &ExternalTableGrantID{
DatabaseName: idParts[0],
SchemaName: idParts[1],
ObjectName: idParts[2],
Privilege: idParts[3],
Roles: helpers.SplitStringToSlice(idParts[4], ","),
Roles: roles,
Shares: []string{},
WithGrantOption: idParts[5] == "true",
WithGrantOption: withGrantOption,
IsOldID: true,
}, nil
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/resources/external_table_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,16 @@ func TestParseExternalTableGrantOldID(t *testing.T) {
r.Equal("role1", grantID.Roles[0])
r.Equal("role2", grantID.Roles[1])
}

func TestParseExternalTableGrantReallyOldID(t *testing.T) {
r := require.New(t)

grantID, err := resources.ParseExternalTableGrantID("test-db|PUBLIC|test-external-table|SELECT|true")
r.NoError(err)
r.Equal("test-db", grantID.DatabaseName)
r.Equal("PUBLIC", grantID.SchemaName)
r.Equal("test-external-table", grantID.ObjectName)
r.Equal("SELECT", grantID.Privilege)
r.Equal(true, grantID.WithGrantOption)
r.Equal(0, len(grantID.Roles))
}
12 changes: 10 additions & 2 deletions pkg/resources/file_format_grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,21 @@ func (v *FileFormatGrantID) String() string {
func ParseFileFormatGrantID(s string) (*FileFormatGrantID, error) {
if IsOldGrantID(s) {
idParts := strings.Split(s, "|")
var roles []string
var withGrantOption bool
if len(idParts) == 6 {
withGrantOption = idParts[5] == "true"
roles = helpers.SplitStringToSlice(idParts[4], ",")
} else {
withGrantOption = idParts[4] == "true"
}
return &FileFormatGrantID{
DatabaseName: idParts[0],
SchemaName: idParts[1],
ObjectName: idParts[2],
Privilege: idParts[3],
Roles: helpers.SplitStringToSlice(idParts[4], ","),
WithGrantOption: idParts[5] == "true",
Roles: roles,
WithGrantOption: withGrantOption,
}, nil
}
idParts := strings.Split(s, "|")
Expand Down
13 changes: 13 additions & 0 deletions pkg/resources/file_format_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,16 @@ func TestParseFileFormatGrantOldID(t *testing.T) {
r.Equal("role1", grantID.Roles[0])
r.Equal("role2", grantID.Roles[1])
}

func TestParseFileFormatGrantReallyOldID(t *testing.T) {
r := require.New(t)

grantID, err := resources.ParseFileFormatGrantID("test-db|PUBLIC|test-file-format|USAGE|true")
r.NoError(err)
r.Equal("test-db", grantID.DatabaseName)
r.Equal("PUBLIC", grantID.SchemaName)
r.Equal("test-file-format", grantID.ObjectName)
r.Equal("USAGE", grantID.Privilege)
r.Equal(true, grantID.WithGrantOption)
r.Equal(0, len(grantID.Roles))
}
2 changes: 1 addition & 1 deletion pkg/resources/function_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestAcc_Function(t *testing.T) {
resource.TestCheckResourceAttr("snowflake_function.test_funct_java", "arguments.#", "1"),
resource.TestCheckResourceAttr("snowflake_function.test_funct_java", "arguments.0.name", "ARG1"),
resource.TestCheckResourceAttr("snowflake_function.test_funct_java", "arguments.0.type", "NUMBER"),
checkBool("snowflake_function.test_funct_java", "is_secure", true), // this is from user_acceptance_test.go
checkBool("snowflake_function.test_funct_java", "is_secure", false), // this is from user_acceptance_test.go

// TODO: temporarily remove unit tests to allow for urgent release
// resource.TestCheckResourceAttr("snowflake_function.test_funct_python", "name", functName),
Expand Down
12 changes: 10 additions & 2 deletions pkg/resources/function_grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,15 +378,23 @@ func ParseFunctionGrantID(s string) (*FunctionGrantID, error) {
argumentDataTypes[i] = parts[1]
}
}
var roles []string
var withGrantOption bool
if len(idParts) == 6 {
withGrantOption = idParts[5] == "true"
roles = helpers.SplitStringToSlice(idParts[4], ",")
} else {
withGrantOption = idParts[4] == "true"
}
return &FunctionGrantID{
DatabaseName: idParts[0],
SchemaName: idParts[1],
ObjectName: objectNameParts[0],
ArgumentDataTypes: argumentDataTypes,
Privilege: idParts[3],
Roles: helpers.SplitStringToSlice(idParts[4], ","),
Roles: roles,
Shares: []string{},
WithGrantOption: idParts[5] == "true",
WithGrantOption: withGrantOption,
IsOldID: true,
}, nil
}
Expand Down
16 changes: 16 additions & 0 deletions pkg/resources/function_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,19 @@ func TestParseFunctionGrantOldIDWithArgsAndNames(t *testing.T) {
r.Equal(0, len(grantID.Shares))
r.Equal(false, grantID.WithGrantOption)
}

func TestParseFunctionGrantReallyOldIDWithArgsAndNames(t *testing.T) {
r := require.New(t)
grantID, err := resources.ParseFunctionGrantID("MY_DATABASE|MY_SCHEMA|MY_FUNCTION(A string, B string)|privilege_name|false")
r.NoError(err)
r.Equal("MY_DATABASE", grantID.DatabaseName)
r.Equal("MY_SCHEMA", grantID.SchemaName)
r.Equal("MY_FUNCTION", grantID.ObjectName)
r.Equal(2, len(grantID.ArgumentDataTypes))
r.Equal("string", grantID.ArgumentDataTypes[0])
r.Equal("string", grantID.ArgumentDataTypes[1])
r.Equal("privilege_name", grantID.Privilege)
r.Equal(0, len(grantID.Roles))
r.Equal(0, len(grantID.Shares))
r.Equal(false, grantID.WithGrantOption)
}
12 changes: 10 additions & 2 deletions pkg/resources/integration_grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,19 @@ func (v *IntegrationGrantID) String() string {
func ParseIntegrationGrantID(s string) (*IntegrationGrantID, error) {
if IsOldGrantID(s) {
idParts := strings.Split(s, "|")
var roles []string
var withGrantOption bool
if len(idParts) == 6 {
withGrantOption = idParts[5] == "true"
roles = helpers.SplitStringToSlice(idParts[4], ",")
} else {
withGrantOption = idParts[4] == "true"
}
return &IntegrationGrantID{
ObjectName: idParts[0],
Privilege: idParts[3],
Roles: helpers.SplitStringToSlice(idParts[4], ","),
WithGrantOption: idParts[5] == "true",
Roles: roles,
WithGrantOption: withGrantOption,
IsOldID: true,
}, nil
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/resources/integration_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,14 @@ func TestParseIntegrationGrantOldID(t *testing.T) {
r.Equal("role1", grantID.Roles[0])
r.Equal("role2", grantID.Roles[1])
}

func TestParseIntegrationGranReallyOldID(t *testing.T) {
r := require.New(t)

grantID, err := resources.ParseIntegrationGrantID("test-integration|||IMPORTED PRIVILEGES|true")
r.NoError(err)
r.Equal("test-integration", grantID.ObjectName)
r.Equal("IMPORTED PRIVILEGES", grantID.Privilege)
r.Equal(true, grantID.WithGrantOption)
r.Equal(0, len(grantID.Roles))
}
12 changes: 10 additions & 2 deletions pkg/resources/masking_policy_grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,21 @@ func (v *MaskingPolicyGrantID) String() string {
func ParseMaskingPolicyGrantID(s string) (*MaskingPolicyGrantID, error) {
if IsOldGrantID(s) {
idParts := strings.Split(s, "|")
var roles []string
var withGrantOption bool
if len(idParts) == 6 {
withGrantOption = idParts[5] == "true"
roles = helpers.SplitStringToSlice(idParts[4], ",")
} else {
withGrantOption = idParts[4] == "true"
}
return &MaskingPolicyGrantID{
DatabaseName: idParts[0],
SchemaName: idParts[1],
ObjectName: idParts[2],
Privilege: idParts[3],
Roles: helpers.SplitStringToSlice(idParts[4], ","),
WithGrantOption: idParts[5] == "true",
Roles: roles,
WithGrantOption: withGrantOption,
IsOldID: true,
}, nil
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/resources/masking_policy_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,16 @@ func TestParseMaskingPolicyGrantOldID(t *testing.T) {
r.Equal("role1", grantID.Roles[0])
r.Equal("role2", grantID.Roles[1])
}

func TestParseMaskingPolicyGrantReallyOldID(t *testing.T) {
r := require.New(t)

grantID, err := resources.ParseMaskingPolicyGrantID("test-db|PUBLIC|test-materialized-view|SELECT|true")
r.NoError(err)
r.Equal("test-db", grantID.DatabaseName)
r.Equal("PUBLIC", grantID.SchemaName)
r.Equal("test-materialized-view", grantID.ObjectName)
r.Equal("SELECT", grantID.Privilege)
r.Equal(true, grantID.WithGrantOption)
r.Equal(0, len(grantID.Roles))
}
12 changes: 10 additions & 2 deletions pkg/resources/materialized_view_grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,22 @@ func (v *MaterializedViewGrantID) String() string {
func ParseMaterializedViewGrantID(s string) (*MaterializedViewGrantID, error) {
if IsOldGrantID(s) {
idParts := strings.Split(s, "|")
var roles []string
var withGrantOption bool
if len(idParts) == 6 {
withGrantOption = idParts[5] == "true"
roles = helpers.SplitStringToSlice(idParts[4], ",")
} else {
withGrantOption = idParts[4] == "true"
}
return &MaterializedViewGrantID{
DatabaseName: idParts[0],
SchemaName: idParts[1],
ObjectName: idParts[2],
Privilege: idParts[3],
Roles: helpers.SplitStringToSlice(idParts[4], ","),
Roles: roles,
Shares: []string{},
WithGrantOption: idParts[5] == "true",
WithGrantOption: withGrantOption,
IsOldID: true,
}, nil
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/resources/materialized_view_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,16 @@ func TestParseMaterializedViewGrantOldID(t *testing.T) {
r.Equal("role1", grantID.Roles[0])
r.Equal("role2", grantID.Roles[1])
}

func TestParseMaterializedViewGrantReallyOldID(t *testing.T) {
r := require.New(t)

grantID, err := resources.ParseMaterializedViewGrantID("test-db|PUBLIC|test-materialized-view|SELECT|true")
r.NoError(err)
r.Equal("test-db", grantID.DatabaseName)
r.Equal("PUBLIC", grantID.SchemaName)
r.Equal("test-materialized-view", grantID.ObjectName)
r.Equal("SELECT", grantID.Privilege)
r.Equal(true, grantID.WithGrantOption)
r.Equal(0, len(grantID.Roles))
}
12 changes: 10 additions & 2 deletions pkg/resources/pipe_grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,21 @@ func (v *PipeGrantID) String() string {
func ParsePipeGrantID(s string) (*PipeGrantID, error) {
if IsOldGrantID(s) {
idParts := strings.Split(s, "|")
var roles []string
var withGrantOption bool
if len(idParts) == 6 {
withGrantOption = idParts[5] == "true"
roles = helpers.SplitStringToSlice(idParts[4], ",")
} else {
withGrantOption = idParts[4] == "true"
}
return &PipeGrantID{
DatabaseName: idParts[0],
SchemaName: idParts[1],
ObjectName: idParts[2],
Privilege: idParts[3],
Roles: helpers.SplitStringToSlice(idParts[4], ","),
WithGrantOption: idParts[5] == "true",
Roles: roles,
WithGrantOption: withGrantOption,
IsOldID: true,
}, nil
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/resources/pipe_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,16 @@ func TestParsePipeGrantOldID(t *testing.T) {
r.Equal("role1", grantID.Roles[0])
r.Equal("role2", grantID.Roles[1])
}

func TestParsePipeGrantReallyOldID(t *testing.T) {
r := require.New(t)

grantID, err := resources.ParsePipeGrantID("test-db|PUBLIC|test-pipe|OPERATE|true")
r.NoError(err)
r.Equal("test-db", grantID.DatabaseName)
r.Equal("PUBLIC", grantID.SchemaName)
r.Equal("test-pipe", grantID.ObjectName)
r.Equal("OPERATE", grantID.Privilege)
r.Equal(true, grantID.WithGrantOption)
r.Equal(0, len(grantID.Roles))
}
Loading

0 comments on commit 0a0256e

Please sign in to comment.