Skip to content
Merged
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
22 changes: 22 additions & 0 deletions cmd/proxies/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,19 @@ func (p ProxyCmd) Create(ctx context.Context, in ProxyCreateInput) error {
}
}

// Set protocol (defaults to https if not specified)
if in.Protocol != "" {
// Validate and convert protocol
switch in.Protocol {
case "http":
params.Protocol = kernel.ProxyNewParamsProtocolHTTP
case "https":
params.Protocol = kernel.ProxyNewParamsProtocolHTTPS
default:
return fmt.Errorf("invalid protocol: %s (must be http or https)", in.Protocol)
}
}

pterm.Info.Printf("Creating %s proxy...\n", proxyType)

proxy, err := p.proxies.New(ctx, params)
Expand All @@ -168,6 +181,13 @@ func (p ProxyCmd) Create(ctx context.Context, in ProxyCreateInput) error {
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})

PrintTableNoPad(rows, true)
return nil
}
Expand All @@ -178,6 +198,7 @@ func runProxiesCreate(cmd *cobra.Command, args []string) error {
// Get all flag values
proxyType, _ := cmd.Flags().GetString("type")
name, _ := cmd.Flags().GetString("name")
protocol, _ := cmd.Flags().GetString("protocol")
country, _ := cmd.Flags().GetString("country")
city, _ := cmd.Flags().GetString("city")
state, _ := cmd.Flags().GetString("state")
Expand All @@ -195,6 +216,7 @@ func runProxiesCreate(cmd *cobra.Command, args []string) error {
return p.Create(cmd.Context(), ProxyCreateInput{
Name: name,
Type: proxyType,
Protocol: protocol,
Country: country,
City: city,
State: state,
Expand Down
47 changes: 47 additions & 0 deletions cmd/proxies/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,53 @@ func TestProxyCreate_InvalidType(t *testing.T) {
assert.Contains(t, err.Error(), "invalid proxy type: invalid")
}

func TestProxyCreate_Protocol_Valid(t *testing.T) {
tests := []struct {
name string
protocol string
}{
{"http protocol", "http"},
{"https protocol", "https"},
{"empty protocol", ""},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
fake := &FakeProxyService{
NewFunc: func(ctx context.Context, body kernel.ProxyNewParams, opts ...option.RequestOption) (*kernel.ProxyNewResponse, error) {
return &kernel.ProxyNewResponse{
ID: "test-proxy",
Name: "Test Proxy",
Type: kernel.ProxyNewResponseTypeDatacenter,
}, nil
},
}

p := ProxyCmd{proxies: fake}
err := p.Create(context.Background(), ProxyCreateInput{
Type: "datacenter",
Country: "US",
Protocol: tt.protocol,
})

assert.NoError(t, err)
})
}
}

func TestProxyCreate_Protocol_Invalid(t *testing.T) {
fake := &FakeProxyService{}
p := ProxyCmd{proxies: fake}
err := p.Create(context.Background(), ProxyCreateInput{
Type: "datacenter",
Country: "US",
Protocol: "ftp",
})

assert.Error(t, err)
assert.Contains(t, err.Error(), "invalid protocol: ftp")
}

func TestProxyCreate_APIError(t *testing.T) {
_ = captureOutput(t)

Expand Down
7 changes: 7 additions & 0 deletions cmd/proxies/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ func (p ProxyCmd) Get(ctx context.Context, in ProxyGetInput) error {
rows = append(rows, []string{"Name", name})
rows = append(rows, []string{"Type", string(item.Type)})

// Display protocol (default to https if not set)
protocol := string(item.Protocol)
if protocol == "" {
protocol = "https"
}
rows = append(rows, []string{"Protocol", protocol})

// Display type-specific config details
rows = append(rows, getProxyConfigRows(item)...)

Expand Down
9 changes: 8 additions & 1 deletion cmd/proxies/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (p ProxyCmd) List(ctx context.Context) error {

// Prepare table data
tableData := pterm.TableData{
{"ID", "Name", "Type", "Config", "Status", "Last Checked"},
{"ID", "Name", "Type", "Protocol", "Config", "Status", "Last Checked"},
}

for _, proxy := range *items {
Expand All @@ -35,6 +35,12 @@ func (p ProxyCmd) List(ctx context.Context) error {
name = "-"
}

// Get protocol (default to https if not set, since that's the default)
protocol := string(proxy.Protocol)
if protocol == "" {
protocol = "https"
}

// Format config based on type
configStr := formatProxyConfig(&proxy)

Expand All @@ -55,6 +61,7 @@ func (p ProxyCmd) List(ctx context.Context) error {
proxy.ID,
name,
string(proxy.Type),
protocol,
configStr,
status,
lastChecked,
Expand Down
13 changes: 4 additions & 9 deletions cmd/proxies/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,22 @@ func TestProxyList_WithProxies(t *testing.T) {
assert.Contains(t, output, "ID")
assert.Contains(t, output, "Name")
assert.Contains(t, output, "Type")
assert.Contains(t, output, "Protocol")
assert.Contains(t, output, "Config")

// Check proxy data
assert.Contains(t, output, "dc-1")
assert.Contains(t, output, "US Datacenter")
assert.Contains(t, output, "datacenter")
assert.Contains(t, output, "Country: US")
assert.Contains(t, output, "https") // Protocol is shown
assert.Contains(t, output, "Country")

assert.Contains(t, output, "res-1")
assert.Contains(t, output, "SF Residential")
assert.Contains(t, output, "residential")
assert.Contains(t, output, "City: sanfrancisco")
assert.Contains(t, output, "State: CA")

assert.Contains(t, output, "custom-1")
assert.Contains(t, output, "My Proxy")
assert.Contains(t, output, "custom")
assert.Contains(t, output, "proxy.example.com:8080")
assert.Contains(t, output, "proxy") // Part of proxy.example.com, will be truncated

assert.Contains(t, output, "mobile-1")
assert.Contains(t, output, "Mobile Proxy")
assert.Contains(t, output, "mobile")
assert.Contains(t, output, "Carrier: verizon")

Expand Down
1 change: 1 addition & 0 deletions cmd/proxies/proxies.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func init() {
proxiesCreateCmd.Flags().String("name", "", "Proxy configuration name")
proxiesCreateCmd.Flags().String("type", "", "Proxy type (datacenter|isp|residential|mobile|custom)")
_ = proxiesCreateCmd.MarkFlagRequired("type")
proxiesCreateCmd.Flags().String("protocol", "https", "Protocol to use for the proxy connection (http|https)")

// Location flags (datacenter, isp, residential, mobile)
proxiesCreateCmd.Flags().String("country", "", "ISO 3166 country code or EU")
Expand Down
5 changes: 3 additions & 2 deletions cmd/proxies/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ type ProxyGetInput struct {
}

type ProxyCreateInput struct {
Name string
Type string
Name string
Type string
Protocol string
// Datacenter/ISP config
Country string
// Residential/Mobile config
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/charmbracelet/fang v0.2.0
github.com/golang-jwt/jwt/v5 v5.2.2
github.com/joho/godotenv v1.5.1
github.com/onkernel/kernel-go-sdk v0.13.0
github.com/onkernel/kernel-go-sdk v0.14.0
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
github.com/pterm/pterm v0.12.80
github.com/samber/lo v1.51.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ github.com/muesli/mango-pflag v0.1.0 h1:UADqbYgpUyRoBja3g6LUL+3LErjpsOwaC9ywvBWe
github.com/muesli/mango-pflag v0.1.0/go.mod h1:YEQomTxaCUp8PrbhFh10UfbhbQrM/xJ4i2PB8VTLLW0=
github.com/muesli/roff v0.1.0 h1:YD0lalCotmYuF5HhZliKWlIx7IEhiXeSfq7hNjFqGF8=
github.com/muesli/roff v0.1.0/go.mod h1:pjAHQM9hdUUwm/krAfrLGgJkXJ+YuhtsfZ42kieB2Ig=
github.com/onkernel/kernel-go-sdk v0.13.0 h1:yxXE8I7Blze7d5oyeyvKWna088o1mFPIAyK+rjmhw3g=
github.com/onkernel/kernel-go-sdk v0.13.0/go.mod h1:MjUR92i8UPqjrmneyVykae6GuB3GGSmnQtnjf1v74Dc=
github.com/onkernel/kernel-go-sdk v0.14.0 h1:77jDkIq/thQ630TwCr2uu7KxUWXrYw6P5qXSwuFfuQw=
github.com/onkernel/kernel-go-sdk v0.14.0/go.mod h1:MjUR92i8UPqjrmneyVykae6GuB3GGSmnQtnjf1v74Dc=
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down