Skip to content

Commit 3f01953

Browse files
authored
fix: hash (#117)
1 parent 804ef0f commit 3f01953

File tree

3 files changed

+57
-14
lines changed

3 files changed

+57
-14
lines changed

provider/data_source_database.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,24 @@ func dataSourceDatabaseRead(ctx context.Context, d *schema.ResourceData, m inter
144144
}
145145

146146
func columnHash(rawColumn interface{}) string {
147+
var buf bytes.Buffer
147148
column := rawColumn.(map[string]interface{})
148-
return column["name"].(string)
149+
150+
if v, ok := column["name"].(string); ok {
151+
_, _ = buf.WriteString(fmt.Sprintf("%s-", v))
152+
}
153+
if v, ok := column["semantic_type"].(string); ok {
154+
_, _ = buf.WriteString(fmt.Sprintf("%s-", v))
155+
}
156+
if v, ok := column["classification"].(string); ok {
157+
_, _ = buf.WriteString(fmt.Sprintf("%s-", v))
158+
}
159+
if v, ok := column["classification"].(map[string]interface{}); ok {
160+
for key, val := range v {
161+
_, _ = buf.WriteString(fmt.Sprintf("[%s:%s]-", key, val.(string)))
162+
}
163+
}
164+
return buf.String()
149165
}
150166

151167
func tableHash(rawTable interface{}) string {
@@ -155,6 +171,9 @@ func tableHash(rawTable interface{}) string {
155171
if v, ok := table["name"].(string); ok {
156172
_, _ = buf.WriteString(fmt.Sprintf("%s-", v))
157173
}
174+
if v, ok := table["classification"].(string); ok {
175+
_, _ = buf.WriteString(fmt.Sprintf("%s-", v))
176+
}
158177
if columns, ok := table["columns"].(*schema.Set); ok {
159178
for _, column := range columns.List() {
160179
rawColumn := column.(map[string]interface{})

provider/resource_instance.go

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package provider
22

33
import (
4+
"bytes"
45
"context"
56
"fmt"
67
"regexp"
@@ -743,27 +744,44 @@ func flattenDataSourceList(d *schema.ResourceData, dataSourceList []*v1pb.DataSo
743744
}
744745

745746
func dataSourceHash(rawDataSource interface{}) int {
746-
dataSource := rawDataSource.(map[string]interface{})
747-
// Include id and SSL-related field presence to detect configuration changes
748-
hashStr := dataSource["id"].(string)
747+
var buf bytes.Buffer
748+
raw := rawDataSource.(map[string]interface{})
749749

750-
// Include use_ssl in hash to detect SSL enablement changes
751-
if v, ok := dataSource["use_ssl"].(bool); ok {
752-
hashStr = fmt.Sprintf("%s-ssl_%t", hashStr, v)
750+
if v, ok := raw["id"].(string); ok {
751+
_, _ = buf.WriteString(fmt.Sprintf("%s-", v))
752+
}
753+
if v, ok := raw["username"].(string); ok {
754+
_, _ = buf.WriteString(fmt.Sprintf("%s-", v))
755+
}
756+
if v, ok := raw["password"].(string); ok {
757+
_, _ = buf.WriteString(fmt.Sprintf("%s-", v))
758+
}
759+
if v, ok := raw["host"].(string); ok {
760+
_, _ = buf.WriteString(fmt.Sprintf("%s-", v))
761+
}
762+
if v, ok := raw["port"].(string); ok {
763+
_, _ = buf.WriteString(fmt.Sprintf("%s-", v))
764+
}
765+
if v, ok := raw["database"].(string); ok {
766+
_, _ = buf.WriteString(fmt.Sprintf("%s-", v))
753767
}
754768

769+
// Include use_ssl in hash to detect SSL enablement changes
770+
if v, ok := raw["use_ssl"].(bool); ok {
771+
_, _ = buf.WriteString(fmt.Sprintf("ssl_%v-", v))
772+
}
755773
// Include whether SSL certificates are present (not the values themselves)
756-
if v, ok := dataSource["ssl_ca"].(string); ok && v != "" {
757-
hashStr = fmt.Sprintf("%s-ca_present", hashStr)
774+
if v, ok := raw["ssl_ca"].(string); ok && v != "" {
775+
_, _ = buf.WriteString(fmt.Sprintf("ca_present_%s-", v))
758776
}
759-
if v, ok := dataSource["ssl_cert"].(string); ok && v != "" {
760-
hashStr = fmt.Sprintf("%s-cert_present", hashStr)
777+
if v, ok := raw["ssl_cert"].(string); ok && v != "" {
778+
_, _ = buf.WriteString(fmt.Sprintf("cert_present_%s-", v))
761779
}
762-
if v, ok := dataSource["ssl_key"].(string); ok && v != "" {
763-
hashStr = fmt.Sprintf("%s-key_present", hashStr)
780+
if v, ok := raw["ssl_key"].(string); ok && v != "" {
781+
_, _ = buf.WriteString(fmt.Sprintf("key_present_%s-", v))
764782
}
765783

766-
return internal.ToHashcodeInt(hashStr)
784+
return internal.ToHashcodeInt(buf.String())
767785
}
768786

769787
func convertDataSourceCreateList(d *schema.ResourceData, validate bool) ([]*v1pb.DataSource, error) {

provider/resource_review_config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,12 @@ func reviewRuleHash(rawRule interface{}) int {
239239
if v, ok := raw["engine"].(string); ok {
240240
_, _ = buf.WriteString(fmt.Sprintf("%s-", v))
241241
}
242+
if v, ok := raw["payload"].(string); ok {
243+
_, _ = buf.WriteString(fmt.Sprintf("%s-", v))
244+
}
245+
if v, ok := raw["level"].(string); ok {
246+
_, _ = buf.WriteString(fmt.Sprintf("%s-", v))
247+
}
242248

243249
return internal.ToHashcodeInt(buf.String())
244250
}

0 commit comments

Comments
 (0)