Skip to content

Commit

Permalink
Update config file to no longer be stored in legacy location to be co…
Browse files Browse the repository at this point in the history
…mpatible with latest versions of ngrok.
  • Loading branch information
alexdlaird committed Dec 1, 2023
1 parent 2292e5d commit 385ae27
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 18 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ All notable changes to this project will be documented in this file.

This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/alexdlaird/java-ngrok/compare/2.2.4...HEAD)
## [Unreleased](https://github.com/alexdlaird/java-ngrok/compare/2.2.5...HEAD)

## [2.2.5](https://github.com/alexdlaird/java-ngrok/compare/2.2.4...2.2.5) - 2023-12-01
### Changed
- `java-ngrok` to no longer install the config file in a legacy location, now respects [`ngrok`'s default locations](https://ngrok.com/docs/agent/config/#default-locations).

### Fixed
- Build improvements.

## [2.2.4](https://github.com/alexdlaird/java-ngrok/compare/2.2.3...2.2.4) - 2023-11-14
### Added
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ on [Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.a
<dependency>
<groupId>com.github.alexdlaird</groupId>
<artifactId>java-ngrok</artifactId>
<version>2.2.4</version>
<version>2.2.5</version>
</dependency>
```

#### Gradle

```groovy
implementation "com.github.alexdlaird:java-ngrok:2.2.4"
implementation "com.github.alexdlaird:java-ngrok:2.2.5"
```

If we want `ngrok` to be available from the command line, [pyngrok](https://github.com/alexdlaird/pyngrok) can be
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group "com.github.alexdlaird"
version "2.2.4"
version "2.2.5"

java {
withJavadocJar()
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/alexdlaird/ngrok/NgrokClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public class NgrokClient {

private static final Logger LOGGER = Logger.getLogger(String.valueOf(NgrokClient.class));

private static final String VERSION = "2.2.4";
private static final String VERSION = "2.2.5";

private final JavaNgrokConfig javaNgrokConfig;
private final NgrokProcess ngrokProcess;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,16 @@ public Builder(final JavaNgrokConfig javaNgrokConfig) {
}

/**
* The path to the <code>ngrok</code> binary, defaults to <code>~/.ngrok2/ngrok</code>.
* The path to the <code>ngrok</code> binary, defaults to being placed in the same directory as
* <a href="https://ngrok.com/docs/ngrok-agent/config" target="_blank"><code>ngrok's</code> configs</a>.
*/
public Builder withNgrokPath(final Path ngrokPath) {
this.ngrokPath = ngrokPath;
return this;
}

/**
* The path to the <code>ngrok</code> config file, defaults to <code>~/.ngrok2/ngrok.yml</code>.
* The path to the <code>ngrok</code> config file, defaults to <a href="https://ngrok.com/docs/ngrok-agent/config" target="_blank"><code>ngrok's</code> default config location</a>.
*/
public Builder withConfigPath(final Path configPath) {
this.configPath = configPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@
* A helper for downloading and installing the <code>ngrok</code> for the current system.
*
* <h2>Config File</h2>
* By default, <a href="https://ngrok.com/docs/ngrok-agent/config" target="_blank"><code>ngrok</code> will look for its config file</a> in the home
* directory’s <code>.ngrok2</code> folder. We can override this behavior with
* {@link JavaNgrokConfig.Builder#withConfigPath(Path)}.
* By default, <code>ngrok</code> will look for its config file in <a href="https://ngrok.com/docs/ngrok-agent/config" target="_blank">the default location</a>.
* We can override this behavior with {@link JavaNgrokConfig.Builder#withConfigPath(Path)}.
*
* <h2>Binary Path</h2>
* The <code>java-ngrok</code> package manages its own <code>ngrok</code> binary. We can use our <code>ngrok</code>
Expand All @@ -75,8 +74,8 @@ public class NgrokInstaller {
public static final String LINUX = "LINUX";
public static final String FREEBSD = "FREEBSD";
public static final List<String> UNIX_BINARIES = List.of(MAC, LINUX, FREEBSD);
public static final Path DEFAULT_NGROK_PATH = Paths.get(System.getProperty("user.home"), ".ngrok2", NgrokInstaller.getNgrokBin());
public static final Path DEFAULT_CONFIG_PATH = Paths.get(System.getProperty("user.home"), ".ngrok2", "ngrok.yml");
public static final Path DEFAULT_NGROK_PATH = Paths.get(getDefaultNgrokDir().toString(), NgrokInstaller.getNgrokBin());
public static final Path DEFAULT_CONFIG_PATH = Paths.get(getDefaultNgrokDir().toString(), "ngrok.yml");

private static final List<String> VALID_LOG_LEVELS = List.of("info", "debug");

Expand Down Expand Up @@ -252,6 +251,18 @@ public static String getSystem() {
}
}

private static Path getDefaultNgrokDir() {
final String system = getSystem();
final String userHome = System.getProperty("user.home");
if (system.equals(MAC)) {
return Paths.get(userHome, "Library", "Application Support", "ngrok");
} else if (system.equals(WINDOWS)) {
return Paths.get(userHome, "AppData", "Local", "ngrok");
} else {
return Paths.get(userHome, ".config", "ngrok");
}
}

/**
* Get the <code>ngrok</code> config from the given path.
*
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ <h3>Maven</h3>
&lt;dependency&gt;
&lt;groupId&gt;com.github.alexdlaird&lt;/groupId&gt;
&lt;artifactId&gt;java-ngrok&lt;/artifactId&gt;
&lt;version&gt;2.2.4&lt;/version&gt;
&lt;version&gt;2.2.5&lt;/version&gt;
&lt;/dependency&gt;
</pre>

<h3>Gradle</h3>

<pre>
implementation "com.github.alexdlaird:java-ngrok:2.2.4"
implementation "com.github.alexdlaird:java-ngrok:2.2.5"
</pre>

If we want <code>ngrok</code> to be available from the command line,
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/github/alexdlaird/ngrok/NgrokTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@
public class NgrokTestCase {

protected final JavaNgrokConfig javaNgrokConfigV2 = new JavaNgrokConfig.Builder()
.withConfigPath(Paths.get("build", ".ngrok2", "config_v2.yml").toAbsolutePath())
.withConfigPath(Paths.get("build", ".ngrok", "config_v2.yml").toAbsolutePath())
.withNgrokPath(Paths.get("build", "bin", "v2", getNgrokBin()))
.withNgrokVersion(NgrokVersion.V2)
.build();

protected final JavaNgrokConfig javaNgrokConfigV3 = new JavaNgrokConfig.Builder()
.withConfigPath(Paths.get("build", ".ngrok2", "config_v3.yml").toAbsolutePath())
.withConfigPath(Paths.get("build", ".ngrok", "config_v3.yml").toAbsolutePath())
.withNgrokPath(Paths.get("build", "bin", "v3", getNgrokBin()))
.withNgrokVersion(NgrokVersion.V3)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void testInstallNgrokV3() throws IOException, InterruptedException {
public void testInstallNgrokDefault() throws IOException, InterruptedException {
// GIVEN
JavaNgrokConfig javaNgrokConfig = new JavaNgrokConfig.Builder()
.withConfigPath(Paths.get("build", ".ngrok2", "config_default.yml").toAbsolutePath())
.withConfigPath(Paths.get("build", ".ngrok", "config_default.yml").toAbsolutePath())
.withNgrokPath(Paths.get("build", "bin", "default", getNgrokBin()))
.build();
givenNgrokNotInstalled(javaNgrokConfig);
Expand Down Expand Up @@ -118,7 +118,7 @@ public void testInstallDefaultConfig() throws IOException {
public void testGetDefaultNgrokConfig() {
// GIVEN
final JavaNgrokConfig javaNgrokConfigV3Tmp = new JavaNgrokConfig.Builder()
.withConfigPath(Paths.get("build", ".ngrok2", "config_v2_tmp.yml").toAbsolutePath())
.withConfigPath(Paths.get("build", ".ngrok", "config_v2_tmp.yml").toAbsolutePath())
.withNgrokPath(Paths.get("build", "bin", "v2", getNgrokBin()))
.withNgrokVersion(NgrokVersion.V3)
.build();
Expand Down

0 comments on commit 385ae27

Please sign in to comment.