Files
zeekayandHanzo Dev 3dd58eadfa fix(license): credit OpenAgent on 7 upstream-derived files (Apache-2.0 §4(c))
These carry Hanzo-only copyright but derive from casibase/OpenAgent upstream
counterparts. record_chain.go is near-verbatim (12 diff lines over 97);
storage/iam.go is upstream's storage/casdoor.go with an import swap and a
CasdoorProvider -> IamProvider rename.

Adds the "Portions Copyright <year> The OpenAgent Authors" line this repo
already uses correctly on 322 other files, with upstream's own years.

cmd/aid/main.go is left alone: it has no upstream counterpart.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-02 09:53:30 -07:00

91 lines
2.8 KiB
Go

// Copyright 2023-2025 Hanzo AI Inc. All Rights Reserved.
// Portions Copyright 2023 The OpenAgent 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 storage
import (
"bytes"
"fmt"
"github.com/hanzoai/ai/conf"
"github.com/hanzoai/ai/i18n"
iam "github.com/hanzoai/ai/internal/iam"
)
type IamProvider struct {
providerName string
org string // organization override; empty = use config default
}
func NewIamProvider(providerName string, lang string) (*IamProvider, error) {
if providerName == "" {
return nil, fmt.Errorf("%s", fmt.Sprintf(i18n.Translate(lang, "storage:storage provider name: [%s] doesn't exist"), providerName))
}
return &IamProvider{providerName: providerName}, nil
}
// NewIamProviderWithOrg creates an IamProvider scoped to a specific organization.
func NewIamProviderWithOrg(providerName string, org string, lang string) (*IamProvider, error) {
if providerName == "" {
return nil, fmt.Errorf("%s", fmt.Sprintf(i18n.Translate(lang, "storage:storage provider name: [%s] doesn't exist"), providerName))
}
return &IamProvider{providerName: providerName, org: org}, nil
}
func (p *IamProvider) ListObjects(prefix string) ([]*Object, error) {
iamOrganization := p.org
if iamOrganization == "" {
iamOrganization = conf.GetConfigString("IAM_ORG")
}
iamApplication := conf.GetConfigString("IAM_APP_NAME")
resources, err := iam.GetResources(iamOrganization, iamApplication, "provider", p.providerName, "Direct", prefix)
if err != nil {
return nil, err
}
res := []*Object{}
for _, resource := range resources {
res = append(res, &Object{
Key: resource.Name,
LastModified: resource.CreatedTime,
Size: int64(resource.FileSize),
Url: resource.Url,
})
}
return res, nil
}
func (p *IamProvider) PutObject(user string, parent string, key string, fileBuffer *bytes.Buffer) (string, error) {
fileUrl, _, err := iam.UploadResource(user, "HanzoCloud", parent, fmt.Sprintf("Direct/%s/%s", p.providerName, key), fileBuffer.Bytes())
if err != nil {
return "", err
}
return fileUrl, nil
}
func (p *IamProvider) DeleteObject(key string) error {
resource := iam.Resource{
Name: key,
}
_, err := iam.DeleteResourceWithTag(&resource, "Direct")
if err != nil {
return err
}
return nil
}