Skip to content

Commit 2ebf832

Browse files
committed
apply sugestions
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
1 parent c723b27 commit 2ebf832

12 files changed

Lines changed: 41 additions & 27 deletions

File tree

app/cli/cmd/attestation_init.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package cmd
1818
import (
1919
"errors"
2020
"fmt"
21+
"slices"
22+
"strings"
2123

2224
"github.com/chainloop-dev/chainloop/app/cli/cmd/output"
2325
"github.com/chainloop-dev/chainloop/app/cli/pkg/action"
@@ -75,6 +77,12 @@ func newAttestationInitCmd() *cobra.Command {
7577
return errors.New("project version is required when using --existing-version")
7678
}
7779

80+
for _, c := range collectors {
81+
if !slices.Contains(action.ValidCollectors, c) {
82+
return fmt.Errorf("unknown collector %q, valid options: %s", c, strings.Join(action.ValidCollectors, ", "))
83+
}
84+
}
85+
7886
return nil
7987
},
8088
RunE: func(cmd *cobra.Command, _ []string) error {

app/cli/pkg/action/attestation_init.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ type AttestationInit struct {
5959

6060
const aiConfigCollectorName = "aiconfig"
6161

62+
// ValidCollectors is the list of known collector names accepted by --collectors.
63+
var ValidCollectors = []string{aiConfigCollectorName}
64+
6265
// ErrAttestationAlreadyExist means that there is an attestation in progress
6366
var ErrAttestationAlreadyExist = errors.New("attestation already initialized")
6467

internal/aiagentconfig/aiagentconfig.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ type GitContext struct {
3030

3131
// ConfigFile represents a single discovered configuration file
3232
type ConfigFile struct {
33-
Path string `json:"path"`
34-
SHA256 string `json:"sha256"`
35-
Size int64 `json:"size"`
36-
Base64Content string `json:"base64_content"`
33+
Path string `json:"path"`
34+
SHA256 string `json:"sha256"`
35+
Size int64 `json:"size"`
36+
Content string `json:"content"`
3737
}
3838

3939
// Evidence is the AI agent configuration payload

internal/aiagentconfig/builder.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ func Build(rootDir string, filePaths []string, gitCtx *GitContext) (*Evidence, e
7575
hashes = append(hashes, fmt.Sprintf("%s:%s", relPath, hexHash))
7676

7777
configFiles = append(configFiles, ConfigFile{
78-
Path: relPath,
79-
SHA256: hexHash,
80-
Size: info.Size(),
81-
Base64Content: base64.StdEncoding.EncodeToString(content),
78+
Path: relPath,
79+
SHA256: hexHash,
80+
Size: info.Size(),
81+
Content: base64.StdEncoding.EncodeToString(content),
8282
})
8383
}
8484

@@ -108,10 +108,12 @@ func computeCombinedHash(hashes []string) string {
108108
// ensureInsideDir verifies that filePath is inside dir. Both paths must be
109109
// already resolved (no symlinks). Returns an error if the file escapes.
110110
func ensureInsideDir(filePath, dir string) error {
111-
cleanDir := filepath.Clean(dir) + string(filepath.Separator)
112-
cleanFile := filepath.Clean(filePath)
111+
rel, err := filepath.Rel(dir, filePath)
112+
if err != nil {
113+
return fmt.Errorf("path escapes root directory via symlink")
114+
}
113115

114-
if !strings.HasPrefix(cleanFile, cleanDir) {
116+
if rel == ".." || strings.HasPrefix(rel, ".."+string(filepath.Separator)) {
115117
return fmt.Errorf("path escapes root directory via symlink")
116118
}
117119

internal/aiagentconfig/builder_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func TestBuild(t *testing.T) {
6868
assert.Equal(t, int64(len(file1Content)), cf1.Size)
6969
hash1 := sha256.Sum256(file1Content)
7070
assert.Equal(t, hex.EncodeToString(hash1[:]), cf1.SHA256)
71-
assert.Equal(t, base64.StdEncoding.EncodeToString(file1Content), cf1.Base64Content)
71+
assert.Equal(t, base64.StdEncoding.EncodeToString(file1Content), cf1.Content)
7272

7373
cf2 := data.ConfigFiles[1]
7474
assert.Equal(t, ".claude/settings.json", cf2.Path)

internal/aiagentconfig/discover.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,22 @@ var claudePatterns = []string{
3333
".claude/skills/*/SKILL.md",
3434
}
3535

36-
// Discover searches rootDir for AI agent configuration files.
37-
// It only looks in rootDir and its subdirectories, never in parent directories.
36+
// Discover searches basePath for AI agent configuration files.
37+
// It only looks in basePath and its subdirectories, never in parent directories.
3838
// Returns deduplicated relative paths sorted alphabetically.
39-
func Discover(rootDir string) ([]string, error) {
39+
func Discover(basePath string) ([]string, error) {
4040
seen := make(map[string]struct{})
4141
var results []string
4242

4343
for _, pattern := range claudePatterns {
44-
absPattern := filepath.Join(rootDir, pattern)
44+
absPattern := filepath.Join(basePath, pattern)
4545
matches, err := filepath.Glob(absPattern)
4646
if err != nil {
4747
return nil, err
4848
}
4949

5050
for _, match := range matches {
51-
rel, err := filepath.Rel(rootDir, match)
51+
rel, err := filepath.Rel(basePath, match)
5252
if err != nil {
5353
return nil, err
5454
}

internal/schemavalidators/internal_schemas/aiagentconfig/ai-agent-config-0.1.schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"minItems": 1,
6767
"items": {
6868
"type": "object",
69-
"required": ["path", "sha256", "size", "base64_content"],
69+
"required": ["path", "sha256", "size", "content"],
7070
"properties": {
7171
"path": {
7272
"type": "string",
@@ -81,7 +81,7 @@
8181
"minimum": 0,
8282
"description": "File size in bytes"
8383
},
84-
"base64_content": {
84+
"content": {
8585
"type": "string",
8686
"description": "Base64-encoded file content"
8787
}

internal/schemavalidators/testdata/ai_agent_config_extra_fields.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"path": "CLAUDE.md",
1111
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
1212
"size": 10,
13-
"base64_content": "Y29udGVudA=="
13+
"content": "Y29udGVudA=="
1414
}
1515
],
1616
"unknown_field": "should fail"

internal/schemavalidators/testdata/ai_agent_config_minimal.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
"config_files": [
99
{
1010
"path": "CLAUDE.md",
11-
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
12-
"size": 10,
13-
"base64_content": "Y29udGVudA=="
11+
"sha256": "ed7002b439e9ac845f22357d822bac1444730fbdb6016d3ec9432297b9ec9f73",
12+
"size": 7,
13+
"content": "Y29udGVudA=="
1414
}
1515
]
1616
}

internal/schemavalidators/testdata/ai_agent_config_missing_agent.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"path": "CLAUDE.md",
88
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
99
"size": 10,
10-
"base64_content": "Y29udGVudA=="
10+
"content": "Y29udGVudA=="
1111
}
1212
]
1313
}

0 commit comments

Comments
 (0)