Skip to content

Commit e8f1d2d

Browse files
committed
comments
1 parent 758cd26 commit e8f1d2d

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

coderd/dynamicparameters/render.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ type Loader struct {
4545
terraformValues *database.TemplateVersionTerraformValue
4646
}
4747

48+
// Prepare is the entrypoint for this package. It is broken into 2 steps to allow
49+
// prepopulating some of the existing data and saving some database queries.
50+
//
51+
// Usage: dynamicparameters.Prepare(...).Renderer(...)
4852
func Prepare(versionID uuid.UUID) *Loader {
4953
return &Loader{
5054
templateVersionID: versionID,
@@ -127,7 +131,7 @@ func (r *Loader) Renderer(ctx context.Context, db database.Store, cache *files.C
127131

128132
// Renderer caches all the necessary files when rendering a template version's
129133
// parameters. It must be closed after use to release the cached files.
130-
func (r *Loader) dynamicRenderer(ctx context.Context, db database.Store, cache *files.Cache) (*DynamicRenderer, error) {
134+
func (r *Loader) dynamicRenderer(ctx context.Context, db database.Store, cache *files.Cache) (*dynamicRenderer, error) {
131135
// If they can read the template version, then they can read the file for
132136
// parameter loading purposes.
133137
//nolint:gocritic
@@ -152,7 +156,7 @@ func (r *Loader) dynamicRenderer(ctx context.Context, db database.Store, cache *
152156
plan = r.terraformValues.CachedPlan
153157
}
154158

155-
return &DynamicRenderer{
159+
return &dynamicRenderer{
156160
data: r,
157161
templateFS: templateFS,
158162
db: db,
@@ -167,7 +171,7 @@ func (r *Loader) dynamicRenderer(ctx context.Context, db database.Store, cache *
167171
}, nil
168172
}
169173

170-
type DynamicRenderer struct {
174+
type dynamicRenderer struct {
171175
db database.Store
172176
data *Loader
173177
templateFS fs.FS
@@ -180,7 +184,7 @@ type DynamicRenderer struct {
180184
close func()
181185
}
182186

183-
func (r *DynamicRenderer) Render(ctx context.Context, ownerID uuid.UUID, values map[string]string) (*preview.Output, hcl.Diagnostics) {
187+
func (r *dynamicRenderer) Render(ctx context.Context, ownerID uuid.UUID, values map[string]string) (*preview.Output, hcl.Diagnostics) {
184188
// Always start with the cached error, if we have one.
185189
ownerErr := r.ownerErrors[ownerID]
186190
if ownerErr == nil {
@@ -210,7 +214,7 @@ func (r *DynamicRenderer) Render(ctx context.Context, ownerID uuid.UUID, values
210214
return preview.Preview(ctx, input, r.templateFS)
211215
}
212216

213-
func (r *DynamicRenderer) getWorkspaceOwnerData(ctx context.Context, ownerID uuid.UUID) error {
217+
func (r *dynamicRenderer) getWorkspaceOwnerData(ctx context.Context, ownerID uuid.UUID) error {
214218
if r.currentOwner != nil && r.currentOwner.ID == ownerID.String() {
215219
return nil // already fetched
216220
}
@@ -318,7 +322,7 @@ func (r *DynamicRenderer) getWorkspaceOwnerData(ctx context.Context, ownerID uui
318322
return nil
319323
}
320324

321-
func (r *DynamicRenderer) Close() {
325+
func (r *dynamicRenderer) Close() {
322326
r.once.Do(r.close)
323327
}
324328

coderd/dynamicparameters/static.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import (
1616
"github.com/coder/terraform-provider-coder/v2/provider"
1717
)
1818

19-
type StaticRender struct {
19+
type staticRender struct {
2020
staticParams []previewtypes.Parameter
2121
}
2222

23-
func (r *Loader) staticRender(ctx context.Context, db database.Store) (*StaticRender, error) {
23+
func (r *Loader) staticRender(ctx context.Context, db database.Store) (*staticRender, error) {
2424
dbTemplateVersionParameters, err := db.GetTemplateVersionParameters(ctx, r.templateVersionID)
2525
if err != nil {
2626
return nil, xerrors.Errorf("template version parameters: %w", err)
@@ -101,12 +101,12 @@ func (r *Loader) staticRender(ctx context.Context, db database.Store) (*StaticRe
101101
params = append(params, param)
102102
}
103103

104-
return &StaticRender{
104+
return &staticRender{
105105
staticParams: params,
106106
}, nil
107107
}
108108

109-
func (r *StaticRender) Render(_ context.Context, _ uuid.UUID, values map[string]string) (*preview.Output, hcl.Diagnostics) {
109+
func (r *staticRender) Render(_ context.Context, _ uuid.UUID, values map[string]string) (*preview.Output, hcl.Diagnostics) {
110110
params := r.staticParams
111111
for i := range params {
112112
param := &params[i]
@@ -131,4 +131,4 @@ func (r *StaticRender) Render(_ context.Context, _ uuid.UUID, values map[string]
131131
}
132132
}
133133

134-
func (*StaticRender) Close() {}
134+
func (*staticRender) Close() {}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy