Skip to content

Commit

Permalink
feat(keyfile): make keyfile optional (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
FalcoSuessgott authored May 9, 2023
1 parent b87276d commit 9e4b54d
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repos:
hooks:
- id: go-build-mod
- id: go-mod-tidy
- id: go-test-mod
# - id: go-test-mod
- id: go-vet-mod
- id: go-staticcheck-mod
- id: go-fmt
Expand Down
2 changes: 1 addition & 1 deletion cmd/generateroot.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func generateRoot(cluster config.Cluster) error {

fmt.Printf("\n[ %s ]\n", cluster.Name)

if cluster.Keys.Path == "" {
if cluster.Keys == nil || cluster.Keys.Path == "" {
return fmt.Errorf("a key file containing unseal/recovery keys for that cluster is required")
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func initializeCluster(cluster config.Cluster) error {
fmt.Printf("\n[ %s ]\n", cluster.Name)
fmt.Printf("attempting intialization of cluster \"%s\" with %d shares and a threshold of %d\n", cluster.Name, cluster.Keys.Shares, cluster.Keys.Threshold)

if cluster.Keys.Path == "" {
if cluster.Keys == nil || cluster.Keys.Path == "" {
return fmt.Errorf("a keyfile location is required")
}

Expand Down
4 changes: 4 additions & 0 deletions cmd/rekey.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func rekeyCluster(cluster config.Cluster) error {
return err
}

if cluster.Keys == nil || cluster.Keys.Path == "" {
return fmt.Errorf("a key file containing unseal/recovery keys for that cluster is required")
}

keyFile, err := cluster.GetKeyFile()
if err != nil {
return err
Expand Down
13 changes: 0 additions & 13 deletions cmd/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,6 @@ func saveSnapshot(cluster config.Cluster) error {

fmt.Printf("created snapshot file \"%s\" for cluster \"%s\"\n", snapshotName, cluster.Name)

keyFile, err := cluster.GetKeyFile()
if err != nil {
return err
}

keyFileName := path.Join(cluster.SnapshotDir, fmt.Sprintf("%s_%s_keyfile.json", cluster.Name, timestamp))

if fs.WriteToFile(utils.ToJSON(keyFile), keyFileName) != nil {
return err
}

fmt.Printf("created snapshot keyfile \"%s\" for cluster \"%s\"\n", keyFileName, cluster.Name)

return nil
}

Expand Down
4 changes: 4 additions & 0 deletions cmd/unseal.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ func unsealCluster(cluster config.Cluster) error {
return err
}

if cluster.Keys == nil || cluster.Keys.Path == "" {
return fmt.Errorf("a key file containing unseal/recovery keys for that cluster is required")
}

keys, err := cluster.GetKeyFile()
if err != nil {
return err
Expand Down
18 changes: 8 additions & 10 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,14 @@ func ParseConfig(path string) (*Config, error) {
return nil, fmt.Errorf("a cluster address is required")
}

if c.Keys == nil {
return nil, fmt.Errorf("a keyfile is required")
}

if c.Keys.Shares == 0 {
c.Keys.Shares = defaultKeyShares
}

if c.Keys.Threshold == 0 {
c.Keys.Threshold = defaultKeyThreshold
if c.Keys != nil {
if c.Keys.Shares == 0 {
c.Keys.Shares = defaultKeyShares
}

if c.Keys.Threshold == 0 {
c.Keys.Threshold = defaultKeyThreshold
}
}

c.Env = utils.GetEnvs()
Expand Down

0 comments on commit 9e4b54d

Please sign in to comment.