Skip to content

Commit

Permalink
feat(backup/source/consul): Add Consul backup source
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejsika committed Apr 12, 2023
1 parent 07e55c0 commit cc5f892
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
28 changes: 28 additions & 0 deletions backup/source/consul/vault.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package consul

import (
"fmt"

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

type ConsulSource struct {
Addr string `yaml:"Addr"`
Token string `yaml:"Token"`
}

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

func (s ConsulSource) Backup() (backup_output.BackupOutput, error) {
return backup_process_utils.BackupProcessHttpGetWithToken(
s.Addr+"/v1/snapshot",
"X-Consul-Token",
s.Token,
)
}
16 changes: 16 additions & 0 deletions backup/source/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package source
import (
"fmt"

"github.com/sikalabs/tergum/backup/source/consul"
"github.com/sikalabs/tergum/backup/source/dir"
"github.com/sikalabs/tergum/backup/source/dummy"
"github.com/sikalabs/tergum/backup/source/ftp"
Expand Down Expand Up @@ -37,6 +38,7 @@ type Source struct {
Vault *vault.VaultSource `yaml:"Vault"`
Dummy *dummy.DummySource `yaml:"Dummy"`
Gitlab *gitlab.GitlabSource `yaml:"Gitlab"`
Consul *consul.ConsulSource `yaml:"Consul"`
}

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

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

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

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

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

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

Expand Down Expand Up @@ -258,5 +270,9 @@ func (s Source) Name() string {
return "Gitlab"
}

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

return ""
}

0 comments on commit cc5f892

Please sign in to comment.