Skip to content

Commit 41f8b0f

Browse files
committed
unexport methods that are internal
1 parent d4e5e9b commit 41f8b0f

File tree

6 files changed

+18
-32
lines changed

6 files changed

+18
-32
lines changed

owner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"golang.org/x/xerrors"
1111
)
1212

13-
func WorkspaceOwnerHook(dfs fs.FS, input Input) (func(ctx *tfcontext.Context, blocks terraform.Blocks, inputVars map[string]cty.Value), error) {
13+
func workspaceOwnerHook(dfs fs.FS, input Input) (func(ctx *tfcontext.Context, blocks terraform.Blocks, inputVars map[string]cty.Value), error) {
1414
if input.Owner.Groups == nil {
1515
input.Owner.Groups = []string{}
1616
}

parameter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/coder/preview/types"
1212
)
1313

14-
func RichParameters(modules terraform.Modules) ([]types.Parameter, hcl.Diagnostics) {
14+
func parameters(modules terraform.Modules) ([]types.Parameter, hcl.Diagnostics) {
1515
diags := make(hcl.Diagnostics, 0)
1616
params := make([]types.Parameter, 0)
1717
exists := make(map[string][]types.Parameter)

paramhook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import (
88
"github.com/coder/preview/hclext"
99
)
1010

11-
// ParameterContextsEvalHook is called in a loop, so if parameters affect
11+
// parameterContextsEvalHook is called in a loop, so if parameters affect
1212
// other parameters, this can solve the problem 1 "evaluation" at a time.
1313
//
1414
// Omitting to set a default value is OK, as long as at least 1 parameter
1515
// is resolvable. The resolvable parameter will be accessible on the next
1616
// iteration.
17-
func ParameterContextsEvalHook(input Input) func(ctx *tfcontext.Context, blocks terraform.Blocks, inputVars map[string]cty.Value) {
17+
func parameterContextsEvalHook(input Input) func(ctx *tfcontext.Context, blocks terraform.Blocks, inputVars map[string]cty.Value) {
1818
return func(ctx *tfcontext.Context, blocks terraform.Blocks, inputVars map[string]cty.Value) {
1919
data := blocks.OfType("data")
2020
for _, block := range data {

plan.go

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"slices"
1111
"strings"
1212

13-
"github.com/aquasecurity/trivy/pkg/iac/scanners/terraformplan/tfjson/parser"
1413
"github.com/aquasecurity/trivy/pkg/iac/terraform"
1514
tfcontext "github.com/aquasecurity/trivy/pkg/iac/terraform/context"
1615
tfjson "github.com/hashicorp/terraform-json"
@@ -20,7 +19,7 @@ import (
2019
"github.com/coder/preview/hclext"
2120
)
2221

23-
func PlanJSONHook(dfs fs.FS, input Input) (func(ctx *tfcontext.Context, blocks terraform.Blocks, inputVars map[string]cty.Value), error) {
22+
func planJSONHook(dfs fs.FS, input Input) (func(ctx *tfcontext.Context, blocks terraform.Blocks, inputVars map[string]cty.Value), error) {
2423
var contents io.Reader = bytes.NewReader(input.PlanJSON)
2524
// Also accept `{}` as an empty plan. If this is stored in postgres or another json
2625
// type, then `{}` is the "empty" value.
@@ -36,7 +35,7 @@ func PlanJSONHook(dfs fs.FS, input Input) (func(ctx *tfcontext.Context, blocks t
3635
}
3736
}
3837

39-
plan, err := ParsePlanJSON(contents)
38+
plan, err := parsePlanJSON(contents)
4039
if err != nil {
4140
return nil, fmt.Errorf("unable to parse plan JSON: %w", err)
4241
}
@@ -216,28 +215,15 @@ func toCtyValue(a any) (cty.Value, error) {
216215
}
217216
}
218217

219-
// ParsePlanJSON can parse the JSON output of a Terraform plan.
218+
// parsePlanJSON can parse the JSON output of a Terraform plan.
220219
// terraform plan out.plan
221220
// terraform show -json out.plan
222-
func ParsePlanJSON(reader io.Reader) (*tfjson.Plan, error) {
221+
func parsePlanJSON(reader io.Reader) (*tfjson.Plan, error) {
223222
plan := new(tfjson.Plan)
224223
plan.FormatVersion = tfjson.PlanFormatVersionConstraints
225224
return plan, json.NewDecoder(reader).Decode(plan)
226225
}
227226

228-
// ParsePlanJSON can parse the JSON output of a Terraform plan.
229-
// terraform plan out.plan
230-
// terraform show -json out.plan
231-
func TrivyParsePlanJSON(reader io.Reader) (*tfjson.Plan, error) {
232-
p := parser.New()
233-
plan, err := p.Parse(reader)
234-
var _ = plan
235-
236-
plan.ToFS()
237-
238-
return nil, err
239-
}
240-
241227
func keyMatcher(key cty.Value) func(to any) bool {
242228
switch {
243229
case key.Type().Equals(cty.Number):

preview.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func Preview(ctx context.Context, input Input, dir fs.FS) (mainOutput *Output, d
6464
}
6565
}
6666

67-
planHook, err := PlanJSONHook(dir, input)
67+
planHook, err := planJSONHook(dir, input)
6868
if err != nil {
6969
return nil, hcl.Diagnostics{
7070
{
@@ -75,7 +75,7 @@ func Preview(ctx context.Context, input Input, dir fs.FS) (mainOutput *Output, d
7575
}
7676
}
7777

78-
ownerHook, err := WorkspaceOwnerHook(dir, input)
78+
ownerHook, err := workspaceOwnerHook(dir, input)
7979
if err != nil {
8080
return nil, hcl.Diagnostics{
8181
{
@@ -95,7 +95,7 @@ func Preview(ctx context.Context, input Input, dir fs.FS) (mainOutput *Output, d
9595
parser.OptionWithTFVarsPaths(varFiles...),
9696
parser.OptionWithEvalHook(planHook),
9797
parser.OptionWithEvalHook(ownerHook),
98-
parser.OptionWithEvalHook(ParameterContextsEvalHook(input)),
98+
parser.OptionWithEvalHook(parameterContextsEvalHook(input)),
9999
)
100100

101101
err = p.ParseFS(ctx, ".")
@@ -121,8 +121,8 @@ func Preview(ctx context.Context, input Input, dir fs.FS) (mainOutput *Output, d
121121
}
122122

123123
diags := make(hcl.Diagnostics, 0)
124-
rp, rpDiags := RichParameters(modules)
125-
tags, tagDiags := WorkspaceTags(modules, p.Files())
124+
rp, rpDiags := parameters(modules)
125+
tags, tagDiags := workspaceTags(modules, p.Files())
126126

127127
// Add warnings
128128
diags = diags.Extend(warnings(modules))

workspacetags.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/coder/preview/types"
1111
)
1212

13-
func WorkspaceTags(modules terraform.Modules, files map[string]*hcl.File) (types.TagBlocks, hcl.Diagnostics) {
13+
func workspaceTags(modules terraform.Modules, files map[string]*hcl.File) (types.TagBlocks, hcl.Diagnostics) {
1414
diags := make(hcl.Diagnostics, 0)
1515
tagBlocks := make(types.TagBlocks, 0)
1616

@@ -65,7 +65,7 @@ func WorkspaceTags(modules terraform.Modules, files map[string]*hcl.File) (types
6565
var tags []types.Tag
6666
tagsValue.ForEachElement(func(key cty.Value, val cty.Value) (stop bool) {
6767
r := tagsAttr.HCLAttribute().Expr.Range()
68-
tag, tagDiag := NewTag(&r, files, key, val)
68+
tag, tagDiag := newTag(&r, files, key, val)
6969
if tagDiag != nil {
7070
diags = diags.Append(tagDiag)
7171
return false
@@ -76,7 +76,7 @@ func WorkspaceTags(modules terraform.Modules, files map[string]*hcl.File) (types
7676
return false
7777
})
7878
//for _, item := range tagsObj.Items {
79-
// tag, tagDiag := NewTag(tagsObj, files, item, evCtx)
79+
// tag, tagDiag := newTag(tagsObj, files, item, evCtx)
8080
// if tagDiag != nil {
8181
// diags = diags.Append(tagDiag)
8282
// continue
@@ -94,8 +94,8 @@ func WorkspaceTags(modules terraform.Modules, files map[string]*hcl.File) (types
9494
return tagBlocks, diags
9595
}
9696

97-
// NewTag creates a workspace tag from its hcl expression.
98-
func NewTag(srcRange *hcl.Range, files map[string]*hcl.File, key, val cty.Value) (types.Tag, *hcl.Diagnostic) {
97+
// newTag creates a workspace tag from its hcl expression.
98+
func newTag(srcRange *hcl.Range, files map[string]*hcl.File, key, val cty.Value) (types.Tag, *hcl.Diagnostic) {
9999
//key, kdiags := expr.KeyExpr.Value(evCtx)
100100
//val, vdiags := expr.ValueExpr.Value(evCtx)
101101

0 commit comments

Comments
 (0)