mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-08 09:15:29 -04:00
ci: static file uploader with automatic cache invalidation (#1833)
This commit is contained in:
parent
8686c5e7e2
commit
29b93065b3
5 changed files with 933 additions and 0 deletions
36
internal/staticupload/upload.go
Normal file
36
internal/staticupload/upload.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
Copyright (c) Edgeless Systems GmbH
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package staticupload
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
s3manager "github.com/aws/aws-sdk-go-v2/feature/s3/manager"
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
)
|
||||
|
||||
// Upload uploads the given object to S3 and invalidates the CDN cache.
|
||||
// It returns the upload output or an error.
|
||||
// The error will be of type InvalidationError if the CDN cache could not be invalidated.
|
||||
func (c *Client) Upload(
|
||||
ctx context.Context, input *s3.PutObjectInput, opts ...func(*s3manager.Uploader),
|
||||
) (*s3manager.UploadOutput, error) {
|
||||
if input == nil || input.Key == nil {
|
||||
return nil, errors.New("key is not set")
|
||||
}
|
||||
output, uploadErr := c.uploadClient.Upload(ctx, input, opts...)
|
||||
if uploadErr != nil {
|
||||
return nil, fmt.Errorf("uploading object: %w", uploadErr)
|
||||
}
|
||||
|
||||
if err := c.invalidate(ctx, []string{*input.Key}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return output, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue