@@ -12,7 +12,6 @@ import (
1212 "strings"
1313 "time"
1414
15- "github.com/AlecAivazis/survey/v2"
1615 "github.com/Azure/azure-sdk-for-go/sdk/azcore"
1716 "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
1817 "github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
@@ -35,39 +34,12 @@ import (
3534 pluralerr "github.com/pluralsh/plural-cli/pkg/utils/errors"
3635)
3736
38- // ResourceGroupClient is the subset of functions we need from armresources.VirtualResourceGroupsClient;
39- // this interface is purely here for allowing unit tests.
40- type ResourceGroupClient interface {
41- CreateOrUpdate (ctx context.Context , resourceGroupName string , parameters armresources.ResourceGroup , options * armresources.ResourceGroupsClientCreateOrUpdateOptions ) (armresources.ResourceGroupsClientCreateOrUpdateResponse , error )
42- Get (ctx context.Context , resourceGroupName string , options * armresources.ResourceGroupsClientGetOptions ) (armresources.ResourceGroupsClientGetResponse , error )
43- }
44-
45- type AccountsClient interface {
46- GetProperties (ctx context.Context , resourceGroupName string , accountName string , options * armstorage.AccountsClientGetPropertiesOptions ) (armstorage.AccountsClientGetPropertiesResponse , error )
47- BeginCreate (ctx context.Context , resourceGroupName string , accountName string , parameters armstorage.AccountCreateParameters , options * armstorage.AccountsClientBeginCreateOptions ) (* runtime.Poller [armstorage.AccountsClientCreateResponse ], error )
48- NewListPager (options * armstorage.AccountsClientListOptions ) * runtime.Pager [armstorage.AccountsClientListResponse ]
49- ListKeys (ctx context.Context , resourceGroupName string , accountName string , options * armstorage.AccountsClientListKeysOptions ) (armstorage.AccountsClientListKeysResponse , error )
50- }
51-
52- type ContainerClient interface {
53- GetProperties (ctx context.Context , ac azblob.LeaseAccessConditions ) (* azblob.ContainerGetPropertiesResponse , error )
54- Create (ctx context.Context , metadata azblob.Metadata , publicAccessType azblob.PublicAccessType ) (* azblob.ContainerCreateResponse , error )
55- }
56-
57- type SubscriptionClient interface {
58- NewListLocationsPager (subscriptionID string , options * armsubscription.SubscriptionsClientListLocationsOptions ) * runtime.Pager [armsubscription.SubscriptionsClientListLocationsResponse ]
59- }
60-
61- type ZonesClient interface {
62- NewListByResourceGroupPager (resourceGroupName string , options * armdns.ZonesClientListByResourceGroupOptions ) * runtime.Pager [armdns.ZonesClientListByResourceGroupResponse ]
63- }
64-
6537type ClientSet struct {
66- Subscriptions SubscriptionClient
67- Groups ResourceGroupClient
68- Accounts AccountsClient
69- Containers ContainerClient
70- Zones ZonesClient
38+ Subscriptions * armsubscription. SubscriptionsClient
39+ Groups * armresources. ResourceGroupsClient
40+ Accounts * armstorage. AccountsClient
41+ Zones * armdns. ZonesClient
42+ Containers * azblob. ContainerURL
7143}
7244
7345func GetClientSet (subscriptionId string ) (* ClientSet , error ) {
@@ -135,65 +107,32 @@ func mkAzure(conf config.Config) (prov *AzureProvider, err error) {
135107 }
136108
137109 ctx := context .Background ()
138- locations := []string {}
139- locationsPager := clients .Subscriptions .NewListLocationsPager (subId , nil )
140- for locationsPager .More () {
141- page , err := locationsPager .NextPage (ctx )
142- if err != nil {
143- return nil , err
144- }
145110
146- for _ , v := range page .Value {
147- if v != nil {
148- locations = append (locations , * v .Name )
149- }
150- }
111+ cluster , err := askCluster ()
112+ if err != nil {
113+ return
151114 }
152115
153- var resp struct {
154- Cluster string
155- Storage string
156- Region string
157- Resource string
116+ location , err := askAzureLocation (ctx , clients .Subscriptions , subId )
117+ if err != nil {
118+ return
158119 }
159- var azureSurvey = []* survey.Question {
160- {
161- Name : "cluster" ,
162- Prompt : & survey.Input {Message : "Enter the name of your cluster:" , Default : clusterFlag },
163- Validate : validCluster ,
164- },
165- {
166- Name : "storage" ,
167- 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:" },
168- Validate : utils .ValidateStorageAccountName ,
169- },
170- {
171- Name : "region" ,
172- Prompt : & survey.Select {Message : "Enter the region you want to deploy to:" , Default : "eastus" , Options : locations },
173- Validate : survey .Required ,
174- },
175- {
176- Name : "resource" ,
177- Prompt : & survey.Input {Message : "Enter the name of the resource group to use:" },
178- Validate : utils .ValidateResourceGroupName ,
179- },
120+
121+ resourceGroup , err := askAzureResourceGroup (ctx , clients .Groups )
122+ if err != nil {
123+ return
180124 }
181125
182- err = survey . Ask ( azureSurvey , & resp )
126+ storageAccount , err := askAzureStorageAccount ( ctx , clients . Accounts )
183127 if err != nil {
184128 return
185129 }
186130
187- prov = & AzureProvider {
188- resp .Cluster ,
189- resp .Resource ,
131+ prov = & AzureProvider {cluster ,
132+ resourceGroup ,
190133 "" ,
191- resp .Region ,
192- map [string ]interface {}{
193- "SubscriptionId" : subId ,
194- "TenantId" : tenID ,
195- "StorageAccount" : resp .Storage ,
196- },
134+ location ,
135+ map [string ]any {"SubscriptionId" : subId , "TenantId" : tenID , "StorageAccount" : storageAccount },
197136 nil ,
198137 clients ,
199138 }
@@ -452,7 +391,7 @@ func (az *AzureProvider) upsertStorageContainer(acc armstorage.Account, name str
452391 u , _ := url .Parse (fmt .Sprintf (`https://%s.blob.core.windows.net` , accountName ))
453392 service := azblob .NewServiceURL (* u , p )
454393 containerClient := service .NewContainerURL (name )
455- az .clients .Containers = containerClient
394+ az .clients .Containers = & containerClient
456395 }
457396
458397 _ , err = az .clients .Containers .GetProperties (ctx , azblob.LeaseAccessConditions {})
0 commit comments