fs

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 10, 2025 License: Apache-2.0 Imports: 22 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// S3Builders s3 provider builders.
	S3Builders = map[Kind]S3ProviderBuilder{}
)

Functions

func GetProviderKey

func GetProviderKey(fs *ProviderConfig) string

GetProviderKey get provider key.

func InitAwsClient

func InitAwsClient(ctx context.Context, fs *ProviderConfig) (*s3.Client, error)

InitAwsClient init aws s3 client.

func RegisterS3Provider

func RegisterS3Provider(kind Kind, builder S3ProviderBuilder)

RegisterS3Provider register s3 provider builder. A builder is a function that creates a new s3 provider.

Types

type AwsS3

type AwsS3 struct {
	// contains filtered or unexported fields
}

AwsS3 aws s3 service for file storage.

func (*AwsS3) GetPreSignedURL

func (p *AwsS3) GetPreSignedURL(ctx context.Context, bucket, path string, expires time.Duration) (string, error)

GetPreSignedURL get pre-signed url

func (*AwsS3) GetSTS

func (p *AwsS3) GetSTS(ctx context.Context, roleSessionName string) (*STSResponse, error)

GetSTS get sts

func (*AwsS3) ParseUrlKey

func (p *AwsS3) ParseUrlKey(urlStr string) (key string, err error)

ParseUrlKey parse url key.

func (*AwsS3) ProviderConfig

func (p *AwsS3) ProviderConfig() *ProviderConfig

ProviderConfig return ProviderConfig. Provider need hold a ProviderConfig.

func (*AwsS3) S3Client

func (p *AwsS3) S3Client() *s3.Client

S3Client get s3Client

type BizKey

type BizKey interface {
	int | string
}

type Client

type Client struct {
	FileIdentityAPI *FileIdentityAPI
	// contains filtered or unexported fields
}

Client file system client.

func NewClient

func NewClient(cfg *Config) (*Client, error)

NewClient create a new file system client.

func (*Client) AddInterceptor

func (c *Client) AddInterceptor(interceptor InterceptFunc)

AddInterceptor adds an interceptor to the APIClient

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request) (res *http.Response, err error)

Do sends an HTTP request and returns an HTTP response.

func (*Client) DownloadObjectByKey

func (c *Client) DownloadObjectByKey(bizKey string, url string, localFile string, optFns ...DownloadOptionFn) error

DownloadObjectByKey download object by biz key(tenantID or ...).If local file exists, it will be overwritten.

func (*Client) GetProviderByBizKey

func (c *Client) GetProviderByBizKey(bizKey string) (S3Provider, error)

GetProviderByBizKey get provider by biz key

func (*Client) RegistryProvider

func (c *Client) RegistryProvider(cfg *ProviderConfig, bizKey string) error

RegistryProvider registry a file system provider.If provider is not exist, create a new one and cache it. Note that the cache key is the combination of access key id, endpoint, bucket and kind, maybe change it later. parameter bizKey is used to set/replace a customer key for the provider, so that you can get the provider by the key.

type Config

type Config struct {
	BasePath   string            `json:"basePath,omitempty" yaml:"basePath,omitempty"`
	Host       string            `json:"host,omitempty" yaml:"host,omitempty"`
	Headers    map[string]string `yaml:"headers,omitempty" json:"headers,omitempty"`
	UserAgent  string            `json:"userAgent,omitempty" yaml:"userAgent,omitempty"`
	HTTPClient *http.Client
	Providers  []ProviderConfig `json:"providers" yaml:"providers"`
}

Config file system config. if you want to add source config in config file.

func NewConfig

func NewConfig() *Config

NewConfig create a new config.

type Data

type Data struct {
	FileIdentitiesForApp []*FileIdentity `json:"fileIdentitiesForApp"`
}

type DownloadOption

type DownloadOption struct {
	// if true, overwrite the local file if it exists
	OverwrittenFile bool
}

type DownloadOptionFn

type DownloadOptionFn func(options *DownloadOption)

func WithOverwrittenFile

func WithOverwrittenFile(overwrittenFile bool) DownloadOptionFn

type EndpointResolverV2

type EndpointResolverV2 struct {
	EndpointImmutable bool
	// contains filtered or unexported fields
}

EndpointResolverV2 customer endpoint resolver

func (*EndpointResolverV2) ResolveEndpoint

func (r *EndpointResolverV2) ResolveEndpoint(ctx context.Context, params s3.EndpointParameters) (
	smithyendpoints.Endpoint, error,
)

ResolveEndpoint resolve endpoint

type FileIdentity

type FileIdentity struct {
	ID              ID          `json:"id"`
	TenantID        ID          `json:"tenantID"`
	AccessKeyID     string      `json:"accessKeyID"`
	AccessKeySecret string      `json:"accessKeySecret"`
	RoleArn         string      `json:"roleArn"`
	Policy          string      `json:"policy,omitempty"`
	DurationSeconds int         `json:"durationSeconds,omitempty"`
	IsDefault       bool        `json:"isDefault"`
	Source          *FileSource `json:"source"`
}

type FileIdentityAPI

type FileIdentityAPI api

func (*FileIdentityAPI) GetFileIdentities

func (a *FileIdentityAPI) GetFileIdentities(ctx context.Context, req *GetFileIdentitiesRequest) (ret []*FileIdentity, resp *http.Response, err error)

GetFileIdentities (POST fileIdentitiesForApp)

type FileSource

type FileSource struct {
	ID                ID     `json:"id,omitempty"`
	Kind              Kind   `json:"kind,omitempty"`
	Endpoint          string `json:"endpoint,omitempty"`
	EndpointImmutable bool   `json:"endpointImmutable,omitempty"`
	StsEndpoint       string `json:"stsEndpoint,omitempty"`
	Region            string `json:"region,omitempty"`
	Bucket            string `json:"bucket,omitempty"`
	BucketURL         string `json:"bucketUrl,omitempty"`
}

type GetFileIdentitiesRequest

type GetFileIdentitiesRequest struct {
	// TenantIDs the tenant id
	TenantIDs []int `binding:"required" form:"tenantID"`
	// IsDefault The default identity of the tenant
	IsDefault bool `form:"isDefault"`
}

type GraphqlRequest

type GraphqlRequest struct {
	Query     string      `json:"query"`
	Variables interface{} `json:"variables"`
}

type ID

type ID int

func (*ID) String

func (i *ID) String() string

func (*ID) UnmarshalJSON

func (i *ID) UnmarshalJSON(data []byte) error

type InterceptFunc

type InterceptFunc func(context.Context, *http.Request) error

InterceptFunc is a function that intercepts a request before it is sent.

type Kind

type Kind string

Kind file source kind

const (
	KindMinio  Kind = "minio"
	KindAliOSS Kind = "aliOSS"
	KindAwsS3  Kind = "awsS3"
)

Kind values.

type ProviderConfig

type ProviderConfig struct {
	// file source kind
	Kind Kind `json:"kind" yaml:"kind"`
	// access key id
	AccessKeyID string `json:"accessKeyID,omitempty" yaml:"accessKeyID"`
	// access key secret
	AccessKeySecret string `json:"accessKeySecret,omitempty" yaml:"accessKeySecret,omitempty"`
	// access endpoint, used for public access
	Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
	// endpoint is immutable, if it's custom domain, set to true
	EndpointImmutable bool `json:"endpointImmutable,omitempty" yaml:"endpointImmutable,omitempty"`
	// sts endpoint, used for sts
	StsEndpoint string `json:"stsEndpoint,omitempty" yaml:"stsEndpoint,omitempty"`
	// region, physical location of data storage
	Region string `json:"region,omitempty" yaml:"region,omitempty"`
	// file storage bucket
	Bucket string `json:"bucket" yaml:"bucket"`
	// file storage bucket url, used for matching url
	BucketUrl string `json:"bucketUrl" yaml:"bucketUrl"`
	// role arn, used for STS
	RoleArn string `json:"roleArn,omitempty" yaml:"roleArn,omitempty"`
	// specify the policy for the returned STS token
	Policy string `json:"policy,omitempty" yaml:"policy,omitempty"`
	// duration of the STS token, default 3600s
	DurationSeconds int `json:"durationSeconds,omitempty" yaml:"durationSeconds,omitempty"`
}

ProviderConfig define file system source config.

func ToProviderConfig

func ToProviderConfig(fi *FileIdentity) *ProviderConfig

type Result

type Result struct {
	Data Data `json:"data"`
}

type S3Provider

type S3Provider interface {
	// ProviderConfig return ProviderConfig. Provider need hold a ProviderConfig.
	ProviderConfig() *ProviderConfig
	// ParseUrlKey parse url key.
	ParseUrlKey(urlStr string) (key string, err error)
	// GetSTS get sts response.
	GetSTS(ctx context.Context, roleSessionName string) (*STSResponse, error)
	// GetPreSignedURL get pre-signed url to make request format match each S3Provider.
	GetPreSignedURL(ctx context.Context, bucket, path string, expires time.Duration) (string, error)
	// S3Client return s3 client.
	S3Client() *s3.Client
}

S3Provider s3 provider interface.

func BuildAwsS3

func BuildAwsS3(ctx context.Context, fileSource *ProviderConfig) (S3Provider, error)

BuildAwsS3 create aws s3 provider. it matches S3ProviderBuilder

type S3ProviderBuilder

type S3ProviderBuilder func(context.Context, *ProviderConfig) (S3Provider, error)

S3ProviderBuilder s3 provider builder.

type STSResponse

type STSResponse struct {
	AccessKeyID     string
	SecretAccessKey string
	SessionToken    string
	Expiration      time.Time
}

STSResponse sts response.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL