Browse Source

Remove resource.go

HEAD
Yang Luo 2 years ago
parent
commit
195d9cfdca
3 changed files with 6 additions and 63 deletions
  1. +0
    -40
      casdoor/resource.go
  2. +4
    -22
      storage/storage.go
  3. +2
    -1
      storage/storage_test.go

+ 0
- 40
casdoor/resource.go 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
}

+ 4
- 22
storage/storage.go View File

@@ -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")


+ 2
- 1
storage/storage_test.go View File

@@ -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)
}


Loading…
Cancel
Save