-
Notifications
You must be signed in to change notification settings - Fork 72
/
completions.go
115 lines (83 loc) · 3.79 KB
/
completions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package create
import (
"github.com/redhat-developer/app-services-cli/pkg/shared/accountmgmtutil"
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
"github.com/redhat-developer/app-services-cli/pkg/shared/remote"
"github.com/spf13/cobra"
)
// GetCloudProviderCompletionValues returns the list of supported cloud providers for creating a Kafka instance
// This is used in the cmd.RegisterFlagCompletionFunc for dynamic completion of --provider
func GetCloudProviderCompletionValues(f *factory.Factory) (validProviders []string, directive cobra.ShellCompDirective) {
validProviders, _ = GetEnabledCloudProviderNames(f)
return validProviders, cobra.ShellCompDirectiveNoSpace
}
// GetCloudProviderRegionCompletionValues returns the list of region IDs for a particular cloud provider
func GetCloudProviderRegionCompletionValues(f *factory.Factory, providerID string) (validRegions []string, directive cobra.ShellCompDirective) {
if providerID == "" {
return
}
validRegions, _ = GetEnabledCloudRegionIDs(f, providerID, nil)
return validRegions, cobra.ShellCompDirectiveNoSpace
}
// GetKafkaSizeCompletionValues returns a list of valid kafka sizes for the specified region and ams instance types
func GetKafkaSizeCompletionValues(f *factory.Factory, providerID string, regionId string) (validSizes []string, directive cobra.ShellCompDirective) {
directive = cobra.ShellCompDirectiveNoSpace
// We need both values to provide a valid list of sizes
if providerID == "" || regionId == "" {
return nil, directive
}
err, constants := remote.GetRemoteServiceConstants(f.Context, f.Logger)
if err != nil {
return nil, directive
}
orgQuota, err := accountmgmtutil.GetOrgQuotas(f, &constants.Kafka.Ams)
if err != nil {
return nil, directive
}
userInstanceType, _ := accountmgmtutil.SelectQuotaForUser(f, orgQuota, accountmgmtutil.MarketplaceInfo{})
// Not including quota in this request as it takes very long time to list quota for all regions in suggestion mode
validSizes, _ = FetchValidKafkaSizesLabels(f, providerID, regionId, *userInstanceType)
return validSizes, cobra.ShellCompDirectiveNoSpace
}
func GetMarketplaceCompletionValues(f *factory.Factory) (validSizes []string, directive cobra.ShellCompDirective) {
directive = cobra.ShellCompDirectiveNoSpace
err, constants := remote.GetRemoteServiceConstants(f.Context, f.Logger)
if err != nil {
return nil, directive
}
orgQuota, err := accountmgmtutil.GetOrgQuotas(f, &constants.Kafka.Ams)
if err != nil {
return nil, directive
}
validMarketPlaces := FetchValidMarketplaces(orgQuota.MarketplaceQuotas)
return validMarketPlaces, cobra.ShellCompDirectiveNoSpace
}
func GetMarketplaceAccountCompletionValues(f *factory.Factory, marketplace string) (validMarketplaceAcctIDs []string, directive cobra.ShellCompDirective) {
directive = cobra.ShellCompDirectiveNoSpace
if marketplace == "" {
return validMarketplaceAcctIDs, directive
}
err, constants := remote.GetRemoteServiceConstants(f.Context, f.Logger)
if err != nil {
return nil, directive
}
orgQuota, err := accountmgmtutil.GetOrgQuotas(f, &constants.Kafka.Ams)
if err != nil {
return nil, directive
}
validMarketplaceAcctIDs = FetchValidMarketplaceAccounts(orgQuota.MarketplaceQuotas, marketplace)
return validMarketplaceAcctIDs, cobra.ShellCompDirectiveNoSpace
}
func GetBillingModelCompletionValues(f *factory.Factory) (availableBillingModels []string, directive cobra.ShellCompDirective) {
directive = cobra.ShellCompDirectiveNoSpace
err, constants := remote.GetRemoteServiceConstants(f.Context, f.Logger)
if err != nil {
return nil, directive
}
orgQuota, err := accountmgmtutil.GetOrgQuotas(f, &constants.Kafka.Ams)
if err != nil {
return nil, directive
}
availableBillingModels = FetchSupportedBillingModels(orgQuota)
return availableBillingModels, directive
}