2024-07-13 12:34:06 +00:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"isle/bootstrap"
|
|
|
|
"isle/garage"
|
|
|
|
"isle/secrets"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GarageClientParams contains all the data needed to instantiate garage
|
|
|
|
// clients.
|
|
|
|
type GarageClientParams struct {
|
|
|
|
Peer garage.RemotePeer
|
|
|
|
GlobalBucketS3APICredentials garage.S3APICredentials
|
|
|
|
|
|
|
|
// RPCSecret may be empty, if the secret is not available on the host.
|
|
|
|
RPCSecret string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *daemon) getGarageClientParams(
|
|
|
|
ctx context.Context, currBootstrap bootstrap.Bootstrap,
|
|
|
|
) (
|
|
|
|
GarageClientParams, error,
|
|
|
|
) {
|
2024-07-14 10:19:39 +00:00
|
|
|
creds, err := getGarageS3APIGlobalBucketCredentials(ctx, d.secretsStore)
|
|
|
|
if err != nil {
|
|
|
|
return GarageClientParams{}, fmt.Errorf("getting garage global bucket creds: %w", err)
|
|
|
|
}
|
|
|
|
|
2024-07-14 09:58:39 +00:00
|
|
|
rpcSecret, err := getGarageRPCSecret(ctx, d.secretsStore)
|
2024-07-13 12:34:06 +00:00
|
|
|
if err != nil && !errors.Is(err, secrets.ErrNotFound) {
|
|
|
|
return GarageClientParams{}, fmt.Errorf("getting garage rpc secret: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return GarageClientParams{
|
|
|
|
Peer: currBootstrap.ChooseGaragePeer(),
|
2024-07-14 10:19:39 +00:00
|
|
|
GlobalBucketS3APICredentials: creds,
|
2024-07-13 12:34:06 +00:00
|
|
|
RPCSecret: rpcSecret,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GlobalBucketS3APIClient returns an S3 client pre-configured with access to
|
|
|
|
// the global bucket.
|
|
|
|
func (p GarageClientParams) GlobalBucketS3APIClient() garage.S3APIClient {
|
|
|
|
var (
|
|
|
|
addr = p.Peer.S3APIAddr()
|
|
|
|
creds = p.GlobalBucketS3APICredentials
|
|
|
|
)
|
|
|
|
return garage.NewS3APIClient(addr, creds)
|
|
|
|
}
|