mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat(provisionersdk): add support for .tf.json templates (#7744)
This commit is contained in:
@@ -15,15 +15,17 @@ const (
|
||||
TemplateArchiveLimit = 1 << 20
|
||||
)
|
||||
|
||||
func dirHasExt(dir string, ext string) (bool, error) {
|
||||
func dirHasExt(dir string, exts ...string) (bool, error) {
|
||||
dirEnts, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
for _, fi := range dirEnts {
|
||||
if strings.HasSuffix(fi.Name(), ext) {
|
||||
return true, nil
|
||||
for _, ext := range exts {
|
||||
if strings.HasSuffix(fi.Name(), ext) {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,8 +37,8 @@ func Tar(w io.Writer, directory string, limit int64) error {
|
||||
tarWriter := tar.NewWriter(w)
|
||||
totalSize := int64(0)
|
||||
|
||||
const tfExt = ".tf"
|
||||
hasTf, err := dirHasExt(directory, tfExt)
|
||||
tfExts := []string{".tf", ".tf.json"}
|
||||
hasTf, err := dirHasExt(directory, tfExts...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -50,7 +52,7 @@ func Tar(w io.Writer, directory string, limit int64) error {
|
||||
// useless.
|
||||
return xerrors.Errorf(
|
||||
"%s is not a valid template since it has no %s files",
|
||||
absPath, tfExt,
|
||||
absPath, tfExts,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,15 @@ func TestTar(t *testing.T) {
|
||||
err = provisionersdk.Tar(io.Discard, dir, 1024)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
t.Run("ValidJSON", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
dir := t.TempDir()
|
||||
file, err := os.CreateTemp(dir, "*.tf.json")
|
||||
require.NoError(t, err)
|
||||
_ = file.Close()
|
||||
err = provisionersdk.Tar(io.Discard, dir, 1024)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
t.Run("HiddenFiles", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
dir := t.TempDir()
|
||||
|
||||
Reference in New Issue
Block a user