uuid_driver.go 704 B

12345678910111213141516171819202122232425262728293031
  1. package preview
  2. import (
  3. "github.com/google/uuid"
  4. "github.com/porter-dev/switchboard/pkg/drivers"
  5. "github.com/porter-dev/switchboard/pkg/models"
  6. )
  7. type UUIDDriver struct {
  8. output map[string]interface{}
  9. }
  10. func NewUUIDDriver(resource *models.Resource, opts *drivers.SharedDriverOpts) (drivers.Driver, error) {
  11. return &BuildDriver{
  12. output: make(map[string]interface{}),
  13. }, nil
  14. }
  15. func (d *UUIDDriver) ShouldApply(resource *models.Resource) bool {
  16. return true
  17. }
  18. func (d *UUIDDriver) Apply(resource *models.Resource) (*models.Resource, error) {
  19. d.output["uuid"] = uuid.NewString()
  20. return resource, nil
  21. }
  22. func (d *UUIDDriver) Output() (map[string]interface{}, error) {
  23. return d.output, nil
  24. }