one more update
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-01-09 16:56:00 +11:00
parent 43e0ecd1ce
commit d8b68f2815
3 changed files with 36 additions and 34 deletions

View File

@@ -9,7 +9,7 @@ import (
"fmt"
"io"
"log"
"reflect"
"smt/utils"
"strings"
"github.com/jmoiron/sqlx"
@@ -54,36 +54,6 @@ func (s *Secret) SaveSecret() (*Secret, error) {
return s, nil
}
func printStructContents(s interface{}, indentLevel int) string {
var result strings.Builder
val := reflect.ValueOf(s)
if val.Kind() == reflect.Ptr {
val = val.Elem()
}
typ := val.Type()
for i := 0; i < val.NumField(); i++ {
field := val.Field(i)
fieldType := typ.Field(i)
indent := strings.Repeat("\t", indentLevel)
result.WriteString(fmt.Sprintf("%s%s: ", indent, fieldType.Name))
switch field.Kind() {
case reflect.Struct:
result.WriteString("\n")
result.WriteString(printStructContents(field.Interface(), indentLevel+1))
default:
result.WriteString(fmt.Sprintf("%v\n", field.Interface()))
}
}
return result.String()
}
func SecretsGetAllowed(s *Secret, userId int) ([]UserSecret, error) {
// Query based on group
// SELECT users.UserId, users.GroupId, permissions.ReadOnly, permissions.SafeId, safes.SafeName, secrets.* FROM users INNER JOIN groups ON users.GroupId = groups.GroupId INNER JOIN permissions ON groups.GroupId = permissions.GroupId INNER JOIN safes on permissions.SafeId = safes.SafeId INNER JOIN secrets on secrets.SafeId = safes.SafeId WHERE users.UserId = 2
@@ -172,7 +142,7 @@ func SecretsGetAllowed(s *Secret, userId int) ([]UserSecret, error) {
return secretResults, err
}
//log.Printf("r: %v\n", r)
debugPrint := printStructContents(&r, 0)
debugPrint := utils.PrintStructContents(&r, 0)
log.Println(debugPrint)
// Don't decrypt the secrets in the results of this query