// MatchHook returns true if the specified hook name matches
// the hook specified by the debug-hooks client.
321243
func (s *ServerSession) MatchHook(hookName string) bool {
	return s.hooks.IsEmpty() || s.hooks.Contains(hookName)
}
1051827
func newHook(source, hook io.Reader) io.Reader {
	if hook == nil {
		return source
	}
	return &hookReader{source, hook}
}
1077537
func (db *baseDB) AddQueryHook(hook QueryHook) {
	db.queryHooks = append(db.queryHooks, hook)
}
1257165
func (t *TableMap) setupHooks(i interface{}) {
	// These hooks must be implemented on a pointer, so if a value is passed in
	// we have to get a pointer for a new value of that type in order for the
	// type assertions to pass.
	ptr := i
	if reflect.ValueOf(i).Kind() == reflect.Struct {
		ptr = reflect.New(reflect.ValueOf(i).Type()).Interface()
	}

	_, t.CanPreInsert = ptr.(PreInserter)
	_, t.CanPostInsert = ptr.(PostInserter)
	_, t.CanPostGet = ptr.(PostGetter)
	_, t.CanPreUpdate = ptr.(PreUpdater)
	_, t.CanPostUpdate = ptr.(PostUpdater)
	_, t.CanPreDelete = ptr.(PreDeleter)
	_, t.CanPostDelete = ptr.(PostDeleter)
}
1295702
func (sc *syncContext) doHookSync(syncTasks []syncTask, hooks []*unstructured.Unstructured) {
	if !sc.startedPreSyncPhase() {
		if !sc.verifyPermittedHooks(hooks) {
			return
		}
	}
	// 1. Run PreSync hooks
	if !sc.runHooks(hooks, appv1.HookTypePreSync) {
		return
	}

	// 2. Run Sync hooks (e.g. blue-green sync workflow)
	// Before performing Sync hooks, apply any normal manifests which aren't annotated with a hook.
	// We only want to do this once per operation.
	shouldContinue := true
	if !sc.startedSyncPhase() {
		if !sc.syncNonHookTasks(syncTasks) {
			sc.setOperationPhase(appv1.OperationFailed, "one or more objects failed to apply")
			return
		}
		shouldContinue = false
	}
	if !sc.runHooks(hooks, appv1.HookTypeSync) {
		shouldContinue = false
	}
	if !shouldContinue {
		return
	}

	// 3. Run PostSync hooks
	// Before running PostSync hooks, we want to make rollout is complete (app is healthy). If we
	// already started the post-sync phase, then we do not need to perform the health check.
	postSyncHooks, _ := sc.getHooks(appv1.HookTypePostSync)
	if len(postSyncHooks) > 0 && !sc.startedPostSyncPhase() {
		sc.log.Infof("PostSync application health check: %s", sc.compareResult.healthStatus.Status)
		if sc.compareResult.healthStatus.Status != appv1.HealthStatusHealthy {
			sc.setOperationPhase(appv1.OperationRunning, fmt.Sprintf("waiting for %s state to run %s hooks (current health: %s)",
				appv1.HealthStatusHealthy, appv1.HookTypePostSync, sc.compareResult.healthStatus.Status))
			return
		}
	}
	if !sc.runHooks(hooks, appv1.HookTypePostSync) {
		return
	}

	// if we get here, all hooks successfully completed
	sc.setOperationPhase(appv1.OperationSucceeded, "successfully synced")
}
573468
func IsArgoHook(obj *unstructured.Unstructured) bool {
	annotations := obj.GetAnnotations()
	if annotations == nil {
		return false
	}
	resHookTypes := strings.Split(annotations[common.AnnotationKeyHook], ",")
	for _, hookType := range resHookTypes {
		hookType = strings.TrimSpace(hookType)
		switch argoappv1.HookType(hookType) {
		case argoappv1.HookTypePreSync, argoappv1.HookTypeSync, argoappv1.HookTypePostSync:
			return true
		}
	}
	return false
}
299782
func (s *OrganizationsService) CreateHook(ctx context.Context, org string, hook *Hook) (*Hook, *Response, error) {
	u := fmt.Sprintf("orgs/%v/hooks", org)

	hookReq := &createHookRequest{
		Name:   "web",
		Events: hook.Events,
		Active: hook.Active,
		Config: hook.Config,
	}

	req, err := s.client.NewRequest("POST", u, hookReq)
	if err != nil {
		return nil, nil, err
	}

	h := new(Hook)
	resp, err := s.client.Do(ctx, req, h)
	if err != nil {
		return nil, resp, err
	}

	return h, resp, nil
}
880157
func NewHook(token string, env string, opts ...OptionFunc) *Hook {
	h := NewHookForLevels(token, env, defaultTriggerLevels)

	for _, o := range opts {
		o(h)
	}

	return h
}
324993
func (s *GenericAPIServer) RunPreShutdownHooks() error {
	var errorList []error

	s.preShutdownHookLock.Lock()
	defer s.preShutdownHookLock.Unlock()
	s.preShutdownHooksCalled = true

	for hookName, hookEntry := range s.preShutdownHooks {
		if err := runPreShutdownHook(hookName, hookEntry); err != nil {
			errorList = append(errorList, err)
		}
	}
	return utilerrors.NewAggregate(errorList)
}
1143227
func durationHook(from, to reflect.Type, data reflect.Value) (reflect.Value, error) {
	if from.Kind() != reflect.String || to != _typeOfDuration {
		return data, nil
	}

	d, err := time.ParseDuration(data.String())
	return reflect.ValueOf(d), err
}
1027837
func (m *SecureMap) HasMatch(key, value interface{}) bool {
	m.lock.RLock()
	k, ok := m.data[key]
	m.lock.RUnlock()

	if ok {
		return k == value
	}

	return false
}
212912
func (r *relations) CommitHook(hookInfo hook.Info) (err error) {
	defer func() {
		if err == nil && hookInfo.Kind == hooks.RelationBroken {
			delete(r.relationers, hookInfo.RelationId)
		}
	}()
	if !hookInfo.Kind.IsRelation() {
		return errors.Errorf("not a relation hook: %#v", hookInfo)
	}
	relationer, found := r.relationers[hookInfo.RelationId]
	if !found {
		return errors.Errorf("unknown relation: %d", hookInfo.RelationId)
	}
	return relationer.CommitHook(hookInfo)
}
222695
func MatchAbHandler(key string, value interface{}, a, b LogHandler) LogHandler {
	return FuncHandler(func(r *Record) error {
		if r.Context[key] == value {
			return a.Log(r)
		} else if b != nil {
			return b.Log(r)
		}

		return nil
	})
}
614957
func (m *Meta) uiHook() *UiHook {
	return &UiHook{
		Colorize: m.Colorize(),
		Ui:       m.Ui,
	}
}
496581
func findHooks(guestHookPath, hookType string) (hooksFound []specs.Hook) {
	hooksPath := path.Join(guestHookPath, hookType)

	files, err := ioutil.ReadDir(hooksPath)
	if err != nil {
		agentLog.WithError(err).WithField("oci-hook-type", hookType).Info("Skipping hook type")
		return
	}

	for _, file := range files {
		name := file.Name()
		if ok, err := isValidHook(file); !ok {
			agentLog.WithError(err).WithField("oci-hook-name", name).Warn("Skipping hook")
			continue
		}

		agentLog.WithFields(logrus.Fields{
			"oci-hook-name": name,
			"oci-hook-type": hookType,
		}).Info("Adding hook")
		hooksFound = append(hooksFound, specs.Hook{
			Path: path.Join(hooksPath, name),
			Args: []string{name, hookType},
		})
	}

	agentLog.WithField("oci-hook-type", hookType).Infof("Added %d hooks", len(hooksFound))

	return
}
170426
func (cl *CoLog) AddHook(hook Hook) {
	cl.mu.Lock()
	defer cl.mu.Unlock()

	for _, l := range hook.Levels() {
		cl.hooks[l] = append(cl.hooks[l], hook)
	}
}
1324179
func strconvHook(from, to reflect.Type, data reflect.Value) (reflect.Value, error) {
	if from.Kind() != reflect.String {
		return data, nil
	}

	s := data.String()
	switch to.Kind() {
	case reflect.Bool:
		b, err := strconv.ParseBool(s)
		return reflect.ValueOf(b), err
	case reflect.Float32, reflect.Float64:
		f, err := strconv.ParseFloat(s, to.Bits())
		return reflect.ValueOf(f).Convert(to), err
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		i, err := strconv.ParseInt(s, 10, to.Bits())
		return reflect.ValueOf(i).Convert(to), err
	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
		u, err := strconv.ParseUint(s, 10, to.Bits())
		return reflect.ValueOf(u).Convert(to), err
	}

	return data, nil
}