Skip to content

Commit c10da46

Browse files
authored
fix: Various fixes and improvements (#616)
* ask for gcp project id instead of name * list subscription locations * update messages * remove splitn contract * ask only for subdomain * survey improvements * survey improvements * lint
1 parent 09b186b commit c10da46

File tree

12 files changed

+73
-151
lines changed

12 files changed

+73
-151
lines changed

go.mod

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ require (
1515
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute v1.0.0
1616
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.2.0
1717
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage v1.6.0
18+
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/subscription/armsubscription v1.2.0
1819
github.com/Azure/azure-storage-blob-go v0.15.0
1920
github.com/Masterminds/sprig/v3 v3.3.0
2021
github.com/Yamashou/gqlgenc v0.30.2
@@ -28,17 +29,12 @@ require (
2829
github.com/gofrs/flock v0.12.1
2930
github.com/google/go-github/v45 v45.2.0
3031
github.com/hashicorp/go-bexpr v0.1.14
31-
github.com/hashicorp/go-retryablehttp v0.7.7
32-
github.com/hashicorp/terraform-plugin-sdk/v2 v2.35.0
33-
github.com/joho/godotenv v1.5.1
3432
github.com/ktrysmt/go-bitbucket v0.9.81
3533
github.com/likexian/doh v0.7.1
36-
github.com/linode/linodego v1.44.1
3734
github.com/mikesmitty/edkey v0.0.0-20170222072505-3356ea4e686a
3835
github.com/mitchellh/go-homedir v1.1.0
3936
github.com/mitchellh/mapstructure v1.5.0
4037
github.com/olekukonko/tablewriter v0.0.5
41-
github.com/packethost/packngo v0.31.0
4238
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
4339
github.com/pluralsh/console/go/client v1.27.1
4440
github.com/pluralsh/console/go/controller v0.0.0-20250131003334-70da5fba4a49
@@ -115,7 +111,6 @@ require (
115111
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
116112
github.com/go-gorp/gorp/v3 v3.1.0 // indirect
117113
github.com/go-logr/stdr v1.2.2 // indirect
118-
github.com/go-resty/resty/v2 v2.16.2 // indirect
119114
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
120115
github.com/google/gnostic-models v0.6.9 // indirect
121116
github.com/google/s2a-go v0.1.9 // indirect
@@ -124,7 +119,7 @@ require (
124119
github.com/gorilla/websocket v1.5.3 // indirect
125120
github.com/hashicorp/errwrap v1.1.0 // indirect
126121
github.com/hashicorp/go-multierror v1.1.1 // indirect
127-
github.com/hashicorp/go-uuid v1.0.3 // indirect
122+
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
128123
github.com/kylelemons/godebug v1.1.0 // indirect
129124
github.com/likexian/gokit v0.25.15 // indirect
130125
github.com/mitchellh/pointerstructure v1.2.1 // indirect
@@ -156,7 +151,6 @@ require (
156151
google.golang.org/genproto/googleapis/api v0.0.0-20250106144421-5f5ef82da422 // indirect
157152
google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422 // indirect
158153
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
159-
gopkg.in/ini.v1 v1.67.0 // indirect
160154
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7 // indirect
161155
)
162156

@@ -210,9 +204,6 @@ require (
210204
github.com/gosuri/uitable v0.0.4 // indirect
211205
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
212206
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
213-
github.com/hashicorp/go-hclog v1.6.3 // indirect
214-
github.com/hashicorp/logutils v1.0.0 // indirect
215-
github.com/hashicorp/terraform-plugin-log v0.9.0 // indirect
216207
github.com/huandu/xstrings v1.5.0 // indirect
217208
github.com/inconshreveable/mousetrap v1.1.0 // indirect
218209
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
@@ -234,7 +225,6 @@ require (
234225
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
235226
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
236227
github.com/mitchellh/copystructure v1.2.0 // indirect
237-
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
238228
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
239229
github.com/mitchellh/reflectwalk v1.0.2 // indirect
240230
github.com/moby/locker v1.0.1 // indirect
@@ -257,7 +247,7 @@ require (
257247
github.com/rivo/uniseg v0.4.7 // indirect
258248
github.com/rubenv/sql-migrate v1.7.1 // indirect
259249
github.com/russross/blackfriday/v2 v2.1.0 // indirect
260-
github.com/schollz/progressbar/v3 v3.18.0 // indirect
250+
github.com/schollz/progressbar/v3 v3.18.0
261251
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
262252
github.com/shopspring/decimal v1.4.0 // indirect
263253
github.com/sirupsen/logrus v1.9.3 // indirect

go.sum

Lines changed: 2 additions & 41 deletions
Large diffs are not rendered by default.

pkg/client/plural.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (p *Plural) HandleInit(c *cli.Context) error {
159159
return err
160160
}
161161

162-
if !git && common.Affirm("you're attempting to setup plural outside a git repository. would you like us to set one up for you here?", "PLURAL_INIT_AFFIRM_SETUP_REPO") {
162+
if !git && common.Affirm("You're attempting to setup plural outside a git repository. Would you like us to set one up for you here?", "PLURAL_INIT_AFFIRM_SETUP_REPO") {
163163
repo, err = scm.Setup()
164164
if err != nil {
165165
return err

pkg/common/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func postLogin(conf *config.Config, client api.Client, c *cli.Context, persist b
8080
}
8181

8282
conf.Email = me.Email
83-
fmt.Printf("\nlogged in as %s!\n", me.Email)
83+
fmt.Printf("\nLogged in as %s!\n", me.Email)
8484

8585
saEmail := c.String("service-account")
8686
if saEmail != "" {

pkg/manifest/manifest.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,21 @@ func (man *Manifest) Write(path string) error {
9292
}
9393

9494
func (pMan *ProjectManifest) Configure(cloud bool, cluster string) Writer {
95-
utils.Highlight("\nLet's get some final information about your workspace set up\n\n")
96-
9795
pMan.BucketPrefix = cluster
9896
pMan.Bucket = fmt.Sprintf("plrl-cloud-%s", cluster)
9997

10098
if !cloud {
101-
res, _ := utils.ReadAlphaNum("Give us a unique, memorable string to use for bucket naming, eg an abbreviation for your company: ")
102-
pMan.BucketPrefix = res
103-
pMan.Bucket = fmt.Sprintf("%s-tf-state", res)
99+
answer := ""
100+
input := &survey.Input{Message: "Enter a unique, memorable string to use for bucket naming, e.g. an abbreviation for your company:"}
101+
if err := survey.AskOne(input, &answer, survey.WithValidator(func(val interface{}) error {
102+
res, _ := val.(string)
103+
return utils.ValidateRegex(res, "[a-z][0-9\\-a-z]+", "String can only contain alphanumeric characters or hyphens")
104+
})); err != nil {
105+
return nil
106+
}
107+
108+
pMan.BucketPrefix = answer
109+
pMan.Bucket = fmt.Sprintf("%s-tf-state", answer)
104110
if err := pMan.ConfigureNetwork(); err != nil {
105111
return nil
106112
}
@@ -113,20 +119,17 @@ func (pMan *ProjectManifest) ConfigureNetwork() error {
113119
return nil
114120
}
115121

116-
utils.Highlight("\nOk, let's get your network configuration set up now...\n")
117-
118-
modifier := ", must be a subdomain under onplural.sh"
119-
120122
subdomain := ""
121-
input := &survey.Input{Message: fmt.Sprintf("\nWhat do you want to use as your domain%s: ", modifier)}
123+
input := &survey.Input{Message: fmt.Sprintf("Enter subdomain of %s domain that you want to use:", pluralDomain)}
122124
if err := survey.AskOne(input, &subdomain, survey.WithValidator(func(val interface{}) error {
123125
res, _ := val.(string)
124-
if err := utils.ValidateDns(res); err != nil {
125-
return err
126-
}
127126

128127
if !strings.HasSuffix(res, pluralDomain) {
129-
return fmt.Errorf("Not an onplural.sh domain")
128+
res += "." + pluralDomain
129+
}
130+
131+
if err := utils.ValidateDns(res); err != nil {
132+
return err
130133
}
131134

132135
client := api.NewClient()

pkg/provider/azure.go

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute"
2020
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
2121
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage"
22+
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/subscription/armsubscription"
2223
"github.com/Azure/azure-storage-blob-go/azblob"
2324
v1 "k8s.io/api/core/v1"
2425

@@ -50,10 +51,15 @@ type ContainerClient interface {
5051
Create(ctx context.Context, metadata azblob.Metadata, publicAccessType azblob.PublicAccessType) (*azblob.ContainerCreateResponse, error)
5152
}
5253

54+
type SubscriptionClient interface {
55+
NewListLocationsPager(subscriptionID string, options *armsubscription.SubscriptionsClientListLocationsOptions) *runtime.Pager[armsubscription.SubscriptionsClientListLocationsResponse]
56+
}
57+
5358
type ClientSet struct {
54-
Groups ResourceGroupClient
55-
Accounts AccountsClient
56-
Containers ContainerClient
59+
Subscriptions SubscriptionClient
60+
Groups ResourceGroupClient
61+
Accounts AccountsClient
62+
Containers ContainerClient
5763
}
5864

5965
func GetClientSet(subscriptionId string) (*ClientSet, error) {
@@ -62,6 +68,11 @@ func GetClientSet(subscriptionId string) (*ClientSet, error) {
6268
return nil, err
6369
}
6470

71+
subscriptionsClient, err := armsubscription.NewSubscriptionsClient(cred, nil)
72+
if err != nil {
73+
return nil, err
74+
}
75+
6576
resourceGroupClient, err := armresources.NewResourceGroupsClient(subscriptionId, cred, nil)
6677
if err != nil {
6778
return nil, err
@@ -73,8 +84,9 @@ func GetClientSet(subscriptionId string) (*ClientSet, error) {
7384
}
7485

7586
return &ClientSet{
76-
Groups: resourceGroupClient,
77-
Accounts: storageAccountsClient,
87+
Subscriptions: subscriptionsClient,
88+
Groups: resourceGroupClient,
89+
Accounts: storageAccountsClient,
7890
}, nil
7991
}
8092

@@ -88,34 +100,33 @@ type AzureProvider struct {
88100
clients *ClientSet
89101
}
90102

91-
var (
92-
azureRegions = []string{
93-
"eastus",
94-
"eastus2",
95-
"southcentralus",
96-
"westus2",
97-
"westus3",
98-
"australiaeast",
99-
"southeastasia",
100-
"northeurope",
101-
"swedencentral",
102-
"uksouth",
103-
"westeurope",
104-
"centralus",
105-
"southafricanorth",
106-
"centralindia",
107-
"eastasia",
108-
"japaneast",
109-
"koreacentral",
110-
"canadacentral",
111-
"francecentral",
112-
"germanywestcentral",
113-
"norwayeast",
114-
"brazilsouth",
103+
func mkAzure(conf config.Config) (prov *AzureProvider, err error) {
104+
subId, tenID, err := GetAzureAccount()
105+
if err != nil {
106+
return
107+
}
108+
109+
clients, err := GetClientSet(subId)
110+
if err != nil {
111+
return
112+
}
113+
114+
ctx := context.Background()
115+
locations := []string{}
116+
locationsPager := clients.Subscriptions.NewListLocationsPager(subId, nil)
117+
for locationsPager.More() {
118+
page, err := locationsPager.NextPage(ctx)
119+
if err != nil {
120+
return nil, err
121+
}
122+
123+
for _, v := range page.Value {
124+
if v != nil {
125+
locations = append(locations, *v.Name)
126+
}
127+
}
115128
}
116-
)
117129

118-
func mkAzure(conf config.Config) (prov *AzureProvider, err error) {
119130
var resp struct {
120131
Cluster string
121132
Storage string
@@ -130,17 +141,17 @@ func mkAzure(conf config.Config) (prov *AzureProvider, err error) {
130141
},
131142
{
132143
Name: "storage",
133-
Prompt: &survey.Input{Message: "Enter the name of the storage account to use for your stage, must be globally unique or already owned by your subscription: "},
144+
Prompt: &survey.Input{Message: "Enter the name of the storage account to use for your stage, must be globally unique or already owned by your subscription:"},
134145
Validate: utils.ValidateStorageAccountName,
135146
},
136147
{
137148
Name: "region",
138-
Prompt: &survey.Select{Message: "Enter the region you want to deploy to:", Default: "eastus", Options: azureRegions},
149+
Prompt: &survey.Select{Message: "Enter the region you want to deploy to:", Default: "eastus", Options: locations},
139150
Validate: survey.Required,
140151
},
141152
{
142153
Name: "resource",
143-
Prompt: &survey.Input{Message: "Enter the name of the resource group to use as default: "},
154+
Prompt: &survey.Input{Message: "Enter the name of the resource group to use:"},
144155
Validate: utils.ValidateResourceGroupName,
145156
},
146157
}
@@ -150,16 +161,6 @@ func mkAzure(conf config.Config) (prov *AzureProvider, err error) {
150161
return
151162
}
152163

153-
subId, tenID, err := GetAzureAccount()
154-
if err != nil {
155-
return
156-
}
157-
158-
clients, err := GetClientSet(subId)
159-
if err != nil {
160-
return
161-
}
162-
163164
prov = &AzureProvider{
164165
resp.Cluster,
165166
resp.Resource,

pkg/provider/gcp.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ func getGCPSurvey() []*survey.Question {
108108
func setProject() (survey.Prompt, survey.Validator) {
109109
projects, err := getGcpProjects()
110110
if err != nil {
111-
return &survey.Input{Message: "Enter the name of its gcp project"}, utils.ValidateAlphaNumeric
111+
return &survey.Input{Message: "Enter the GCP project ID: "}, utils.ValidateAlphaNumeric
112112
}
113113

114-
return &survey.Select{Message: "Select the name of gcp project?", Options: projects}, survey.Required
114+
return &survey.Select{Message: "Select the GCP project ID:", Options: projects}, survey.Required
115115
}
116116

117117
func getGcpProjects() ([]string, error) {

pkg/provider/provider.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,12 @@ func GetProvider() (Provider, error) {
6969

7070
provider := ""
7171
prompt := &survey.Select{
72-
Message: "Select one of the following providers:",
72+
Message: "Select the cloud provider:",
7373
Options: providers.AvailableProviders,
7474
}
7575
if err := survey.AskOne(prompt, &provider, survey.WithValidator(survey.Required)); err != nil {
7676
return nil, err
7777
}
78-
utils.Success("Using provider %s\n", provider)
7978
return New(provider)
8079
}
8180

pkg/utils/print.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,6 @@ func ReadLine(prompt string) (string, error) {
1919
return strings.TrimSpace(res), err
2020
}
2121

22-
func ReadAlphaNum(prompt string) (string, error) {
23-
val, err := ReadLine(prompt)
24-
if err != nil {
25-
return val, err
26-
}
27-
28-
return val, ValidateRegex(val, "[a-z][0-9\\-a-z]+", "String can only contain alphanumeric characters or hyphens")
29-
}
30-
31-
func ReadAlphaNumDefault(prompt string, def string) (string, error) {
32-
result, err := ReadAlphaNum(fmt.Sprintf("%s [%s]: ", prompt, def))
33-
if result == "" {
34-
return def, nil
35-
}
36-
37-
return result, err
38-
}
39-
4022
func ReadLineDefault(prompt string, def string) (string, error) {
4123
result, err := ReadLine(fmt.Sprintf("%s [%s]: ", prompt, def))
4224
if result == "" {

pkg/wkspace/validator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func Preflight() (bool, error) {
1717
return true, utils.HighlightError(fmt.Errorf("%s not installed", req))
1818
}
1919
}
20-
fmt.Print("\ntesting if git ssh is properly configured ")
20+
fmt.Print("\nTesting if git ssh is properly configured...")
2121
if err := checkGitSSH(); err != nil {
2222
return true, err
2323
}

0 commit comments

Comments
 (0)