diff --git a/client_example/README.md b/client_example/README.md new file mode 100644 index 00000000000..ef147c78e47 --- /dev/null +++ b/client_example/README.md @@ -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 - +``` diff --git a/client_example/main.go b/client_example/main.go index 08cf1c4372d..ab97da9bebc 100644 --- a/client_example/main.go +++ b/client_example/main.go @@ -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) @@ -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) @@ -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) } diff --git a/client_example/squid.conf b/client_example/squid.conf new file mode 100644 index 00000000000..1632afe1874 --- /dev/null +++ b/client_example/squid.conf @@ -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