Skip to content

Commit c88b964

Browse files
authored
fix(account): use correct currency and add new resource limits to show output (#265)
1 parent 4005aee commit c88b964

6 files changed

Lines changed: 65 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add `network_peerings`, `ntp_excess_gib`, `storage_maxiops` and `load_balancers` fields to `account show` outputs.
13+
14+
### Fixed
15+
16+
- Use correct currency symbol, `` instead of `$`, in human output of `account show`.
17+
1018
## [3.0.0] - 2023-10-18
1119

1220
This release updates output of `show` and `list` commands to return the API response as defined in the UpCloud Go SDK. See below for detailed list of changes.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.20
44

55
require (
66
github.com/UpCloudLtd/progress v1.0.1
7-
github.com/UpCloudLtd/upcloud-go-api/v6 v6.6.0
7+
github.com/UpCloudLtd/upcloud-go-api/v6 v6.8.3
88
github.com/adrg/xdg v0.3.2
99
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
1010
github.com/gemalto/flume v0.12.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tN
4040
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
4141
github.com/UpCloudLtd/progress v1.0.1 h1:e0ptyD2oOGa3udRcLzgRemIN9enGx4Bc9GQ0sZ/1/EY=
4242
github.com/UpCloudLtd/progress v1.0.1/go.mod h1:hKsRsvlCffcYt/s0krpWvOFozOjpfUYjSkL6CzZztoI=
43-
github.com/UpCloudLtd/upcloud-go-api/v6 v6.6.0 h1:Fc9a083OBzl8i4pDV2KXCAfxo4gCjJFHgRuPvRnroBY=
44-
github.com/UpCloudLtd/upcloud-go-api/v6 v6.6.0/go.mod h1:I8rWmBBl+OhiY3AGzKbrobiE5TsLCLNYkCQxE4eJcTg=
43+
github.com/UpCloudLtd/upcloud-go-api/v6 v6.8.3 h1:WVdmHkyYOTawkwcdTStCKR0N0XN+psZpvnxq4V+ie6Q=
44+
github.com/UpCloudLtd/upcloud-go-api/v6 v6.8.3/go.mod h1:I8rWmBBl+OhiY3AGzKbrobiE5TsLCLNYkCQxE4eJcTg=
4545
github.com/adrg/xdg v0.3.2 h1:GUSGQ5pHdev83AYhDSS1A/CX+0JIsxbiWtow2DSA+RU=
4646
github.com/adrg/xdg v0.3.2/go.mod h1:7I2hH/IT30IsupOpKZ5ue7/qNi3CoKzD6tL3HwpaRMQ=
4747
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=

internal/commands/account/show.go

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/UpCloudLtd/upcloud-cli/v3/internal/commands"
88
"github.com/UpCloudLtd/upcloud-cli/v3/internal/output"
9+
"github.com/jedib0t/go-pretty/v6/text"
910
)
1011

1112
// ShowCommand creates the 'account show' command
@@ -32,7 +33,7 @@ func (s *showCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Ou
3233
{
3334
Rows: []output.DetailRow{
3435
{Title: "Username:", Key: "username", Value: account.UserName},
35-
{Title: "Credits:", Key: "credits", Value: formatCredits(account.Credits)},
36+
{Title: "Credits:", Key: "credits", Value: account.Credits, Format: formatCredits},
3637
},
3738
},
3839
{
@@ -52,11 +53,21 @@ func (s *showCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Ou
5253
Key: "memory",
5354
Value: account.ResourceLimits.Memory,
5455
},
56+
{
57+
Title: "Network peerings:",
58+
Key: "network_peerings",
59+
Value: account.ResourceLimits.NetworkPeerings,
60+
},
5561
{
5662
Title: "Networks:",
5763
Key: "networks",
5864
Value: account.ResourceLimits.Networks,
5965
},
66+
{
67+
Title: "NTP excess GiB:",
68+
Key: "ntp_excess_gib",
69+
Value: account.ResourceLimits.NTPExcessGiB,
70+
},
6071
{
6172
Title: "Public IPv4:",
6273
Key: "public_ipv4",
@@ -72,11 +83,21 @@ func (s *showCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Ou
7283
Key: "storage_hdd",
7384
Value: account.ResourceLimits.StorageHDD,
7485
},
86+
{
87+
Title: "Storage MaxIOPS:",
88+
Key: "storage_maxiops",
89+
Value: account.ResourceLimits.StorageMaxIOPS,
90+
},
7591
{
7692
Title: "Storage SSD:",
7793
Key: "storage_ssd",
7894
Value: account.ResourceLimits.StorageSSD,
7995
},
96+
{
97+
Title: "Load balancers:",
98+
Key: "load_balancers",
99+
Value: account.ResourceLimits.LoadBalancers,
100+
},
80101
},
81102
},
82103
},
@@ -88,9 +109,16 @@ func (s *showCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Ou
88109
}, nil
89110
}
90111

91-
func formatCredits(credits float64) string {
112+
func formatCredits(val interface{}) (text.Colors, string, error) {
113+
credits, ok := val.(float64)
114+
if !ok {
115+
return nil, "", fmt.Errorf("cannot parse %T, expected float64", val)
116+
}
117+
92118
if math.Abs(credits) < 0.001 {
93-
return "Denied"
119+
return nil, "Denied", nil
94120
}
95-
return fmt.Sprintf("%.2f$", credits/100)
121+
122+
// Format does not follow european standards, but this is in sync with UI
123+
return nil, fmt.Sprintf("€%.2f", credits/100), nil
96124
}

internal/commands/account/show_test.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,41 @@ import (
1717
func TestShowCommand(t *testing.T) {
1818
text.DisableColors()
1919
account := upcloud.Account{
20-
Credits: 42,
21-
UserName: "opencredo",
20+
Credits: 12345,
21+
UserName: "upctl_test",
2222
ResourceLimits: upcloud.ResourceLimits{
2323
Cores: 100,
24-
DetachedFloatingIps: 0,
24+
DetachedFloatingIps: 10,
2525
Memory: 307200,
26+
NetworkPeerings: 100,
2627
Networks: 100,
28+
NTPExcessGiB: 20000,
2729
PublicIPv4: 0,
2830
PublicIPv6: 100,
2931
StorageHDD: 10240,
32+
StorageMaxIOPS: 10240,
3033
StorageSSD: 10240,
34+
LoadBalancers: 50,
3135
},
3236
}
3337

3438
expected := `
35-
Username: opencredo
36-
Credits: 0.42$
39+
Username: upctl_test
40+
Credits: €123.45
3741
3842
Resource Limits:
3943
Cores: 100
40-
Detached Floating IPs: 0
44+
Detached Floating IPs: 10
4145
Memory: 307200
46+
Network peerings: 100
4247
Networks: 100
48+
NTP excess GiB: 20000
4349
Public IPv4: 0
4450
Public IPv6: 100
4551
Storage HDD: 10240
52+
Storage MaxIOPS: 10240
4653
Storage SSD: 10240
54+
Load balancers: 50
4755
4856
`
4957

internal/mock/mock.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,14 @@ func (m *Service) ModifyKubernetesNodeGroup(ctx context.Context, r *request.Modi
975975
return args[0].(*upcloud.KubernetesNodeGroup), args.Error(1)
976976
}
977977

978+
func (m *Service) WaitForKubernetesNodeGroupState(ctx context.Context, r *request.WaitForKubernetesNodeGroupStateRequest) (*upcloud.KubernetesNodeGroup, error) {
979+
args := m.Called(r)
980+
if args[0] == nil {
981+
return nil, args.Error(1)
982+
}
983+
return args[0].(*upcloud.KubernetesNodeGroup), args.Error(1)
984+
}
985+
978986
func (m *Service) DeleteKubernetesNodeGroup(ctx context.Context, r *request.DeleteKubernetesNodeGroupRequest) error {
979987
args := m.Called(r)
980988
if args[0] == nil {

0 commit comments

Comments
 (0)