Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(template): enable remote file templating #680

Merged
merged 14 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/cmd/tools/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/defenseunicorns/go-oscal/src/pkg/files"
"github.com/defenseunicorns/lula/src/cmd/common"
"github.com/defenseunicorns/lula/src/internal/template"
pkgCommon "github.com/defenseunicorns/lula/src/pkg/common"
"github.com/defenseunicorns/lula/src/pkg/common/network"
"github.com/defenseunicorns/lula/src/pkg/message"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -46,7 +46,7 @@ func TemplateCommand() *cobra.Command {
Example: templateHelp,
RunE: func(cmd *cobra.Command, args []string) error {
// Read file
data, err := pkgCommon.ReadFileToBytes(inputFile)
data, err := network.Fetch(inputFile)
if err != nil {
return fmt.Errorf("error reading file: %v", err)
}
Expand Down
20 changes: 19 additions & 1 deletion src/internal/template/helpers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package template

import "fmt"
import (
"fmt"
"time"

"github.com/defenseunicorns/go-oscal/src/pkg/uuid"
)

func concatToRegoList(list []any) string {
regoList := ""
Expand All @@ -12,3 +17,16 @@ func concatToRegoList(list []any) string {
}
return regoList
}

func newUUID(source ...string) string {
if len(source) == 0 {
return uuid.NewUUID()
} else {
return uuid.NewUUIDWithSource(source[0])
}
}

func timestamp() string {
t := time.Now()
return t.Format("2006-01-02T15:04:05.999999999Z")
}
2 changes: 2 additions & 0 deletions src/internal/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ func createTemplate() *template.Template {
"concatToRegoList": func(a []any) string {
return concatToRegoList(a)
},
"uuid": newUUID,
"timestamp": timestamp,
// Add more custom functions as needed
}

Expand Down