-
Notifications
You must be signed in to change notification settings - Fork 49
Refactor backend handling #828
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,38 +17,24 @@ package local | |
import ( | ||
"github.com/hashicorp/hcl/v2" | ||
"github.com/hashicorp/hcl/v2/gohcl" | ||
|
||
"github.com/kinvolk/lokomotive/internal/template" | ||
"github.com/kinvolk/lokomotive/pkg/backend" | ||
) | ||
|
||
type local struct { | ||
// Config represents the configuration of a local backend. | ||
type Config struct { | ||
Path string `hcl:"path,optional"` | ||
} | ||
|
||
// init registers local as a backend. | ||
func init() { | ||
backend.Register("local", NewLocalBackend()) | ||
} | ||
// NewConfig creates a new Config and returns a pointer to it as well as any HCL diagnostics. | ||
func NewConfig(b *hcl.Body, ctx *hcl.EvalContext) (*Config, hcl.Diagnostics) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I'd get rid of this code completely and do the reading only once somewhere, as reading is always exactly the same regardless of the backend type. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's what we had with |
||
c := &Config{} | ||
|
||
// LoadConfig loads the configuration for the local backend. | ||
func (l *local) LoadConfig(configBody *hcl.Body, evalContext *hcl.EvalContext) hcl.Diagnostics { | ||
if configBody == nil { | ||
return hcl.Diagnostics{} | ||
if b == nil { | ||
return nil, hcl.Diagnostics{} | ||
} | ||
return gohcl.DecodeBody(*configBody, evalContext, l) | ||
} | ||
|
||
func NewLocalBackend() *local { | ||
return &local{} | ||
} | ||
|
||
// Render renders the Go template with local backend configuration. | ||
func (l *local) Render() (string, error) { | ||
return template.Render(backendConfigTmpl, l) | ||
} | ||
if d := gohcl.DecodeBody(*b, ctx, c); len(d) != 0 { | ||
return nil, d | ||
} | ||
|
||
// Validate validates the local backend configuration. | ||
func (l *local) Validate() error { | ||
return nil | ||
return c, hcl.Diagnostics{} | ||
} |
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why empty interface if we know all the types we deal with?