func (c *DebugHooksCommand) validateHooks(unit *state.Unit) error { if len(c.hooks) == 0 { return nil } service, err := unit.Service() if err != nil { return err } eps, err := service.Endpoints() if err != nil { return err } validHooks := make(map[string]bool) for _, hook := range hooks.UnitHooks() { validHooks[string(hook)] = true } for _, ep := range eps { for _, hook := range hooks.RelationHooks() { hook := fmt.Sprintf("%s-%s", ep.Relation.Name, hook) validHooks[hook] = true } } for _, hook := range c.hooks { if !validHooks[hook] { return fmt.Errorf("unit %q does not contain hook %q", unit.Name(), hook) } } return nil }
func generateRelationHooks(relName string, allHooks map[string]bool) { for _, hookName := range hooks.RelationHooks() { allHooks[fmt.Sprintf("%s-%s", relName, hookName)] = true } }