Skip to content

Commit

Permalink
[FAB-9312] Resolve metalinter warnings
Browse files Browse the repository at this point in the history
- fix msp package
- fix util package

Change-Id: I85ab0032f8e114eb14fa0ef3ca034c7d6385053a
Signed-off-by: Firas Qutishat <firas.qutishat@securekey.com>
  • Loading branch information
fqutishat committed Apr 13, 2018
1 parent c8911f3 commit ea94ad2
Show file tree
Hide file tree
Showing 31 changed files with 369 additions and 291 deletions.
1 change: 1 addition & 0 deletions gometalinter.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"Enable": [
"deadcode",
"gocyclo",
"gofmt",
"gotype",
"goimports",
"golint",
Expand Down
34 changes: 17 additions & 17 deletions pkg/common/errors/retry/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,93 +68,93 @@ var DefaultResMgmtOpts = Opts{
// DefaultRetryableCodes these are the error codes, grouped by source of error,
// that are considered to be transient error conditions by default
var DefaultRetryableCodes = map[status.Group][]status.Code{
status.EndorserClientStatus: []status.Code{
status.EndorserClientStatus: {
status.EndorsementMismatch,
status.PrematureChaincodeExecution,
},
status.EndorserServerStatus: []status.Code{
status.EndorserServerStatus: {
status.Code(common.Status_SERVICE_UNAVAILABLE),
status.Code(common.Status_INTERNAL_SERVER_ERROR),
},
status.OrdererServerStatus: []status.Code{
status.OrdererServerStatus: {
status.Code(common.Status_SERVICE_UNAVAILABLE),
status.Code(common.Status_INTERNAL_SERVER_ERROR),
},
status.EventServerStatus: []status.Code{
status.EventServerStatus: {
status.Code(pb.TxValidationCode_DUPLICATE_TXID),
status.Code(pb.TxValidationCode_ENDORSEMENT_POLICY_FAILURE),
status.Code(pb.TxValidationCode_MVCC_READ_CONFLICT),
status.Code(pb.TxValidationCode_PHANTOM_READ_CONFLICT),
},
// TODO: gRPC introduced retries in v1.8.0. This can be replaced with the
// gRPC fail fast option, once available
status.GRPCTransportStatus: []status.Code{
status.GRPCTransportStatus: {
status.Code(grpcCodes.Unavailable),
},
}

// ResMgmtDefaultRetryableCodes are the suggested codes that should be treated as
// transient by fabric-sdk-go/pkg/client/resmgmt.Client
var ResMgmtDefaultRetryableCodes = map[status.Group][]status.Code{
status.EndorserClientStatus: []status.Code{
status.EndorserClientStatus: {
status.EndorsementMismatch,
status.PrematureChaincodeExecution,
},
status.EndorserServerStatus: []status.Code{
status.EndorserServerStatus: {
status.Code(common.Status_SERVICE_UNAVAILABLE),
status.Code(common.Status_INTERNAL_SERVER_ERROR),
},
status.OrdererServerStatus: []status.Code{
status.OrdererServerStatus: {
status.Code(common.Status_SERVICE_UNAVAILABLE),
status.Code(common.Status_INTERNAL_SERVER_ERROR),
status.Code(common.Status_BAD_REQUEST),
status.Code(common.Status_NOT_FOUND),
},
status.EventServerStatus: []status.Code{
status.EventServerStatus: {
status.Code(pb.TxValidationCode_DUPLICATE_TXID),
status.Code(pb.TxValidationCode_ENDORSEMENT_POLICY_FAILURE),
status.Code(pb.TxValidationCode_MVCC_READ_CONFLICT),
status.Code(pb.TxValidationCode_PHANTOM_READ_CONFLICT),
},
// TODO: gRPC introduced retries in v1.8.0. This can be replaced with the
// gRPC fail fast option, once available
status.GRPCTransportStatus: []status.Code{
status.GRPCTransportStatus: {
status.Code(grpcCodes.Unavailable),
},
}

// ChannelClientRetryableCodes are the suggested codes that should be treated as
// transient by fabric-sdk-go/pkg/client/channel.Client
var ChannelClientRetryableCodes = map[status.Group][]status.Code{
status.EndorserClientStatus: []status.Code{
status.EndorserClientStatus: {
status.ConnectionFailed, status.EndorsementMismatch,
status.PrematureChaincodeExecution,
},
status.EndorserServerStatus: []status.Code{
status.EndorserServerStatus: {
status.Code(common.Status_SERVICE_UNAVAILABLE),
status.Code(common.Status_INTERNAL_SERVER_ERROR),
},
status.OrdererClientStatus: []status.Code{
status.OrdererClientStatus: {
status.ConnectionFailed,
},
status.OrdererServerStatus: []status.Code{
status.OrdererServerStatus: {
status.Code(common.Status_SERVICE_UNAVAILABLE),
status.Code(common.Status_INTERNAL_SERVER_ERROR),
},
status.EventServerStatus: []status.Code{
status.EventServerStatus: {
status.Code(pb.TxValidationCode_DUPLICATE_TXID),
status.Code(pb.TxValidationCode_ENDORSEMENT_POLICY_FAILURE),
status.Code(pb.TxValidationCode_MVCC_READ_CONFLICT),
status.Code(pb.TxValidationCode_PHANTOM_READ_CONFLICT),
},
// TODO: gRPC introduced retries in v1.8.0. This can be replaced with the
// gRPC fail fast option, once available
status.GRPCTransportStatus: []status.Code{
status.GRPCTransportStatus: {
status.Code(grpcCodes.Unavailable),
},
}

// ChannelConfigRetryableCodes error codes to be taken into account for query channel config retry
var ChannelConfigRetryableCodes = map[status.Group][]status.Code{
status.EndorserClientStatus: []status.Code{status.EndorsementMismatch},
status.EndorserClientStatus: {status.EndorsementMismatch},
}
10 changes: 5 additions & 5 deletions pkg/core/logging/metadata/callerInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ func (l *CallerInfo) IsCallerInfoEnabled(module string, level api.Level) bool {
//getDefaultCallerInfoSetting default setting for callerinfo
func (l *CallerInfo) getDefaultCallerInfoSetting() map[callerInfoKey]bool {
return map[callerInfoKey]bool{
callerInfoKey{"", api.CRITICAL}: true,
callerInfoKey{"", api.ERROR}: true,
callerInfoKey{"", api.WARNING}: true,
callerInfoKey{"", api.INFO}: true,
callerInfoKey{"", api.DEBUG}: true,
{"", api.CRITICAL}: true,
{"", api.ERROR}: true,
{"", api.WARNING}: true,
{"", api.INFO}: true,
{"", api.DEBUG}: true,
}
}
6 changes: 3 additions & 3 deletions pkg/fab/events/eventhubclient/connection/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestSend(t *testing.T) {
Event: &pb.Event_Register{
Register: &pb.Register{
Events: []*pb.Interest{
&pb.Interest{EventType: pb.EventType_FILTEREDBLOCK},
{EventType: pb.EventType_FILTEREDBLOCK},
},
},
},
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestSend(t *testing.T) {
Event: &pb.Event_Unregister{
Unregister: &pb.Unregister{
Events: []*pb.Interest{
&pb.Interest{EventType: pb.EventType_FILTEREDBLOCK},
{EventType: pb.EventType_FILTEREDBLOCK},
},
},
},
Expand Down Expand Up @@ -155,7 +155,7 @@ func TestDisconnected(t *testing.T) {
Event: &pb.Event_Register{
Register: &pb.Register{
Events: []*pb.Interest{
&pb.Interest{EventType: pb.EventType_FILTEREDBLOCK},
{EventType: pb.EventType_FILTEREDBLOCK},
},
},
},
Expand Down
10 changes: 5 additions & 5 deletions pkg/fab/events/eventhubclient/dispatcher/dispatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestRegisterInterests(t *testing.T) {
// Unregister interests
dispatcherEventch <- NewUnregisterInterestsEvent(
[]*pb.Interest{
&pb.Interest{
{
EventType: pb.EventType_FILTEREDBLOCK,
},
},
Expand Down Expand Up @@ -108,7 +108,7 @@ func TestRegisterInterests(t *testing.T) {
func registerFilteredBlockEvent(dispatcherEventch chan<- interface{}, errch chan error, t *testing.T) chan<- interface{} {
dispatcherEventch <- NewRegisterInterestsEvent(
[]*pb.Interest{
&pb.Interest{
{
EventType: pb.EventType_FILTEREDBLOCK,
},
},
Expand All @@ -127,7 +127,7 @@ func registerFilteredBlockEvent(dispatcherEventch chan<- interface{}, errch chan
func checkFailedRegisterInterest(dispatcherEventch chan<- interface{}, errch chan error, t *testing.T) chan<- interface{} {
dispatcherEventch <- NewRegisterInterestsEvent(
[]*pb.Interest{
&pb.Interest{
{
EventType: pb.EventType_FILTEREDBLOCK,
},
},
Expand Down Expand Up @@ -164,7 +164,7 @@ func TestRegisterInterestsInvalid(t *testing.T) {
// Unregister interests
dispatcherEventch <- NewUnregisterInterestsEvent(
[]*pb.Interest{
&pb.Interest{
{
EventType: pb.EventType_FILTEREDBLOCK,
},
},
Expand Down Expand Up @@ -278,7 +278,7 @@ func TestTimedOutRegister(t *testing.T) {
// Register interests
dispatcherEventch <- NewRegisterInterestsEvent(
[]*pb.Interest{
&pb.Interest{
{
EventType: pb.EventType_FILTEREDBLOCK,
},
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/fab/events/eventhubclient/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
)

var blockInterests = []*pb.Interest{&pb.Interest{EventType: pb.EventType_BLOCK}}
var filteredBlockInterests = []*pb.Interest{&pb.Interest{EventType: pb.EventType_FILTEREDBLOCK}}
var blockInterests = []*pb.Interest{{EventType: pb.EventType_BLOCK}}
var filteredBlockInterests = []*pb.Interest{{EventType: pb.EventType_FILTEREDBLOCK}}

type params struct {
connProvider api.ConnectionProvider
Expand Down
2 changes: 1 addition & 1 deletion pkg/fab/events/service/mocks/mockevents.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func NewFilteredTxWithCCEvent(txID, ccID, event string) *pb.FilteredTransaction
Data: &pb.FilteredTransaction_TransactionActions{
TransactionActions: &pb.FilteredTransactionActions{
ChaincodeActions: []*pb.FilteredChaincodeAction{
&pb.FilteredChaincodeAction{
{
ChaincodeEvent: &pb.ChaincodeEvent{
ChaincodeId: ccID,
EventName: event,
Expand Down
2 changes: 1 addition & 1 deletion pkg/fab/mocks/mockbroadcastserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func StartMockBroadcastServer(broadcastTestURL string, grpcServer *grpc.Server)
po.RegisterAtomicBroadcastServer(grpcServer, broadcastServer)
go func() {
if err := grpcServer.Serve(lis); err != nil {
panic(err.Error())
fmt.Printf("StartMockBroadcastServer failed to start %v", err.Error())
}
}()

Expand Down
6 changes: 3 additions & 3 deletions pkg/fab/mocks/mockendorserserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ func (m *MockEndorserServer) createProposalResponsePayload() []byte {

if m.AddkvWrite {
txRwSet.NsRwSets = []*rwsetutil.NsRwSet{
&rwsetutil.NsRwSet{NameSpace: "ns1", KvRwSet: &kvrwset.KVRWSet{
Reads: []*kvrwset.KVRead{&kvrwset.KVRead{Key: "key1", Version: &kvrwset.Version{BlockNum: 1, TxNum: 1}}},
Writes: []*kvrwset.KVWrite{&kvrwset.KVWrite{Key: "key2", IsDelete: false, Value: []byte("value2")}},
{NameSpace: "ns1", KvRwSet: &kvrwset.KVRWSet{
Reads: []*kvrwset.KVRead{{Key: "key1", Version: &kvrwset.Version{BlockNum: 1, TxNum: 1}}},
Writes: []*kvrwset.KVWrite{{Key: "key2", IsDelete: false, Value: []byte("value2")}},
}}}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/fab/mocks/mockeventserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func StartMockEventServer(testAddress string) (*MockEventServer, error) {
fmt.Printf("Starting mock event server\n")
go func() {
if err := grpcServer.Serve(lis); err != nil {
panic(err.Error())
fmt.Printf("StartMockEventServer failed %v", err.Error())
}
}()

Expand Down
2 changes: 1 addition & 1 deletion pkg/fab/txn/proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestSendTransactionProposal(t *testing.T) {
request := fab.ChaincodeInvokeRequest{
ChaincodeID: "cc",
Fcn: "Hello",
Args: [][]byte{[]byte{1, 2, 3}},
Args: [][]byte{{1, 2, 3}},
}

txh, err := NewHeader(ctx, testChannel)
Expand Down
6 changes: 3 additions & 3 deletions pkg/msp/caclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ func NewCAClient(orgName string, ctx contextApi.Client) (*CAClientImpl, error) {
}

if orgName == "" {
clientConfig, err := ctx.IdentityConfig().Client()
if err != nil {
return nil, errors.Wrapf(err, "client config retrieval failed")
clientConfig, err1 := ctx.IdentityConfig().Client()
if err1 != nil {
return nil, errors.Wrapf(err1, "client config retrieval failed")
}
orgName = clientConfig.Organization
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/msp/caclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ func TestEnrollAndReenroll(t *testing.T) {

// Successful enrollment
enrollUsername := createRandomName()
enrolledUserData, err := f.userStore.Load(msp.IdentityIdentifier{MSPID: orgMSPID, ID: enrollUsername})
_, err = f.userStore.Load(msp.IdentityIdentifier{MSPID: orgMSPID, ID: enrollUsername})
if err != msp.ErrUserNotFound {
t.Fatalf("Expected to not find user in user store")
}
err = f.caClient.Enroll(enrollUsername, "enrollmentSecret")
if err != nil {
t.Fatalf("identityManager Enroll return error %v", err)
}
enrolledUserData, err = f.userStore.Load(msp.IdentityIdentifier{MSPID: orgMSPID, ID: enrollUsername})
enrolledUserData, err := f.userStore.Load(msp.IdentityIdentifier{MSPID: orgMSPID, ID: enrollUsername})
if err != nil {
t.Fatalf("Expected to load user from user store")
}
Expand All @@ -75,6 +75,10 @@ func TestEnrollAndReenroll(t *testing.T) {
}

// Reenroll with appropriate user
reenrollWithAppropriateUser(f, t, enrolledUserData)
}

func reenrollWithAppropriateUser(f textFixture, t *testing.T, enrolledUserData *msp.UserData) {
iManager, ok := f.identityManagerProvider.IdentityManager("org1")
if !ok {
t.Fatalf("failed to get identity manager")
Expand Down
7 changes: 0 additions & 7 deletions pkg/msp/certfileuserstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ type CertFileUserStore struct {
store core.KVStore
}

func userIdentifierFromUser(user msp.UserData) msp.IdentityIdentifier {
return msp.IdentityIdentifier{
MSPID: user.MSPID,
ID: user.ID,
}
}

func storeKeyFromUserIdentifier(key msp.IdentityIdentifier) string {
return key.ID + "@" + key.MSPID + "-cert.pem"
}
Expand Down
Loading

0 comments on commit ea94ad2

Please sign in to comment.