Skip to content

Commit

Permalink
feat(backup/source/dummy): Add DummySource (for devel/testing purposes)
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejsika committed Jan 28, 2023
1 parent 97cbb52 commit 6f298ed
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
24 changes: 24 additions & 0 deletions backup/source/dummy/dummy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package dummy

import (
"bytes"
"fmt"

"github.com/sikalabs/tergum/backup_output"
)

type DummySource struct {
Content string `yaml:"Content"`
}

func (s DummySource) Validate() error {
if s.Content == "" {
return fmt.Errorf("DummySource need to have a Content")
}
return nil
}

func (s DummySource) Backup() (backup_output.BackupOutput, error) {
out := bytes.NewReader([]byte(s.Content))
return backup_output.BackupOutput{Data: out}, nil
}
16 changes: 16 additions & 0 deletions backup/source/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/sikalabs/tergum/backup/source/dir"
"github.com/sikalabs/tergum/backup/source/dummy"
"github.com/sikalabs/tergum/backup/source/ftp"
"github.com/sikalabs/tergum/backup/source/kubernetes"
"github.com/sikalabs/tergum/backup/source/kubernetes_tls_secret"
Expand Down Expand Up @@ -33,6 +34,7 @@ type Source struct {
FTP *ftp.FTPSource `yaml:"FTP"`
Redis *redis.RedisSource `yaml:"Redis"`
Vault *vault.VaultSource `yaml:"Vault"`
Dummy *dummy.DummySource `yaml:"Dummy"`
}

func (s Source) Validate() error {
Expand Down Expand Up @@ -101,6 +103,11 @@ func (s Source) Validate() error {
return p.Validate()
}

if s.Dummy != nil {
p := *s.Dummy
return p.Validate()
}

return fmt.Errorf("source/validate: no source detected")
}

Expand Down Expand Up @@ -170,6 +177,11 @@ func (s Source) Backup() (backup_output.BackupOutput, error) {
return p.Backup()
}

if s.Dummy != nil {
p := *s.Dummy
return p.Backup()
}

return backup_output.BackupOutput{}, fmt.Errorf("source/backup: no source detected")
}

Expand Down Expand Up @@ -226,5 +238,9 @@ func (s Source) Name() string {
return "Vault"
}

if s.Dummy != nil {
return "Dummy"
}

return ""
}

0 comments on commit 6f298ed

Please sign in to comment.