<commit_before>package acl

import (
	"fmt"
	"github.com/Aptomi/aptomi/pkg/lang"
	"github.com/Aptomi/aptomi/pkg/lang/expression"
	"sync"
)

type Resolver struct {
	rules     []*Rule
	cache     *expression.Cache
	roleCache sync.Map
}

func NewResolver(rules []*Rule) *Resolver {
	return &Resolver{
		rules:     rules,
		cache:     expression.NewCache(),
		roleCache: sync.Map{},
	}
}

func (resolver *Resolver) GetUserRole(user *lang.User) (*Role, error) {
	resultCached, ok := resolver.roleCache.Load(user.ID)
	if ok {
		return resultCached.(*Role), nil
	}

	result := lang.NewRuleActionResult(lang.NewLabelSet(make(map[string]string)))
	params := expression.NewParams(user.Labels, nil)
	for _, rule := range resolver.rules {
		matched, err := rule.Matches(params, resolver.cache)
		if err != nil {
			return nil, fmt.Errorf("unable to resolve role for user '%s': %s", user.ID, err)
		}
		if matched {
			rule.ApplyActions(result)
			if rule.Actions.Stop {
				break
			}
		}
	}

	roleID := result.Labels.Labels[LabelRole]
	role, ok := Roles[roleID]
	if !ok {
		return Nobody, nil
	}

	resolver.roleCache.Store(user.ID, role)
	return role, nil
}

func (resolver *Resolver) GetUserPrivileges(user *lang.User) (*Role, error) {
}
<commit_msg>Fix compilation error in acl PoC<commit_after>package acl

import (
	"fmt"
	"github.com/Aptomi/aptomi/pkg/lang"
	"github.com/Aptomi/aptomi/pkg/lang/expression"
	"sync"
)

type Resolver struct {
	rules     []*Rule
	cache     *expression.Cache
	roleCache sync.Map
}

func NewResolver(rules []*Rule) *Resolver {
	return &Resolver{
		rules:     rules,
		cache:     expression.NewCache(),
		roleCache: sync.Map{},
	}
}

func (resolver *Resolver) GetUserRole(user *lang.User) (*Role, error) {
	resultCached, ok := resolver.roleCache.Load(user.ID)
	if ok {
		return resultCached.(*Role), nil
	}

	result := lang.NewRuleActionResult(lang.NewLabelSet(make(map[string]string)))
	params := expression.NewParams(user.Labels, nil)
	for _, rule := range resolver.rules {
		matched, err := rule.Matches(params, resolver.cache)
		if err != nil {
			return nil, fmt.Errorf("unable to resolve role for user '%s': %s", user.ID, err)
		}
		if matched {
			rule.ApplyActions(result)
			if rule.Actions.Stop {
				break
			}
		}
	}

	roleID := result.Labels.Labels[LabelRole]
	role, ok := Roles[roleID]
	if !ok {
		return Nobody, nil
	}

	resolver.roleCache.Store(user.ID, role)
	return role, nil
}

func (resolver *Resolver) GetUserPrivileges(user *lang.User) (*Role, error) {
	// todo implement
	return nil, nil
}

{'fraction_non_alphanumeric': 0.14172917489143308, 'fraction_numerical': 0.0, 'mean_word_length': 3.891891891891892, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3916068', 'n_tokens_mistral': 965, 'n_tokens_neox': 916, 'n_words': 208}