Feat/risk and subject templates#13
Conversation
📝 WalkthroughWalkthroughThe PR adds EC2 instance subject template registration to the AWS EC2 compliance plugin. Subject templates are defined with templated metadata, integrated into plugin initialization, and tested for correctness. The build system and documentation are updated to reflect this new initialization flow. ChangesSubject Template Initialization and Documentation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@subject_templates_test.go`:
- Around line 18-48: Replace direct proto field accesses on tpl in
subject_templates_test.go with the protobuf getter methods: use tpl.GetName()
instead of tpl.Name, tpl.GetType() instead of tpl.Type,
tpl.GetIdentityLabelKeys() for IdentityLabelKeys, tpl.GetSelectorLabels() for
SelectorLabels, and tpl.GetLabelSchema() for LabelSchema; for nested label
entries use entry.GetKey() and entry.GetValue() instead of .Key/.Value. Update
the comparisons and loops to call these getters (e.g., iterate over
tpl.GetIdentityLabelKeys(), compare
tpl.GetSelectorLabels()[0].GetKey()/GetValue(), and
tpl.GetLabelSchema()[i].GetKey()) so the test uses protogetter accessors
throughout.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 35ce44f6-06a2-45ac-8a3b-cebccae38a06
📒 Files selected for processing (5)
MakefileREADME.mdmain.gosubject_templates.gosubject_templates_test.go
| if tpl.Name != "aws-ec2-instance" { | ||
| t.Fatalf("unexpected template name: %s", tpl.Name) | ||
| } | ||
| if tpl.Type != proto.SubjectType_SUBJECT_TYPE_COMPONENT { | ||
| t.Fatalf("unexpected template type: %v", tpl.Type) | ||
| } | ||
|
|
||
| expectedIdentityKeys := []string{"provider", "region", "instance-id"} | ||
| if len(tpl.IdentityLabelKeys) != len(expectedIdentityKeys) { | ||
| t.Fatalf("unexpected identity key count: %d", len(tpl.IdentityLabelKeys)) | ||
| } | ||
| for i, key := range expectedIdentityKeys { | ||
| if tpl.IdentityLabelKeys[i] != key { | ||
| t.Fatalf("unexpected identity key at %d: %s", i, tpl.IdentityLabelKeys[i]) | ||
| } | ||
| } | ||
|
|
||
| if len(tpl.SelectorLabels) != 1 { | ||
| t.Fatalf("unexpected selector count: %d", len(tpl.SelectorLabels)) | ||
| } | ||
| if tpl.SelectorLabels[0].Key != "type" || tpl.SelectorLabels[0].Value != "ec2" { | ||
| t.Fatalf("unexpected selector label: %s=%s", tpl.SelectorLabels[0].Key, tpl.SelectorLabels[0].Value) | ||
| } | ||
|
|
||
| expectedSchemaKeys := []string{"provider", "type", "instance-id", "_vpc-id", "_subnet-id", "region"} | ||
| if len(tpl.LabelSchema) != len(expectedSchemaKeys) { | ||
| t.Fatalf("unexpected label schema count: %d", len(tpl.LabelSchema)) | ||
| } | ||
| for i, key := range expectedSchemaKeys { | ||
| if tpl.LabelSchema[i].Key != key { | ||
| t.Fatalf("unexpected label schema key at %d: %s", i, tpl.LabelSchema[i].Key) |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify remaining direct proto field access in test file (should return no matches after fix)
rg -nP 'tpl\.(Name|Type|IdentityLabelKeys|SelectorLabels|LabelSchema)\b' subject_templates_test.goRepository: compliance-framework/plugin-aws-ec2
Length of output: 1114
Fix protogetter lint failures by using protobuf getters in subject_templates_test.go
Direct proto field access (tpl.Name, tpl.Type, tpl.IdentityLabelKeys, tpl.SelectorLabels, tpl.LabelSchema, and their nested .Key/.Value) still exists in this test (lines 18-48) and will trip protogetter-style lint. Replace with GetX() accessors.
Proposed fix
- if tpl.Name != "aws-ec2-instance" {
- t.Fatalf("unexpected template name: %s", tpl.Name)
+ if tpl.GetName() != "aws-ec2-instance" {
+ t.Fatalf("unexpected template name: %s", tpl.GetName())
}
- if tpl.Type != proto.SubjectType_SUBJECT_TYPE_COMPONENT {
- t.Fatalf("unexpected template type: %v", tpl.Type)
+ if tpl.GetType() != proto.SubjectType_SUBJECT_TYPE_COMPONENT {
+ t.Fatalf("unexpected template type: %v", tpl.GetType())
}
expectedIdentityKeys := []string{"provider", "region", "instance-id"}
- if len(tpl.IdentityLabelKeys) != len(expectedIdentityKeys) {
- t.Fatalf("unexpected identity key count: %d", len(tpl.IdentityLabelKeys))
+ if len(tpl.GetIdentityLabelKeys()) != len(expectedIdentityKeys) {
+ t.Fatalf("unexpected identity key count: %d", len(tpl.GetIdentityLabelKeys()))
}
for i, key := range expectedIdentityKeys {
- if tpl.IdentityLabelKeys[i] != key {
- t.Fatalf("unexpected identity key at %d: %s", i, tpl.IdentityLabelKeys[i])
+ if tpl.GetIdentityLabelKeys()[i] != key {
+ t.Fatalf("unexpected identity key at %d: %s", i, tpl.GetIdentityLabelKeys()[i])
}
}
- if len(tpl.SelectorLabels) != 1 {
- t.Fatalf("unexpected selector count: %d", len(tpl.SelectorLabels))
+ if len(tpl.GetSelectorLabels()) != 1 {
+ t.Fatalf("unexpected selector count: %d", len(tpl.GetSelectorLabels()))
}
- if tpl.SelectorLabels[0].Key != "type" || tpl.SelectorLabels[0].Value != "ec2" {
- t.Fatalf("unexpected selector label: %s=%s", tpl.SelectorLabels[0].Key, tpl.SelectorLabels[0].Value)
+ if tpl.GetSelectorLabels()[0].GetKey() != "type" || tpl.GetSelectorLabels()[0].GetValue() != "ec2" {
+ t.Fatalf("unexpected selector label: %s=%s", tpl.GetSelectorLabels()[0].GetKey(), tpl.GetSelectorLabels()[0].GetValue())
}
expectedSchemaKeys := []string{"provider", "type", "instance-id", "_vpc-id", "_subnet-id", "region"}
- if len(tpl.LabelSchema) != len(expectedSchemaKeys) {
- t.Fatalf("unexpected label schema count: %d", len(tpl.LabelSchema))
+ if len(tpl.GetLabelSchema()) != len(expectedSchemaKeys) {
+ t.Fatalf("unexpected label schema count: %d", len(tpl.GetLabelSchema()))
}
for i, key := range expectedSchemaKeys {
- if tpl.LabelSchema[i].Key != key {
- t.Fatalf("unexpected label schema key at %d: %s", i, tpl.LabelSchema[i].Key)
+ if tpl.GetLabelSchema()[i].GetKey() != key {
+ t.Fatalf("unexpected label schema key at %d: %s", i, tpl.GetLabelSchema()[i].GetKey())
}
}🧰 Tools
🪛 golangci-lint (2.12.2)
[error] 18-18: avoid direct access to proto field tpl.Name, use tpl.GetName() instead
(protogetter)
[error] 19-19: avoid direct access to proto field tpl.Name, use tpl.GetName() instead
(protogetter)
[error] 21-21: avoid direct access to proto field tpl.Type, use tpl.GetType() instead
(protogetter)
[error] 22-22: avoid direct access to proto field tpl.Type, use tpl.GetType() instead
(protogetter)
[error] 26-26: avoid direct access to proto field tpl.IdentityLabelKeys, use tpl.GetIdentityLabelKeys() instead
(protogetter)
[error] 27-27: avoid direct access to proto field tpl.IdentityLabelKeys, use tpl.GetIdentityLabelKeys() instead
(protogetter)
[error] 30-30: avoid direct access to proto field tpl.IdentityLabelKeys, use tpl.GetIdentityLabelKeys() instead
(protogetter)
[error] 35-35: avoid direct access to proto field tpl.SelectorLabels, use tpl.GetSelectorLabels() instead
(protogetter)
[error] 36-36: avoid direct access to proto field tpl.SelectorLabels, use tpl.GetSelectorLabels() instead
(protogetter)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@subject_templates_test.go` around lines 18 - 48, Replace direct proto field
accesses on tpl in subject_templates_test.go with the protobuf getter methods:
use tpl.GetName() instead of tpl.Name, tpl.GetType() instead of tpl.Type,
tpl.GetIdentityLabelKeys() for IdentityLabelKeys, tpl.GetSelectorLabels() for
SelectorLabels, and tpl.GetLabelSchema() for LabelSchema; for nested label
entries use entry.GetKey() and entry.GetValue() instead of .Key/.Value. Update
the comparisons and loops to call these getters (e.g., iterate over
tpl.GetIdentityLabelKeys(), compare
tpl.GetSelectorLabels()[0].GetKey()/GetValue(), and
tpl.GetLabelSchema()[i].GetKey()) so the test uses protogetter accessors
throughout.
Summary by CodeRabbit
Documentation
Build & Infrastructure