Skip to content

Commit

Permalink
Merge pull request #32 from dmikusa/gh_issue_20
Browse files Browse the repository at this point in the history
Add proxy support
  • Loading branch information
dmikusa authored Feb 14, 2023
2 parents 4ee2e3a + 57ab1a7 commit f1d95c1
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 38 deletions.
92 changes: 58 additions & 34 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The initial implementation focuses on creating bindings for use locally with `pa
## Usage

```
binding_tool 0.6.0
binding_tool
Daniel Mikusa <[email protected]>
Generate Kubernetes service bindings for use with Cloud Native Buildpacks
Expand All @@ -28,6 +28,16 @@ SUBCOMMANDS:
help Print this message or the help of the given subcommand(s)
```

## Proxy Support

The binding-tool uses ureq to make HTTP/HTTPS requests like when it downloads dependencies. The ureq library has proxy support for the http, socks4, socks4a, and socks5 protocols. The CLI reads in proxy configuration from the `PROXY` environment variable. The variable name is intentionally different from the standard `HTTP_PROXY`/`HTTPS_PROXY` environment variables because the ureq format is different. The ureq library supports configuration in the format `<protocol>://<user>:<password>@<host>:port`.

To enable proxy support simply set `PROXY=http://localhost:8080` and insert your proxy settings.

## CA Certificates

The binding-tool uses rustls and rustls-native-certs, which will read CA certificates from the local system store. The CLI reads TLS certificates from the local system store, so if you need to add or trust additional certificates you can just add them to your OS and the tool will pick them up automatically. If you do not or cannot add the certificate to the system store, you may set `SSL_CERT_FILE` and point it to a PEM encoded CA certs file which will be trusted instead.

## Examples

### Creating Dependency Mapping Bindings
Expand Down
15 changes: 12 additions & 3 deletions src/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use std::sync::{Arc, Mutex};
use std::thread::JoinHandle;
use std::{path, thread};
use toml::Value as Toml;
use ureq::Proxy;
use url::Url;

#[derive(Clone)]
Expand Down Expand Up @@ -143,10 +144,18 @@ fn configure_agent() -> Result<ureq::Agent> {
.unwrap_or_else(|_| String::from("30"))
.parse()?;

Ok(ureq::builder()
let mut agent_builder = ureq::builder()
.timeout_connect(std::time::Duration::from_secs(conn_timeout))
.timeout(std::time::Duration::from_secs(timeout))
.build())
.timeout(std::time::Duration::from_secs(timeout));

let proxy_url = std::env::var("PROXY");
if let Ok(proxy_url) = proxy_url {
let proxy = Proxy::new(&proxy_url)
.with_context(|| format!("unable to parse PROXY url {proxy_url}"))?;
agent_builder = agent_builder.proxy(proxy);
}

Ok(agent_builder.build())
}

fn transform(toml: Toml) -> Result<Vec<Dependency>> {
Expand Down

0 comments on commit f1d95c1

Please sign in to comment.