2022-06-02 12:24:31 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
internalclient "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/client"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
|
|
|
|
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
2023-08-18 14:44:17 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
2022-06-02 12:24:31 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var getExtendedACLCmd = &cobra.Command{
|
|
|
|
Use: "get-eacl",
|
|
|
|
Short: "Get extended ACL table of container",
|
2022-09-28 08:46:23 +00:00
|
|
|
Long: `Get extended ACL table of container`,
|
2022-06-02 12:24:31 +00:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
id := parseContainerID(cmd)
|
|
|
|
pk := key.GetOrGenerate(cmd)
|
|
|
|
cli := internalclient.GetSDKClientByFlag(cmd, pk, commonflags.RPC)
|
|
|
|
|
2023-08-18 14:44:17 +00:00
|
|
|
eaclPrm := internalclient.EACLPrm{
|
|
|
|
Client: cli,
|
|
|
|
ClientParams: client.PrmContainerEACL{
|
|
|
|
ContainerID: &id,
|
|
|
|
},
|
|
|
|
}
|
2022-06-02 12:24:31 +00:00
|
|
|
|
2023-05-24 13:51:57 +00:00
|
|
|
res, err := internalclient.EACL(cmd.Context(), eaclPrm)
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
|
2022-06-02 12:24:31 +00:00
|
|
|
|
|
|
|
eaclTable := res.EACL()
|
|
|
|
|
|
|
|
if containerPathTo == "" {
|
|
|
|
cmd.Println("eACL: ")
|
2022-08-22 11:04:00 +00:00
|
|
|
common.PrettyPrintJSON(cmd, &eaclTable, "eACL")
|
2022-06-02 12:24:31 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var data []byte
|
|
|
|
|
|
|
|
if containerJSON {
|
|
|
|
data, err = eaclTable.MarshalJSON()
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "can't encode to JSON: %w", err)
|
2022-06-02 12:24:31 +00:00
|
|
|
} else {
|
|
|
|
data, err = eaclTable.Marshal()
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "can't encode to binary: %w", err)
|
2022-06-02 12:24:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd.Println("dumping data to file:", containerPathTo)
|
|
|
|
|
2023-10-31 11:56:55 +00:00
|
|
|
err = os.WriteFile(containerPathTo, data, 0o644)
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "could not write eACL to file: %w", err)
|
2022-06-02 12:24:31 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func initContainerGetEACLCmd() {
|
|
|
|
commonflags.Init(getExtendedACLCmd)
|
|
|
|
|
|
|
|
flags := getExtendedACLCmd.Flags()
|
|
|
|
|
2022-10-18 11:43:04 +00:00
|
|
|
flags.StringVar(&containerID, commonflags.CIDFlag, "", commonflags.CIDFlagUsage)
|
2022-10-11 14:02:03 +00:00
|
|
|
flags.StringVar(&containerPathTo, "to", "", "Path to dump encoded container (default: binary encoded)")
|
|
|
|
flags.BoolVar(&containerJSON, commonflags.JSON, false, "Encode EACL table in json format")
|
2022-06-02 12:24:31 +00:00
|
|
|
}
|