From 195d9cfdca31614539be2a40a59a8eddccc08c86 Mon Sep 17 00:00:00 2001 From: Yang Luo Date: Sun, 30 Jul 2023 23:48:06 +0800 Subject: [PATCH] Remove resource.go --- casdoor/resource.go | 40 ---------------------------------------- storage/storage.go | 26 ++++---------------------- storage/storage_test.go | 3 ++- 3 files changed, 6 insertions(+), 63 deletions(-) delete mode 100644 casdoor/resource.go diff --git a/casdoor/resource.go b/casdoor/resource.go deleted file mode 100644 index 1891dd4..0000000 --- a/casdoor/resource.go +++ /dev/null @@ -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 -} diff --git a/storage/storage.go b/storage/storage.go index c593218..cd99e22 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -17,10 +17,8 @@ package storage import ( "bytes" "fmt" - "io" - "net/http" - "github.com/casbin/casibase/casdoor" + "github.com/astaxie/beego" "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") } - 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 { return nil, err } @@ -53,24 +53,6 @@ func ListObjects(provider string, prefix string) ([]*Object, error) { 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 { if provider == "" { return fmt.Errorf("storage provider is empty") diff --git a/storage/storage_test.go b/storage/storage_test.go index c08ce12..b30b7dc 100644 --- a/storage/storage_test.go +++ b/storage/storage_test.go @@ -30,7 +30,8 @@ func TestStorage(t *testing.T) { object.InitConfig() controllers.InitAuthConfig() - objects, err := storage.ListObjects("provider_storage_casibase", "") + provider := "provider_storage_casibase" + objects, err := storage.ListObjects(provider, "") if err != nil { panic(err) }