Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/cmd/cli/command/whoami.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"github.com/DefangLabs/defang/src/pkg/cli"
"github.com/DefangLabs/defang/src/pkg/cli/client"
"github.com/DefangLabs/defang/src/pkg/term"
defangv1 "github.com/DefangLabs/defang/src/protos/io/defang/v1"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -49,9 +48,6 @@ var whoamiCmd = &cobra.Command{
if !global.Verbose {
data.Tenant = ""
data.TenantID = ""
if data.SubscriberTier == defangv1.SubscriptionTier_SUBSCRIPTION_TIER_UNSPECIFIED {
data.SubscriberTier = defangv1.SubscriptionTier_HOBBY // don't show "SUBSCRIPTION_TIER_UNSPECIFIED"
}
}

cols := []string{
Expand Down
21 changes: 10 additions & 11 deletions src/pkg/cli/whoami.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@ package cli
import (
"context"

"github.com/DefangLabs/defang/src/pkg"
"github.com/DefangLabs/defang/src/pkg/auth"
"github.com/DefangLabs/defang/src/pkg/cli/client"
"github.com/DefangLabs/defang/src/pkg/term"
"github.com/DefangLabs/defang/src/pkg/types"

defangv1 "github.com/DefangLabs/defang/src/protos/io/defang/v1"
)

type ShowAccountData struct {
Provider client.ProviderID `json:"provider"`
SubscriberTier defangv1.SubscriptionTier `json:"subscriberTier"`
Region string `json:"region"`
Workspace string `json:"workspace"`
Tenant string `json:"tenant,omitempty"` // this is the subdomain
TenantID string `json:"tenantId,omitempty"`
Email string `json:"email"`
Name string `json:"name"`
Provider client.ProviderID `json:"provider"`
SubscriberTier string `json:"subscriberTier"`
Region string `json:"region"`
Workspace string `json:"workspace"`
Tenant string `json:"tenant,omitempty"` // this is the subdomain
TenantID string `json:"tenantId,omitempty"`
Email string `json:"email"`
Name string `json:"name"`
}

func Whoami(ctx context.Context, fabric client.FabricClient, maybeProvider client.Provider, userInfo *auth.UserInfo, tenantSelection types.TenantNameOrID) (ShowAccountData, error) {
Expand All @@ -36,7 +35,7 @@ func Whoami(ctx context.Context, fabric client.FabricClient, maybeProvider clien
term.Debug("User ID: " + resp.UserId)
showData := ShowAccountData{
Region: resp.Region,
SubscriberTier: resp.Tier,
SubscriberTier: pkg.SubscriptionTierToString(resp.Tier),
Tenant: resp.Tenant,
TenantID: resp.TenantId,
Workspace: ResolveWorkspaceName(userInfo, tenantSelection),
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/cli/whoami_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestWhoami(t *testing.T) {

want := ShowAccountData{
Provider: client.ProviderDefang,
SubscriberTier: defangv1.SubscriptionTier_PRO,
SubscriberTier: "Pro",
Region: "us-west-2",
Workspace: "Tenant One",
Tenant: "tenant-1",
Expand Down
6 changes: 3 additions & 3 deletions src/pkg/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ func SubscriptionTierToString(tier defangv1.SubscriptionTier) string {
case defangv1.SubscriptionTier_SUBSCRIPTION_TIER_UNSPECIFIED:
fallthrough // free tier
case defangv1.SubscriptionTier_HOBBY:
return "Hobby"
return "Starter"
case defangv1.SubscriptionTier_PERSONAL:
return "Personal"
return "Starter" // Personal tier eliminated in v5; maps to Starter
case defangv1.SubscriptionTier_PRO:
return "Pro"
case defangv1.SubscriptionTier_TEAM:
return "Team"
return "Enterprise"
default:
return "Unknown"
}
Expand Down
24 changes: 24 additions & 0 deletions src/pkg/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"
"time"

defangv1 "github.com/DefangLabs/defang/src/protos/io/defang/v1"
"google.golang.org/protobuf/types/known/timestamppb"
)

Expand Down Expand Up @@ -256,3 +257,26 @@ func TestGetFirstEnv(t *testing.T) {
})
}
}

func TestSubscriptionTierToString(t *testing.T) {
tests := []struct {
name string
tier defangv1.SubscriptionTier
want string
}{
{"unspecified maps to Starter", defangv1.SubscriptionTier_SUBSCRIPTION_TIER_UNSPECIFIED, "Starter"},
{"hobby maps to Starter", defangv1.SubscriptionTier_HOBBY, "Starter"},
{"personal maps to Starter", defangv1.SubscriptionTier_PERSONAL, "Starter"},
{"pro maps to Pro", defangv1.SubscriptionTier_PRO, "Pro"},
{"team maps to Enterprise", defangv1.SubscriptionTier_TEAM, "Enterprise"},
{"expired maps to Unknown", defangv1.SubscriptionTier_EXPIRED, "Unknown"},
{"unknown value maps to Unknown", defangv1.SubscriptionTier(99), "Unknown"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := SubscriptionTierToString(tt.tier); got != tt.want {
t.Errorf("SubscriptionTierToString(%v) = %q, want %q", tt.tier, got, tt.want)
}
})
}
}
Loading