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, ) { rpcSecret, err := getGarageRPCSecret(ctx, d.secretsStore) if err != nil && !errors.Is(err, secrets.ErrNotFound) { return GarageClientParams{}, fmt.Errorf("getting garage rpc secret: %w", err) } return GarageClientParams{ Peer: currBootstrap.ChooseGaragePeer(), GlobalBucketS3APICredentials: currBootstrap.Garage.GlobalBucketS3APICredentials, 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) }