mirror of
https://github.com/apple/pkl.git
synced 2026-07-10 23:22:46 +02:00
Change CLI flag and Gradle name for proxy options (#526)
Rationale: "proxy" can mean very different things (e.g. java.lang.reflect.Proxy in Java). This makes the flag name more specific. CLI: * `--proxy` -> `--http-proxy` * `--no-proxy` -> `--http-no-proxy` Gradle: * `proxyAddress` -> `httpProxy` * `noProxy` -> `httpNoProxy`
This commit is contained in:
@@ -841,12 +841,12 @@ When determining proxy settings, Pkl will look at the following locations, in or
|
|||||||
1. OS settings (on macOS, Windows, and GNOME environments)
|
1. OS settings (on macOS, Windows, and GNOME environments)
|
||||||
2. <<settings-file,Settings file>>
|
2. <<settings-file,Settings file>>
|
||||||
3. xref:language-reference:index.adoc#projects[PklProject file]
|
3. xref:language-reference:index.adoc#projects[PklProject file]
|
||||||
4. `--proxy` and `--no-proxy` CLI flags
|
4. `--http-proxy` and `--http-no-proxy` CLI flags
|
||||||
|
|
||||||
[NOTE]
|
[NOTE]
|
||||||
====
|
====
|
||||||
The proxy and noproxy values are individually set.
|
The proxy and noproxy values are individually set.
|
||||||
For example, using the `--no-proxy` flag but not the `--proxy` flag will cause Pkl to look at the PklProject file, then the settings file, then system settings for the proxy address.
|
For example, using the `--http-no-proxy` flag but not the `--http-proxy` flag will cause Pkl to look at the PklProject file, then the settings file, then system settings for the proxy address.
|
||||||
|
|
||||||
One exception to this rule is that setting a proxy address will cause Pkl to ignore any noproxy values set at the OS level.
|
One exception to this rule is that setting a proxy address will cause Pkl to ignore any noproxy values set at the OS level.
|
||||||
====
|
====
|
||||||
@@ -858,10 +858,10 @@ When specifying a proxy address, it must have scheme `http`, and may not contain
|
|||||||
|
|
||||||
=== Proxy exclusions
|
=== Proxy exclusions
|
||||||
|
|
||||||
Pkl can be configured to bypass the proxy for specific requests via a proxy exclusion rule (i.e. the `--no-proxy` flag).
|
Pkl can be configured to bypass the proxy for specific requests via a proxy exclusion rule (i.e. the `--http-no-proxy` flag).
|
||||||
It may be provided either as a hostname, an IP address, or an IP range via https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation[CIDR notation].
|
It may be provided either as a hostname, an IP address, or an IP range via https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation[CIDR notation].
|
||||||
When determining whether a proxy should be excluded, hostnames do not get resolved to their IP address.
|
When determining whether a proxy should be excluded, hostnames do not get resolved to their IP address.
|
||||||
For example, a request to `localhost` will not match `--no-proxy=127.0.0.1`.
|
For example, a request to `localhost` will not match `--http-no-proxy=127.0.0.1`.
|
||||||
|
|
||||||
For individual hosts (not CIDRs), ports can be specified.
|
For individual hosts (not CIDRs), ports can be specified.
|
||||||
When no port is specified for a given host, connections to all ports bypass the proxy.
|
When no port is specified for a given host, connections to all ports bypass the proxy.
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ Certificates need to be X.509 certificates in PEM format.
|
|||||||
For other methods of configuring certificates, see xref:pkl-cli:index.adoc#ca-certs[CA Certificates].
|
For other methods of configuring certificates, see xref:pkl-cli:index.adoc#ca-certs[CA Certificates].
|
||||||
====
|
====
|
||||||
|
|
||||||
.--proxy
|
.--http-proxy
|
||||||
[%collapsible]
|
[%collapsible]
|
||||||
====
|
====
|
||||||
Default: (none) +
|
Default: (none) +
|
||||||
@@ -132,7 +132,7 @@ Configures HTTP connections to connect to the provided proxy address.
|
|||||||
The URI must have scheme `http`, and may not contain anything other than a host and port.
|
The URI must have scheme `http`, and may not contain anything other than a host and port.
|
||||||
====
|
====
|
||||||
|
|
||||||
.--no-proxy
|
.--http-no-proxy
|
||||||
[%collapsible]
|
[%collapsible]
|
||||||
====
|
====
|
||||||
Default: (none) +
|
Default: (none) +
|
||||||
|
|||||||
@@ -1276,7 +1276,7 @@ result = someLib.x
|
|||||||
CliEvaluatorOptions(
|
CliEvaluatorOptions(
|
||||||
CliBaseOptions(
|
CliBaseOptions(
|
||||||
sourceModules = listOf(URI("http://not.a.valid.host/bar.pkl")),
|
sourceModules = listOf(URI("http://not.a.valid.host/bar.pkl")),
|
||||||
proxyAddress = URI("http://localhost:${wwRuntimeInfo.httpPort}"),
|
httpProxy = URI("http://localhost:${wwRuntimeInfo.httpPort}"),
|
||||||
allowedModules = SecurityManagers.defaultAllowedModules + Pattern.compile("http:"),
|
allowedModules = SecurityManagers.defaultAllowedModules + Pattern.compile("http:"),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -1295,8 +1295,8 @@ result = someLib.x
|
|||||||
CliBaseOptions(
|
CliBaseOptions(
|
||||||
// use loopback address to prevent test from making outbound http connection.
|
// use loopback address to prevent test from making outbound http connection.
|
||||||
sourceModules = listOf(URI("$targetAddress/foo.pkl")),
|
sourceModules = listOf(URI("$targetAddress/foo.pkl")),
|
||||||
proxyAddress = URI(wwRuntimeInfo.httpBaseUrl),
|
httpProxy = URI(wwRuntimeInfo.httpBaseUrl),
|
||||||
noProxy = listOf("*"),
|
httpNoProxy = listOf("*"),
|
||||||
allowedModules = SecurityManagers.defaultAllowedModules + Pattern.compile("http:"),
|
allowedModules = SecurityManagers.defaultAllowedModules + Pattern.compile("http:"),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -1315,7 +1315,7 @@ result = someLib.x
|
|||||||
CliBaseOptions(
|
CliBaseOptions(
|
||||||
sourceModules = listOf(URI("package://localhost:1/birds@0.5.0#/catalog/Ostritch.pkl")),
|
sourceModules = listOf(URI("package://localhost:1/birds@0.5.0#/catalog/Ostritch.pkl")),
|
||||||
noCache = true,
|
noCache = true,
|
||||||
proxyAddress = URI(wwRuntimeInfo.httpBaseUrl),
|
httpProxy = URI(wwRuntimeInfo.httpBaseUrl),
|
||||||
caCertificates = listOf(FileTestUtils.selfSignedCertificate),
|
caCertificates = listOf(FileTestUtils.selfSignedCertificate),
|
||||||
allowedModules = SecurityManagers.defaultAllowedModules + Pattern.compile("http:")
|
allowedModules = SecurityManagers.defaultAllowedModules + Pattern.compile("http:")
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -130,10 +130,10 @@ data class CliBaseOptions(
|
|||||||
val caCertificates: List<Path> = listOf(),
|
val caCertificates: List<Path> = listOf(),
|
||||||
|
|
||||||
/** The proxy to connect to. */
|
/** The proxy to connect to. */
|
||||||
val proxyAddress: URI? = null,
|
val httpProxy: URI? = null,
|
||||||
|
|
||||||
/** Hostnames, IP addresses, or CIDR blocks to not proxy. */
|
/** Hostnames, IP addresses, or CIDR blocks to not proxy. */
|
||||||
val noProxy: List<String>? = null,
|
val httpNoProxy: List<String>? = null,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
@@ -160,12 +160,12 @@ abstract class CliCommand(protected val cliOptions: CliBaseOptions) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val proxyAddress by lazy {
|
private val proxyAddress by lazy {
|
||||||
cliOptions.proxyAddress
|
cliOptions.httpProxy
|
||||||
?: project?.evaluatorSettings?.http?.proxy?.address ?: settings.http?.proxy?.address
|
?: project?.evaluatorSettings?.http?.proxy?.address ?: settings.http?.proxy?.address
|
||||||
}
|
}
|
||||||
|
|
||||||
private val noProxy by lazy {
|
private val noProxy by lazy {
|
||||||
cliOptions.noProxy
|
cliOptions.httpNoProxy
|
||||||
?: project?.evaluatorSettings?.http?.proxy?.noProxy ?: settings.http?.proxy?.noProxy
|
?: project?.evaluatorSettings?.http?.proxy?.noProxy ?: settings.http?.proxy?.noProxy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ class BaseOptions : OptionGroup() {
|
|||||||
@Suppress("HttpUrlsUsage")
|
@Suppress("HttpUrlsUsage")
|
||||||
val proxy: URI? by
|
val proxy: URI? by
|
||||||
option(
|
option(
|
||||||
names = arrayOf("--proxy"),
|
names = arrayOf("--http-proxy"),
|
||||||
metavar = "<address>",
|
metavar = "<address>",
|
||||||
help = "Proxy to use for HTTP(S) connections."
|
help = "Proxy to use for HTTP(S) connections."
|
||||||
)
|
)
|
||||||
@@ -191,7 +191,7 @@ class BaseOptions : OptionGroup() {
|
|||||||
|
|
||||||
val noProxy: List<String>? by
|
val noProxy: List<String>? by
|
||||||
option(
|
option(
|
||||||
names = arrayOf("--no-proxy"),
|
names = arrayOf("--http-no-proxy"),
|
||||||
metavar = "<pattern1,pattern2>",
|
metavar = "<pattern1,pattern2>",
|
||||||
help = "Hostnames that should not be connected to via a proxy."
|
help = "Hostnames that should not be connected to via a proxy."
|
||||||
)
|
)
|
||||||
@@ -229,8 +229,8 @@ class BaseOptions : OptionGroup() {
|
|||||||
omitProjectSettings = projectOptions?.omitProjectSettings ?: false,
|
omitProjectSettings = projectOptions?.omitProjectSettings ?: false,
|
||||||
noProject = projectOptions?.noProject ?: false,
|
noProject = projectOptions?.noProject ?: false,
|
||||||
caCertificates = caCertificates,
|
caCertificates = caCertificates,
|
||||||
proxyAddress = proxy,
|
httpProxy = proxy,
|
||||||
noProxy = noProxy ?: emptyList()
|
httpNoProxy = noProxy ?: emptyList()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -282,7 +282,7 @@ public class PklPlugin implements Plugin<Project> {
|
|||||||
|
|
||||||
spec.getTestPort().convention(-1);
|
spec.getTestPort().convention(-1);
|
||||||
|
|
||||||
spec.getNoProxy().convention(List.of());
|
spec.getHttpNoProxy().convention(List.of());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void configureCodeGenSpec(CodeGenSpec spec) {
|
private void configureCodeGenSpec(CodeGenSpec spec) {
|
||||||
@@ -427,8 +427,8 @@ public class PklPlugin implements Plugin<Project> {
|
|||||||
task.getModuleCacheDir().set(spec.getModuleCacheDir());
|
task.getModuleCacheDir().set(spec.getModuleCacheDir());
|
||||||
task.getEvalTimeout().set(spec.getEvalTimeout());
|
task.getEvalTimeout().set(spec.getEvalTimeout());
|
||||||
task.getTestPort().set(spec.getTestPort());
|
task.getTestPort().set(spec.getTestPort());
|
||||||
task.getProxyAddress().set(spec.getProxyAddress());
|
task.getHttpProxy().set(spec.getHttpProxy());
|
||||||
task.getNoProxy().set(spec.getNoProxy());
|
task.getHttpNoProxy().set(spec.getHttpNoProxy());
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T extends ModulesTask, S extends ModulesSpec> void configureModulesTask(T task, S spec) {
|
private <T extends ModulesTask, S extends ModulesSpec> void configureModulesTask(T task, S spec) {
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public interface BasePklSpec {
|
|||||||
|
|
||||||
Property<Integer> getTestPort();
|
Property<Integer> getTestPort();
|
||||||
|
|
||||||
Property<URI> getProxyAddress();
|
Property<URI> getHttpProxy();
|
||||||
|
|
||||||
ListProperty<String> getNoProxy();
|
ListProperty<String> getHttpNoProxy();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,11 +127,11 @@ public abstract class BasePklTask extends DefaultTask {
|
|||||||
|
|
||||||
@Input
|
@Input
|
||||||
@Optional
|
@Optional
|
||||||
public abstract Property<URI> getProxyAddress();
|
public abstract Property<URI> getHttpProxy();
|
||||||
|
|
||||||
@Input
|
@Input
|
||||||
@Optional
|
@Optional
|
||||||
public abstract ListProperty<String> getNoProxy();
|
public abstract ListProperty<String> getHttpNoProxy();
|
||||||
|
|
||||||
@TaskAction
|
@TaskAction
|
||||||
public void runTask() {
|
public void runTask() {
|
||||||
@@ -165,8 +165,8 @@ public abstract class BasePklTask extends DefaultTask {
|
|||||||
false,
|
false,
|
||||||
getTestPort().getOrElse(-1),
|
getTestPort().getOrElse(-1),
|
||||||
Collections.emptyList(),
|
Collections.emptyList(),
|
||||||
getProxyAddress().getOrNull(),
|
getHttpProxy().getOrNull(),
|
||||||
getNoProxy().getOrElse(List.of()));
|
getHttpNoProxy().getOrElse(List.of()));
|
||||||
}
|
}
|
||||||
return cachedOptions;
|
return cachedOptions;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user