casbin / mongodb-adapter

MongoDB adapter for Casbin

Home Page:https://github.com/casbin/casbin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

It is not possible to use adapter with casbin v2

adamwasila opened this issue · comments

Even though interfaces used by mongodb adapter are identical in v1 and v2 it is not possible to reuse this module in v2. This is because imports paths have changed to:

	"github.com/casbin/casbin/v2/model"
	"github.com/casbin/casbin/v2/persist"

I thought that easy workaround will be to create wrapping adapter (kind of decorator pattern) that will convert v2/persist.Adapter to v1/persist.Adapter but trying to convert model.Model argument of LoadPolicy() and SavePolicy() is not that easy (mostly becauase it is not an interface). Even if there is some hackish way to make these compatible - it may stop to work in the future if v1 and v2 strutcs will diverge.

So my proposal would be to:

  • tag and release current version as v1 compatible (eg. as 1.0.0)
  • modify imports to use casbin v2 and update go.mod dependency
  • if v1 version will ever need patch or update - branch starting from 1.0.0 version would be required; go modules allows to add dependency on branch (@branch syntax).

I can prepare PR for second bullet (imports/README/gomod to v2) if you wish.

Hi @adamwasila , I have released v1.0.0: https://github.com/casbin/mongodb-adapter/releases. Please go ahead with the PR.

OK, now it works - checked on local example project, using go modules; dependencies are, for v1:

github.com/casbin/mongodb-adapter v1.0.0

and for v2 where it uses top of the branch:

github.com/casbin/mongodb-adapter/v2 v2.0.0-20190808230153-2c83387195d9

Compiles and executes succesfully, so it's fixed, I guess.

Good.