package ape import ( "fmt" "strconv" apechain "git.frostfs.info/TrueCloudLab/policy-engine/pkg/chain" "github.com/spf13/cobra" ) // PrintHumanReadableAPEChain print APE chain rules. func PrintHumanReadableAPEChain(cmd *cobra.Command, chain *apechain.Chain) { cmd.Println("Chain ID: " + string(chain.ID)) cmd.Printf(" HEX: %x\n", chain.ID) cmd.Println("Rules:") for _, rule := range chain.Rules { cmd.Println("\n\tStatus: " + rule.Status.String()) cmd.Println("\tAny: " + strconv.FormatBool(rule.Any)) cmd.Println("\tConditions:") for _, c := range rule.Condition { var ot string switch c.Kind { case apechain.KindResource: ot = "Resource" case apechain.KindRequest: ot = "Request" default: panic("unknown object type") } cmd.Println(fmt.Sprintf("\t\t%s %s %s %s", ot, c.Key, c.Op, c.Value)) } cmd.Println("\tActions:\tInverted:" + strconv.FormatBool(rule.Actions.Inverted)) for _, name := range rule.Actions.Names { cmd.Println("\t\t" + name) } cmd.Println("\tResources:\tInverted:" + strconv.FormatBool(rule.Resources.Inverted)) for _, name := range rule.Resources.Names { cmd.Println("\t\t" + name) } } }