Skip to content

Commit

Permalink
api: remove deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
gsanchietti committed Aug 22, 2024
1 parent b1c787e commit 65142d4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
4 changes: 2 additions & 2 deletions api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
package main

import (
"io/ioutil"
"io"
"net/http"

"github.com/fatih/structs"
Expand Down Expand Up @@ -61,7 +61,7 @@ func main() {

// disable log to stdout when running in release mode
if gin.Mode() == gin.ReleaseMode {
gin.DefaultWriter = ioutil.Discard
gin.DefaultWriter = io.Discard
}

// init routers
Expand Down
5 changes: 2 additions & 3 deletions api/methods/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
package methods

import (
"io/ioutil"
"os"
"strings"

Expand All @@ -19,7 +18,7 @@ import (

func CheckTokenValidation(username string, token string) bool {
// read whole file
secrestListB, err := ioutil.ReadFile(configuration.Config.TokensDir + "/" + username)
secrestListB, err := os.ReadFile(configuration.Config.TokensDir + "/" + username)
if err != nil {
return false
}
Expand All @@ -43,7 +42,7 @@ func SetTokenValidation(username string, token string) bool {

func DelTokenValidation(username string, token string) bool {
// read whole file
secrestListB, errR := ioutil.ReadFile(configuration.Config.TokensDir + "/" + username)
secrestListB, errR := os.ReadFile(configuration.Config.TokensDir + "/" + username)
if errR != nil {
return false
}
Expand Down
5 changes: 2 additions & 3 deletions api/methods/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"bytes"
"encoding/json"
"errors"
"io/ioutil"
"net/http"
"os"
"os/exec"
Expand Down Expand Up @@ -399,7 +398,7 @@ func RegisterUnit(c *gin.Context) {

// read credentials from file
var credentials models.LoginRequest
jsonString, errRead := ioutil.ReadFile(configuration.Config.CredentialsDir + "/" + jsonRequest.UnitId)
jsonString, errRead := os.ReadFile(configuration.Config.CredentialsDir + "/" + jsonRequest.UnitId)

// credentials exists, update only if username matches
if errRead == nil {
Expand Down Expand Up @@ -557,7 +556,7 @@ func getUnitToken(unitId string) (string, string, error) {

// read credentials
var credentials models.LoginRequest
body, err := ioutil.ReadFile(configuration.Config.CredentialsDir + "/" + unitId)
body, err := os.ReadFile(configuration.Config.CredentialsDir + "/" + unitId)
if err != nil {
return "", "", errors.New("cannot open credentials file for: " + unitId)
}
Expand Down
7 changes: 3 additions & 4 deletions api/middleware/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"bytes"
"encoding/json"
"io"
"io/ioutil"
"net/http"
"os"
"strings"
Expand Down Expand Up @@ -153,16 +152,16 @@ func InitJWT() *jwt.GinJWTMiddleware {
// extract body
var buf bytes.Buffer
tee := io.TeeReader(c.Request.Body, &buf)
body, _ := ioutil.ReadAll(tee)
c.Request.Body = ioutil.NopCloser(&buf)
body, _ := io.ReadAll(tee)
c.Request.Body = io.NopCloser(&buf)

// convert to map and flat it
var jsonDyn map[string]interface{}
json.Unmarshal(body, &jsonDyn)
in, _ := flat.Flatten(jsonDyn, nil)

// search for sensitve data, in sensitive list
for k, _ := range in {
for k := range in {
for _, s := range configuration.Config.SensitiveList {
if strings.Contains(strings.ToLower(k), strings.ToLower(s)) {
in[k] = "XXX"
Expand Down

0 comments on commit 65142d4

Please sign in to comment.