-
Notifications
You must be signed in to change notification settings - Fork 23
feat(projects): add command to get project info and private network details #1163
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
Changes from all commits
2e08144
afda74f
3f54185
6f52c1a
39b7a20
db6b9e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package projects | ||
|
|
||
| import ( | ||
| "context" | ||
| "os" | ||
| "strconv" | ||
|
|
||
| "github.com/olekukonko/tablewriter" | ||
|
|
||
| "github.com/Scalingo/cli/config" | ||
| "github.com/Scalingo/go-utils/errors/v2" | ||
| "github.com/Scalingo/go-utils/logger" | ||
| ) | ||
|
|
||
| func Get(ctx context.Context, projectID string) error { | ||
| log := logger.Get(ctx) | ||
| client, err := config.ScalingoClient(ctx) | ||
| if err != nil { | ||
| return errors.Wrap(ctx, err, "get Scalingo client") | ||
| } | ||
|
|
||
| project, err := client.ProjectGet(ctx, projectID) | ||
| if err != nil { | ||
| return errors.Wrap(ctx, err, "get project") | ||
| } | ||
|
|
||
| t := tablewriter.NewWriter(os.Stdout) | ||
| t.Header([]string{"Project Field", "Value"}) | ||
|
|
||
| _ = t.Append([]string{"Name", project.Name}) | ||
| _ = t.Append([]string{"ID", project.ID}) | ||
| _ = t.Append([]string{"Default", strconv.FormatBool(project.Default)}) | ||
| _ = t.Append([]string{"Owner", project.Owner.Username}) | ||
|
|
||
| if project.Flags["private-network"] { | ||
| _ = t.Append([]string{"", ""}) | ||
matthieu526-scalingo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| _ = t.Append([]string{"Private Network", "true"}) | ||
|
|
||
| privateNetworkInfo, err := client.ProjectPrivateNetworkGet(ctx, projectID) | ||
| if err != nil { | ||
| log.WithError(err).Error("Failed to fetch private network info") | ||
| _ = t.Append([]string{"", "Failed to fetch private network info"}) | ||
| } else { | ||
| _ = t.Append([]string{" - ID", privateNetworkInfo.ID}) | ||
| _ = t.Append([]string{" - Subnet", privateNetworkInfo.Subnet}) | ||
| _ = t.Append([]string{" - Gateway IP", privateNetworkInfo.Gateway}) | ||
| _ = t.Append([]string{" - Total number of assignable IPs", strconv.Itoa(privateNetworkInfo.MaxIPsCount)}) | ||
| _ = t.Append([]string{" - Used IPs count", strconv.Itoa(privateNetworkInfo.UsedIPsCount)}) | ||
|
|
||
| if len(privateNetworkInfo.UsedIPs) == 0 { | ||
| _ = t.Append([]string{" - Used IPs", "None"}) | ||
| } else { | ||
| _ = t.Append([]string{" - Used IPs", privateNetworkInfo.UsedIPs[0]}) | ||
| } | ||
| for _, usedIP := range privateNetworkInfo.UsedIPs[1:] { | ||
| _ = t.Append([]string{"", usedIP}) | ||
matthieu526-scalingo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| _ = t.Render() | ||
|
|
||
| return nil | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.