2022-10-20 19:59:46 +00:00
|
|
|
package main
|
2021-04-20 21:31:37 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2022-11-08 13:54:31 +00:00
|
|
|
"path/filepath"
|
2021-04-20 21:31:37 +00:00
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
|
|
|
var subCmdGarageMC = subCmd{
|
|
|
|
name: "mc",
|
2023-08-05 21:53:17 +00:00
|
|
|
descr: "Runs the mc (minio-client) binary. The isle garage can be accessed under the `garage` alias",
|
2021-04-20 21:31:37 +00:00
|
|
|
checkLock: true,
|
|
|
|
do: func(subCmdCtx subCmdCtx) error {
|
|
|
|
|
|
|
|
flags := subCmdCtx.flagSet(true)
|
|
|
|
|
|
|
|
keyID := flags.StringP(
|
|
|
|
"key-id", "i", "",
|
2023-08-07 20:12:51 +00:00
|
|
|
"Optional key ID to use, defaults to that of the shared global key",
|
2021-04-20 21:31:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
keySecret := flags.StringP(
|
|
|
|
"key-secret", "s", "",
|
2023-08-07 20:12:51 +00:00
|
|
|
"Optional key secret to use, defaults to that of the shared global key",
|
2021-04-20 21:31:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
if err := flags.Parse(subCmdCtx.args); err != nil {
|
|
|
|
return fmt.Errorf("parsing flags: %w", err)
|
|
|
|
}
|
|
|
|
|
2022-10-26 22:37:03 +00:00
|
|
|
hostBootstrap, err := loadHostBootstrap()
|
2022-10-26 22:23:39 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("loading host bootstrap: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
s3APIAddr := hostBootstrap.ChooseGaragePeer().S3APIAddr()
|
2021-04-20 21:31:37 +00:00
|
|
|
|
2022-11-13 19:14:16 +00:00
|
|
|
if *keyID == "" {
|
|
|
|
*keyID = hostBootstrap.Garage.GlobalBucketS3APICredentials.ID
|
|
|
|
}
|
2021-04-20 21:31:37 +00:00
|
|
|
|
2022-11-13 19:14:16 +00:00
|
|
|
if *keySecret == "" {
|
|
|
|
*keySecret = hostBootstrap.Garage.GlobalBucketS3APICredentials.Secret
|
2021-04-20 21:31:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
args := flags.Args()
|
|
|
|
|
|
|
|
if i := flags.ArgsLenAtDash(); i >= 0 {
|
|
|
|
args = args[i:]
|
|
|
|
}
|
|
|
|
|
2023-04-23 14:30:47 +00:00
|
|
|
args = append([]string{binPath("mc")}, args...)
|
2021-04-20 21:31:37 +00:00
|
|
|
|
|
|
|
var (
|
2022-11-13 19:14:16 +00:00
|
|
|
mcHostVar = fmt.Sprintf(
|
|
|
|
"MC_HOST_garage=http://%s:%s@%s",
|
|
|
|
*keyID, *keySecret, s3APIAddr,
|
|
|
|
)
|
|
|
|
|
2022-11-08 13:54:31 +00:00
|
|
|
binPath = filepath.Join(envAppDirPath, "bin/mc")
|
2021-04-20 21:31:37 +00:00
|
|
|
cliEnv = append(
|
|
|
|
os.Environ(),
|
2022-11-13 19:14:16 +00:00
|
|
|
mcHostVar,
|
2021-04-20 21:31:37 +00:00
|
|
|
|
|
|
|
// 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",
|
2023-08-05 21:53:17 +00:00
|
|
|
descr: "Runs the garage binary, automatically configured to point to the garage sub-process of a running isle daemon",
|
2021-04-20 21:31:37 +00:00
|
|
|
checkLock: true,
|
|
|
|
do: func(subCmdCtx subCmdCtx) error {
|
|
|
|
|
2022-10-26 22:37:03 +00:00
|
|
|
hostBootstrap, err := loadHostBootstrap()
|
2022-10-26 22:23:39 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("loading host bootstrap: %w", err)
|
|
|
|
}
|
|
|
|
|
2021-04-20 21:31:37 +00:00
|
|
|
var (
|
2023-04-23 14:30:47 +00:00
|
|
|
binPath = binPath("garage")
|
2021-04-20 21:31:37 +00:00
|
|
|
args = append([]string{"garage"}, subCmdCtx.args...)
|
|
|
|
cliEnv = append(
|
|
|
|
os.Environ(),
|
2022-11-08 13:54:31 +00:00
|
|
|
"GARAGE_RPC_HOST="+hostBootstrap.ChooseGaragePeer().RPCPeerAddr(),
|
2022-11-02 13:34:40 +00:00
|
|
|
"GARAGE_RPC_SECRET="+hostBootstrap.Garage.RPCSecret,
|
2021-04-20 21:31:37 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
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",
|
2023-08-05 21:53:17 +00:00
|
|
|
descr: "Runs the garage binary, automatically configured to point to the garage sub-process of a running isle daemon",
|
2021-04-20 21:31:37 +00:00
|
|
|
do: func(subCmdCtx subCmdCtx) error {
|
|
|
|
return subCmdCtx.doSubCmd(
|
|
|
|
subCmdGarageCLI,
|
|
|
|
subCmdGarageMC,
|
|
|
|
)
|
|
|
|
},
|
|
|
|
}
|