Skip to content

Fix documentation for environment variable substitution #404

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

Closed
Closed
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
6 changes: 6 additions & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
= Changes

== [Future] - ?

=== Fixed

* (*Breaking*) Since migrating to a Kotlin Scripting backend, environment variables for repository authentication now use the `$FOO` syntax vs the `{{FOO}}` syntax. This has been broken since 4.2.0. (fixed thanks to https://github.com/rocketraman[rocketraman])

== [4.2.2] - 2023-04-29

=== Added
Expand Down
18 changes: 9 additions & 9 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Two workarounds for ArchLinux exists, which can be used to make 'kscript' workin
[source,bash]
----
sudo mkdir /usr/share/kotlin/bin
sudo ln -s /usr/bin/kotlin /usr/share/kotlin/bin/kotlin
sudo ln -s /usr/bin/kotlin /usr/share/kotlin/bin/kotlin
sudo ln -s /usr/bin/kotlinc /usr/share/kotlin/bin/kotlinc
----

Expand Down Expand Up @@ -243,7 +243,7 @@ EOF

[source,bash]
----
kscript <(echo 'println("k-onliner")') arg1 arg2 arg3
kscript <(echo 'println("k-onliner")') arg1 arg2 arg3
----

Inlined _kscripts_ are also cached based on `md5` checksum, so running the same snippet again will use a cached jar (
Expand All @@ -259,7 +259,7 @@ script for better readability)

[source,bash]
----
kscript https://git.io/v1cG6 my argu ments
kscript https://git.io/v1cG6 my argu ments
----

To streamline the usage, the first part could be even aliased:
Expand Down Expand Up @@ -414,12 +414,12 @@ The latter is the default for `kt` files and could be omitted
@file:DependsOnMaven("net.clearvolume:cleargl:2.0.1")
// Note that for compatibility reasons, only one locator argument is allowed for @DependsOnMaven

// also protected artifact repositories are supported, see <https://github.com/kscripting/kscript/blob/master/test/TestsReadme.md#manual-testing>
// also protected repositories are supported, see <https://github.com/kscripting/kscript/blob/master/test/TestsReadme.md#manual-testing>
// @file:Repository("my-art", "http://localhost:8081/artifactory/authenticated_repo", user="auth_user", password="password")
// You can use environment variables for user and password when string surrounded by double {} brackets
// @file:Repository("my-art", "http://localhost:8081/artifactory/authenticated_repo", user="{{ARTIFACTORY_USER}}", password="{{ARTIFACTORY_PASSWORD}}")
// You can use environment variables for user and password
// @file:Repository("my-art", "http://localhost:8081/artifactory/authenticated_repo", user="$ARTIFACTORY_USER", password="$ARTIFACTORY_PASSWORD")
// will be use 'ARTIFACTORY_USER' and 'ARTIFACTORY_PASSWORD' environment variables
// if the value doesn't found in the script environment will fail
// if a referenced environment variable is not found, the script will fail

// Include helper scripts without deployment or prior compilation
@file:Import("util.kt")
Expand Down Expand Up @@ -516,7 +516,7 @@ which will bring up the classpath-enhanced REPL:
Creating REPL from CountRecords.kts
Welcome to Kotlin version 1.1.51 (JRE 1.8.0_151-b12)
>>> import de.mpicbg.scicomp.bioinfo.openFasta
>>>
>>>
----

== Boostrap IDEA from a scriptlet
Expand Down Expand Up @@ -582,7 +582,7 @@ KScript follows XDG directory standard, so the file should be created in (paths
existing path is used):

|===
|OS |PATH
|OS |PATH

|*Windows* | %LOCALAPPDATA%\kscript\kscript.properties; %USERPROFILE%.config\kscript\kscript.properties
|*MacOs* | ~/Library/Application Support/kscript/kscript.properties;
Expand Down
42 changes: 38 additions & 4 deletions test/TestsReadme.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@ As of this writing, testing the credentials is only done manually with a dockeri
docker run --name artifactory -d -p 8081:8081 docker.bintray.io/jfrog/artifactory-oss:latest

# Copy preconfigured gloabl config (with custom repo) and security config (with credentials user) into container.
docker cp ./test/resources/artifactory_config/artifactory.config.xml artifactory:/var/opt/jfrog/artifactory/etc/artifactory.config.import.xml
docker cp ./test/resources/artifactory_config/security_descriptor.xml artifactory:/var/opt/jfrog/artifactory/etc/security.import.xml
docker cp ./test/resources/artifactory_config/artifactory.config.xml artifactory:/var/opt/jfrog/artifactory/etc/artifactory/artifactory.config.import.xml
docker cp ./test/resources/artifactory_config/security_descriptor.xml artifactory:/var/opt/jfrog/artifactory/etc/artifactory/security.import.xml

# Make the configs accessable
docker exec -u 0 -it artifactory sh -c 'chmod 777 $ARTIFACTORY_HOME/etc/*.import.xml'
docker exec -u 0 -it artifactory sh -c 'chmod 777 /var/opt/jfrog/artifactory/etc/artifactory/*.import.xml'

# Restart docker after is done with initial booting (otherwise restart breaks the container).
echo "sleeping for 15..." && sleep 15
Expand All @@ -189,7 +189,41 @@ echo '
@file:DependsOn("com.jcabi:jcabi-aether:0.10.1") // If unencrypted works via jcenter
@file:DependsOnMaven("group:somejar:1.0") // If encrypted works.
println("Hello, World!")
' | kscript -
' | kscript -c -
```

#### 4. Test environment variable substitution

```bash
export auth_user="auth_user"
export auth_password="password"

echo '
@file:Repository("http://localhost:8081/artifactory/authenticated_repo", user="$auth_user", password="$auth_password")
@file:DependsOn("com.jcabi:jcabi-aether:0.10.1") // If unencrypted works via jcenter
@file:DependsOnMaven("group:somejar:1.0") // If encrypted works.
println("Hello, World!")
' | kscript -c -
```

#### 5. Test environment variable substitution with packaging

```bash
export auth_user="auth_user"
export auth_password="password"

echo '
@file:Repository("http://localhost:8081/artifactory/authenticated_repo", user="$auth_user", password="$auth_password")
@file:DependsOn("com.jcabi:jcabi-aether:0.10.1") // If unencrypted works via jcenter
@file:DependsOnMaven("group:somejar:1.0") // If encrypted works.
println("Hello, World!")
' | kscript -c --package -
```

#### 6. (Optional) Cleanup Local Maven Cache

```bash
rm -fr ~/.m2/repository/group
```

### Additional info for manual testing
Expand Down