Skip to content

Instantly share code, notes, and snippets.

@mvo5

mvo5/validate.go Secret

Created December 4, 2017 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvo5/6e0ac963aacce9d0c78f1c7cf829f9c4 to your computer and use it in GitHub Desktop.
Save mvo5/6e0ac963aacce9d0c78f1c7cf829f9c4 to your computer and use it in GitHub Desktop.
type appStartupOrder int
const (
orderBefore appStartupOrder = iota
orderAfter
)
func (a appStartupOrder) String() string {
switch a {
case orderBefore:
return "before"
case orderAfter:
return "after"
}
panic(fmt.Sprintf("unsupported order: %v", a))
}
func appStartOrdering(app *AppInfo, order appStartupOrder) []string {
switch order {
case orderBefore:
return app.Before
case orderAfter:
return app.After
}
panic(fmt.Sprintf("unsupported order: %v", order))
}
func validateAppStartup(app *AppInfo, order appStartupOrder) error {
for _, dep := range appStartOrdering(app, order) {
// dependency is not defined
other, ok := app.Snap.Apps[dep]
if !ok {
return fmt.Errorf("cannot validate app %q startup ordering: needs to be started %s %q, but %q is not defined",
app.Name, order.String(), dep, dep)
}
// it depends on us in the same order, eg. foo is
// started after bar, but bar is to be started after foo
// as well, validate only one dependency step
otherDeps := appStartOrdering(other, order)
if strutil.ListContains(otherDeps, app.Name) {
return fmt.Errorf("cannot validate app %q startup ordering: needs to be started %s %q, but %q is declared to start %s %q",
app.Name, order, other.Name, other.Name, order, app.Name)
}
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment