implement read ifd from file

This commit is contained in:
William Banfield
2022-10-18 15:18:55 -04:00
parent 59b28e71a0
commit 5b98095ac3
2 changed files with 22 additions and 0 deletions

View File

@@ -1,8 +1,10 @@
package e2e
import (
"encoding/json"
"fmt"
"net"
"os"
)
// InfrastructureData contains the relevant information for a set of existing
@@ -42,3 +44,13 @@ func NewDockerInfrastructureData(m Manifest) (InfrastructureData, error) {
}
return ifd, nil
}
func InfrastructureDataFromFile(p string) (InfrastructureData, error) {
ifd := InfrastructureData{}
b, err := os.ReadFile(p)
err = json.Unmarshal(b, &ifd)
if err != nil {
return InfrastructureData{}, err
}
return ifd, nil
}

View File

@@ -2,6 +2,7 @@ package main
import (
"context"
"errors"
"fmt"
"math/rand"
"os"
@@ -59,6 +60,15 @@ func NewCLI() *CLI {
if err != nil {
return err
}
case "digital-ocean":
p, err := cmd.Flags().GetString("infrastructure-data")
if err != nil {
return err
}
if p == "" {
return errors.New("'--infrastructure-data' must be set when using the 'digital-ocean' infrastructure-type")
}
ifd, err = e2e.InfrastructureDataFromFile(p)
// TODO(williambanfield): add a section that implements the 'digital-ocean' infrastructure-type
default:
return fmt.Errorf("unknown infrastructure type '%s'", t)