github.com/pvitto98/fabric@v2.1.1+incompatible/common/tools/protolator/protoext/commonext/configuration.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package commonext
     8  
     9  import (
    10  	"fmt"
    11  
    12  	"github.com/golang/protobuf/proto"
    13  	"github.com/hyperledger/fabric-protos-go/common"
    14  	"github.com/hyperledger/fabric-protos-go/msp"
    15  	"github.com/hyperledger/fabric/common/tools/protolator/protoext/ordererext"
    16  	"github.com/hyperledger/fabric/common/tools/protolator/protoext/peerext"
    17  
    18  	"github.com/pkg/errors"
    19  )
    20  
    21  type DynamicChannelGroup struct {
    22  	*common.ConfigGroup
    23  }
    24  
    25  func (dcg *DynamicChannelGroup) DynamicMapFields() []string {
    26  	return []string{"values", "groups"}
    27  }
    28  
    29  func (dcg *DynamicChannelGroup) Underlying() proto.Message {
    30  	return dcg.ConfigGroup
    31  }
    32  
    33  func (dcg *DynamicChannelGroup) DynamicMapFieldProto(name string, key string, base proto.Message) (proto.Message, error) {
    34  	switch name {
    35  	case "groups":
    36  		cg, ok := base.(*common.ConfigGroup)
    37  		if !ok {
    38  			return nil, fmt.Errorf("ConfigGroup groups can only contain ConfigGroup messages")
    39  		}
    40  
    41  		switch key {
    42  		case "Consortiums":
    43  			return &DynamicConsortiumsGroup{ConfigGroup: cg}, nil
    44  		case "Orderer":
    45  			return &ordererext.DynamicOrdererGroup{ConfigGroup: cg}, nil
    46  		case "Application":
    47  			return &peerext.DynamicApplicationGroup{ConfigGroup: cg}, nil
    48  		default:
    49  			return nil, errors.Errorf("unknown channel group sub-group '%s'", key)
    50  		}
    51  	case "values":
    52  		cv, ok := base.(*common.ConfigValue)
    53  		if !ok {
    54  			return nil, fmt.Errorf("ConfigGroup values can only contain ConfigValue messages")
    55  		}
    56  		return &DynamicChannelConfigValue{
    57  			ConfigValue: cv,
    58  			name:        key,
    59  		}, nil
    60  	default:
    61  		return nil, fmt.Errorf("ConfigGroup does not have a dynamic field: %s", name)
    62  	}
    63  }
    64  
    65  type DynamicChannelConfigValue struct {
    66  	*common.ConfigValue
    67  	name string
    68  }
    69  
    70  func (dccv *DynamicChannelConfigValue) StaticallyOpaqueFields() []string {
    71  	return []string{"value"}
    72  }
    73  
    74  func (dccv *DynamicChannelConfigValue) Underlying() proto.Message {
    75  	return dccv.ConfigValue
    76  }
    77  
    78  func (dccv *DynamicChannelConfigValue) StaticallyOpaqueFieldProto(name string) (proto.Message, error) {
    79  	if name != "value" {
    80  		return nil, fmt.Errorf("not a marshaled field: %s", name)
    81  	}
    82  	switch dccv.name {
    83  	case "HashingAlgorithm":
    84  		return &common.HashingAlgorithm{}, nil
    85  	case "BlockDataHashingStructure":
    86  		return &common.BlockDataHashingStructure{}, nil
    87  	case "OrdererAddresses":
    88  		return &common.OrdererAddresses{}, nil
    89  	case "Consortium":
    90  		return &common.Consortium{}, nil
    91  	case "Capabilities":
    92  		return &common.Capabilities{}, nil
    93  	default:
    94  		return nil, fmt.Errorf("unknown Channel ConfigValue name: %s", dccv.name)
    95  	}
    96  }
    97  
    98  type DynamicConsortiumsGroup struct {
    99  	*common.ConfigGroup
   100  }
   101  
   102  func (dcg *DynamicConsortiumsGroup) Underlying() proto.Message {
   103  	return dcg.ConfigGroup
   104  }
   105  
   106  func (dcg *DynamicConsortiumsGroup) DynamicMapFields() []string {
   107  	return []string{"values", "groups"}
   108  }
   109  
   110  func (dcg *DynamicConsortiumsGroup) DynamicMapFieldProto(name string, key string, base proto.Message) (proto.Message, error) {
   111  	switch name {
   112  	case "groups":
   113  		cg, ok := base.(*common.ConfigGroup)
   114  		if !ok {
   115  			return nil, fmt.Errorf("ConfigGroup groups can only contain ConfigGroup messages")
   116  		}
   117  
   118  		return &DynamicConsortiumGroup{
   119  			ConfigGroup: cg,
   120  		}, nil
   121  	case "values":
   122  		return nil, fmt.Errorf("Consortiums currently support no config values")
   123  	default:
   124  		return nil, fmt.Errorf("ConfigGroup does not have a dynamic field: %s", name)
   125  	}
   126  }
   127  
   128  type DynamicConsortiumGroup struct {
   129  	*common.ConfigGroup
   130  }
   131  
   132  func (dcg *DynamicConsortiumGroup) Underlying() proto.Message {
   133  	return dcg.ConfigGroup
   134  }
   135  
   136  func (dcg *DynamicConsortiumGroup) DynamicMapFields() []string {
   137  	return []string{"values", "groups"}
   138  }
   139  
   140  func (dcg *DynamicConsortiumGroup) DynamicMapFieldProto(name string, key string, base proto.Message) (proto.Message, error) {
   141  	switch name {
   142  	case "groups":
   143  		cg, ok := base.(*common.ConfigGroup)
   144  		if !ok {
   145  			return nil, fmt.Errorf("ConfigGroup groups can only contain ConfigGroup messages")
   146  		}
   147  		return &DynamicConsortiumOrgGroup{
   148  			ConfigGroup: cg,
   149  		}, nil
   150  	case "values":
   151  		cv, ok := base.(*common.ConfigValue)
   152  		if !ok {
   153  			return nil, fmt.Errorf("ConfigGroup values can only contain ConfigValue messages")
   154  		}
   155  
   156  		return &DynamicConsortiumConfigValue{
   157  			ConfigValue: cv,
   158  			name:        key,
   159  		}, nil
   160  	default:
   161  		return nil, fmt.Errorf("not a dynamic orderer map field: %s", name)
   162  	}
   163  }
   164  
   165  type DynamicConsortiumConfigValue struct {
   166  	*common.ConfigValue
   167  	name string
   168  }
   169  
   170  func (dccv *DynamicConsortiumConfigValue) Underlying() proto.Message {
   171  	return dccv.ConfigValue
   172  }
   173  
   174  func (dccv *DynamicConsortiumConfigValue) VariablyOpaqueFields() []string {
   175  	return []string{"value"}
   176  }
   177  
   178  func (dccv *DynamicConsortiumConfigValue) VariablyOpaqueFieldProto(name string) (proto.Message, error) {
   179  	if name != "value" {
   180  		return nil, fmt.Errorf("not a marshaled field: %s", name)
   181  	}
   182  	switch dccv.name {
   183  	case "ChannelCreationPolicy":
   184  		return &common.Policy{}, nil
   185  	default:
   186  		return nil, fmt.Errorf("unknown Consortium ConfigValue name: %s", dccv.name)
   187  	}
   188  }
   189  
   190  type DynamicConsortiumOrgGroup struct {
   191  	*common.ConfigGroup
   192  }
   193  
   194  func (dcg *DynamicConsortiumOrgGroup) Underlying() proto.Message {
   195  	return dcg.ConfigGroup
   196  }
   197  
   198  func (dcg *DynamicConsortiumOrgGroup) DynamicMapFields() []string {
   199  	return []string{"groups", "values"}
   200  }
   201  
   202  func (dcg *DynamicConsortiumOrgGroup) DynamicMapFieldProto(name string, key string, base proto.Message) (proto.Message, error) {
   203  	switch name {
   204  	case "groups":
   205  		return nil, fmt.Errorf("ConsortiumOrg groups do not support sub groups")
   206  	case "values":
   207  		cv, ok := base.(*common.ConfigValue)
   208  		if !ok {
   209  			return nil, fmt.Errorf("ConfigGroup values can only contain ConfigValue messages")
   210  		}
   211  
   212  		return &DynamicConsortiumOrgConfigValue{
   213  			ConfigValue: cv,
   214  			name:        key,
   215  		}, nil
   216  	default:
   217  		return nil, fmt.Errorf("not a dynamic orderer map field: %s", name)
   218  	}
   219  }
   220  
   221  type DynamicConsortiumOrgConfigValue struct {
   222  	*common.ConfigValue
   223  	name string
   224  }
   225  
   226  func (dcocv *DynamicConsortiumOrgConfigValue) Underlying() proto.Message {
   227  	return dcocv.ConfigValue
   228  }
   229  
   230  func (dcocv *DynamicConsortiumOrgConfigValue) StaticallyOpaqueFields() []string {
   231  	return []string{"value"}
   232  }
   233  
   234  func (dcocv *DynamicConsortiumOrgConfigValue) StaticallyOpaqueFieldProto(name string) (proto.Message, error) {
   235  	if name != "value" {
   236  		return nil, fmt.Errorf("not a marshaled field: %s", name)
   237  	}
   238  	switch dcocv.name {
   239  	case "MSP":
   240  		return &msp.MSPConfig{}, nil
   241  	default:
   242  		return nil, fmt.Errorf("unknown Consortium Org ConfigValue name: %s", dcocv.name)
   243  	}
   244  }