2022-05-25 16:15:27 +00:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
|
|
|
|
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
2022-05-25 16:15:27 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var convertEACLCmd = &cobra.Command{
|
|
|
|
Use: "eacl",
|
|
|
|
Short: "Convert representation of extended ACL table",
|
|
|
|
Run: convertEACLTable,
|
|
|
|
}
|
|
|
|
|
|
|
|
func initConvertEACLCmd() {
|
|
|
|
flags := convertEACLCmd.Flags()
|
|
|
|
|
|
|
|
flags.String("from", "", "File with JSON or binary encoded extended ACL table")
|
|
|
|
_ = convertEACLCmd.MarkFlagFilename("from")
|
|
|
|
_ = convertEACLCmd.MarkFlagRequired("from")
|
|
|
|
|
|
|
|
flags.String("to", "", "File to dump extended ACL table (default: binary encoded)")
|
2022-06-23 13:52:47 +00:00
|
|
|
flags.Bool(commonflags.JSON, false, "Dump extended ACL table in JSON encoding")
|
2022-05-25 16:15:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func convertEACLTable(cmd *cobra.Command, _ []string) {
|
|
|
|
pathFrom := cmd.Flag("from").Value.String()
|
|
|
|
to := cmd.Flag("to").Value.String()
|
2022-06-23 13:52:47 +00:00
|
|
|
jsonFlag, _ := cmd.Flags().GetBool(commonflags.JSON)
|
2022-05-25 16:15:27 +00:00
|
|
|
|
|
|
|
table := common.ReadEACL(cmd, pathFrom)
|
|
|
|
|
|
|
|
var data []byte
|
|
|
|
var err error
|
|
|
|
if jsonFlag || len(to) == 0 {
|
|
|
|
data, err = table.MarshalJSON()
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "can't JSON encode extended ACL table: %w", err)
|
2022-05-25 16:15:27 +00:00
|
|
|
} else {
|
|
|
|
data, err = table.Marshal()
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "can't binary encode extended ACL table: %w", err)
|
2022-05-25 16:15:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(to) == 0 {
|
2022-12-27 09:36:30 +00:00
|
|
|
common.PrettyPrintJSON(cmd, table, "eACL")
|
2022-05-25 16:15:27 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-10-31 11:56:55 +00:00
|
|
|
err = os.WriteFile(to, data, 0o644)
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "can't write exteded ACL table to file: %w", err)
|
2022-05-25 16:15:27 +00:00
|
|
|
|
|
|
|
cmd.Printf("extended ACL table was successfully dumped to %s\n", to)
|
|
|
|
}
|