-
Notifications
You must be signed in to change notification settings - Fork 0
/
charmclient.go
30 lines (25 loc) · 909 Bytes
/
charmclient.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright 2024 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package s3client
import (
"context"
"fmt"
"io"
)
// Charms is the client desienged to interact with the
// s3 compatible object store hosted by the apiserver
type Charms struct {
session Session
}
// GetCharm retrieves a charm from the S3-compatible object store hosted
// by the apiserver. Returns an archived charm as a stream of bytes
func (c *Charms) GetCharm(ctx context.Context, modelUUID, charmRef string) (io.ReadCloser, error) {
bucketName := fmt.Sprintf("model-%s", modelUUID)
objectName := fmt.Sprintf("charms/%s", charmRef)
return c.session.GetObject(ctx, bucketName, objectName)
}
// NewCharmsS3Client creates a client to interact with charm blobs stored
// on the apiserver's s3 comptabile object store.
func NewCharmsS3Client(session Session) *Charms {
return &Charms{session: session}
}