Skip to content

Commit bcba28d

Browse files
committed
style fix: avoid indentation by returning early when ok is false
1 parent 90f4a3f commit bcba28d

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

bundle/config/mutator/resourcemutator/configure_dashboards_serialized_dashboard.go

+25-24
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (c configureDashboardSerializedDashboard) Name() string {
2424
return "ConfigureDashboardSerializedDashboard"
2525
}
2626

27-
func (c configureDashboardSerializedDashboard) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
27+
func (c configureDashboardSerializedDashboard) Apply(_ context.Context, b *bundle.Bundle) diag.Diagnostics {
2828
var diags diag.Diagnostics
2929

3030
pattern := dyn.NewPattern(
@@ -39,34 +39,35 @@ func (c configureDashboardSerializedDashboard) Apply(ctx context.Context, b *bun
3939
// Include "serialized_dashboard" field if "file_path" is set.
4040
// Note: the Terraform resource supports "file_path" natively, but we read the contents of the dashboard here
4141
// to cover the use case of deployments from the workspace
42-
if path, ok := v.Get(filePathFieldName).AsString(); ok {
42+
path, ok := v.Get(filePathFieldName).AsString()
43+
if !ok {
44+
return v, nil
45+
}
4346

44-
contents, err := b.SyncRoot.ReadFile(path)
45-
if err != nil {
46-
return dyn.InvalidValue, fmt.Errorf("failed to read serialized dashboard from file_path %s: %w", path, err)
47-
}
47+
contents, err := b.SyncRoot.ReadFile(path)
48+
if err != nil {
49+
return dyn.InvalidValue, fmt.Errorf("failed to read serialized dashboard from file_path %s: %w", path, err)
50+
}
4851

49-
v, err := dyn.Set(v, serializedDashboardFieldName, dyn.V(string(contents)))
50-
if err != nil {
51-
return dyn.InvalidValue, fmt.Errorf("failed to set serialized_dashboard: %w", err)
52-
}
52+
v, err = dyn.Set(v, serializedDashboardFieldName, dyn.V(string(contents)))
53+
if err != nil {
54+
return dyn.InvalidValue, fmt.Errorf("failed to set serialized_dashboard: %w", err)
55+
}
5356

54-
// Drop the "file_path" field. It is mutually exclusive with "serialized_dashboard".
55-
return dyn.Walk(v, func(p dyn.Path, v dyn.Value) (dyn.Value, error) {
56-
switch len(p) {
57-
case 0:
58-
return v, nil
59-
case 1:
60-
if p[0] == dyn.Key(filePathFieldName) {
61-
return v, dyn.ErrDrop
62-
}
57+
// Drop the "file_path" field. It is mutually exclusive with "serialized_dashboard".
58+
return dyn.Walk(v, func(p dyn.Path, v dyn.Value) (dyn.Value, error) {
59+
switch len(p) {
60+
case 0:
61+
return v, nil
62+
case 1:
63+
if p[0] == dyn.Key(filePathFieldName) {
64+
return v, dyn.ErrDrop
6365
}
66+
}
6467

65-
// Skip everything else.
66-
return v, dyn.ErrSkip
67-
})
68-
}
69-
return v, nil
68+
// Skip everything else.
69+
return v, dyn.ErrSkip
70+
})
7071
})
7172
})
7273

0 commit comments

Comments
 (0)