Skip to content

Commit

Permalink
methods. expose private key in GET /accounts/ssh-keys
Browse files Browse the repository at this point in the history
  • Loading branch information
edospadoni committed Mar 18, 2024
1 parent 81fd428 commit b459129
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 196 deletions.
6 changes: 0 additions & 6 deletions api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,6 @@ func main() {
units.POST("", methods.AddUnit)
units.DELETE("/:unit_id", methods.DeleteUnit)
}

// web ssh APIs
webssh := api.Group("/webssh")
{
webssh.POST("", methods.GetWebSSH)
}
}

// handle missing endpoint
Expand Down
19 changes: 16 additions & 3 deletions api/methods/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,22 @@ func GetSSHKeys(c *gin.Context) {
// get path for ssh keys
keysPath := configuration.Config.DataDir + "/" + username + ".key"

// read key
keyPrivate, err := os.ReadFile(keysPath)
if err != nil {
c.JSON(http.StatusBadRequest, structs.Map(response.StatusBadRequest{
Code: 400,
Message: "access ssh private key failed",
Data: err.Error(),
}))
}

// read key.pub
keyPub, err := os.ReadFile(keysPath + ".pub")
if err != nil {
c.JSON(http.StatusBadRequest, structs.Map(response.StatusBadRequest{
Code: 400,
Message: "access ssh directory keys file failed",
Message: "access ssh public key failed",
Data: err.Error(),
}))
}
Expand All @@ -301,7 +311,10 @@ func GetSSHKeys(c *gin.Context) {
c.JSON(http.StatusOK, structs.Map(response.StatusOK{
Code: 200,
Message: "success",
Data: gin.H{"key.pub": strings.TrimSuffix(string(keyPub), "\n")},
Data: gin.H{
"key_pub": strings.TrimSuffix(string(keyPub), "\n"),
"key": strings.TrimSuffix(string(keyPrivate), "\n"),
},
}))
}

Expand Down Expand Up @@ -348,6 +361,6 @@ func AddSSHKeys(c *gin.Context) {
c.JSON(http.StatusOK, structs.Map(response.StatusOK{
Code: 200,
Message: "success",
Data: gin.H{"key.pub": strings.TrimSuffix(string(keyPub), "\n")},
Data: gin.H{"key_pub": strings.TrimSuffix(string(keyPub), "\n")},
}))
}
186 changes: 0 additions & 186 deletions api/methods/webssh.go

This file was deleted.

2 changes: 1 addition & 1 deletion api/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func GetUnit(unitId string) (models.Unit, error) {
// loop rows
var result models.Unit
for rows.Next() {
if err := rows.Scan(&result.ID, &result.Name, &result.Version, &result.SubscriptionType, &result.SystemID); err != nil {
if err := rows.Scan(&result.ID, &result.Name, &result.Version, &result.SubscriptionType, &result.SystemID, &result.Created); err != nil {
logs.Logs.Println("[ERR][STORAGE][GET_UNIT] error in query row extraction" + err.Error())
}
}
Expand Down

0 comments on commit b459129

Please sign in to comment.