CoreSLS : Get client and server ip address

Merged Vikram Ingawale requested to merge vi_clientserverip into devbranch
Compare and
3 files
+ 87
19
Preferences
File browser
Compare changes
@@ -219,7 +219,7 @@ func RestrictedHandler(c *routing.Context) error {
c.SetStatusCode(412)
return err
}
pricipalObj.ClientIP = c.RemoteIP().String()
// pricipalObj.ClientIP = c.RemoteIP().String()
commonHandler(c, true, false, false, pricipalObj)
return nil
}
@@ -234,7 +234,7 @@ func RoleBasedHandler(c *routing.Context) error {
c.SetStatusCode(412)
return err
}
pricipalObj.ClientIP = c.RemoteIP().String()
// pricipalObj.ClientIP = c.RemoteIP().String()
commonHandler(c, true, true, false, pricipalObj)
return nil
}
@@ -259,7 +259,7 @@ func HeavyRestrictedHandler(c *routing.Context) error {
c.SetStatusCode(412)
return err
}
pricipalObj.ClientIP = c.RemoteIP().String()
// pricipalObj.ClientIP = c.RemoteIP().String()
commonHandler(c, true, false, true, pricipalObj)
return nil
}
@@ -274,7 +274,7 @@ func HeavyRoleBasedHandler(c *routing.Context) error {
c.SetStatusCode(412)
return err
}
pricipalObj.ClientIP = c.RemoteIP().String()
// pricipalObj.ClientIP = c.RemoteIP().String()
commonHandler(c, true, true, true, pricipalObj)
return nil
}
@@ -323,11 +323,6 @@ func extractPricipalObject(c *routing.Context) (servicebuildermdl.Principal, err
return principal, errormdl.CheckErr(grperr)
}
userID, _ := claim["userId"].(string)
// if !ok {
// loggermdl.LogError("Unable to parse UserID from JWT Token")
// return principal, errormdl.Wrap("Unable to parse UserID from JWT Token")
// }
if len(userID) < 2 {
loggermdl.LogError("UserID length is less than 2")
return principal, errormdl.Wrap("UserID length is less than 2")
@@ -345,5 +340,19 @@ func extractPricipalObject(c *routing.Context) (servicebuildermdl.Principal, err
principal.Groups = groups
principal.UserID = userID
principal.Token = string(c.Request.Header.Peek("Authorization"))
// set client ip
principal.ClientIP = getClientIP(c)
return principal, nil
}
// getClientIP - returns respected header value from request header
func getClientIP(c *routing.Context) string {
clientIP := string(c.Request.Header.Peek("X-Real-Ip"))
if clientIP == "" {
clientIP = string(c.Request.Header.Peek("X-Forwarded-For"))
}
if clientIP == "" {
clientIP = c.RemoteIP().String()
}
return clientIP
}