2022-11-18 09:57:31 +00:00
|
|
|
package mutator
|
|
|
|
|
|
|
|
import (
|
2022-11-28 09:59:43 +00:00
|
|
|
"context"
|
2022-11-18 09:57:31 +00:00
|
|
|
"fmt"
|
|
|
|
|
2023-05-16 16:35:39 +00:00
|
|
|
"github.com/databricks/cli/bundle"
|
|
|
|
"github.com/databricks/cli/bundle/config"
|
2022-11-18 09:57:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type defineDefaultEnvironment struct {
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
|
|
|
// DefineDefaultEnvironment adds an environment named "default"
|
|
|
|
// to the configuration if none have been defined.
|
2022-11-28 09:59:43 +00:00
|
|
|
func DefineDefaultEnvironment() bundle.Mutator {
|
2022-11-18 09:57:31 +00:00
|
|
|
return &defineDefaultEnvironment{
|
|
|
|
name: "default",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *defineDefaultEnvironment) Name() string {
|
|
|
|
return fmt.Sprintf("DefineDefaultEnvironment(%s)", m.name)
|
|
|
|
}
|
|
|
|
|
2022-11-28 09:59:43 +00:00
|
|
|
func (m *defineDefaultEnvironment) Apply(_ context.Context, b *bundle.Bundle) ([]bundle.Mutator, error) {
|
2022-11-18 09:57:31 +00:00
|
|
|
// Nothing to do if the configuration has at least 1 environment.
|
2022-12-15 20:28:27 +00:00
|
|
|
if len(b.Config.Environments) > 0 {
|
2022-11-18 09:57:31 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Define default environment.
|
2022-11-28 09:59:43 +00:00
|
|
|
b.Config.Environments = make(map[string]*config.Environment)
|
|
|
|
b.Config.Environments[m.name] = &config.Environment{}
|
2022-11-18 09:57:31 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|