elimity-com / scim

Golang Implementation of the SCIM v2 Specification
MIT License
177 stars 55 forks source link

Publish filters package #144

Closed Bladrak closed 7 months ago

Bladrak commented 2 years ago

I've stumbled upon a need to use the filters package, which is internal at the moment. This proposal aims at making it usable from other packages. What do you think?

mibanescu commented 2 years ago

Any chance this can be merged or commented upon?

As it stands, I believe there's a problem with the code flow. I am trying to implement my resource handler. In the GetAll method, I need to apply query filters. I cannot do that in the persistence layer.

I am using schemasHandler in handlers.go as an example - I was hoping I can just call PassesFilter on the ListRequestParams.Filter parameter. However, that is a expression.Expression - I would have to convert it to a validator, which is inside an internal package.

There are two ways out of my dilemma:

Thank you!

rocktavious commented 2 years ago

I have run into this problem as well. Because the validator is on the internal package there is no way for the end user to use it. It feels like ListRequestParams should have a function that returns the validator for the filter so you can do

func (t userHandler) GetAll(r *http.Request, params scim.ListRequestParams) (scim.Page, error) {
    validator := params.GetValidator()
    users, _ := MyClient().ListUsers()
    for _, user := range users {
            attributes := scim.ResourceAttributes{}
        attributes["userName"] = user.Email
        if validator.Passes(attributes) != nil {
            continue
        }
        ... Continue Processing User ...
    }
}

Currently as it stands there is literally no way for an end user of this library to use filters without forking the codebase.