Skip to content

Commit 4d54e32

Browse files
authored
CP: Add python to allowed script extensions (#43485)
Cherry-picks #43467
1 parent 0a082f9 commit 4d54e32

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

pkg/spec/gitops.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,7 @@ var defaultAllowedExtensions = map[string]bool{
11401140
var allowedScriptExtensions = map[string]bool{
11411141
".sh": true,
11421142
".ps1": true,
1143+
".py": true,
11431144
}
11441145

11451146
// GlobExpandOptions configures how flattenBaseItems expands glob patterns.

pkg/spec/gitops_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,6 +2007,25 @@ func TestResolveScriptPaths(t *testing.T) {
20072007
require.Len(t, result, 2)
20082008
})
20092009

2010+
t.Run("glob_filters_non_script_extensions", func(t *testing.T) {
2011+
t.Parallel()
2012+
dir := t.TempDir()
2013+
require.NoError(t, os.WriteFile(filepath.Join(dir, "a.sh"), []byte("#!/bin/bash"), 0o644))
2014+
require.NoError(t, os.WriteFile(filepath.Join(dir, "b.ps1"), []byte("Write-Host"), 0o644))
2015+
require.NoError(t, os.WriteFile(filepath.Join(dir, "c.py"), []byte("#!/usr/bin/env python3"), 0o644))
2016+
require.NoError(t, os.WriteFile(filepath.Join(dir, "d.txt"), []byte("not a script"), 0o644))
2017+
2018+
items := []fleet.BaseItem{{Paths: ptr.String("*")}} //nolint:modernize
2019+
result, errs := resolveScriptPaths(items, dir, nopLogf)
2020+
require.Empty(t, errs)
2021+
require.Len(t, result, 3)
2022+
got := make([]string, 0, len(result))
2023+
for _, r := range result {
2024+
got = append(got, filepath.Base(*r.Path))
2025+
}
2026+
assert.Equal(t, []string{"a.sh", "b.ps1", "c.py"}, got)
2027+
})
2028+
20102029
t.Run("inline_not_allowed", func(t *testing.T) {
20112030
t.Parallel()
20122031
items := []fleet.BaseItem{{}}

0 commit comments

Comments
 (0)