Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ jobs:
uses: actions/[email protected]
with:
# maximize compatibility with minecraft images
java-version: '8'
distribution: 'adopt'
distribution: 'temurin'
java-version: '17'
cache: gradle

- name: Grant execute permission for gradlew
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ jobs:
uses: actions/[email protected]
with:
# maximize compatibility with minecraft images
java-version: '8'
distribution: 'adopt'
distribution: 'temurin'
java-version: '17'
cache: gradle

- name: Grant execute permission for gradlew
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/.idea/
/.vscode/
/target/
/build/
/bin/
/.gradle/

/dependency-reduced-pom.xml
/pom.xml.releaseBackup
/release.properties
/release.properties
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ plugins {
group = 'com.github.itzg'
description = 'mc-image-helper'

compileJava {
options.release = 8
}

test {
useJUnitPlatform()

Expand Down
12 changes: 11 additions & 1 deletion src/main/java/me/itzg/helpers/get/GetCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ public class GetCommand implements Callable<Integer> {
)
String acceptHeader;

@Option(names = "--apikey",
description = "Specifies the accept header to use with the request"
)
String apikeyHeader;

@Option(names = "--uris-file",
description = "A file that contains a URL per line"
)
Expand Down Expand Up @@ -194,7 +199,9 @@ private int checkUrisExist(CloseableHttpClient client) {
if (acceptHeader != null) {
request.addHeader(HttpHeaders.ACCEPT, acceptHeader);
}

if (apikeyHeader != null) {
request.addHeader("x-api-key", apikeyHeader);
}
try {
final int statusCode = client.execute(request).getCode();
if (statusCode == HttpStatus.SC_OK) {
Expand Down Expand Up @@ -347,6 +354,9 @@ private Path processSingleUri(URI uri, CloseableHttpClient client, PrintWriter s
if (acceptHeader != null) {
request.addHeader(HttpHeaders.ACCEPT, acceptHeader);
}
if (apikeyHeader != null) {
request.addHeader("x-api-key", apikeyHeader);
}
if (modifiedSinceFile != null && Files.exists(modifiedSinceFile)) {
final FileTime lastModifiedTime = Files.getLastModifiedTime(modifiedSinceFile);
request.addHeader(HttpHeaders.IF_MODIFIED_SINCE,
Expand Down
23 changes: 22 additions & 1 deletion src/test/java/me/itzg/helpers/get/GetCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,27 @@ void usesGivenAcceptHeader() throws MalformedURLException {
assertThat(output.toString()).isEqualTo("Some text");
}

@Test
void usesGivenApiKeyHeader() throws MalformedURLException {
expectRequest("GET","/content.txt",
request -> request.withHeader("x-api-key", "xxxxxx"),
response()
.withBody("Some text", MediaType.TEXT_PLAIN)
);

final StringWriter output = new StringWriter();
final int status =
new CommandLine(new GetCommand())
.setOut(new PrintWriter(output))
.execute(
"--apikey", "xxxxxx",
buildMockedUrl("/content.txt").toString()
);

assertThat(status).isEqualTo(0);
assertThat(output.toString()).isEqualTo("Some text");
}

@Nested
class ExistsTests {

Expand Down Expand Up @@ -857,4 +878,4 @@ private void expectRequest(String method,
);
}

}
}