125 lines
2.8 KiB
Go
125 lines
2.8 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"syscall"
|
|
)
|
|
|
|
var subCmdGarageMC = subCmd{
|
|
name: "mc",
|
|
descr: "Runs the mc (minio-client) binary. The isle garage can be accessed under the `garage` alias",
|
|
checkLock: true,
|
|
do: func(subCmdCtx subCmdCtx) error {
|
|
|
|
flags := subCmdCtx.flagSet(true)
|
|
|
|
keyID := flags.StringP(
|
|
"key-id", "i", "",
|
|
"Optional key ID to use, defaults to that of the shared global key",
|
|
)
|
|
|
|
keySecret := flags.StringP(
|
|
"key-secret", "s", "",
|
|
"Optional key secret to use, defaults to that of the shared global key",
|
|
)
|
|
|
|
if err := flags.Parse(subCmdCtx.args); err != nil {
|
|
return fmt.Errorf("parsing flags: %w", err)
|
|
}
|
|
|
|
hostBootstrap, err := loadHostBootstrap()
|
|
if err != nil {
|
|
return fmt.Errorf("loading host bootstrap: %w", err)
|
|
}
|
|
|
|
s3APIAddr := hostBootstrap.ChooseGaragePeer().S3APIAddr()
|
|
|
|
if *keyID == "" {
|
|
*keyID = hostBootstrap.Garage.GlobalBucketS3APICredentials.ID
|
|
}
|
|
|
|
if *keySecret == "" {
|
|
*keySecret = hostBootstrap.Garage.GlobalBucketS3APICredentials.Secret
|
|
}
|
|
|
|
args := flags.Args()
|
|
|
|
if i := flags.ArgsLenAtDash(); i >= 0 {
|
|
args = args[i:]
|
|
}
|
|
|
|
args = append([]string{binPath("mc")}, args...)
|
|
|
|
var (
|
|
mcHostVar = fmt.Sprintf(
|
|
"MC_HOST_garage=http://%s:%s@%s",
|
|
*keyID, *keySecret, s3APIAddr,
|
|
)
|
|
|
|
binPath = filepath.Join(envAppDirPath, "bin/mc")
|
|
cliEnv = append(
|
|
os.Environ(),
|
|
mcHostVar,
|
|
|
|
// The garage docs say this is necessary, though nothing bad
|
|
// seems to happen if we leave it out *shrug*
|
|
"MC_REGION=garage",
|
|
)
|
|
)
|
|
|
|
if err := syscall.Exec(binPath, args, cliEnv); err != nil {
|
|
return fmt.Errorf(
|
|
"calling exec(%q, %#v, %#v): %w",
|
|
binPath, args, cliEnv, err,
|
|
)
|
|
}
|
|
|
|
return nil
|
|
},
|
|
}
|
|
|
|
var subCmdGarageCLI = subCmd{
|
|
name: "cli",
|
|
descr: "Runs the garage binary, automatically configured to point to the garage sub-process of a running isle daemon",
|
|
checkLock: true,
|
|
do: func(subCmdCtx subCmdCtx) error {
|
|
|
|
hostBootstrap, err := loadHostBootstrap()
|
|
if err != nil {
|
|
return fmt.Errorf("loading host bootstrap: %w", err)
|
|
}
|
|
|
|
var (
|
|
binPath = binPath("garage")
|
|
args = append([]string{"garage"}, subCmdCtx.args...)
|
|
cliEnv = append(
|
|
os.Environ(),
|
|
"GARAGE_RPC_HOST="+hostBootstrap.ChooseGaragePeer().RPCPeerAddr(),
|
|
"GARAGE_RPC_SECRET="+hostBootstrap.Garage.RPCSecret,
|
|
)
|
|
)
|
|
|
|
if err := syscall.Exec(binPath, args, cliEnv); err != nil {
|
|
return fmt.Errorf(
|
|
"calling exec(%q, %#v, %#v): %w",
|
|
binPath, args, cliEnv, err,
|
|
)
|
|
}
|
|
|
|
return nil
|
|
},
|
|
}
|
|
|
|
var subCmdGarage = subCmd{
|
|
name: "garage",
|
|
descr: "Runs the garage binary, automatically configured to point to the garage sub-process of a running isle daemon",
|
|
do: func(subCmdCtx subCmdCtx) error {
|
|
return subCmdCtx.doSubCmd(
|
|
subCmdGarageCLI,
|
|
subCmdGarageMC,
|
|
)
|
|
},
|
|
}
|