This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
@@ -55,6 +56,36 @@ func (s *Secret) SaveSecret() (*Secret, error) {
|
|||||||
return s, nil
|
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) {
|
func SecretsGetAllowed(s *Secret, userId int) ([]UserSecret, error) {
|
||||||
// Query based on group
|
// 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
|
// 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
|
||||||
@@ -141,7 +172,9 @@ func SecretsGetAllowed(s *Secret, userId int) ([]UserSecret, error) {
|
|||||||
log.Printf("SecretsGetAllowedForGroup error parsing sql record : '%s'\n", err)
|
log.Printf("SecretsGetAllowedForGroup error parsing sql record : '%s'\n", err)
|
||||||
return secretResults, err
|
return secretResults, err
|
||||||
}
|
}
|
||||||
log.Printf("r: %v\n", r)
|
//log.Printf("r: %v\n", r)
|
||||||
|
debugPrint := printStructContents(&r, 0)
|
||||||
|
log.Println(debugPrint)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// Decrypt the secret
|
// Decrypt the secret
|
||||||
|
Reference in New Issue
Block a user