Skip to content

Commit

Permalink
Print error when --project-id flag is not set for gce and packet
Browse files Browse the repository at this point in the history
Prints an error message prompting to set the --project-id flag
when using gce or packet as the provider
Fixes #52

Signed-off-by: Utsav Anand <utsavanand2@gmail.com>
  • Loading branch information
utsavanand2 authored and alexellis committed Feb 9, 2020
1 parent a03f5e2 commit d488f49
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ package cmd
import (
"encoding/base64"
"fmt"
"github.com/inlets/inletsctl/pkg/env"
"strconv"
"strings"
"time"

"github.com/inlets/inletsctl/pkg/env"

"github.com/inlets/inletsctl/pkg/names"
"github.com/inlets/inletsctl/pkg/provision"

Expand Down Expand Up @@ -126,24 +127,26 @@ func runCreate(cmd *cobra.Command, _ []string) error {

var secretKey string
var organisationID string
var projectID string
if provider == "scaleway" || provider == "ec2" {

var secretKeyErr error
secretKey, secretKeyErr = env.GetRequiredFileOrString(cmd.Flags(),
"secret-key-file",
"secret-key",
"INLETS_SECRET_KEY",
)
secretKey, secretKeyErr = getFileOrString(cmd.Flags(), "secret-key-file", "secret-key", true)
if secretKeyErr != nil {
return secretKeyErr
}

if provider == "scaleway" {
organisationID, _ = cmd.Flags().GetString("organisation-id")
if len(organisationID) == 0 {
return fmt.Errorf("--organisation-id cannot be empty")
return fmt.Errorf("--organisation-id flag must be set")
}
}
} else if provider == "gce" || provider == "packet" {
projectID, _ = cmd.Flags().GetString("project-id")
if len(projectID) == 0 {
return fmt.Errorf("--project-id flag must be set")
}
}

provisioner, err := getProvisioner(provider, accessToken, secretKey, organisationID, region)
Expand All @@ -162,8 +165,6 @@ func runCreate(cmd *cobra.Command, _ []string) error {

userData := makeUserdata(inletsToken, inletsControlPort, remoteTCP)

projectID, _ := cmd.Flags().GetString("project-id")

hostReq, err := createHost(provider, name, region, zone, projectID, userData, strconv.Itoa(inletsControlPort), pro)
if err != nil {
return err
Expand Down

0 comments on commit d488f49

Please sign in to comment.