func LoadAPILookup() (APILookup, error) {
	mappings, err := assethelper.LoadRBACAPIMappings()
	if err != nil {
		return nil, fmt.Errorf("error loading loading api mapping from assethelper: %w", err)
	}
	var apiMappings map[string]apiMapping
	if err := yaml.UnmarshalStrict([]byte(mappings), &apiMappings); err != nil {
		return nil, fmt.Errorf("error unmarshalling api mappings yaml: %w", err)
	}
	endpoints := APILookup{}
	for mappingPath, mapping := range apiMappings {
		for _, e := range mapping.Endpoints {
			path, hasPath := endpoints[e.Path]
			if !hasPath {
				endpoints[e.Path] = apiLookupEndpoint{
					Methods: map[string]string{e.Method: mappingPath},
					Param:   e.Resource,
				}
				continue
			}
			path.Methods[e.Method] = mappingPath
		}
	}
	return endpoints, nil
}
LoadAPILookup loads our yaml based RBACApiMappings and transforms them into a quicker lookup map.
package rbac
import (
	"errors"
	"fmt"
	"strings"
	"github.com/casbin/casbin/v2"
	"github.com/casbin/casbin/v2/model"
	"gopkg.in/yaml.v2"
	"github.com/gaia-pipeline/gaia/helper/assethelper"
)
const rolePrefix = "role:"
type (
	apiMapping struct {
		Description string        `json:"description"`
		Endpoints   []apiEndpoint `json:"endpoints"`
	}
	apiEndpoint struct {
		Method   string `json:"method"`
		Path     string `json:"path"`
		Resource string `json:"resource"`
	}
	APILookup         map[string]apiLookupEndpoint
	apiLookupEndpoint struct {
		Param   string            `yaml:"param"`
		Methods map[string]string `yaml:"methods"`
	}
	RoleRule struct {
		Namespace string `json:"namespace"`
		Action    string `json:"action"`
		Resource  string `json:"resource"`
		Effect    string `json:"effect"`
	}
	Service interface {
		EndpointEnforcer
		AddRole(role string, roleRules []RoleRule) error
		DeleteRole(role string) error
		GetAllRoles() []string
		GetUserAttachedRoles(username string) ([]string, error)
		GetRoleAttachedUsers(role string) ([]string, error)
		AttachRole(username string, role string) error
		DetachRole(username string, role string) error
		DeleteUser(username string) error
	}
	enforcerService struct {
		enforcer      casbin.IEnforcer
		rbacAPILookup APILookup
	}
)
func NewEnforcerSvc(enforcer casbin.IEnforcer, rbacAPILookup APILookup) Service {
	return &enforcerService{
		enforcer:      enforcer,
		rbacAPILookup: rbacAPILookup,
	}
}
func LoadModel() (model.Model, error) {
	modelStr, err := assethelper.LoadRBACModel()
	if err != nil {
		return nil, fmt.Errorf("error loading rbac model from assethelper: %w", err)
	}
	m, err := model.NewModelFromString(modelStr)
	if err != nil {
		return nil, fmt.Errorf("error creating model from string: %w", err)
	}
	return m, nil
}