versionsapi: use read-only client

Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
This commit is contained in:
Paul Meyer 2022-12-29 08:32:18 +01:00
parent 0011d960f7
commit d2d3a8e068
3 changed files with 23 additions and 2 deletions

View File

@ -47,7 +47,7 @@ func runLatest(cmd *cobra.Command, args []string) error {
}
log.Debugf("Creating versions API client.")
client, err := verclient.NewClient(cmd.Context(), flags.region, flags.bucket, flags.distributionID, true, log)
client, err := verclient.NewReadOnlyClient(cmd.Context(), flags.region, flags.bucket, flags.distributionID, log)
if err != nil {
return fmt.Errorf("creating client: %w", err)
}

View File

@ -50,7 +50,7 @@ func runList(cmd *cobra.Command, args []string) error {
}
log.Debugf("Creating versions API client.")
client, err := verclient.NewClient(cmd.Context(), flags.region, flags.bucket, flags.distributionID, true, log)
client, err := verclient.NewReadOnlyClient(cmd.Context(), flags.region, flags.bucket, flags.distributionID, log)
if err != nil {
return fmt.Errorf("creating client: %w", err)
}

View File

@ -59,6 +59,27 @@ type Client struct {
log *logger.Logger
}
// NewReadOnlyClient creates a new read-only client.
// This client can be used to fetch objects but cannot write updates.
func NewReadOnlyClient(ctx context.Context, region, bucket, distributionID string,
log *logger.Logger,
) (*Client, error) {
cfg, err := awsconfig.LoadDefaultConfig(ctx, awsconfig.WithRegion(region))
if err != nil {
return nil, err
}
s3c := s3.NewFromConfig(cfg)
return &Client{
config: cfg,
s3Client: s3c,
bucket: bucket,
distributionID: distributionID,
dryRun: true,
log: log,
}, nil
}
// NewClient creates a new client for the versions API.
func NewClient(ctx context.Context, region, bucket, distributionID string, dryRun bool,
log *logger.Logger,