func()

in pkg/client/keycloak/adapter/gocloak_adapter_auth_flow.go [164:202]


func (a GoCloakAdapter) syncBaseAuthFlow(realmName string, flow *KeycloakAuthFlow) (string, error) {
	authFlowID, err := a.getAuthFlowID(realmName, flow)
	if err != nil {
		if !IsErrNotFound(err) {
			return "", errors.Wrap(err, "unable to get auth flow")
		}

		id, err := a.createAuthFlow(realmName, flow)
		if err != nil {
			return "", errors.Wrap(err, "unable to create auth flow")
		}

		authFlowID = id
	} else {
		if err := a.clearFlowExecutions(realmName, flow.Alias); err != nil {
			return "", errors.Wrap(err, "unable to clear flow executions")
		}
	}

	if flow.ParentName != "" && flow.ChildRequirement != "" {
		exec, err := a.getFlowExecution(realmName, flow)
		if err != nil {
			return "", err
		}

		// We cant set child flow requirement during creation, so we need to update it.
		exec.Requirement = flow.ChildRequirement

		if err := a.updateFlowExecution(realmName, flow.ParentName, exec); err != nil {
			return "", fmt.Errorf("unable to update flow execution requirement: %w", err)
		}
	}

	if err := a.validateChildFlowsCreated(realmName, flow); err != nil {
		return "", errors.Wrap(err, "child flows validation failed")
	}

	return authFlowID, nil
}