@@ -4,40 +4,48 @@ import (
4
4
"fmt"
5
5
)
6
6
7
+ // TODO (iapershin)
8
+ // rawOrigin is not suitable here since image stack contains `doc` property and couldn't be used along with doc()
9
+ // refactor to use common approach
10
+ type rawParent interface {
11
+ getDoc () * doc
12
+ }
13
+
7
14
type rawSecret struct {
8
- Id string `yaml:"id"`
15
+ Id string `yaml:"id,omitempty "`
9
16
Env string `yaml:"env,omitempty"`
10
17
Src string `yaml:"src,omitempty"`
11
18
PlainValue string `yaml:"value,omitempty"`
12
19
13
- doc * doc `yaml:"-"` // parent
20
+ parent rawParent `yaml:"-"` // parent
14
21
15
22
UnsupportedAttributes map [string ]interface {} `yaml:",inline"`
16
23
}
17
24
18
25
func (s * rawSecret ) UnmarshalYAML (unmarshal func (interface {}) error ) error {
19
- parentStack .Push (s )
26
+ if parent , ok := parentStack .Peek ().(rawParent ); ok {
27
+ s .parent = parent
28
+ }
29
+
20
30
type plain rawSecret
21
- err := unmarshal ((* plain )(s ))
22
- parentStack .Pop ()
23
- if err != nil {
24
- return fmt .Errorf ("secrets parsing error: %w" , err )
31
+ if err := unmarshal ((* plain )(s )); err != nil {
32
+ return err
25
33
}
26
34
27
35
if err := s .validate (); err != nil {
28
- return fmt .Errorf ("secrets validation error: %w " , err )
36
+ return newDetailedConfigError ( fmt .Sprintf ("secrets validation error: %s " , err . Error ()), s , s . parent . getDoc () )
29
37
}
30
38
31
- if err := checkOverflow (s .UnsupportedAttributes , nil , s .doc ); err != nil {
32
- return fmt . Errorf ( "secrets validation error: %w" , err )
39
+ if err := checkOverflow (s .UnsupportedAttributes , nil , s .parent . getDoc () ); err != nil {
40
+ return err
33
41
}
34
42
35
43
return nil
36
44
}
37
45
38
46
func (s * rawSecret ) validate () error {
39
47
if ! oneOrNone ([]bool {s .Env != "" , s .Src != "" , s .PlainValue != "" }) {
40
- return newDetailedConfigError ( "specify only env or src or value in secret" , s , s . doc )
48
+ return fmt . Errorf ( "secret type could be ONLY `env`, ` src` or ` value`" )
41
49
}
42
50
return nil
43
51
}
@@ -51,6 +59,6 @@ func (s *rawSecret) toDirective() (Secret, error) {
51
59
case s .PlainValue != "" :
52
60
return newSecretFromPlainValue (s )
53
61
default :
54
- return nil , newDetailedConfigError ("secret type is not supported " , s , s .doc )
62
+ return nil , newDetailedConfigError ("secret should be defined as `env`, `src` or `value` " , s , s .parent . getDoc () )
55
63
}
56
64
}
0 commit comments