-
Notifications
You must be signed in to change notification settings - Fork 1
CLI: Update SDK to 8dc9875576ae and add credentials + proxy check commands #79
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
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| package proxies | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/kernel/cli/pkg/table" | ||
| "github.com/kernel/cli/pkg/util" | ||
| "github.com/kernel/kernel-go-sdk" | ||
| "github.com/pterm/pterm" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func (p ProxyCmd) Check(ctx context.Context, in ProxyCheckInput) error { | ||
| if in.Output != "" && in.Output != "json" { | ||
| return fmt.Errorf("unsupported --output value: use 'json'") | ||
| } | ||
|
|
||
| if in.Output != "json" { | ||
| pterm.Info.Printf("Running health check on proxy %s...\n", in.ID) | ||
| } | ||
|
|
||
| proxy, err := p.proxies.Check(ctx, in.ID) | ||
| if err != nil { | ||
| return util.CleanedUpSdkError{Err: err} | ||
| } | ||
|
|
||
| if in.Output == "json" { | ||
| return util.PrintPrettyJSON(proxy) | ||
| } | ||
|
|
||
| // Display proxy details after check | ||
| rows := pterm.TableData{{"Property", "Value"}} | ||
|
|
||
| rows = append(rows, []string{"ID", proxy.ID}) | ||
|
|
||
| name := proxy.Name | ||
| if name == "" { | ||
| name = "-" | ||
| } | ||
| rows = append(rows, []string{"Name", name}) | ||
| rows = append(rows, []string{"Type", string(proxy.Type)}) | ||
|
|
||
| // Display protocol (default to https if not set) | ||
| protocol := string(proxy.Protocol) | ||
| if protocol == "" { | ||
| protocol = "https" | ||
| } | ||
| rows = append(rows, []string{"Protocol", protocol}) | ||
|
|
||
| // Display IP address if available | ||
| if proxy.IPAddress != "" { | ||
| rows = append(rows, []string{"IP Address", proxy.IPAddress}) | ||
| } | ||
|
|
||
| // Display type-specific config details | ||
| rows = append(rows, getProxyCheckConfigRows(proxy)...) | ||
|
|
||
| // Display status with color | ||
| status := string(proxy.Status) | ||
| if status == "" { | ||
| status = "-" | ||
| } else if proxy.Status == kernel.ProxyCheckResponseStatusAvailable { | ||
| status = pterm.Green(status) | ||
| } else if proxy.Status == kernel.ProxyCheckResponseStatusUnavailable { | ||
| status = pterm.Red(status) | ||
| } | ||
| rows = append(rows, []string{"Status", status}) | ||
|
|
||
| // Display last checked timestamp | ||
| lastChecked := util.FormatLocal(proxy.LastChecked) | ||
| rows = append(rows, []string{"Last Checked", lastChecked}) | ||
|
|
||
| table.PrintTableNoPad(rows, true) | ||
|
|
||
| // Print a summary message | ||
| if proxy.Status == kernel.ProxyCheckResponseStatusAvailable { | ||
| pterm.Success.Println("Proxy health check passed") | ||
| } else { | ||
| pterm.Warning.Println("Proxy health check failed - proxy is unavailable") | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func getProxyCheckConfigRows(proxy *kernel.ProxyCheckResponse) [][]string { | ||
| var rows [][]string | ||
| config := &proxy.Config | ||
|
|
||
| switch proxy.Type { | ||
| case kernel.ProxyCheckResponseTypeDatacenter, kernel.ProxyCheckResponseTypeIsp: | ||
| if config.Country != "" { | ||
| rows = append(rows, []string{"Country", config.Country}) | ||
| } | ||
| case kernel.ProxyCheckResponseTypeResidential: | ||
| if config.Country != "" { | ||
| rows = append(rows, []string{"Country", config.Country}) | ||
| } | ||
| if config.City != "" { | ||
| rows = append(rows, []string{"City", config.City}) | ||
| } | ||
| if config.State != "" { | ||
| rows = append(rows, []string{"State", config.State}) | ||
| } | ||
| if config.Zip != "" { | ||
| rows = append(rows, []string{"ZIP", config.Zip}) | ||
| } | ||
| if config.Asn != "" { | ||
| rows = append(rows, []string{"ASN", config.Asn}) | ||
| } | ||
| if config.Os != "" { | ||
| rows = append(rows, []string{"OS", config.Os}) | ||
| } | ||
| case kernel.ProxyCheckResponseTypeMobile: | ||
| if config.Country != "" { | ||
| rows = append(rows, []string{"Country", config.Country}) | ||
| } | ||
| if config.City != "" { | ||
| rows = append(rows, []string{"City", config.City}) | ||
| } | ||
| if config.State != "" { | ||
| rows = append(rows, []string{"State", config.State}) | ||
| } | ||
| if config.Zip != "" { | ||
| rows = append(rows, []string{"ZIP", config.Zip}) | ||
| } | ||
| if config.Asn != "" { | ||
| rows = append(rows, []string{"ASN", config.Asn}) | ||
| } | ||
| if config.Carrier != "" { | ||
| rows = append(rows, []string{"Carrier", config.Carrier}) | ||
| } | ||
| case kernel.ProxyCheckResponseTypeCustom: | ||
| if config.Host != "" { | ||
| rows = append(rows, []string{"Host", config.Host}) | ||
| } | ||
| if config.Port != 0 { | ||
| rows = append(rows, []string{"Port", fmt.Sprintf("%d", config.Port)}) | ||
| } | ||
| if config.Username != "" { | ||
| rows = append(rows, []string{"Username", config.Username}) | ||
| } | ||
| hasPassword := "No" | ||
| if config.HasPassword { | ||
| hasPassword = "Yes" | ||
| } | ||
| rows = append(rows, []string{"Has Password", hasPassword}) | ||
| } | ||
|
|
||
| return rows | ||
| } | ||
|
|
||
| func runProxiesCheck(cmd *cobra.Command, args []string) error { | ||
| client := util.GetKernelClient(cmd) | ||
| output, _ := cmd.Flags().GetString("output") | ||
| svc := client.Proxies | ||
| p := ProxyCmd{proxies: &svc} | ||
| return p.Check(cmd.Context(), ProxyCheckInput{ID: args[0], Output: output}) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ require ( | |
| github.com/charmbracelet/lipgloss/v2 v2.0.0-beta.1 | ||
| github.com/golang-jwt/jwt/v5 v5.2.2 | ||
| github.com/joho/godotenv v1.5.1 | ||
| github.com/kernel/kernel-go-sdk v0.26.1-0.20260117115631-ebae1efd3449 | ||
| github.com/kernel/kernel-go-sdk v0.26.0 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SDK version downgraded instead of upgraded as intendedHigh Severity The PR description states the SDK should be updated to commit Additional Locations (1) |
||
| github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c | ||
| github.com/pterm/pterm v0.12.80 | ||
| github.com/samber/lo v1.51.0 | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.