feat(reconcile): add attachment consistency reconciler
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"io"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http"
|
||||
@@ -24,6 +25,7 @@ var (
|
||||
ErrObjectNotFound = errors.New("object not found")
|
||||
ErrPutObject = errors.New("put object")
|
||||
ErrGetObject = errors.New("get object")
|
||||
ErrListObjects = errors.New("list objects")
|
||||
ErrDeleteObject = errors.New("delete object")
|
||||
)
|
||||
|
||||
@@ -34,6 +36,17 @@ type Client struct {
|
||||
log *slog.Logger
|
||||
}
|
||||
|
||||
type ObjectInfo struct {
|
||||
Key string
|
||||
Size int64
|
||||
LastModified time.Time
|
||||
}
|
||||
|
||||
type ListResult struct {
|
||||
Objects []ObjectInfo
|
||||
Pages int
|
||||
}
|
||||
|
||||
func New(ctx context.Context, cfg appconfig.S3Config, log *slog.Logger) (*Client, error) {
|
||||
apiAccessKey, err := cfg.APIAccessKey()
|
||||
if err != nil {
|
||||
@@ -144,6 +157,35 @@ func (c *Client) Get(ctx context.Context, key string) (*awss3.GetObjectOutput, e
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *Client) ListAll(ctx context.Context, prefix string) (ListResult, error) {
|
||||
result := ListResult{Objects: []ObjectInfo{}}
|
||||
|
||||
paginator := awss3.NewListObjectsV2Paginator(c.bootstrap, &awss3.ListObjectsV2Input{
|
||||
Bucket: aws.String(c.bucket),
|
||||
Prefix: aws.String(prefix),
|
||||
})
|
||||
|
||||
for paginator.HasMorePages() {
|
||||
page, err := paginator.NextPage(ctx)
|
||||
if err != nil {
|
||||
c.log.Error("list objects", "bucket", c.bucket, "prefix", prefix, "error", err)
|
||||
return ListResult{}, ErrListObjects
|
||||
}
|
||||
|
||||
result.Pages++
|
||||
|
||||
for _, obj := range page.Contents {
|
||||
result.Objects = append(result.Objects, ObjectInfo{
|
||||
Key: aws.ToString(obj.Key),
|
||||
Size: aws.ToInt64(obj.Size),
|
||||
LastModified: aws.ToTime(obj.LastModified),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (c *Client) DeleteAdmin(ctx context.Context, key string) error {
|
||||
_, err := c.bootstrap.DeleteObject(ctx, &awss3.DeleteObjectInput{
|
||||
Bucket: aws.String(c.bucket),
|
||||
|
||||
Reference in New Issue
Block a user