Skip to content

Commit

Permalink
enable cli request logging (#85)
Browse files Browse the repository at this point in the history
* enable cli request logging

* fix test
  • Loading branch information
amalshaji authored Aug 15, 2024
1 parent 9749947 commit 2e1c18f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 23 deletions.
1 change: 1 addition & 0 deletions admin/apis/v1/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class GetConfigInput(BaseModel):
server_url: {server_url}
ssh_url: {ssh_url}
secret_key: {secret_key}
enable_request_logging: false
tunnels:
- name: portr
subdomain: portr
Expand Down
2 changes: 1 addition & 1 deletion admin/tests/api_tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_download_config_should_pass(self):
"/api/v1/config/download", json={"secret_key": self.team_user.secret_key}
)
assert resp.json() == {
"message": f"server_url: {settings.server_url}\nssh_url: {settings.ssh_url}\nsecret_key: {self.team_user.secret_key}\ntunnels:\n - name: portr\n subdomain: portr\n port: 4321"
"message": f"server_url: {settings.server_url}\nssh_url: {settings.ssh_url}\nsecret_key: {self.team_user.secret_key}\nenable_request_logging: false\ntunnels:\n - name: portr\n subdomain: portr\n port: 4321"
}

def test_download_config_with_wrong_secret_key_should_fail(self):
Expand Down
15 changes: 8 additions & 7 deletions tunnel/internal/client/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ func (c *Client) Start(ctx context.Context, services ...string) error {
continue
}
clientConfigs = append(clientConfigs, config.ClientConfig{
ServerUrl: c.config.ServerUrl,
SshUrl: c.config.SshUrl,
TunnelUrl: c.config.TunnelUrl,
SecretKey: c.config.SecretKey,
Tunnel: tunnel,
UseLocalHost: c.config.UseLocalHost,
Debug: c.config.Debug,
ServerUrl: c.config.ServerUrl,
SshUrl: c.config.SshUrl,
TunnelUrl: c.config.TunnelUrl,
SecretKey: c.config.SecretKey,
Tunnel: tunnel,
UseLocalHost: c.config.UseLocalHost,
Debug: c.config.Debug,
EnableRequestLogging: c.config.EnableRequestLogging,
})
}

Expand Down
32 changes: 17 additions & 15 deletions tunnel/internal/client/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ func (t *Tunnel) GetLocalAddr() string {
}

type Config struct {
ServerUrl string `yaml:"server_url"`
SshUrl string `yaml:"ssh_url"`
TunnelUrl string `yaml:"tunnel_url"`
SecretKey string `yaml:"secret_key"`
Tunnels []Tunnel `yaml:"tunnels"`
UseLocalHost bool `yaml:"use_localhost"`
Debug bool `yaml:"debug"`
UseVite bool `yaml:"use_vite"`
ServerUrl string `yaml:"server_url"`
SshUrl string `yaml:"ssh_url"`
TunnelUrl string `yaml:"tunnel_url"`
SecretKey string `yaml:"secret_key"`
Tunnels []Tunnel `yaml:"tunnels"`
UseLocalHost bool `yaml:"use_localhost"`
Debug bool `yaml:"debug"`
UseVite bool `yaml:"use_vite"`
EnableRequestLogging bool `yaml:"enable_request_logging"`
}

func (c *Config) SetDefaults() {
Expand Down Expand Up @@ -83,13 +84,14 @@ func (c Config) GetAdminAddress() string {
}

type ClientConfig struct {
ServerUrl string
SshUrl string
TunnelUrl string
SecretKey string
Tunnel Tunnel
UseLocalHost bool
Debug bool
ServerUrl string
SshUrl string
TunnelUrl string
SecretKey string
Tunnel Tunnel
UseLocalHost bool
Debug bool
EnableRequestLogging bool
}

func (c *ClientConfig) GetHttpTunnelAddr() string {
Expand Down
11 changes: 11 additions & 0 deletions tunnel/internal/client/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,17 @@ func (s *SshClient) logHttpRequest(
}
return
}

if s.config.EnableRequestLogging {
fmt.Printf(
"%s [%d] %-6s %d %s\n",
req.LoggedAt.Local().Format("2006-01-02 15:04:05"),
req.Localport,
req.Method,
req.ResponseStatusCode,
req.Url,
)
}
}

func (s *SshClient) tcpTunnel(src, dst net.Conn) {
Expand Down

0 comments on commit 2e1c18f

Please sign in to comment.