1
1
package config
2
2
3
3
import (
4
+ "fmt"
4
5
"io/ioutil"
5
6
"net/http"
6
7
"reflect"
@@ -88,6 +89,13 @@ func (m *Manifest) Validate() error {
88
89
}
89
90
}
90
91
92
+ for _ , parameter := range m .Parameters {
93
+ err = parameter .Validate ()
94
+ if err != nil {
95
+ result = multierror .Append (result , err )
96
+ }
97
+ }
98
+
91
99
return result
92
100
}
93
101
@@ -104,6 +112,45 @@ type ParameterDefinition struct {
104
112
definition.Schema `yaml:",inline"`
105
113
}
106
114
115
+ func (pd * ParameterDefinition ) Validate () error {
116
+ var result * multierror.Error
117
+
118
+ if pd .Name == "" {
119
+ result = multierror .Append (result , errors .New ("parameter name is required" ))
120
+ }
121
+
122
+ // Porter supports declaring a parameter of type: "file",
123
+ // which we will convert to the appropriate bundle.Parameter type in adapter.go
124
+ // Here, we copy the ParameterDefinition and make the same modification before validation
125
+ pdCopy := pd .DeepCopy ()
126
+ if pdCopy .Type == "file" {
127
+ if pd .Destination .Path == "" {
128
+ result = multierror .Append (result , fmt .Errorf ("no destination path supplied for parameter %s" , pd .Name ))
129
+ }
130
+ pdCopy .Type = "string"
131
+ pdCopy .ContentEncoding = "base64"
132
+ }
133
+
134
+ schemaValidationErrs , err := pdCopy .Schema .Validate (pdCopy )
135
+ if err != nil {
136
+ result = multierror .Append (result , errors .Wrapf (err , "encountered error while validating parameter %s" , pdCopy .Name ))
137
+ }
138
+ for _ , schemaValidationErr := range schemaValidationErrs {
139
+ result = multierror .Append (result , errors .Wrapf (err , "encountered validation error(s) for parameter %s: %v" , pdCopy .Name , schemaValidationErr ))
140
+ }
141
+
142
+ return result .ErrorOrNil ()
143
+ }
144
+
145
+ // DeepCopy copies a ParameterDefinition and returns the copy
146
+ func (pd * ParameterDefinition ) DeepCopy () * ParameterDefinition {
147
+ var p2 ParameterDefinition
148
+ p2 = * pd
149
+ p2 .ApplyTo = make ([]string , len (pd .ApplyTo ))
150
+ copy (p2 .ApplyTo , pd .ApplyTo )
151
+ return & p2
152
+ }
153
+
107
154
type CredentialDefinition struct {
108
155
Name string `yaml:"name"`
109
156
Description string `yaml:"description,omitempty"`
@@ -239,7 +286,13 @@ func (od *OutputDefinition) Validate() error {
239
286
return errors .New ("output name is required" )
240
287
}
241
288
242
- // TODO: Validate inline Schema
289
+ schemaValidationErrs , err := od .Schema .Validate (od )
290
+ if err != nil {
291
+ return errors .Wrapf (err , "encountered error while validating output %s" , od .Name )
292
+ }
293
+ if len (schemaValidationErrs ) != 0 {
294
+ return errors .Wrapf (err , "encountered validation error(s) for output %s: %v" , od .Name , schemaValidationErrs )
295
+ }
243
296
244
297
return nil
245
298
}
0 commit comments