Use bytes in control service proto definition for chainID #885
10 changed files with 45 additions and 12 deletions
|
@ -3,6 +3,7 @@ package control
|
|||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client"
|
||||
|
@ -42,6 +43,15 @@ func addRule(cmd *cobra.Command, _ []string) {
|
|||
pk := key.Get(cmd)
|
||||
|
||||
chainID, _ := cmd.Flags().GetString(chainIDFlag)
|
||||
hexEncoded, _ := cmd.Flags().GetBool(chainIDHexFlag)
|
||||
|
||||
chainIDRaw := []byte(chainID)
|
||||
|
||||
if hexEncoded {
|
||||
var err error
|
||||
chainIDRaw, err = hex.DecodeString(chainID)
|
||||
commonCmd.ExitOnErr(cmd, "can't decode chain ID as hex: %w", err)
|
||||
}
|
||||
|
||||
var cnr cid.ID
|
||||
cidStr, _ := cmd.Flags().GetString(commonflags.CIDFlag)
|
||||
|
@ -54,7 +64,7 @@ func addRule(cmd *cobra.Command, _ []string) {
|
|||
|
||||
chain := new(apechain.Chain)
|
||||
commonCmd.ExitOnErr(cmd, "parser error: %w", util.ParseAPEChain(chain, []string{rule}))
|
||||
chain.ID = apechain.ID(chainID)
|
||||
chain.ID = apechain.ID(chainIDRaw)
|
||||
serializedChain := chain.Bytes()
|
||||
|
||||
cmd.Println("CID: " + cidStr)
|
||||
|
@ -84,7 +94,8 @@ func addRule(cmd *cobra.Command, _ []string) {
|
|||
|
||||
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())
|
||||
|
||||
cmd.Println("Rule has been added. Chain id: ", resp.GetBody().GetChainId())
|
||||
chainIDRaw = resp.GetBody().GetChainId()
|
||||
cmd.Printf("Rule has been added.\nChain id: '%s'\nChain id hex: '%x'\n", string(chainIDRaw), chainIDRaw)
|
||||
}
|
||||
|
||||
func initControlAddRuleCmd() {
|
||||
|
@ -94,4 +105,5 @@ func initControlAddRuleCmd() {
|
|||
ff.String(commonflags.CIDFlag, "", commonflags.CIDFlagUsage)
|
||||
ff.String(ruleFlag, "", "Rule statement")
|
||||
ff.String(chainIDFlag, "", "Assign ID to the parsed chain")
|
||||
ff.Bool(chainIDHexFlag, false, "Flag to parse chain ID as hex")
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package control
|
|||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
|
||||
|
@ -31,6 +32,13 @@ func getRule(cmd *cobra.Command, _ []string) {
|
|||
cnr.Encode(rawCID)
|
||||
|
||||
chainID, _ := cmd.Flags().GetString(chainIDFlag)
|
||||
hexEncoded, _ := cmd.Flags().GetBool(chainIDHexFlag)
|
||||
|
||||
if hexEncoded {
|
||||
chainIDBytes, err := hex.DecodeString(chainID)
|
||||
commonCmd.ExitOnErr(cmd, "can't decode chain ID as hex: %w", err)
|
||||
chainID = string(chainIDBytes)
|
||||
}
|
||||
|
||||
req := &control.GetChainLocalOverrideRequest{
|
||||
Body: &control.GetChainLocalOverrideRequest_Body{
|
||||
|
@ -38,7 +46,7 @@ func getRule(cmd *cobra.Command, _ []string) {
|
|||
Name: cidStr,
|
||||
Type: control.ChainTarget_CONTAINER,
|
||||
},
|
||||
ChainId: chainID,
|
||||
ChainId: []byte(chainID),
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -60,7 +68,7 @@ func getRule(cmd *cobra.Command, _ []string) {
|
|||
commonCmd.ExitOnErr(cmd, "decode error: %w", chain.DecodeBytes(resp.GetBody().GetChain()))
|
||||
|
||||
// TODO (aarifullin): make pretty-formatted output for chains.
|
||||
cmd.Println("Parsed chain:\n" + prettyJSONFormat(cmd, chain.Bytes()))
|
||||
cmd.Printf("Parsed chain (chain id hex: '%x'):\n%s\n", chain.ID, prettyJSONFormat(cmd, chain.Bytes()))
|
||||
}
|
||||
|
||||
func initControGetRuleCmd() {
|
||||
|
@ -69,4 +77,5 @@ func initControGetRuleCmd() {
|
|||
ff := getRuleCmd.Flags()
|
||||
ff.String(commonflags.CIDFlag, "", commonflags.CIDFlagUsage)
|
||||
ff.String(chainIDFlag, "", "Chain id")
|
||||
ff.Bool(chainIDHexFlag, false, "Flag to parse chain ID as hex")
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ func listRules(cmd *cobra.Command, _ []string) {
|
|||
// TODO (aarifullin): make pretty-formatted output for chains.
|
||||
var chain apechain.Chain
|
||||
commonCmd.ExitOnErr(cmd, "decode error: %w", chain.DecodeBytes(c))
|
||||
cmd.Println("Parsed chain:\n" + prettyJSONFormat(cmd, chain.Bytes()))
|
||||
cmd.Printf("Parsed chain (chain id hex: '%x'):\n%s\n", chain.ID, prettyJSONFormat(cmd, chain.Bytes()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package control
|
|||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
|
||||
|
@ -14,6 +15,7 @@ import (
|
|||
|
||||
const (
|
||||
chainIDFlag = "chain-id"
|
||||
chainIDHexFlag = "chain-id-hex"
|
||||
)
|
||||
|
||||
var removeRuleCmd = &cobra.Command{
|
||||
|
@ -34,6 +36,15 @@ func removeRule(cmd *cobra.Command, _ []string) {
|
|||
cnr.Encode(rawCID)
|
||||
|
||||
chainID, _ := cmd.Flags().GetString(chainIDFlag)
|
||||
hexEncoded, _ := cmd.Flags().GetBool(chainIDHexFlag)
|
||||
|
||||
chainIDRaw := []byte(chainID)
|
||||
|
||||
if hexEncoded {
|
||||
var err error
|
||||
chainIDRaw, err = hex.DecodeString(chainID)
|
||||
commonCmd.ExitOnErr(cmd, "can't decode chain ID as hex: %w", err)
|
||||
}
|
||||
|
||||
req := &control.RemoveChainLocalOverrideRequest{
|
||||
Body: &control.RemoveChainLocalOverrideRequest_Body{
|
||||
|
@ -41,7 +52,7 @@ func removeRule(cmd *cobra.Command, _ []string) {
|
|||
Name: cidStr,
|
||||
Type: control.ChainTarget_CONTAINER,
|
||||
},
|
||||
ChainId: chainID,
|
||||
ChainId: chainIDRaw,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -72,4 +83,5 @@ func initControlRemoveRuleCmd() {
|
|||
ff := removeRuleCmd.Flags()
|
||||
ff.String(commonflags.CIDFlag, "", commonflags.CIDFlagUsage)
|
||||
ff.String(chainIDFlag, "", "Chain id")
|
||||
ff.Bool(chainIDHexFlag, false, "Flag to parse chain ID as hex")
|
||||
}
|
||||
|
|
BIN
pkg/services/control/ir/service_grpc.pb.go
generated
BIN
pkg/services/control/ir/service_grpc.pb.go
generated
Binary file not shown.
|
@ -7,7 +7,7 @@ import (
|
|||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control"
|
||||
apechain "git.frostfs.info/TrueCloudLab/policy-engine/pkg/chain"
|
||||
engine "git.frostfs.info/TrueCloudLab/policy-engine/pkg/engine"
|
||||
"git.frostfs.info/TrueCloudLab/policy-engine/pkg/engine"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
@ -51,7 +51,7 @@ func (s *Server) AddChainLocalOverride(_ context.Context, req *control.AddChainL
|
|||
|
||||
resp := &control.AddChainLocalOverrideResponse{
|
||||
Body: &control.AddChainLocalOverrideResponse_Body{
|
||||
ChainId: string(chain.ID),
|
||||
ChainId: []byte(chain.ID),
|
||||
},
|
||||
}
|
||||
err = SignMessage(s.key, resp)
|
||||
|
|
BIN
pkg/services/control/service.pb.go
generated
BIN
pkg/services/control/service.pb.go
generated
Binary file not shown.
|
@ -446,7 +446,7 @@ message AddChainLocalOverrideResponse {
|
|||
// Chain ID assigned for the added rule chain.
|
||||
// If chain ID is left empty in the request, then
|
||||
// it will be generated.
|
||||
string chain_id = 1;
|
||||
bytes chain_id = 1;
|
||||
}
|
||||
|
||||
Body body = 1;
|
||||
|
@ -461,7 +461,7 @@ message GetChainLocalOverrideRequest {
|
|||
ChainTarget target = 1;
|
||||
|
||||
// Chain ID assigned for the added rule chain.
|
||||
string chain_id = 2;
|
||||
bytes chain_id = 2;
|
||||
}
|
||||
|
||||
Body body = 1;
|
||||
|
@ -511,7 +511,7 @@ message RemoveChainLocalOverrideRequest {
|
|||
ChainTarget target = 1;
|
||||
|
||||
// Chain ID assigned for the added rule chain.
|
||||
string chain_id = 2;
|
||||
bytes chain_id = 2;
|
||||
}
|
||||
|
||||
Body body = 1;
|
||||
|
|
BIN
pkg/services/control/service_frostfs.pb.go
generated
BIN
pkg/services/control/service_frostfs.pb.go
generated
Binary file not shown.
BIN
pkg/services/tree/service_grpc.pb.go
generated
BIN
pkg/services/tree/service_grpc.pb.go
generated
Binary file not shown.
Loading…
Reference in a new issue