Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
gsanchietti committed Apr 2, 2024
1 parent 0742571 commit 46ae4df
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
15 changes: 8 additions & 7 deletions api/methods/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/NethServer/nethsecurity-api/response"
"github.com/NethServer/nethsecurity-controller/api/cache"
"github.com/NethServer/nethsecurity-controller/api/configuration"
"github.com/NethServer/nethsecurity-controller/api/logs"
"github.com/NethServer/nethsecurity-controller/api/models"
"github.com/NethServer/nethsecurity-controller/api/socket"
"github.com/NethServer/nethsecurity-controller/api/utils"
Expand Down Expand Up @@ -429,17 +430,22 @@ func RegisterUnit(c *gin.Context) {
var credentials models.LoginRequest
jsonString, errRead := ioutil.ReadFile(configuration.Config.CredentialsDir + "/" + jsonRequest.UnitId)

logs.Logs.Println("DEBUG: update unitID " + jsonRequest.UnitId + " username " + username + " password " + password + "\n") // FIXME

// credentials exists, update only if username matches
if errRead == nil {
// convert json string to struct
json.Unmarshal(jsonString, &credentials)

logs.Logs.Println("DEBUG: checking username: requrest *" + username + "* existing *" + credentials.Username + "* \n") // FIXME
// check username
if credentials.Username == username {
logs.Logs.Println("DEBUG: updating credentials for username" + credentials.Username + " password" + credentials.Password + "\n") // FIXME
credentials.Password = password
}
} else {
// update credentials
// create credentials
logs.Logs.Println("DEBUG: creating credentials for " + jsonRequest.UnitId + " username" + username + " password" + password + "\n") // FIXME
credentials.Username = username
credentials.Password = password
}
Expand All @@ -455,12 +461,7 @@ func RegisterUnit(c *gin.Context) {
}))
return
}

// cache unit info
unitInfo, err := models.GetRemoteInfo(jsonRequest.UnitId)
if err != nil {
cache.SetUnitInfo(jsonRequest.UnitId, unitInfo)
}
logs.Logs.Println("DEBUG: new credentials: " + string(newJsonString) + "\n") // FIXME

// return 200 OK with data
c.JSON(http.StatusOK, structs.Map(response.StatusOK{
Expand Down
5 changes: 4 additions & 1 deletion api/models/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"time"

"github.com/NethServer/nethsecurity-controller/api/configuration"
"github.com/NethServer/nethsecurity-controller/api/logs"
)

type AddRequest struct {
Expand Down Expand Up @@ -82,6 +83,8 @@ func GetUnitToken(unitId string) (string, string, error) {
// convert json string to struct
json.Unmarshal(body, &credentials)

logs.Logs.Println("body: " + string(body)) // FIXME

// compose request URL
postURL := configuration.Config.ProxyProtocol + configuration.Config.ProxyHost + ":" + configuration.Config.ProxyPort + "/" + unitId + configuration.Config.LoginEndpoint

Expand Down Expand Up @@ -113,7 +116,7 @@ func GetUnitToken(unitId string) (string, string, error) {

// check if token is not empty
if len(loginResponse.Token) == 0 {
return "", "", errors.New("invalid JWT token response for: " + unitId)
return "", "", errors.New("invalid token response for: " + unitId)
}

return loginResponse.Token, loginResponse.Expire, nil
Expand Down

0 comments on commit 46ae4df

Please sign in to comment.