forked from TrueCloudLab/frostfs-node
[#989] cli: Read and parse chains from file
* Introduce path flag to make add-rule command read and parse chain from file. File is binary/JSON-encoded chain. Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
This commit is contained in:
parent
9adcb253be
commit
9611710e19
2 changed files with 45 additions and 10 deletions
|
@ -3,6 +3,7 @@ package util
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
@ -57,6 +58,23 @@ func PrintHumanReadableAPEChain(cmd *cobra.Command, chain *apechain.Chain) {
|
|||
}
|
||||
}
|
||||
|
||||
func ParseAPEChainBinaryOrJSON(chain *apechain.Chain, path string) error {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("read file <%s>: %w", path, err)
|
||||
}
|
||||
|
||||
err = chain.UnmarshalBinary(data)
|
||||
if err != nil {
|
||||
err = chain.UnmarshalJSON(data)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid format: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ParseAPEChain parses APE chain rules.
|
||||
func ParseAPEChain(chain *apechain.Chain, rules []string) error {
|
||||
if len(rules) == 0 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue