MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / loadAndProcessTemplates

Function loadAndProcessTemplates

app/cli/internal/policydevel/init.go:94–129  ·  view source on GitHub ↗
(opts *InitOptions)

Source from the content-addressed store, hash-verified

92}
93
94func loadAndProcessTemplates(opts *InitOptions) (*Content, error) {
95 regoContent, err := templateFS.ReadFile(policyTemplateRegoPath)
96 if err != nil {
97 return nil, fmt.Errorf("failed to read Rego template: %w", err)
98 }
99
100 data := &TemplateData{
101 Name: getPolicyName(opts.Name),
102 Description: getPolicyDescription(opts.Description),
103 RegoPath: sanitizeName(getPolicyName(opts.Name)) + ".rego",
104 RegoContent: string(regoContent),
105 Embedded: opts.Embedded,
106 MaterialKind: defaultMaterialKind,
107 }
108
109 // Process main template
110 content, err := templateFS.ReadFile(policyTemplatePath)
111 if err != nil {
112 return nil, fmt.Errorf("failed to read policy template: %w", err)
113 }
114
115 yamlContent, err := executeTemplate(string(content), data)
116 if err != nil {
117 return nil, fmt.Errorf("failed to execute template: %w", err)
118 }
119
120 // For non-embedded case, we still need the Rego content to write to file
121 if !opts.Embedded {
122 return &Content{
123 YAML: yamlContent,
124 Rego: data.RegoContent,
125 }, nil
126 }
127
128 return &Content{YAML: yamlContent}, nil
129}
130
131// Add custom template functions
132func executeTemplate(content string, data *TemplateData) (string, error) {

Callers 2

InitializeFunction · 0.85

Calls 4

getPolicyNameFunction · 0.85
getPolicyDescriptionFunction · 0.85
sanitizeNameFunction · 0.85
executeTemplateFunction · 0.85

Tested by 1