Skip to content
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

Use coursier support for ~/.m2/settings.xml for proxy auth #1058

Merged
merged 1 commit into from
Jun 1, 2022
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
1 change: 1 addition & 0 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ trait Cli extends SbtModule with ProtoBuildModule with CliLaunchers

def ivyDeps = super.ivyDeps() ++ Agg(
Deps.coursierLauncher,
Deps.coursierProxySetup,
Deps.coursierPublish,
Deps.jimfs, // scalaJsEnvNodeJs pulls jimfs:1.1, whose class path seems borked (bin compat issue with the guava version it depends on)
Deps.jniUtils,
Expand Down
4 changes: 2 additions & 2 deletions modules/cli/src/main/scala/scala/cli/ScalaCli.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package scala.cli

import coursier.cache.CacheUrl
import coursier.proxy.SetupProxy
import sun.misc.{Signal, SignalHandler}

import java.io.{ByteArrayOutputStream, File, PrintStream}
Expand Down Expand Up @@ -153,7 +153,7 @@ object ScalaCli {

(new BouncycastleSignerMaker).maybeInit()

CacheUrl.setupProxyAuth()
SetupProxy.setup()

// Getting killed by SIGPIPE quite often when on musl (in the "static" native
// image), but also sometimes on glibc, or even on macOS, when we use domain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1585,7 +1585,8 @@ abstract class RunTestDefinitions(val scalaVersionOpt: Option[String])
s"-D$scheme.proxyHost=$host",
s"-D$scheme.proxyPort=$port",
s"-D$scheme.proxyUser=$user",
s"-D$scheme.proxyPassword=$password"
s"-D$scheme.proxyPassword=$password",
s"-D$scheme.proxyProtocol=http"
)
}
val proxyArgs = authProperties("localhost", 9083, "jack", "insecure")
Expand Down
11 changes: 6 additions & 5 deletions project/deps.sc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ object InternalDeps {
object Deps {
object Versions {
// jni-utils version may need to be sync-ed when bumping the coursier version
def coursier = "2.1.0-M6"
def coursier = "2.1.0-M6-26-gcec901e9a"
def coursierCli = "2.1.0-M5-18-gfebf9838c"
def jsoniterScala = "2.13.26"
def scalaMeta = "4.5.8"
Expand All @@ -72,10 +72,11 @@ object Deps {
def caseApp = ivy"com.github.alexarchambault:case-app_2.13:2.1.0-M13"
def collectionCompat = ivy"org.scala-lang.modules::scala-collection-compat:2.7.0"
// Force using of 2.13 - is there a better way?
def coursier = ivy"io.get-coursier:coursier_2.13:${Versions.coursier}"
def coursierJvm = ivy"io.get-coursier:coursier-jvm_2.13:${Versions.coursier}"
def coursierLauncher = ivy"io.get-coursier:coursier-launcher_2.13:${Versions.coursier}"
def coursierPublish = ivy"io.get-coursier.publish:publish_2.13:0.1.2"
def coursier = ivy"io.get-coursier:coursier_2.13:${Versions.coursier}"
def coursierJvm = ivy"io.get-coursier:coursier-jvm_2.13:${Versions.coursier}"
def coursierLauncher = ivy"io.get-coursier:coursier-launcher_2.13:${Versions.coursier}"
def coursierProxySetup = ivy"io.get-coursier:coursier-proxy-setup:${Versions.coursier}"
def coursierPublish = ivy"io.get-coursier.publish:publish_2.13:0.1.2"
// TODO - update to working version
def dependency = ivy"io.get-coursier::dependency:0.2.2"
def dockerClient = ivy"com.spotify:docker-client:8.16.0"
Expand Down
67 changes: 67 additions & 0 deletions website/docs/reference/proxy-authentication.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
title: Proxy authentication
sidebar_position: 9
---

Scala CLI can download dependencies via HTTP proxies. Proxies can be setup in several ways:
- via the Maven configuration file (recommended for now)
- via command-line options
- via Scala CLI or coursier configuration files (soon)

## Maven configuration file

This file lives at `~/.m2/settings.xml`

Example configuration file, without authentication:
```xml
<settings>
<proxies>
<proxy>
<id>test-proxy</id>
<protocol>http</protocol>
<host>proxy.corp.com</host>
<port>8080</port>
</proxy>
</proxies>
</settings>
```

Example configuration file, with authentication:
```xml
<settings>
<proxies>
<proxy>
<id>test-proxy</id>
<protocol>http</protocol>
<host>proxy.corp.com</host>
<port>8080</port>
<username>alex</username>
<password>1234</password>
</proxy>
</proxies>
</settings>
```

The value in `<protocol>…</protocol>` is assumed to be the protocol of the proxy itself
(can be either `http` or `https`, `https` is assumed by default not to inadvertently leak
proxy credentials).

Such a proxy is used for both http and https by Scala CLI.

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).

## Command-line options

Example
```
$ scala-cli \
-Dhttp.proxyProtocol=http -Dhttp.proxyHost=proxy.corp.com -Dhttp.proxyPort=8080 \
-Dhttp.proxyUsername=alex -Dhttp.proxyPassword=1234 \
-Dhttps.proxyProtocol=http -Dhttps.proxyHost=proxy.corp.com -Dhttps.proxyPort=8080 \
-Dhttps.proxyUsername=alex -Dhttps.proxyPassword=1234 \
<(echo 'println("Hello from Scala CLI")')
```

## Coursier or Scala CLI configuration files

Support to be added soon