-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bundle): add param and cred validation (#191)
* feat(bundle): add param and cred validation Signed-off-by: Vaughn Dice <vadice@microsoft.com> * feat(bundle.go): log path in Location validation error message Signed-off-by: Vaughn Dice <vadice@microsoft.com>
- Loading branch information
Showing
6 changed files
with
171 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,18 @@ | ||
package bundle | ||
|
||
import "errors" | ||
|
||
// Credential represents the definition of a CNAB credential | ||
type Credential struct { | ||
Location `yaml:",inline"` | ||
Description string `json:"description,omitempty" yaml:"description,omitempty"` | ||
Required bool `json:"required,omitempty" yaml:"required,omitempty"` | ||
} | ||
|
||
// Validate a Credential | ||
func (c *Credential) Validate() error { | ||
if c.Location.EnvironmentVariable == "" && c.Location.Path == "" { | ||
return errors.New("credential env or path must be supplied") | ||
} | ||
return c.Location.Validate() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,37 @@ | ||
package bundle | ||
|
||
import "errors" | ||
|
||
// Parameter defines a single parameter for a CNAB bundle | ||
type Parameter struct { | ||
Definition string `json:"definition" yaml:"definition"` | ||
ApplyTo []string `json:"applyTo,omitempty" yaml:"applyTo,omitempty"` | ||
Description string `json:"description,omitempty" yaml:"description,omitempty"` | ||
Destination *Location `json:"destination,omitemtpty" yaml:"destination,omitempty"` | ||
Destination *Location `json:"destination" yaml:"destination"` | ||
Required bool `json:"required,omitempty" yaml:"required,omitempty"` | ||
} | ||
|
||
// AppliesTo returns a boolean value specifying whether or not | ||
// the Parameter applies to the provided action | ||
func (parameter *Parameter) AppliesTo(action string) bool { | ||
if len(parameter.ApplyTo) == 0 { | ||
func (p *Parameter) AppliesTo(action string) bool { | ||
if len(p.ApplyTo) == 0 { | ||
return true | ||
} | ||
for _, act := range parameter.ApplyTo { | ||
for _, act := range p.ApplyTo { | ||
if action == act { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
// Validate a Parameter | ||
func (p *Parameter) Validate() error { | ||
if p.Definition == "" { | ||
return errors.New("parameter definition must be provided") | ||
} | ||
if p.Destination == nil { | ||
return errors.New("parameter destination must be provided") | ||
} | ||
return p.Destination.Validate() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters