mirror of
https://git.freecumextremist.com/grumbulon/pomme.git
synced 2024-11-22 10:03:45 +00:00
safer type assertion
This commit is contained in:
parent
64c43839de
commit
2a6c9eee4d
1 changed files with 13 additions and 3 deletions
|
@ -91,7 +91,17 @@ func ReceiveFile(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
zoneFile := newDNSRequest(header.Filename, claims["username"].(string), b)
|
||||
user, ok := claims["username"].(string)
|
||||
if !ok {
|
||||
logger.Response = Response{
|
||||
Message: "Expected username to be a string",
|
||||
Status: http.StatusInternalServerError,
|
||||
Err: errors.New("unable to assert string type to claims interface{}"),
|
||||
}
|
||||
logger.newLogEntry().errorLogger(logger.Response)
|
||||
}
|
||||
|
||||
zoneFile := newDNSRequest(header.Filename, user, b)
|
||||
|
||||
if err := zoneFile.parse(); err != nil {
|
||||
logger.Response = Response{
|
||||
|
@ -120,7 +130,7 @@ func ReceiveFile(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
// check if request is coming from user not in the DB but has a valid JWT
|
||||
db.Where("username = ?", claims["username"].(string)).First(&result)
|
||||
db.Where("username = ?", user).First(&result)
|
||||
|
||||
if result.Username == "" {
|
||||
logger.Response = Response{
|
||||
|
@ -136,7 +146,7 @@ func ReceiveFile(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
db.Create(
|
||||
&ZoneRequest{
|
||||
User: claims["username"].(string),
|
||||
User: user,
|
||||
Zone: &Zone{
|
||||
FileName: header.Filename,
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue