Skip to content

Commit 26115be

Browse files
committed
fix: copilot issues
Signed-off-by: Gustavo Carvalho <gustavo.carvalho@container-solutions.com>
1 parent 39979ed commit 26115be

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

main.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ func hashResource(resource interface{}) string {
755755
content = []byte(fmt.Sprintf("%#v", resource))
756756
}
757757
sum := sha256.Sum256(content)
758-
return hex.EncodeToString(sum[:])[:16]
758+
return hex.EncodeToString(sum[:])
759759
}
760760

761761
func buildInventoryCheck(resourceType string) CustodianCheck {
@@ -1137,8 +1137,8 @@ func (p *CloudCustodianPlugin) buildSubjectTemplates() []*proto.SubjectTemplate
11371137
provider := extractProvider(resourceType)
11381138
templates = append(templates, &proto.SubjectTemplate{
11391139
Name: fmt.Sprintf("cloud-custodian-%s", sanitizeIdentifier(resourceType)),
1140-
// So that automation renders component definitions
1141-
Type: proto.SubjectType_SUBJECT_TYPE_COMPONENT,
1140+
// These templates represent cloud resources collected during evaluation.
1141+
Type: proto.SubjectType_SUBJECT_TYPE_RESOURCE,
11421142
TitleTemplate: "Cloud Resource: {{ .resource_type }} {{ .resource_id }}",
11431143
DescriptionTemplate: "Cloud Custodian resource {{ .resource_id }} of type {{ .resource_type }} from provider {{ .provider }}",
11441144
PurposeTemplate: "Represents a cloud resource collected by Cloud Custodian for compliance evaluation.",
@@ -1620,6 +1620,18 @@ func (p *CloudCustodianPlugin) logPolicyPayload(payload *StandardizedResourcePay
16201620
if payload == nil || !p.Logger.IsDebug() {
16211621
return
16221622
}
1623+
1624+
if p.parsedConfig == nil || !p.parsedConfig.DebugDumpPayloads {
1625+
p.Logger.Debug("Policy payload",
1626+
"check_name", payload.Check.Name,
1627+
"resource_id", payload.Resource.ID,
1628+
"assessment_status", payload.Assessment.Status,
1629+
"resource_type", payload.Resource.Type,
1630+
"provider", payload.Resource.Provider,
1631+
)
1632+
return
1633+
}
1634+
16231635
raw, err := json.MarshalIndent(payload, "", " ")
16241636
if err != nil {
16251637
p.Logger.Debug("Policy payload serialization failed",
@@ -1629,7 +1641,7 @@ func (p *CloudCustodianPlugin) logPolicyPayload(payload *StandardizedResourcePay
16291641
)
16301642
return
16311643
}
1632-
p.Logger.Debug("Policy payload",
1644+
p.Logger.Debug("Policy payload with data",
16331645
"check_name", payload.Check.Name,
16341646
"resource_id", payload.Resource.ID,
16351647
"assessment_status", payload.Assessment.Status,

main_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,13 @@ func TestBuildResourceRecordCanonicalizesHostedZoneARN(t *testing.T) {
801801
}
802802
}
803803

804+
func TestHashResourceUsesFullSHA256Digest(t *testing.T) {
805+
got := hashResource(map[string]interface{}{"id": "example", "name": "bucket"})
806+
if len(got) != 64 {
807+
t.Fatalf("expected full sha256 hex digest length 64, got %d (%q)", len(got), got)
808+
}
809+
}
810+
804811
func TestInitUpsertsSubjectAndRiskTemplates(t *testing.T) {
805812
policyDir := t.TempDir()
806813
rego := `package compliance_framework.cloud_custodian_test

0 commit comments

Comments
 (0)