func (s Service) ValidateBox(ctx context.Context, r BoxRequest) error {
	if len(r.SecretIDs) == 0 {
		return fmt.Errorf("0 secrets provided")
	}
	secretIDs := []string{}
	errored := false
	for _, secretID := range r.SecretIDs {
		logger := s.logger.WithValues(log.Kv{"secret-id": secretID})
		pSecret, err := s.secretIDProcessor.ProcessID(ctx, secretID)
		if err != nil {
			logger.Errorf("Invalid secret: %s", err)
			errored = true
			continue
		}
		if pSecret == "" {
			continue
		}
		secretIDs = append(secretIDs, pSecret)
	}
	if errored {
		return fmt.Errorf("validation process failed")
	}
	if !r.Decrypt {
		return nil
	}
	privKeys, err := s.keyRepo.ListPrivateKeys(ctx)
	if err != nil {
		return fmt.Errorf("could not get private key: %w", err)
	}
	errored = false
	for _, secretID := range secretIDs {
		logger := s.logger.WithValues(log.Kv{"secret-id": secretID})
		err := s.procesSecret(ctx, privKeys.Items, secretID)
		if err != nil {
			logger.Errorf("Invalid secret: %s", err)
			errored = true
			continue
		}
	}
	if errored {
		return fmt.Errorf("validation process failed")
	}
	return nil
}
ValidateBox will validate secrets.
package validate
import (
	"context"
	"fmt"
	"github.com/slok/agebox/internal/log"
	"github.com/slok/agebox/internal/model"
	"github.com/slok/agebox/internal/secret/encrypt"
	"github.com/slok/agebox/internal/secret/process"
	"github.com/slok/agebox/internal/storage"
)
type ServiceConfig struct {
	KeyRepo           storage.KeyRepository
	SecretRepo        storage.SecretRepository
	Encrypter         encrypt.Encrypter
	SecretIDProcessor process.IDProcessor
	Logger            log.Logger
}
func (c *ServiceConfig) defaults() error {
	if c.KeyRepo == nil {
		return fmt.Errorf("keys repository is required")
	}
	if c.SecretRepo == nil {
		return fmt.Errorf("secret repository is required")
	}
	if c.Encrypter == nil {
		return fmt.Errorf("encrypter is required")
	}
	if c.SecretIDProcessor == nil {
		c.SecretIDProcessor = process.NoopIDProcessor
	}
	if c.Logger == nil {
		c.Logger = log.Noop
	}
	c.Logger = c.Logger.WithValues(log.Kv{"svc": "box.validate.Service"})
	return nil
}
type Service struct {
	keyRepo           storage.KeyRepository
	secretRepo        storage.SecretRepository
	encrypter         encrypt.Encrypter
	secretIDProcessor process.IDProcessor
	logger            log.Logger
}
func NewService(config ServiceConfig) (*Service, error) {
	err := config.defaults()
	if err != nil {
		return nil, fmt.Errorf("invalid configuration: %w", err)
	}
	return &Service{
		keyRepo:           config.KeyRepo,
		secretRepo:        config.SecretRepo,
		encrypter:         config.Encrypter,
		secretIDProcessor: config.SecretIDProcessor,
		logger:            config.Logger,
	}, nil
}
type BoxRequest struct {
	SecretIDs []string
	Decrypt   bool
}