Remove resource.go

This commit is contained in:
Yang Luo 2023-07-30 23:48:06 +08:00
parent da3193673c
commit 195d9cfdca
3 changed files with 6 additions and 63 deletions

View File

@ -1,40 +0,0 @@
// Copyright 2023 The casbin Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package casdoor
import (
"fmt"
"github.com/astaxie/beego"
"github.com/casdoor/casdoor-go-sdk/casdoorsdk"
)
func ListResources(provider string, prefix string) ([]*casdoorsdk.Resource, error) {
casdoorOrganization := beego.AppConfig.String("casdoorOrganization")
casdoorApplication := beego.AppConfig.String("casdoorApplication")
res, err := casdoorsdk.GetResources(casdoorOrganization, casdoorApplication, "provider", provider, "Direct", prefix)
return res, err
}
func GetResource(provider string, key string) (*casdoorsdk.Resource, error) {
casdoorOrganization := beego.AppConfig.String("casdoorOrganization")
res, err := casdoorsdk.GetResourceEx(casdoorOrganization, key)
if provider != res.Provider {
panic(fmt.Errorf("the resource's provider expected to be: %s, but got: %s", provider, res.Provider))
}
return res, err
}

View File

@ -17,10 +17,8 @@ package storage
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io"
"net/http"
"github.com/casbin/casibase/casdoor" "github.com/astaxie/beego"
"github.com/casdoor/casdoor-go-sdk/casdoorsdk" "github.com/casdoor/casdoor-go-sdk/casdoorsdk"
) )
@ -36,7 +34,9 @@ func ListObjects(provider string, prefix string) ([]*Object, error) {
return nil, fmt.Errorf("storage provider is empty") return nil, fmt.Errorf("storage provider is empty")
} }
resources, err := casdoor.ListResources(provider, prefix) casdoorOrganization := beego.AppConfig.String("casdoorOrganization")
casdoorApplication := beego.AppConfig.String("casdoorApplication")
resources, err := casdoorsdk.GetResources(casdoorOrganization, casdoorApplication, "provider", provider, "Direct", prefix)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -53,24 +53,6 @@ func ListObjects(provider string, prefix string) ([]*Object, error) {
return res, nil return res, nil
} }
func GetObject(provider string, key string) (io.ReadCloser, error) {
if provider == "" {
return nil, fmt.Errorf("storage provider is empty")
}
res, err := casdoor.GetResource(provider, key)
if err != nil {
return nil, err
}
response, err := http.Get(res.Url)
if err != nil {
return nil, err
}
return response.Body, nil
}
func PutObject(provider string, user string, parent string, key string, fileBuffer *bytes.Buffer) error { func PutObject(provider string, user string, parent string, key string, fileBuffer *bytes.Buffer) error {
if provider == "" { if provider == "" {
return fmt.Errorf("storage provider is empty") return fmt.Errorf("storage provider is empty")

View File

@ -30,7 +30,8 @@ func TestStorage(t *testing.T) {
object.InitConfig() object.InitConfig()
controllers.InitAuthConfig() controllers.InitAuthConfig()
objects, err := storage.ListObjects("provider_storage_casibase", "") provider := "provider_storage_casibase"
objects, err := storage.ListObjects(provider, "")
if err != nil { if err != nil {
panic(err) panic(err)
} }