feat: add global casdoor config variables

This commit is contained in:
WintBit 2023-07-22 22:58:27 +08:00
parent b411c053da
commit 832d13aa85
3 changed files with 10 additions and 10 deletions

View File

@ -23,8 +23,9 @@ import (
)
var (
adapter *Adapter = nil
CasdoorOrganization string
adapter *Adapter = nil
Organization string
Application string
)
type Session struct {
@ -41,7 +42,8 @@ func InitCasdoorAdapter() {
adapter = NewAdapter(beego.AppConfig.String("driverName"), beego.AppConfig.String("dataSourceName"), beego.AppConfig.String("casdoorDbName"))
CasdoorOrganization = beego.AppConfig.String("casdoorOrganization")
Organization = beego.AppConfig.String("casdoorOrganization")
Application = beego.AppConfig.String("casdoorApplication")
}
// Adapter represents the MySQL adapter for policy storage.

View File

@ -23,10 +23,8 @@ func ListResources(prefix string) ([]*casdoorsdk.Resource, error) {
}
func GetResource(key string) (*casdoorsdk.Resource, error) {
id := util.GetIdFromOwnerAndName(fmt.Sprintf("/resource/%s/%s/casibase",
beego.AppConfig.String("casdoorOrganization"),
beego.AppConfig.String("casdoorApplication")), key)
resource := casdoorsdk.Resource{Owner: CasdoorOrganization, Name: id}
id := fmt.Sprintf("/resource/%s/%s/casibase/%s", Organization, Application, key)
resource := casdoorsdk.Resource{Owner: Organization, Name: id}
existed, err := adapter.Engine.Get(&resource)
if err != nil {
return nil, err

View File

@ -36,9 +36,9 @@ func (s *casdoorClient) Get(key string) (io.ReadCloser, error) {
func (s *casdoorClient) Put(user, key string, bytes []byte) error {
_, _, err := casdoorsdk.UploadResource(user, "Casibase", "Casibase",
util.GetIdFromOwnerAndName(fmt.Sprintf("/resource/%s/%s/casibase",
beego.AppConfig.String("casdoorOrganization"),
beego.AppConfig.String("casdoorApplication")), key), bytes)
fmt.Sprintf("/resource/%s/%s/%s",
casdoor.Organization, casdoor.Application, key),
bytes)
if err != nil {
return err
}