forked from TrueCloudLab/frostfs-node
[#1259] neofs-cli: Return non-zero exit code in acl extended create
command failures
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
(cherry picked from commit 44138adacf
)
This commit is contained in:
parent
1cfa1763e9
commit
437687f78d
1 changed files with 13 additions and 11 deletions
|
@ -7,6 +7,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/flynn-archive/go-shlex"
|
"github.com/flynn-archive/go-shlex"
|
||||||
|
@ -67,20 +68,20 @@ func createEACL(cmd *cobra.Command, _ []string) {
|
||||||
|
|
||||||
containerID := cid.New()
|
containerID := cid.New()
|
||||||
if err := containerID.Parse(cidArg); err != nil {
|
if err := containerID.Parse(cidArg); err != nil {
|
||||||
cmd.Printf("invalid container ID: %v", err)
|
cmd.Printf("invalid container ID: %v\n", err)
|
||||||
return
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
rulesFile, err := getRulesFromFile(fileArg)
|
rulesFile, err := getRulesFromFile(fileArg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.Printf("can't read rules from file : %v", err)
|
cmd.Printf("can't read rules from file: %v\n", err)
|
||||||
return
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
rules = append(rules, rulesFile...)
|
rules = append(rules, rulesFile...)
|
||||||
if len(rules) == 0 {
|
if len(rules) == 0 {
|
||||||
cmd.Println("no extended ACL rules has been provided")
|
cmd.Println("no extended ACL rules has been provided")
|
||||||
return
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
tb := eacl.NewTable()
|
tb := eacl.NewTable()
|
||||||
|
@ -88,14 +89,14 @@ func createEACL(cmd *cobra.Command, _ []string) {
|
||||||
for _, ruleStr := range rules {
|
for _, ruleStr := range rules {
|
||||||
r, err := shlex.Split(ruleStr)
|
r, err := shlex.Split(ruleStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.Printf("can't parse rule '%s': %v)", ruleStr, err)
|
cmd.Printf("can't parse rule '%s': %v\n", ruleStr, err)
|
||||||
return
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = parseTable(tb, r)
|
err = parseTable(tb, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.Printf("can't create extended ACL record from rule '%s': %v", ruleStr, err)
|
cmd.Printf("can't create extended ACL record from rule '%s': %v\n", ruleStr, err)
|
||||||
return
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,14 +105,14 @@ func createEACL(cmd *cobra.Command, _ []string) {
|
||||||
data, err := tb.MarshalJSON()
|
data, err := tb.MarshalJSON()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.Println(err)
|
cmd.Println(err)
|
||||||
return
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
err = json.Indent(buf, data, "", " ")
|
err = json.Indent(buf, data, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.Println(err)
|
cmd.Println(err)
|
||||||
return
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(outArg) == 0 {
|
if len(outArg) == 0 {
|
||||||
|
@ -122,6 +123,7 @@ func createEACL(cmd *cobra.Command, _ []string) {
|
||||||
err = ioutil.WriteFile(outArg, buf.Bytes(), 0644)
|
err = ioutil.WriteFile(outArg, buf.Bytes(), 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.Println(err)
|
cmd.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue