Skip to content

Commit dec9916

Browse files
Use coursier support for ~/.m2/settings.xml for proxy auth (#1058)
1 parent 6ce00ad commit dec9916

File tree

5 files changed

+78
-8
lines changed

5 files changed

+78
-8
lines changed

build.sc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,7 @@ trait Cli extends SbtModule with ProtoBuildModule with CliLaunchers
699699

700700
def ivyDeps = super.ivyDeps() ++ Agg(
701701
Deps.coursierLauncher,
702+
Deps.coursierProxySetup,
702703
Deps.coursierPublish,
703704
Deps.jimfs, // scalaJsEnvNodeJs pulls jimfs:1.1, whose class path seems borked (bin compat issue with the guava version it depends on)
704705
Deps.jniUtils,

modules/cli/src/main/scala/scala/cli/ScalaCli.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package scala.cli
22

3-
import coursier.cache.CacheUrl
3+
import coursier.proxy.SetupProxy
44
import sun.misc.{Signal, SignalHandler}
55

66
import java.io.{ByteArrayOutputStream, File, PrintStream}
@@ -153,7 +153,7 @@ object ScalaCli {
153153

154154
(new BouncycastleSignerMaker).maybeInit()
155155

156-
CacheUrl.setupProxyAuth()
156+
SetupProxy.setup()
157157

158158
// Getting killed by SIGPIPE quite often when on musl (in the "static" native
159159
// image), but also sometimes on glibc, or even on macOS, when we use domain

modules/integration/src/test/scala/scala/cli/integration/RunTestDefinitions.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1586,7 +1586,8 @@ abstract class RunTestDefinitions(val scalaVersionOpt: Option[String])
15861586
s"-D$scheme.proxyHost=$host",
15871587
s"-D$scheme.proxyPort=$port",
15881588
s"-D$scheme.proxyUser=$user",
1589-
s"-D$scheme.proxyPassword=$password"
1589+
s"-D$scheme.proxyPassword=$password",
1590+
s"-D$scheme.proxyProtocol=http"
15901591
)
15911592
}
15921593
val proxyArgs = authProperties("localhost", 9083, "jack", "insecure")

project/deps.sc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ object InternalDeps {
5656
object Deps {
5757
object Versions {
5858
// jni-utils version may need to be sync-ed when bumping the coursier version
59-
def coursier = "2.1.0-M6"
59+
def coursier = "2.1.0-M6-26-gcec901e9a"
6060
def coursierCli = "2.1.0-M5-18-gfebf9838c"
6161
def jsoniterScala = "2.13.26"
6262
def scalaMeta = "4.5.8"
@@ -72,10 +72,11 @@ object Deps {
7272
def caseApp = ivy"com.github.alexarchambault:case-app_2.13:2.1.0-M13"
7373
def collectionCompat = ivy"org.scala-lang.modules::scala-collection-compat:2.7.0"
7474
// Force using of 2.13 - is there a better way?
75-
def coursier = ivy"io.get-coursier:coursier_2.13:${Versions.coursier}"
76-
def coursierJvm = ivy"io.get-coursier:coursier-jvm_2.13:${Versions.coursier}"
77-
def coursierLauncher = ivy"io.get-coursier:coursier-launcher_2.13:${Versions.coursier}"
78-
def coursierPublish = ivy"io.get-coursier.publish:publish_2.13:0.1.2"
75+
def coursier = ivy"io.get-coursier:coursier_2.13:${Versions.coursier}"
76+
def coursierJvm = ivy"io.get-coursier:coursier-jvm_2.13:${Versions.coursier}"
77+
def coursierLauncher = ivy"io.get-coursier:coursier-launcher_2.13:${Versions.coursier}"
78+
def coursierProxySetup = ivy"io.get-coursier:coursier-proxy-setup:${Versions.coursier}"
79+
def coursierPublish = ivy"io.get-coursier.publish:publish_2.13:0.1.2"
7980
// TODO - update to working version
8081
def dependency = ivy"io.get-coursier::dependency:0.2.2"
8182
def dockerClient = ivy"com.spotify:docker-client:8.16.0"
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
title: Proxy authentication
3+
sidebar_position: 9
4+
---
5+
6+
Scala CLI can download dependencies via HTTP proxies. Proxies can be setup in several ways:
7+
- via the Maven configuration file (recommended for now)
8+
- via command-line options
9+
- via Scala CLI or coursier configuration files (soon)
10+
11+
## Maven configuration file
12+
13+
This file lives at `~/.m2/settings.xml`
14+
15+
Example configuration file, without authentication:
16+
```xml
17+
<settings>
18+
<proxies>
19+
<proxy>
20+
<id>test-proxy</id>
21+
<protocol>http</protocol>
22+
<host>proxy.corp.com</host>
23+
<port>8080</port>
24+
</proxy>
25+
</proxies>
26+
</settings>
27+
```
28+
29+
Example configuration file, with authentication:
30+
```xml
31+
<settings>
32+
<proxies>
33+
<proxy>
34+
<id>test-proxy</id>
35+
<protocol>http</protocol>
36+
<host>proxy.corp.com</host>
37+
<port>8080</port>
38+
<username>alex</username>
39+
<password>1234</password>
40+
</proxy>
41+
</proxies>
42+
</settings>
43+
```
44+
45+
The value in `<protocol>…</protocol>` is assumed to be the protocol of the proxy itself
46+
(can be either `http` or `https`, `https` is assumed by default not to inadvertently leak
47+
proxy credentials).
48+
49+
Such a proxy is used for both http and https by Scala CLI.
50+
51+
The [coursier](https://github.com/coursier/coursier) command-line and library also pick those credentials, since version `2.1.0-M6-26-gcec901e9a` (2022/05/31).
52+
53+
## Command-line options
54+
55+
Example
56+
```
57+
$ scala-cli \
58+
-Dhttp.proxyProtocol=http -Dhttp.proxyHost=proxy.corp.com -Dhttp.proxyPort=8080 \
59+
-Dhttp.proxyUsername=alex -Dhttp.proxyPassword=1234 \
60+
-Dhttps.proxyProtocol=http -Dhttps.proxyHost=proxy.corp.com -Dhttps.proxyPort=8080 \
61+
-Dhttps.proxyUsername=alex -Dhttps.proxyPassword=1234 \
62+
<(echo 'println("Hello from Scala CLI")')
63+
```
64+
65+
## Coursier or Scala CLI configuration files
66+
67+
Support to be added soon

0 commit comments

Comments
 (0)