Skip to content

Commit

Permalink
fix(account): use correct currency and add new resource limits to `sh…
Browse files Browse the repository at this point in the history
…ow` output (#265)
  • Loading branch information
kangasta authored Nov 2, 2023
1 parent 4005aee commit c88b964
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 13 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add `network_peerings`, `ntp_excess_gib`, `storage_maxiops` and `load_balancers` fields to `account show` outputs.

### Fixed

- Use correct currency symbol, `` instead of `$`, in human output of `account show`.

## [3.0.0] - 2023-10-18

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.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/UpCloudLtd/progress v1.0.1
github.com/UpCloudLtd/upcloud-go-api/v6 v6.6.0
github.com/UpCloudLtd/upcloud-go-api/v6 v6.8.3
github.com/adrg/xdg v0.3.2
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
github.com/gemalto/flume v0.12.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tN
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
github.com/UpCloudLtd/progress v1.0.1 h1:e0ptyD2oOGa3udRcLzgRemIN9enGx4Bc9GQ0sZ/1/EY=
github.com/UpCloudLtd/progress v1.0.1/go.mod h1:hKsRsvlCffcYt/s0krpWvOFozOjpfUYjSkL6CzZztoI=
github.com/UpCloudLtd/upcloud-go-api/v6 v6.6.0 h1:Fc9a083OBzl8i4pDV2KXCAfxo4gCjJFHgRuPvRnroBY=
github.com/UpCloudLtd/upcloud-go-api/v6 v6.6.0/go.mod h1:I8rWmBBl+OhiY3AGzKbrobiE5TsLCLNYkCQxE4eJcTg=
github.com/UpCloudLtd/upcloud-go-api/v6 v6.8.3 h1:WVdmHkyYOTawkwcdTStCKR0N0XN+psZpvnxq4V+ie6Q=
github.com/UpCloudLtd/upcloud-go-api/v6 v6.8.3/go.mod h1:I8rWmBBl+OhiY3AGzKbrobiE5TsLCLNYkCQxE4eJcTg=
github.com/adrg/xdg v0.3.2 h1:GUSGQ5pHdev83AYhDSS1A/CX+0JIsxbiWtow2DSA+RU=
github.com/adrg/xdg v0.3.2/go.mod h1:7I2hH/IT30IsupOpKZ5ue7/qNi3CoKzD6tL3HwpaRMQ=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
Expand Down
36 changes: 32 additions & 4 deletions internal/commands/account/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/UpCloudLtd/upcloud-cli/v3/internal/commands"
"github.com/UpCloudLtd/upcloud-cli/v3/internal/output"
"github.com/jedib0t/go-pretty/v6/text"
)

// ShowCommand creates the 'account show' command
Expand All @@ -32,7 +33,7 @@ func (s *showCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Ou
{
Rows: []output.DetailRow{
{Title: "Username:", Key: "username", Value: account.UserName},
{Title: "Credits:", Key: "credits", Value: formatCredits(account.Credits)},
{Title: "Credits:", Key: "credits", Value: account.Credits, Format: formatCredits},
},
},
{
Expand All @@ -52,11 +53,21 @@ func (s *showCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Ou
Key: "memory",
Value: account.ResourceLimits.Memory,
},
{
Title: "Network peerings:",
Key: "network_peerings",
Value: account.ResourceLimits.NetworkPeerings,
},
{
Title: "Networks:",
Key: "networks",
Value: account.ResourceLimits.Networks,
},
{
Title: "NTP excess GiB:",
Key: "ntp_excess_gib",
Value: account.ResourceLimits.NTPExcessGiB,
},
{
Title: "Public IPv4:",
Key: "public_ipv4",
Expand All @@ -72,11 +83,21 @@ func (s *showCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Ou
Key: "storage_hdd",
Value: account.ResourceLimits.StorageHDD,
},
{
Title: "Storage MaxIOPS:",
Key: "storage_maxiops",
Value: account.ResourceLimits.StorageMaxIOPS,
},
{
Title: "Storage SSD:",
Key: "storage_ssd",
Value: account.ResourceLimits.StorageSSD,
},
{
Title: "Load balancers:",
Key: "load_balancers",
Value: account.ResourceLimits.LoadBalancers,
},
},
},
},
Expand All @@ -88,9 +109,16 @@ func (s *showCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Ou
}, nil
}

func formatCredits(credits float64) string {
func formatCredits(val interface{}) (text.Colors, string, error) {
credits, ok := val.(float64)
if !ok {
return nil, "", fmt.Errorf("cannot parse %T, expected float64", val)
}

if math.Abs(credits) < 0.001 {
return "Denied"
return nil, "Denied", nil
}
return fmt.Sprintf("%.2f$", credits/100)

// Format does not follow european standards, but this is in sync with UI
return nil, fmt.Sprintf("€%.2f", credits/100), nil
}
20 changes: 14 additions & 6 deletions internal/commands/account/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,41 @@ import (
func TestShowCommand(t *testing.T) {
text.DisableColors()
account := upcloud.Account{
Credits: 42,
UserName: "opencredo",
Credits: 12345,
UserName: "upctl_test",
ResourceLimits: upcloud.ResourceLimits{
Cores: 100,
DetachedFloatingIps: 0,
DetachedFloatingIps: 10,
Memory: 307200,
NetworkPeerings: 100,
Networks: 100,
NTPExcessGiB: 20000,
PublicIPv4: 0,
PublicIPv6: 100,
StorageHDD: 10240,
StorageMaxIOPS: 10240,
StorageSSD: 10240,
LoadBalancers: 50,
},
}

expected := `
Username: opencredo
Credits: 0.42$
Username: upctl_test
Credits: €123.45
Resource Limits:
Cores: 100
Detached Floating IPs: 0
Detached Floating IPs: 10
Memory: 307200
Network peerings: 100
Networks: 100
NTP excess GiB: 20000
Public IPv4: 0
Public IPv6: 100
Storage HDD: 10240
Storage MaxIOPS: 10240
Storage SSD: 10240
Load balancers: 50
`

Expand Down
8 changes: 8 additions & 0 deletions internal/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,14 @@ func (m *Service) ModifyKubernetesNodeGroup(ctx context.Context, r *request.Modi
return args[0].(*upcloud.KubernetesNodeGroup), args.Error(1)
}

func (m *Service) WaitForKubernetesNodeGroupState(ctx context.Context, r *request.WaitForKubernetesNodeGroupStateRequest) (*upcloud.KubernetesNodeGroup, error) {
args := m.Called(r)
if args[0] == nil {
return nil, args.Error(1)
}
return args[0].(*upcloud.KubernetesNodeGroup), args.Error(1)
}

func (m *Service) DeleteKubernetesNodeGroup(ctx context.Context, r *request.DeleteKubernetesNodeGroupRequest) error {
args := m.Called(r)
if args[0] == nil {
Expand Down

0 comments on commit c88b964

Please sign in to comment.