Use id file for init ip

This commit is contained in:
katexochen 2022-07-29 10:01:10 +02:00 committed by Paul Meyer
parent 7bbcc564bb
commit a859accf1f
4 changed files with 112 additions and 136 deletions

View file

@ -11,6 +11,7 @@ import (
"github.com/edgelesssys/constellation/internal/cloud/cloudprovider"
"github.com/edgelesssys/constellation/internal/constants"
"github.com/edgelesssys/constellation/internal/file"
"github.com/edgelesssys/constellation/internal/state"
"github.com/spf13/afero"
"github.com/spf13/cobra"
)
@ -101,6 +102,10 @@ func create(cmd *cobra.Command, creator cloudCreator, fileHandler file.Handler,
return err
}
if err := writeIPtoIDFile(fileHandler, state); err != nil {
return err
}
cmd.Println("Your Constellation cluster was created successfully.")
return nil
}
@ -198,10 +203,22 @@ func checkDirClean(fileHandler file.Handler) error {
if _, err := fileHandler.Stat(constants.MasterSecretFilename); !errors.Is(err, fs.ErrNotExist) {
return fmt.Errorf("file '%s' already exists in working directory. Constellation won't overwrite previous master secrets. Move it somewhere or delete it before creating a new cluster", constants.MasterSecretFilename)
}
if _, err := fileHandler.Stat(constants.ClusterIDsFileName); !errors.Is(err, fs.ErrNotExist) {
return fmt.Errorf("file '%s' already exists in working directory. Constellation won't overwrite previous cluster IDs. Move it somewhere or delete it before creating a new cluster", constants.ClusterIDsFileName)
}
return nil
}
func writeIPtoIDFile(fileHandler file.Handler, state state.ConstellationState) error {
ip := state.BootstrapperHost
if ip == "" {
return fmt.Errorf("bootstrapper ip not found")
}
idFile := clusterIDsFile{IP: ip}
return fileHandler.WriteJSON(constants.ClusterIDsFileName, idFile, file.OptNone)
}
// createCompletion handles the completion of the create command. It is frequently called
// while the user types arguments of the command to suggest completion.
func createCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {