Skip to content

Commit

Permalink
Merge pull request #35 from ehaligow/ehaligow-fix-for-Issue#25
Browse files Browse the repository at this point in the history
Deletes logging sensitive information (fix for Issue #25)
  • Loading branch information
Maciej Miś authored Jan 18, 2023
2 parents 563898e + b6efc76 commit 4039bde
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 29 deletions.
32 changes: 6 additions & 26 deletions src/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,7 @@ func (s *Server) getFunctionsResult(function string, deviceIPAddress string, aut
}
} else {
if errRet := s.validateDeviceAccountData(deviceIPAddress, userName, password); errRet != "" {
logrus.WithFields(logrus.Fields{
"IP address:port": deviceIPAddress,
"Username": userName,
}).Errorf(errRet)
logrus.Errorf(errRet)
return http.StatusBadRequest, errors.New(errRet)
}
}
Expand Down Expand Up @@ -177,10 +174,7 @@ func (s *Server) getFunctionsResult(function string, deviceIPAddress string, aut
}
} else {
if s.getLoginStatus(deviceIPAddress, authStr, userName) == false {
logrus.WithFields(logrus.Fields{
"IP address:port": deviceIPAddress,
"Username": userName,
}).Errorf(ErrUserLogin.String())
logrus.Errorf(ErrUserLogin.String())
return http.StatusBadRequest, errors.New(ErrUserLogin.String())
}
}
Expand All @@ -204,10 +198,7 @@ func (s *Server) getFunctionsResult(function string, deviceIPAddress string, aut
}
} else {
if s.getUserStatus(deviceIPAddress, authStr, userName) == false {
logrus.WithFields(logrus.Fields{
"IP address:port": deviceIPAddress,
"Username": userName,
}).Errorf(ErrUserStatus.String())
logrus.Errorf(ErrUserStatus.String())
return http.StatusBadRequest, errors.New(ErrUserStatus.String())
}
}
Expand All @@ -233,12 +224,7 @@ func (s *Server) getFunctionsResult(function string, deviceIPAddress string, aut
userPrivilege := s.getUserPrivilege(deviceIPAddress, authStr, userName)
defineUserPrivilege := s.getDefineUserPrivilege(deviceIPAddress, authStr)[0]
if userPrivilege != defineUserPrivilege {
logrus.WithFields(logrus.Fields{
"IP address:port": deviceIPAddress,
"Username": userName,
"Privilege": userPrivilege,
"Defined User Privilege": defineUserPrivilege,
}).Errorf(ErrUserAdmin.String())
logrus.Errorf(ErrUserAdmin.String())
return http.StatusBadRequest, errors.New(ErrUserAdmin.String())
}
}
Expand Down Expand Up @@ -267,10 +253,7 @@ func (s *Server) getFunctionsResult(function string, deviceIPAddress string, aut
if userPrivilege != privilege[0] {
if (userPrivilege == privilege[1] && TargetUserPrivilege == privilege[0]) ||
(userPrivilege == privilege[2] && TargetUserPrivilege != privilege[2]) {
logrus.WithFields(logrus.Fields{
"IP address:port": deviceIPAddress,
"Username": userName,
}).Errorf(args[2])
logrus.Errorf(ErrUserHigherPrivilege.String())
return http.StatusBadRequest, errors.New(args[2])
}
}
Expand All @@ -297,10 +280,7 @@ func (s *Server) getFunctionsResult(function string, deviceIPAddress string, aut
userPrivilege := s.getUserPrivilege(deviceIPAddress, authStr, userName)
privilege := s.getDefineUserPrivilege(deviceIPAddress, authStr)
if userPrivilege == privilege[2] {
logrus.WithFields(logrus.Fields{
"IP address:port": deviceIPAddress,
"Username": userName,
}).Errorf(args[1])
logrus.Errorf(ErrWrongPrivilege.String())
return http.StatusBadRequest, errors.New(args[1])
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/error_define.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const (
ErrUserStatus
ErrUserAdmin
ErrUserPrivilege
ErrWrongPrivilege
ErrUserHigherPrivilege
ErrSessionExists
ErrSessionFailed
Expand Down Expand Up @@ -132,6 +133,7 @@ func (e errorIndex) String(args ...string) string {
/*ErrUserStatus*/ "Please check this user account in this device",
/*ErrUserAdmin*/ "The user privilege is not administrator",
/*ErrUserPrivilege*/ "The user privilege could not configure this action to the device",
/*ErrWrongPrivilege*/ "Wrong privilege for this action",
/*ErrUserHigherPrivilege*/ "The user privilege could not configure this action than other higher user",
/*ErrSessionExists*/ "The session service was enabled on the device " + argsStrs[0] + ". Please login device first and assige the token",
/*ErrSessionFailed*/ "The session service is not enable to configure on device " + argsStrs[0] + " now, status code " + argsStrs[1],
Expand Down
3 changes: 0 additions & 3 deletions src/grpcAPIs.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,6 @@ func (s *Server) CreateDeviceAccount(c context.Context, account *manager.DeviceA
errStatus, _ := status.FromError(err)
logrus.WithFields(logrus.Fields{
"Username": newUsername,
"Password": newPassword,
}).Error(errStatus.Message())
return &empty.Empty{}, status.Errorf(codes.Code(statusCode), errStatus.Message())
}
Expand Down Expand Up @@ -500,7 +499,6 @@ func (s *Server) LoginDevice(c context.Context, account *manager.DeviceAccount)
logrus.WithFields(logrus.Fields{
"IP address:port": ipAddress,
"Username": loginUserName,
"Password": loginPassword,
}).Error(errStatus.Message())
return nil, status.Errorf(codes.Code(statusCode), errStatus.Message())
}
Expand Down Expand Up @@ -576,7 +574,6 @@ func (s *Server) ChangeDeviceUserPassword(c context.Context, account *manager.De
errStatus, _ := status.FromError(err)
logrus.WithFields(logrus.Fields{
"Username": userName,
"Password": password,
}).Error(errStatus.Message())
return &empty.Empty{}, status.Errorf(codes.Code(statusCode), errStatus.Message())
}
Expand Down

0 comments on commit 4039bde

Please sign in to comment.