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