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
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ anywhere a project ID does.
- `--output json`, `-o json` - Output raw JSON object

- `--name <name>` - Proxy configuration name (required)
- `--type <type>` - Proxy type: datacenter, isp, residential, mobile, custom (required)
- `--type <type>` - Proxy type: isp, residential, mobile, custom (required)
- `--protocol <http|https>` - Protocol to use (default: https)
- `--country <code>` - ISO 3166 country code or "EU" (location-based types)
- `--city <name>` - City name (no spaces, e.g. sanfrancisco) (residential, mobile; requires `--country`)
Expand Down Expand Up @@ -1589,11 +1589,11 @@ kernel browsers extensions upload my-browser ./extension1 ./extension2
# List proxy configurations
kernel proxies list

# Create a datacenter proxy
kernel proxies create --type datacenter --country US --name "US Datacenter"
# Create an ISP proxy
kernel proxies create --type isp --country US --name "US ISP"

# Create a datacenter proxy using HTTP protocol
kernel proxies create --type datacenter --country US --protocol http --name "US DC (HTTP)"
# Create an ISP proxy using HTTP protocol
kernel proxies create --type isp --country US --protocol http --name "US ISP (HTTP)"

# Create a custom proxy
kernel proxies create --type custom --host proxy.example.com --port 8080 --username myuser --password mypass --name "My Custom Proxy"
Expand Down
2 changes: 1 addition & 1 deletion cmd/proxies/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func getProxyCheckConfigRows(proxy *kernel.ProxyCheckResponse) [][]string {
config := &proxy.Config

switch proxy.Type {
case kernel.ProxyCheckResponseTypeDatacenter, kernel.ProxyCheckResponseTypeIsp:
case kernel.ProxyCheckResponseTypeIsp:
if config.Country != "" {
rows = append(rows, []string{"Country", config.Country})
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/proxies/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestProxyCheck_ShowsBypassHosts(t *testing.T) {
return &kernel.ProxyCheckResponse{
ID: id,
Name: "Proxy 1",
Type: kernel.ProxyCheckResponseTypeDatacenter,
Type: kernel.ProxyCheckResponseTypeIsp,
BypassHosts: []string{"localhost", "internal.service.local"},
Status: kernel.ProxyCheckResponseStatusAvailable,
}, nil
Expand Down Expand Up @@ -45,7 +45,7 @@ func TestProxyCheck_PassesURL(t *testing.T) {
return &kernel.ProxyCheckResponse{
ID: id,
Name: "Proxy 1",
Type: kernel.ProxyCheckResponseTypeDatacenter,
Type: kernel.ProxyCheckResponseTypeIsp,
Status: kernel.ProxyCheckResponseStatusAvailable,
}, nil
},
Expand Down
12 changes: 6 additions & 6 deletions cmd/proxies/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@ func (f *FakeProxyService) Get(ctx context.Context, id string, opts ...option.Re
if f.GetFunc != nil {
return f.GetFunc(ctx, id, opts...)
}
return &kernel.ProxyGetResponse{ID: id, Type: kernel.ProxyGetResponseTypeDatacenter}, nil
return &kernel.ProxyGetResponse{ID: id, Type: kernel.ProxyGetResponseTypeIsp}, nil
}

func (f *FakeProxyService) New(ctx context.Context, body kernel.ProxyNewParams, opts ...option.RequestOption) (*kernel.ProxyNewResponse, error) {
if f.NewFunc != nil {
return f.NewFunc(ctx, body, opts...)
}
return &kernel.ProxyNewResponse{ID: "new-proxy", Type: kernel.ProxyNewResponseTypeDatacenter}, nil
return &kernel.ProxyNewResponse{ID: "new-proxy", Type: kernel.ProxyNewResponseTypeIsp}, nil
}

func (f *FakeProxyService) Update(ctx context.Context, id string, body kernel.ProxyUpdateParams, opts ...option.RequestOption) (*kernel.ProxyUpdateResponse, error) {
if f.UpdateFunc != nil {
return f.UpdateFunc(ctx, id, body, opts...)
}
return &kernel.ProxyUpdateResponse{ID: id, Name: body.Name, Type: kernel.ProxyUpdateResponseTypeDatacenter}, nil
return &kernel.ProxyUpdateResponse{ID: id, Name: body.Name, Type: kernel.ProxyUpdateResponseTypeIsp}, nil
}

func (f *FakeProxyService) Delete(ctx context.Context, id string, opts ...option.RequestOption) error {
Expand All @@ -85,15 +85,15 @@ func (f *FakeProxyService) Check(ctx context.Context, id string, body kernel.Pro
if f.CheckFunc != nil {
return f.CheckFunc(ctx, id, body, opts...)
}
return &kernel.ProxyCheckResponse{ID: id, Type: kernel.ProxyCheckResponseTypeDatacenter}, nil
return &kernel.ProxyCheckResponse{ID: id, Type: kernel.ProxyCheckResponseTypeIsp}, nil
}

// Helper function to create test proxy responses
func createDatacenterProxy(id, name, country string) kernel.ProxyListResponse {
func createISPProxy(id, name, country string) kernel.ProxyListResponse {
return kernel.ProxyListResponse{
ID: id,
Name: name,
Type: kernel.ProxyListResponseTypeDatacenter,
Type: kernel.ProxyListResponseTypeIsp,
Config: kernel.ProxyListResponseConfigUnion{
Country: country,
},
Expand Down
11 changes: 0 additions & 11 deletions cmd/proxies/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ func (p ProxyCmd) Create(ctx context.Context, in ProxyCreateInput) error {
// Validate proxy type
var proxyType kernel.ProxyNewParamsType
switch in.Type {
case "datacenter":
proxyType = kernel.ProxyNewParamsTypeDatacenter
case "isp":
proxyType = kernel.ProxyNewParamsTypeIsp
case "residential":
Expand All @@ -48,15 +46,6 @@ func (p ProxyCmd) Create(ctx context.Context, in ProxyCreateInput) error {

// Build config based on type
switch proxyType {
case kernel.ProxyNewParamsTypeDatacenter:
config := kernel.ProxyNewParamsConfigDatacenter{}
if in.Country != "" {
config.Country = kernel.Opt(in.Country)
}
params.Config = kernel.ProxyNewParamsConfigUnion{
OfDatacenter: &config,
}

case kernel.ProxyNewParamsTypeIsp:
config := kernel.ProxyNewParamsConfigIsp{}
if in.Country != "" {
Expand Down
76 changes: 21 additions & 55 deletions cmd/proxies/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,84 +13,50 @@ import (
"github.com/stretchr/testify/require"
)

func TestProxyCreate_Datacenter_Success(t *testing.T) {
func TestProxyCreate_ISP_BypassHosts(t *testing.T) {
buf := captureOutput(t)

fake := &FakeProxyService{
NewFunc: func(ctx context.Context, body kernel.ProxyNewParams, opts ...option.RequestOption) (*kernel.ProxyNewResponse, error) {
// Verify the request
assert.Equal(t, kernel.ProxyNewParamsTypeDatacenter, body.Type)
assert.Equal(t, "My DC Proxy", body.Name.Value)
assert.Equal(t, kernel.ProxyNewParamsTypeIsp, body.Type)
assert.Equal(t, "My ISP Proxy", body.Name.Value)
assert.Equal(t, []string{"localhost", "internal.service.local"}, body.BypassHosts)

// Check config
dcConfig := body.Config.OfDatacenter
assert.NotNil(t, dcConfig)
assert.Equal(t, "US", dcConfig.Country.Value)
ispConfig := body.Config.OfIsp
assert.NotNil(t, ispConfig)
assert.Equal(t, "US", ispConfig.Country.Value)

return &kernel.ProxyNewResponse{
ID: "dc-new",
Name: "My DC Proxy",
Type: kernel.ProxyNewResponseTypeDatacenter,
ID: "isp-new",
Name: "My ISP Proxy",
Type: "isp",
BypassHosts: []string{"localhost", "internal.service.local"},
}, nil
},
}

p := ProxyCmd{proxies: fake}
err := p.Create(context.Background(), ProxyCreateInput{
Name: "My DC Proxy",
Type: "datacenter",
Name: "My ISP Proxy",
Type: "isp",
Country: "US",
BypassHosts: []string{"localhost", "internal.service.local"},
})

assert.NoError(t, err)
output := buf.String()

assert.Contains(t, output, "Creating datacenter proxy")
assert.Contains(t, output, "Creating isp proxy")
assert.Contains(t, output, "Successfully created proxy")
assert.Contains(t, output, "dc-new")
assert.Contains(t, output, "My DC Proxy")
assert.Contains(t, output, "isp-new")
assert.Contains(t, output, "My ISP Proxy")
assert.Contains(t, output, "Bypass Hosts")
assert.Contains(t, output, "localhost")
assert.Contains(t, output, "internal.service.local")
}

func TestProxyCreate_Datacenter_WithoutCountry(t *testing.T) {
buf := captureOutput(t)

fake := &FakeProxyService{
NewFunc: func(ctx context.Context, body kernel.ProxyNewParams, opts ...option.RequestOption) (*kernel.ProxyNewResponse, error) {
// Verify the request
assert.Equal(t, kernel.ProxyNewParamsTypeDatacenter, body.Type)
assert.Equal(t, "My DC Proxy", body.Name.Value)

// Check config - country should not be set (it should be zero/nil)
dcConfig := body.Config.OfDatacenter
assert.NotNil(t, dcConfig)

return &kernel.ProxyNewResponse{
ID: "dc-new",
Name: "My DC Proxy",
Type: kernel.ProxyNewResponseTypeDatacenter,
}, nil
},
}

p := ProxyCmd{proxies: fake}
err := p.Create(context.Background(), ProxyCreateInput{
Name: "My DC Proxy",
Type: "datacenter",
// Country is now optional
})

assert.NoError(t, err)
output := buf.String()
assert.Contains(t, output, "Creating datacenter proxy")
assert.Contains(t, output, "Successfully created proxy")
}

func TestProxyCreate_Residential_Success(t *testing.T) {
buf := captureOutput(t)

Expand Down Expand Up @@ -163,7 +129,7 @@ func TestProxyCreate_Residential_InvalidOS(t *testing.T) {
func TestProxyCreate_MissingName(t *testing.T) {
p := ProxyCmd{proxies: &FakeProxyService{}}
err := p.Create(context.Background(), ProxyCreateInput{
Type: "datacenter",
Type: "isp",
Country: "US",
})

Expand Down Expand Up @@ -356,15 +322,15 @@ func TestProxyCreate_Protocol_Valid(t *testing.T) {
return &kernel.ProxyNewResponse{
ID: "test-proxy",
Name: "Test Proxy",
Type: kernel.ProxyNewResponseTypeDatacenter,
Type: kernel.ProxyNewResponseTypeIsp,
}, nil
},
}

p := ProxyCmd{proxies: fake}
err := p.Create(context.Background(), ProxyCreateInput{
Name: "Test Proxy",
Type: "datacenter",
Type: "isp",
Country: "US",
Protocol: tt.protocol,
})
Expand All @@ -379,7 +345,7 @@ func TestProxyCreate_Protocol_Invalid(t *testing.T) {
p := ProxyCmd{proxies: fake}
err := p.Create(context.Background(), ProxyCreateInput{
Name: "Test Proxy",
Type: "datacenter",
Type: "isp",
Country: "US",
Protocol: "ftp",
})
Expand All @@ -394,15 +360,15 @@ func TestProxyCreate_BypassHosts_Normalized(t *testing.T) {
assert.Equal(t, []string{"localhost", "internal.service.local"}, body.BypassHosts)
return &kernel.ProxyNewResponse{
ID: "test-proxy",
Type: kernel.ProxyNewResponseTypeDatacenter,
Type: kernel.ProxyNewResponseTypeIsp,
}, nil
},
}

p := ProxyCmd{proxies: fake}
err := p.Create(context.Background(), ProxyCreateInput{
Name: "Test Proxy",
Type: "datacenter",
Type: "isp",
Country: "US",
BypassHosts: []string{" localhost ", "", "internal.service.local"},
})
Expand All @@ -422,7 +388,7 @@ func TestProxyCreate_APIError(t *testing.T) {
p := ProxyCmd{proxies: fake}
err := p.Create(context.Background(), ProxyCreateInput{
Name: "Test",
Type: "datacenter",
Type: "isp",
Country: "US",
})

Expand Down
2 changes: 1 addition & 1 deletion cmd/proxies/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func getProxyConfigRows(proxy *kernel.ProxyGetResponse) [][]string {
config := &proxy.Config

switch proxy.Type {
case kernel.ProxyGetResponseTypeDatacenter, kernel.ProxyGetResponseTypeIsp:
case kernel.ProxyGetResponseTypeIsp:
if config.Country != "" {
rows = append(rows, []string{"Country", config.Country})
}
Expand Down
16 changes: 8 additions & 8 deletions cmd/proxies/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import (
"github.com/stretchr/testify/assert"
)

func TestProxyGet_Datacenter(t *testing.T) {
func TestProxyGet_ISP(t *testing.T) {
buf := captureOutput(t)

fake := &FakeProxyService{
GetFunc: func(ctx context.Context, id string, opts ...option.RequestOption) (*kernel.ProxyGetResponse, error) {
return &kernel.ProxyGetResponse{
ID: "dc-1",
Name: "US Datacenter",
Type: kernel.ProxyGetResponseTypeDatacenter,
ID: "isp-us",
Name: "US ISP",
Type: kernel.ProxyGetResponseTypeIsp,
BypassHosts: []string{"localhost", "internal.service.local"},
Config: kernel.ProxyGetResponseConfigUnion{
Country: "US",
Expand All @@ -29,18 +29,18 @@ func TestProxyGet_Datacenter(t *testing.T) {
}

p := ProxyCmd{proxies: fake}
err := p.Get(context.Background(), ProxyGetInput{ID: "dc-1"})
err := p.Get(context.Background(), ProxyGetInput{ID: "isp-us"})

assert.NoError(t, err)
output := buf.String()

// Check all fields are displayed
assert.Contains(t, output, "ID")
assert.Contains(t, output, "dc-1")
assert.Contains(t, output, "isp-us")
assert.Contains(t, output, "Name")
assert.Contains(t, output, "US Datacenter")
assert.Contains(t, output, "US ISP")
assert.Contains(t, output, "Type")
assert.Contains(t, output, "datacenter")
assert.Contains(t, output, "isp")
assert.Contains(t, output, "Bypass Hosts")
assert.Contains(t, output, "localhost")
assert.Contains(t, output, "internal.service.local")
Expand Down
2 changes: 1 addition & 1 deletion cmd/proxies/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (p ProxyCmd) List(ctx context.Context, in ProxyListInput) error {
func formatProxyConfig(proxy *kernel.ProxyListResponse) string {
config := &proxy.Config
switch proxy.Type {
case kernel.ProxyListResponseTypeDatacenter, kernel.ProxyListResponseTypeIsp:
case kernel.ProxyListResponseTypeIsp:
if config.Country != "" {
return fmt.Sprintf("Country: %s", config.Country)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/proxies/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestProxyList_WithProxies(t *testing.T) {
buf := captureOutput(t)

proxies := []kernel.ProxyListResponse{
createDatacenterProxy("dc-1", "US Datacenter", "US"),
createISPProxy("isp-us", "US ISP", "US"),
createResidentialProxy("res-1", "SF Residential", "US", "sanfrancisco", "CA"),
createCustomProxy("custom-1", "My Proxy", "proxy.example.com", 8080),
{
Expand Down Expand Up @@ -73,9 +73,9 @@ func TestProxyList_WithProxies(t *testing.T) {
assert.Contains(t, output, "Status")

// Check proxy data - verify IDs and short columns are fully visible
assert.Contains(t, output, "dc-1")
assert.Contains(t, output, "isp-us")
assert.Contains(t, output, "https") // Protocol is shown
assert.Contains(t, output, "datacenter")
assert.Contains(t, output, "isp")

assert.Contains(t, output, "res-1")
assert.Contains(t, output, "residential")
Expand Down
Loading
Loading