-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuilder_lambda_property_task.go
More file actions
114 lines (96 loc) · 4.58 KB
/
Copy pathbuilder_lambda_property_task.go
File metadata and controls
114 lines (96 loc) · 4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package tasks
// BuilderLambdaPropertyTask manages the builder-lambda configuration for a given dokku application
type BuilderLambdaPropertyTask struct {
// App is the name of the app. Required if Global is false.
App string `required:"false" yaml:"app" description:"Name of the app. Required if Global is false."`
// Global is a flag indicating if the builder-lambda configuration should be applied globally
Global bool `required:"false" yaml:"global,omitempty" description:"Flag indicating if the builder-lambda configuration should be applied globally"`
// Property is the name of the builder-lambda property to set
Property string `required:"true" yaml:"property" description:"Name of the builder-lambda property to set"`
// Value is the value to set for the builder-lambda property
Value string `required:"false" yaml:"value,omitempty" description:"Value to set for the builder-lambda property"`
// State is the desired state of the builder-lambda configuration
State State `required:"false" yaml:"state,omitempty" default:"present" options:"present,absent" description:"Desired state of the builder-lambda configuration"`
}
// BuilderLambdaPropertyTaskExample contains an example of a BuilderLambdaPropertyTask
type BuilderLambdaPropertyTaskExample struct {
// Name is the task name holding the BuilderLambdaPropertyTask description
Name string `yaml:"-"`
// BuilderLambdaPropertyTask is the BuilderLambdaPropertyTask configuration
BuilderLambdaPropertyTask BuilderLambdaPropertyTask `yaml:"dokku_builder_lambda_property"`
}
// GetName returns the name of the example
func (e BuilderLambdaPropertyTaskExample) GetName() string {
return e.Name
}
// Doc returns the docblock for the builder-lambda property task
func (t BuilderLambdaPropertyTask) Doc() string {
return "Manages the builder-lambda configuration for a given dokku application"
}
// ExportSupport reports how docket export handles this task.
func (t BuilderLambdaPropertyTask) ExportSupport() ExportSupport {
return ExportSupport{Status: ExportSupported}
}
// Examples returns the examples for the builder-lambda property task
func (t BuilderLambdaPropertyTask) Examples() ([]Doc, error) {
return MarshalExamples([]BuilderLambdaPropertyTaskExample{
{
Name: "Setting the lambda.yml path for an app",
BuilderLambdaPropertyTask: BuilderLambdaPropertyTask{
App: "node-js-app",
Property: "lambdayml-path",
Value: "config/lambda.yml",
},
},
{
Name: "Setting the lambda.yml path globally",
BuilderLambdaPropertyTask: BuilderLambdaPropertyTask{
Global: true,
Property: "lambdayml-path",
Value: "lambda.yml",
},
},
{
Name: "Clearing the lambda.yml path for an app",
BuilderLambdaPropertyTask: BuilderLambdaPropertyTask{
App: "node-js-app",
Property: "lambdayml-path",
State: StateAbsent,
},
},
})
}
// Execute sets or unsets the builder-lambda property
func (t BuilderLambdaPropertyTask) Execute() TaskOutputState {
return ExecutePlan(t.Plan())
}
// builderLambdaPropertyKeys maps builder-lambda property names to the JSON
// keys emitted by `dokku builder-lambda:report --format json` on dokku
// 0.38.8+.
var builderLambdaPropertyKeys = map[string]PropertyKeys{
"lambdayml-path": {PerApp: "lambdayml-path", Global: "global-lambdayml-path"},
}
// Validate checks the BuilderLambdaPropertyTask's inputs without contacting the server.
func (t BuilderLambdaPropertyTask) Validate() error {
return validatePropertyInput(t.State, t.App, t.Global, t.Property, t.Value, "builder-lambda:set", builderLambdaPropertyKeys)
}
// Plan reports the drift the BuilderLambdaPropertyTask would produce.
func (t BuilderLambdaPropertyTask) Plan() PlanResult {
return planProperty(t.State, t.App, t.Global, t.Property, t.Value, "builder-lambda:set", builderLambdaPropertyKeys)
}
// ExportApp reconstructs the app's explicitly-set properties.
func (t BuilderLambdaPropertyTask) ExportApp(app string) ([]interface{}, error) {
return exportProperties(app, "builder-lambda:set", builderLambdaPropertyKeys, func(app, property, value string) interface{} {
return BuilderLambdaPropertyTask{App: app, Property: property, Value: value}
})
}
// ExportGlobal reconstructs the globally-set properties.
func (t BuilderLambdaPropertyTask) ExportGlobal() ([]interface{}, error) {
return exportGlobalProperties("builder-lambda:set", builderLambdaPropertyKeys, func(property, value string) interface{} {
return BuilderLambdaPropertyTask{Global: true, Property: property, Value: value}
})
}
// init registers the BuilderLambdaPropertyTask with the task registry
func init() {
RegisterTask(&BuilderLambdaPropertyTask{})
}