Skip to content

[skip changelog] Update client_example with proxy testing #1162

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

Merged
merged 1 commit into from
Feb 2, 2021
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
32 changes: 32 additions & 0 deletions client_example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Client example

This a client that simulates a gRPC consumer. We're using this for the time being to document the interaction with the
gRPC interface.

To use it run `arduino-cli daemon` and then `client_example`.

To test the proxy settings first run:

```
docker run --name squid -d --restart=always \
--publish 3128:3128 \
--volume /path/to/squid.conf:/etc/squid/squid.conf \
--volume /srv/docker/squid/cache:/var/spool/squid \
sameersbn/squid:3.5.27-2
```

The `squid.conf` file to use is in this directory so change the volume path to that.

To verify that requests are passing through the local proxy run:

```
docker exec -it squid tail -f /var/log/squid/access.log
```

If it works you should see logs similar to this:

```
1612176447.893 400234 172.17.0.1 TCP_TUNNEL/200 116430 CONNECT downloads.arduino.cc:443 - HIER_DIRECT/104.18.28.45 -
1612176448.197 400245 172.17.0.1 TCP_TUNNEL/200 1621708 CONNECT downloads.arduino.cc:443 - HIER_DIRECT/104.18.28.45 -
1612176448.946 400256 172.17.0.1 TCP_TUNNEL/200 354882 CONNECT downloads.arduino.cc:443 - HIER_DIRECT/104.18.28.45 -
```
37 changes: 37 additions & 0 deletions client_example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ func main() {
log.Println("calling GetValue(foo)")
callGetValue(settingsClient)

// List all the settings.
log.Println("calling GetAll()")
callGetAll(settingsClient)

// Write settings to file.
log.Println("calling Write()")
callWrite(settingsClient)
Expand All @@ -100,11 +104,19 @@ func main() {
log.Println("calling Init")
instance := initInstance(client)

// We set up the proxy and then run the update to verify that the proxy settings are currently used
log.Println("calling setProxy")
callSetProxy(settingsClient)

// With a brand new instance, the first operation should always be updating
// the index.
log.Println("calling UpdateIndex")
callUpdateIndex(client, instance)

// And we run update again
log.Println("calling UpdateIndex")
callUpdateIndex(client, instance)

// Let's search for a platform (also known as 'core') called 'samd'.
log.Println("calling PlatformSearch(samd)")
callPlatformSearch(client, instance)
Expand Down Expand Up @@ -220,6 +232,31 @@ func callSetValue(client settings.SettingsClient) {
JsonData: `{"data": "` + dataDir + `", "downloads": "` + path.Join(dataDir, "staging") + `", "user": "` + path.Join(dataDir, "sketchbook") + `"}`,
})

if err != nil {
log.Fatalf("Error setting settings value: %s", err)

}
}

func callSetProxy(client settings.SettingsClient) {
_, err := client.SetValue(context.Background(),
&settings.Value{
Key: "network.proxy",
JsonData: `"http://localhost:3128"`,
})

if err != nil {
log.Fatalf("Error setting settings value: %s", err)
}
}

func callUnsetProxy(client settings.SettingsClient) {
_, err := client.SetValue(context.Background(),
&settings.Value{
Key: "network.proxy",
JsonData: `""`,
})

if err != nil {
log.Fatalf("Error setting settings value: %s", err)
}
Expand Down
42 changes: 42 additions & 0 deletions client_example/squid.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
http_port 3128

acl localnet src 10.0.0.0/8 # RFC1918 possible internal network
acl localnet src 172.16.0.0/12 # RFC1918 possible internal network
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
acl localnet src fc00::/7 # RFC 4193 local private network range
acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines

acl SSL_ports port 443

acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl Safe_ports port 1025-65535 # unregistered ports

acl CONNECT method CONNECT

http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost manager
http_access deny manager

#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#

http_access allow localnet
http_access allow localhost
http_access allow all

coredump_dir /squid/var/cache/squid

refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern . 0 20% 4320