Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IP service & network to ip list #3279

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions api/resource_ip_addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ func (c *Client) GetIPAddresses(ctx context.Context, appName string) ([]IPAddres
type
region
createdAt
network {
name
organization {
slug
}
}
serviceName
}
}
sharedIpAddress
Expand Down
17 changes: 12 additions & 5 deletions api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,18 @@ type DNSRecords struct {
}

type IPAddress struct {
ID string
Address string
Type string
Region string
CreatedAt time.Time
ID string
Address string
Type string
Region string
CreatedAt time.Time
ServiceName string
Network *struct {
Name string
Organization *struct {
Slug string
}
}
}

type VMSize struct {
Expand Down
28 changes: 22 additions & 6 deletions internal/command/ips/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,36 @@ func renderListTable(ctx context.Context, ipAddresses []api.IPAddress) {

switch {
case ipAddr.Type == "v4":
rows = append(rows, []string{"v4", ipAddr.Address, "public (dedicated, $2/mo)", ipAddr.Region, createdAt})
rows = append(rows, []string{"v4", ipAddr.Address, "public (dedicated, $2/mo)", ipAddr.Region, "", ipAddr.ServiceName, createdAt})
case ipAddr.Type == "shared_v4":
rows = append(rows, []string{"v4", ipAddr.Address, "public (shared)", ipAddr.Region, createdAt})
rows = append(rows, []string{"v4", ipAddr.Address, "public (shared)", ipAddr.Region, "", ipAddr.ServiceName, createdAt})
case ipAddr.Type == "v6":
rows = append(rows, []string{"v6", ipAddr.Address, "public (dedicated)", ipAddr.Region, createdAt})
rows = append(rows, []string{"v6", ipAddr.Address, "public (dedicated)", ipAddr.Region, formatNetwork(ipAddr), ipAddr.ServiceName, createdAt})
case ipAddr.Type == "private_v6":
rows = append(rows, []string{"v6", ipAddr.Address, "private", ipAddr.Region, createdAt})
rows = append(rows, []string{"v6", ipAddr.Address, "private", ipAddr.Region, formatNetwork(ipAddr), ipAddr.ServiceName, createdAt})
default:
rows = append(rows, []string{ipAddr.Type, ipAddr.Address, ipType, ipAddr.Region, createdAt})
rows = append(rows, []string{ipAddr.Type, ipAddr.Address, ipType, ipAddr.Region, "", ipAddr.ServiceName, createdAt})
}
}

out := iostreams.FromContext(ctx).Out
render.Table(out, "", rows, "Version", "IP", "Type", "Region", "Created At")
render.Table(out, "", rows, "Version", "IP", "Type", "Region", "Network", "Service", "Created At")
}

func formatNetwork(ipAddr api.IPAddress) string {
if ipAddr.Network == nil {
return ""
}
name := ipAddr.Network.Name
if name == "" {
name = "default"
}

if ipAddr.Network.Organization != nil {
return ipAddr.Network.Organization.Slug + "/" + name
}

return name
}

func renderPrivateTableMachines(ctx context.Context, machines []*api.Machine) {
Expand Down
Loading