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
21 changes: 13 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import org.apache.tools.ant.filters.ReplaceTokens
import java.util.*

plugins {
id("groovy")
id("groovy")
id("io.micronaut.application") version "4.5.3"
id("com.gradleup.shadow") version "8.3.6"
id("io.micronaut.openapi") version "4.5.3"
Expand All @@ -10,7 +13,7 @@ plugins {
version = project.properties["justserveCliVersion"]!!
group = "org.justserve"

apply(from="gradle/asciidoc.gradle")
apply(from = "gradle/asciidoc.gradle")

repositories {
mavenCentral()
Expand Down Expand Up @@ -38,11 +41,15 @@ java {
sourceCompatibility = JavaVersion.toVersion("21")
targetCompatibility = JavaVersion.toVersion("21")
}
tasks.withType<Test>().configureEach {
// This makes the project version available as a system property to the test JVM.
// Micronaut can then read and inject it using @Value.
systemProperty("justserveCliVersion", version)

tasks.withType<ProcessResources> {
val props = Properties()
file("gradle.properties").inputStream().use { props.load(it) }
filesMatching("**/application.yml") {
filter(mapOf("tokens" to props), ReplaceTokens::class.java)
}
}

micronaut {
testRuntime("spock2")
openapi {
Expand Down Expand Up @@ -74,5 +81,3 @@ graalvmNative.binaries {
tasks.named<io.micronaut.gradle.docker.NativeImageDockerfile>("dockerfileNative") {
jdkVersion = "21"
}


2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
micronautVersion=4.8.3
justserveCliVersion=0.0.3-SNAPSHOT
justserveCliVersion=0.0.3
21 changes: 12 additions & 9 deletions src/main/java/org/justserve/FulcrumCommand.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package org.justserve;

import static org.justserve.JustServeUtils.justServePrint;
import static org.justserve.JustServeUtils.justServePrintErr;
import org.justserve.client.UserClient;
import org.justserve.model.UserHashRequestByEmail;

import io.micronaut.configuration.picocli.PicocliRunner;
import io.micronaut.context.annotation.Value;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.client.exceptions.HttpClientResponseException;
import jakarta.inject.Inject;
import org.justserve.client.UserClient;
import org.justserve.model.UserHashRequestByEmail;
import jakarta.inject.Provider;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

import static org.justserve.JustServeUtils.justServePrint;
import static org.justserve.JustServeUtils.justServePrintErr;

@Command(name = "justserve",
description = "justserve-cli is a terminal tool to help specialists and admin using JustServe")
public class FulcrumCommand implements Runnable {
Expand All @@ -23,10 +24,11 @@ public class FulcrumCommand implements Runnable {
@Option(names = {"version", "--version", "-v"})
boolean version = false;

String justServeCliVersion = "0.0.3-SNAPSHOT";
@Value("${micronaut.application.version}")
String justserveCliVersion;

@Inject
UserClient userClient;
Provider<UserClient> userClientProvider;

@Value("${justserve.token}")
String token;
Expand All @@ -37,16 +39,17 @@ public static void main(String[] args) {

public void run() {
if (version) {
justServePrint(justServeCliVersion);
justServePrint(justserveCliVersion);
return;
}
HttpResponse<String> response;
if ("i-need-to-be-defined".equals(token) || null == token) {
if ("i-need-to-be-defined".equals(token) || null == token ) {
justServePrintErr("The Authentication token is not assigned as an environment variable. " +
"Please define the environment variable \"JUSTSERVE_TOKEN\" and try again.");
return;
}
try {
UserClient userClient = userClientProvider.get();
response = userClient.getTempPassword(new UserHashRequestByEmail(email));
} catch (HttpClientResponseException e) {
justServePrintErr("received an unexpected response from JustServe: %d (%s)%n",
Expand Down
7 changes: 4 additions & 3 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
micronaut:
application:
name: fulcrum
name: justserve-cli
version: "@justserveCliVersion@"
http:
services:
justserve:
url: ${JUSTSERVE_URL:`https://www.justserve.org`}
url: ${:https://www.justserve.org}
client:
read-timeout: 20s
justserve:
token: ${JUSTSERVE_TOKEN:i-need-to-be-defined}
token: ${:i-need-to-be-defined}
jackson:
deserialization:
ACCEPT_EMPTY_STRING_AS_NULL_OBJECT: true
9 changes: 8 additions & 1 deletion src/test/groovy/org/justserve/FulcrumCommandSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.justserve

import io.micronaut.configuration.picocli.PicocliRunner
import io.micronaut.context.ApplicationContext
import io.micronaut.context.annotation.Value
import io.micronaut.context.env.Environment
import io.micronaut.test.extensions.spock.annotation.MicronautTest
import spock.lang.Shared
Expand All @@ -16,6 +17,9 @@ class FulcrumCommandSpec extends Specification {
@Shared
Pattern cliVersion

@Shared
String justServeUrl

@Shared
Pattern blankRegex = Pattern.compile "^\\s*\$"

Expand All @@ -31,6 +35,7 @@ class FulcrumCommandSpec extends Specification {


def setupSpec() {
justServeUrl = System.getenv("JUSTSERVE_URL") ?: "https://www.justserve.org"
def props = new Properties()
new File('gradle.properties').withInputStream { stream ->
props.load(stream)
Expand All @@ -49,7 +54,8 @@ class FulcrumCommandSpec extends Specification {
ctx = ApplicationContext.builder()
.environments(Environment.CLI, Environment.TEST)
.properties([
"JUSTSERVE_TOKEN": System.getenv("TEST_TOKEN")
"justserve.token": System.getenv("TEST_TOKEN"),
"micronaut.http.services.justserve.url" : justServeUrl
])
.build()
.start()
Expand All @@ -58,6 +64,7 @@ class FulcrumCommandSpec extends Specification {
.builder()
.environments(Environment.CLI, Environment.TEST)
.environmentVariableExcludes("JUSTSERVE_TOKEN")
.properties(["micronaut.http.services.justserve.url": justServeUrl])
.build()
.start()
}
Expand Down
5 changes: 4 additions & 1 deletion src/test/groovy/org/justserve/client/UserClientSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,21 @@ class UserClientSpec extends Specification {
UserClient userClient

void setupSpec() {
def justServeUrl = System.getenv("JUSTSERVE_URL") ?: "https://www.justserve.org"
if (null != System.getenv("JUSTSERVE_TOKEN")) {
throw new IllegalStateException("JUSTSERVE_TOKEN is set. Do not define this variable in testing.")
}
noAuthCtx = ApplicationContext.builder(EmbeddedServer)
.environmentVariableExcludes("JUSTSERVE_TOKEN", "TEST_TOKEN")
.properties(["micronaut.http.services.justserve.url": justServeUrl])
.build()
.start()
noAuthUserClient = noAuthCtx.getBean(UserClient)
ctx = ApplicationContext.builder(EmbeddedServer)
.environmentVariableExcludes("JUSTSERVE_TOKEN")
.properties([
"JUSTSERVE_TOKEN": System.getenv("TEST_TOKEN")
"justserve.token" : System.getenv("TEST_TOKEN"),
"micronaut.http.services.justserve.url": justServeUrl
])
.build()
.start()
Expand Down
Loading