Skip to content
Prev Previous commit
Next Next commit
minor fixes for api
  • Loading branch information
Abhishek Singh authored and Abhishek Singh committed Oct 28, 2025
commit 131da61a169143c7d053d42db0e5bde949e64c74
33 changes: 20 additions & 13 deletions adapters/vault/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Vault struct {
siteURL string
cryptoManager *cryptography.CryptoManager
timeOut time.Duration
vaultSecrets []*models.Secret
}

// NewVault creates a new Vault with options
Expand Down Expand Up @@ -83,7 +84,8 @@ func NewVault(opts ...Option) *Vault {
}

// Check if at least one client is usable
if v.infisicalClient == nil && v.awsClient.GetSecretsManagerClient() == nil && v.awsClient.GetSSMClient() == nil {
if v.infisicalClient == nil &&
v.awsClient.GetSecretsManagerClient() == nil && v.awsClient.GetSSMClient() == nil {
helpers.Println(constant.ERROR, "no secret backend clients could be initialized")
os.Exit(1)
}
Expand Down Expand Up @@ -143,8 +145,8 @@ func (v *Vault) retrieveInfisicalSecrets() ([]*models.Secret, error) {
return nil, fmt.Errorf("failed to list secrets: %w", err)
}
var secretList []*models.Secret
for _, secret := range secrets {
secretList = append(secretList, &secret)
for i := range secrets {
secretList = append(secretList, &secrets[i])
}
return secretList, nil
}
Expand Down Expand Up @@ -220,13 +222,16 @@ func (v *Vault) FetchVaultValue(key string) (string, error) {

case strings.HasPrefix(key, InfisicalPrefix):
// source = "Infisical"
if len(v.vaultSecrets) == 0 {
var err error
v.vaultSecrets, err = v.retrieveInfisicalSecrets()
if err != nil {
return "", err
}
}
actualKey = strings.TrimPrefix(key, InfisicalPrefix)
// helpers.Println(constant.DEBUG, "Fetching from", source, "(explicit prefix) - Key:", actualKey)
secrets, err := v.retrieveInfisicalSecrets()
if err != nil {
return "", err
}
return v.retrieveInfisicalSecret(actualKey, secrets)
return v.retrieveInfisicalSecret(actualKey, v.vaultSecrets)
case strings.HasPrefix(key, AWSKMSPrefix):
// source = "AWS KMS"
actualKey = strings.TrimPrefix(key, AWSKMSPrefix)
Expand All @@ -239,12 +244,14 @@ func (v *Vault) FetchVaultValue(key string) (string, error) {
if v.defaultSource == "aws" {
return v.retrieveAWSParameterStoreSecret(ctx, actualKey, true)
}
// helpers.Println(constant.DEBUG, "Fetching from", source, "(default) - Key:", actualKey)
secrets, err := v.retrieveInfisicalSecrets()
if err != nil {
return "", err
if len(v.vaultSecrets) == 0 {
var err error
v.vaultSecrets, err = v.retrieveInfisicalSecrets()
if err != nil {
return "", err
}
}
return v.retrieveInfisicalSecret(actualKey, secrets)
return v.retrieveInfisicalSecret(actualKey, v.vaultSecrets)
}
}

Expand Down
5 changes: 3 additions & 2 deletions utils/timeutil/timeutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,10 @@ func (t *TimeWrapper) AddDate(years, months, days int) *TimeWrapper {

// GetCurrentTimeIn returns current time in given timezone
func GetCurrentTimeIn(timezone string) time.Time {
now := Now()
location, err := LoadLocation(timezone)
if err != nil {
return time.Now().UTC()
return now.Time
}
return Now().In(location).Time
return now.In(location).Time
}
16 changes: 16 additions & 0 deletions utils/types/pgtype.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package types

import (
"fmt"
"time"

"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
)

Expand Down Expand Up @@ -53,3 +55,17 @@ func ToTimestamp(value time.Time) pgtype.Timestamp {
Valid: true,
}
}

func PGTypeToUUID(p pgtype.UUID) (uuid.UUID, error) {
if !p.Valid {
return uuid.Nil, fmt.Errorf("uuid is null")
}
return uuid.UUID(p.Bytes), nil
}

func UUIDToPGType(u uuid.UUID) pgtype.UUID {
return pgtype.UUID{
Bytes: u,
Valid: true,
}
}