fix: enable weekly storage cleanup
Desktop Client Build / Resolve Build Metadata (push) Successful in 32s
Frontend CI / Frontend (push) Successful in 2m6s
Backend CI / Backend (push) Successful in 16m11s
Desktop Client Build / Build Desktop Client (push) Successful in 23m50s
Desktop Client Build / Publish Client Artifacts to NAS (push) Successful in 37s
Desktop Client Build / Resolve Build Metadata (push) Successful in 32s
Frontend CI / Frontend (push) Successful in 2m6s
Backend CI / Backend (push) Successful in 16m11s
Desktop Client Build / Build Desktop Client (push) Successful in 23m50s
Desktop Client Build / Publish Client Artifacts to NAS (push) Successful in 37s
This commit is contained in:
@@ -92,7 +92,7 @@ func (c *aliyunClient) PutReader(
|
||||
return fmt.Errorf("object reader is required")
|
||||
}
|
||||
|
||||
exists, err := c.client.IsBucketExist(c.bucket)
|
||||
exists, err := c.bucketExists(ctx)
|
||||
if err != nil {
|
||||
c.logError(ctx, "aliyun bucket exists check failed",
|
||||
zap.String("bucket", c.bucket),
|
||||
@@ -102,7 +102,7 @@ func (c *aliyunClient) PutReader(
|
||||
return fmt.Errorf("check aliyun bucket: %w", err)
|
||||
}
|
||||
if !exists {
|
||||
if err := c.client.CreateBucket(c.bucket); err != nil {
|
||||
if err := c.client.CreateBucket(c.bucket, oss.WithContext(ctx)); err != nil {
|
||||
c.logError(ctx, "aliyun create bucket failed",
|
||||
zap.String("bucket", c.bucket),
|
||||
zap.String("object_key", objectKey),
|
||||
@@ -126,6 +126,7 @@ func (c *aliyunClient) PutReader(
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
options = append(options, oss.WithContext(ctx))
|
||||
if err := bucket.PutObject(objectKey, reader, options...); err != nil {
|
||||
c.logError(ctx, "aliyun put object failed",
|
||||
zap.String("bucket", c.bucket),
|
||||
@@ -144,6 +145,14 @@ func (c *aliyunClient) PutReader(
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *aliyunClient) bucketExists(ctx context.Context) (bool, error) {
|
||||
listRes, err := c.client.ListBuckets(oss.Prefix(c.bucket), oss.MaxKeys(1), oss.WithContext(ctx))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return len(listRes.Buckets) == 1 && listRes.Buckets[0].Name == c.bucket, nil
|
||||
}
|
||||
|
||||
func aliyunPutObjectOptions(cfg config.ObjectStorageConfig, contentType string) ([]oss.Option, error) {
|
||||
options := []oss.Option{oss.ContentType(contentType)}
|
||||
acl := strings.ToLower(strings.TrimSpace(cfg.ObjectACL))
|
||||
@@ -200,7 +209,7 @@ func (c *aliyunClient) GetBytes(ctx context.Context, objectKey string) ([]byte,
|
||||
return nil, fmt.Errorf("get aliyun bucket: %w", err)
|
||||
}
|
||||
|
||||
reader, err := bucket.GetObject(objectKey)
|
||||
reader, err := bucket.GetObject(objectKey, oss.WithContext(ctx))
|
||||
if err != nil {
|
||||
c.logError(ctx, "aliyun get object failed",
|
||||
zap.String("bucket", c.bucket),
|
||||
@@ -255,7 +264,7 @@ func (c *aliyunClient) Exists(ctx context.Context, objectKey string) (bool, erro
|
||||
return false, fmt.Errorf("get aliyun bucket: %w", err)
|
||||
}
|
||||
|
||||
exists, err := bucket.IsObjectExist(objectKey)
|
||||
exists, err := bucket.IsObjectExist(objectKey, oss.WithContext(ctx))
|
||||
if err != nil {
|
||||
c.logError(ctx, "aliyun stat object failed",
|
||||
zap.String("bucket", c.bucket),
|
||||
@@ -285,7 +294,7 @@ func (c *aliyunClient) Delete(ctx context.Context, objectKey string) error {
|
||||
return fmt.Errorf("get aliyun bucket: %w", err)
|
||||
}
|
||||
|
||||
if err := bucket.DeleteObject(objectKey); err != nil {
|
||||
if err := bucket.DeleteObject(objectKey, oss.WithContext(ctx)); err != nil {
|
||||
c.logError(ctx, "aliyun delete object failed",
|
||||
zap.String("bucket", c.bucket),
|
||||
zap.String("object_key", objectKey),
|
||||
@@ -336,7 +345,7 @@ func (c *aliyunClient) Usage(ctx context.Context) (*UsageInfo, error) {
|
||||
if err := c.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
stat, err := c.client.GetBucketStat(c.bucket)
|
||||
stat, err := c.client.GetBucketStat(c.bucket, oss.WithContext(ctx))
|
||||
if err != nil {
|
||||
c.logError(ctx, "aliyun get bucket stat failed",
|
||||
zap.String("bucket", c.bucket),
|
||||
@@ -382,6 +391,7 @@ func (c *aliyunClient) List(ctx context.Context, in ListInput) (*ListResult, err
|
||||
if startAfter := normalizeObjectKeyPath(in.StartAfter); startAfter != "" {
|
||||
options = append(options, oss.StartAfter(startAfter))
|
||||
}
|
||||
options = append(options, oss.WithContext(ctx))
|
||||
|
||||
result, err := bucket.ListObjectsV2(options...)
|
||||
if err != nil {
|
||||
@@ -426,7 +436,7 @@ func (c *aliyunClient) Stat(ctx context.Context, objectKey string) (*ObjectInfo,
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("get aliyun bucket: %w", err)
|
||||
}
|
||||
header, err := bucket.GetObjectDetailedMeta(objectKey)
|
||||
header, err := bucket.GetObjectDetailedMeta(objectKey, oss.WithContext(ctx))
|
||||
if err != nil {
|
||||
c.logError(ctx, "aliyun stat object failed",
|
||||
zap.String("bucket", c.bucket),
|
||||
@@ -457,7 +467,7 @@ func (c *aliyunClient) Copy(ctx context.Context, sourceKey, destinationKey strin
|
||||
if err != nil {
|
||||
return fmt.Errorf("get aliyun bucket: %w", err)
|
||||
}
|
||||
if _, err := bucket.CopyObject(sourceKey, destinationKey); err != nil {
|
||||
if _, err := bucket.CopyObject(sourceKey, destinationKey, oss.WithContext(ctx)); err != nil {
|
||||
c.logError(ctx, "aliyun copy object failed",
|
||||
zap.String("bucket", c.bucket),
|
||||
zap.String("source_key", sourceKey),
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package objectstorage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/geo-platform/tenant-api/internal/shared/config"
|
||||
)
|
||||
@@ -34,6 +38,61 @@ func TestAliyunPutObjectOptionsRejectsUnsupportedObjectACL(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAliyunExistsHonorsContextCancellation(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
requestStarted := make(chan struct{})
|
||||
blockRequest := make(chan struct{})
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
select {
|
||||
case <-requestStarted:
|
||||
default:
|
||||
close(requestStarted)
|
||||
}
|
||||
<-blockRequest
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}))
|
||||
defer func() {
|
||||
close(blockRequest)
|
||||
server.Close()
|
||||
}()
|
||||
|
||||
client := NewAliyunClient(config.ObjectStorageConfig{
|
||||
Provider: "aliyun",
|
||||
Endpoint: server.URL,
|
||||
AccessKey: "test-access-key",
|
||||
SecretKey: "test-secret-key",
|
||||
Bucket: "test-bucket",
|
||||
Region: "cn-test",
|
||||
}, nil)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond)
|
||||
defer cancel()
|
||||
|
||||
started := make(chan struct{})
|
||||
done := make(chan error, 1)
|
||||
go func() {
|
||||
close(started)
|
||||
_, err := client.Exists(ctx, "desktop-client/releases/test.dmg")
|
||||
done <- err
|
||||
}()
|
||||
<-started
|
||||
|
||||
select {
|
||||
case <-requestStarted:
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("expected aliyun request to reach the test server")
|
||||
}
|
||||
|
||||
select {
|
||||
case err := <-done:
|
||||
if err == nil {
|
||||
t.Fatal("expected context cancellation error")
|
||||
}
|
||||
case <-time.After(2 * time.Second):
|
||||
t.Fatal("aliyun Exists did not honor context cancellation")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsPublicReadACL(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user