Skip to content

Commit

Permalink
fix: hide sensitive info when listing targets (#1289)
Browse files Browse the repository at this point in the history
Signed-off-by: Luka Brecic <[email protected]>
  • Loading branch information
lbrecic authored Oct 25, 2024
1 parent e5b360e commit eb32a37
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions pkg/api/controllers/target/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package target

import (
"encoding/json"
"fmt"
"net/http"

Expand All @@ -30,5 +31,40 @@ func ListTargets(ctx *gin.Context) {
return
}

for _, target := range targets {
p, err := server.ProviderManager.GetProvider(target.ProviderInfo.Name)
if err != nil {
target.Options = fmt.Sprintf("Error: %s", err.Error())
continue
}

manifest, err := (*p).GetTargetManifest()
if err != nil {
target.Options = fmt.Sprintf("Error: %s", err.Error())
continue
}

var opts map[string]interface{}
err = json.Unmarshal([]byte(target.Options), &opts)
if err != nil {
target.Options = fmt.Sprintf("Error: %s", err.Error())
continue
}

for name, property := range *manifest {
if property.InputMasked {
delete(opts, name)
}
}

updatedOptions, err := json.MarshalIndent(opts, "", " ")
if err != nil {
target.Options = fmt.Sprintf("Error: %s", err.Error())
continue
}

target.Options = string(updatedOptions)
}

ctx.JSON(200, targets)
}

0 comments on commit eb32a37

Please sign in to comment.