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
18 changes: 9 additions & 9 deletions cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ dependencies {
annotationProcessor("io.micronaut.serde:micronaut-serde-processor")
annotationProcessor("io.micronaut.validation:micronaut-validation")
implementation("io.micronaut.validation:micronaut-validation")
implementation("io.micronaut.reactor:micronaut-reactor")
implementation("info.picocli:picocli")
implementation("info.picocli:picocli-jansi-graalvm:1.2.0")
implementation("org.fusesource.jansi:jansi:2.4.2")
implementation("info.picocli:picocli-shell-jline3:4.7.6")
implementation("org.jline:jline:3.30.5")
implementation("info.picocli:picocli-jansi-graalvm:${project.properties["jansiGraalvmVersion"]}")
implementation("org.fusesource.jansi:jansi:${project.properties["jansiVersion"]}")
implementation("info.picocli:picocli-shell-jline3:${project.properties["picocliShellVersion"]}")
implementation("org.jline:jline:${project.properties["jlineVersion"]}")
implementation("io.micronaut.picocli:micronaut-picocli")
implementation("org.simplejavamail:simple-java-mail:8.12.6")
implementation("org.simplejavamail:simple-java-mail:${project.properties["simpleJavaMailVersion"]}")
implementation("io.micronaut.serde:micronaut-serde-jackson")
implementation("io.micronaut:micronaut-http-client")
implementation("org.simplejavamail:simple-java-mail:8.12.6")
implementation("org.jsoup:jsoup:1.21.2")
implementation("org.jsoup:jsoup:${project.properties["jsoupVersion"]}")
implementation(project(":core"))
testImplementation("net.datafaker:datafaker:2.5.1")
testImplementation("org.apache.commons:commons-lang3:3.20.0")
testImplementation("net.datafaker:datafaker:${project.properties["datafakerVersion"]}")
testImplementation("org.apache.commons:commons-lang3:${project.properties["commonsLangVersion"]}")
testImplementation(project(path = ":core", configuration = "testArchives"))
compileOnly("org.projectlombok:lombok")
runtimeOnly("ch.qos.logback:logback-classic")
Expand Down
15 changes: 3 additions & 12 deletions cli/src/main/java/org/justserve/command/AssignOrgToProject.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.justserve.command;

import io.micronaut.http.HttpResponse;
import io.micronaut.http.HttpStatus;
import io.micronaut.http.client.exceptions.HttpClientResponseException;
import jakarta.inject.Inject;
import jakarta.inject.Provider;
Expand Down Expand Up @@ -39,16 +37,9 @@ public void run() {

try {
log.atTrace().log("Assigning organization {} to project {}", orgId, projectId);
HttpResponse<Object> response = client.assignOrganizationToProject(projectId, orgId);
if (response.status() == HttpStatus.OK) {
printNormal("Successfully assigned organization %s to project %s", orgId, projectId);
log.atTrace().log("received api response status: {}", response.status());
} else {
printError("Failed to assign organization " + orgId + " to project " + projectId +
". Expected HTTP Status 'OK', but got " + response.status());
log.atError().log("Failed to assign organization {} to project {}. Expected HTTP Status 'OK', but got {}",
orgId, projectId, response.status());
}
client.assignOrganizationToProject(projectId, orgId).block();
printNormal("Successfully assigned organization %s to project %s", orgId, projectId);
log.atTrace().log("Successfully assigned organization to project");
} catch (HttpClientResponseException e) {
printError("Failed to assign organization %s to project %s. (%s: %s)",
orgId, projectId, e.getStatus().getCode(), e.getMessage());
Expand Down
21 changes: 0 additions & 21 deletions cli/src/main/java/org/justserve/command/ConsoleOutput.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,6 @@
package org.justserve.command;

public interface ConsoleOutput {
ConsoleOutput NOOP = new ConsoleOutput() {
@Override
public void out(String message) { }

@Override
public void err(String message) { }

@Override
public void warning(String message) { }

@Override
public boolean showStacktrace() {
return false;
}

@Override
public boolean verbose() {
return false;
}

};

void out(String message);

Expand Down
7 changes: 3 additions & 4 deletions cli/src/main/java/org/justserve/command/GetTempPassword.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.justserve.command;

import io.micronaut.http.HttpResponse;
import io.micronaut.http.client.exceptions.HttpClientResponseException;
import jakarta.inject.Inject;
import jakarta.inject.Provider;
Expand Down Expand Up @@ -30,18 +29,18 @@ public void run() {
if (isTokenInvalid()) {
return;
}
HttpResponse<String> response;
String response;
try {
UserClient userClient = userClientProvider.get();
response = userClient.getTempPassword(new UserHashRequestByEmail(email));
response = userClient.getTempPassword(new UserHashRequestByEmail(email)).block();
} catch (HttpClientResponseException e) {
String errorMessage = "Received an unexpected response from JustServe:" +
String.format("%n%d (%s)", e.getResponse().status().getCode(), e.reason());
printError(errorMessage);
return;
}
if (response != null) {
printNormal(response.body().replace("\"", "").trim());
printNormal(response.replace("\"", "").trim());
} else {
printError("An unexpected error occurred. Response from JustServe was null.");
}
Expand Down
22 changes: 12 additions & 10 deletions cli/src/main/java/org/justserve/command/MakeOrgAdmin.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.justserve.command;

import io.micronaut.core.annotation.Nullable;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.client.exceptions.HttpClientResponseException;
import jakarta.inject.Inject;
import jakarta.inject.Provider;
Expand All @@ -10,6 +9,7 @@
import lombok.extern.slf4j.Slf4j;
import org.justserve.client.BoundaryPermissionClient;
import org.justserve.client.DynamicRoutingClient;
import org.justserve.model.DynamicRoutingDataResponse;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
Expand Down Expand Up @@ -47,16 +47,19 @@ public void run() {
// since we allow submitting orgId's and orgUrl, convert any slugs to orgId's
Map<Org, UUID> orgUuidMap = Arrays.stream(orgs).distinct().parallel()
.map(org -> {
if (org instanceof OrgId) {
return new AbstractMap.SimpleEntry<>(org, ((OrgId) org).getId());
if (org instanceof OrgId orgId) {
return new AbstractMap.SimpleEntry<>(org, orgId.getId());
}
DynamicRoutingDataResponse response;
try {
return new AbstractMap.SimpleEntry<>(org, dynamicRoutingClient
.getOrgIdFromSlug(((OrgSlug) org).getSlug()).body().getId());
} catch (NullPointerException noOrgFound) {
response = dynamicRoutingClient.getOrgIdFromSlug(((OrgSlug) org).getSlug()).block();
assert response != null;
return new AbstractMap.SimpleEntry<>(org, response.getId());
} catch (HttpClientResponseException | NullPointerException noOrgFound) {
err(String.format("The org '%s' is not found on JustServe", ((OrgSlug) org).getSlug()));
return null;
}
}

})
.filter(Objects::nonNull)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
Expand All @@ -67,13 +70,12 @@ public void run() {
orgUuidMap.entrySet().stream().parallel().forEach(entry -> {
Org org = entry.getKey();
UUID orgId = entry.getValue();
String orgIdentifier = org instanceof OrgSlug ? ((OrgSlug) org).getSlug() + " (" + orgId + ")" : orgId.toString();
String orgIdentifier = org instanceof OrgSlug orgSlug ? orgSlug.getSlug() + " (" + orgId + ")" : orgId.toString();

log.atTrace().log("Making user {} an admin for org {}", user, orgIdentifier);
try {
log.atTrace().log("sending request to make user {} an admin for org {}.", user, orgIdentifier);
HttpResponse<Object> response = boundaryPermissionClient.makeAdminForOrg(orgId, user);
log.atTrace().log("received api response status: {}", response.status());
boundaryPermissionClient.makeAdminForOrg(orgId, user).block();
log.atDebug().log("Successfully made user {} an admin for org {}.", user, orgIdentifier);
successfulReassignments.put(org, orgId);
} catch (HttpClientResponseException e) {
Expand Down
22 changes: 6 additions & 16 deletions cli/src/main/java/org/justserve/command/UnReassignProjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,16 @@ public void run() {
for (UUID projectId : projectIds) {
GetProjectRequest getProjectRequest = new GetProjectRequest();
Project project;
String failedToGetError = ("Failed to get project '" + projectName + "' (" + projectId + ")");
try {
project = client.getProject(projectId, " ", getProjectRequest).body();
project = client.getProject(projectId, " ", getProjectRequest).block();
} catch (HttpClientResponseException | NullPointerException e) {
printError("Failed to get project " + projectName + " (" + projectId + ")");
printError(failedToGetError);
log.atError().setCause(e).log("Error getting project");
continue;
}
if (null == project) {
printError("Failed to get project '" + projectName + "' (" + projectId + ")");
printError(failedToGetError);
log.atError().log("Project {} not found", projectId);
continue;
}
Expand All @@ -106,24 +107,13 @@ public void run() {
}
ReassignProjectRequest reassignProjectRequest = new ReassignProjectRequest(userID, project.getProjectOwnerUserId());
log.atTrace().log("Reassigning project {} ({}) to user {}", projectName, projectId, userID);
HttpResponse<Object> reassignResponse = null;
try {
reassignResponse = client.reassignProject(projectId, reassignProjectRequest);
client.reassignProject(projectId, reassignProjectRequest).block();
successCount ++;
} catch (HttpClientResponseException e) {
printError("Failed to reassign project " + projectName + " (" + projectId + ") to user " + userID);
log.atError().setCause(e).log("Error response from API: {}", e.getResponse().body());
}
if (null != reassignResponse && reassignResponse.status() == HttpStatus.OK) {
printNormal("Successfully reassigned project %s (%s) to user %s", projectName, projectId, userID);
log.atTrace().log("received api response status: {}", reassignResponse.status());
successCount++;
continue;
}
String reason = reassignResponse == null ? "response is null" : reassignResponse.status().toString();
printError("Failed to reassign project " + projectName + " (" + projectId + ") to user " + userID +
". Expected HTTP Status 'OK', but got " + reason);
log.atError().log("Failed to reassign project {} ({}) to user {}. Expected HTTP Status 'OK', but got {}",
projectName, projectId, userID, reason);
}
}
printNormal("Successfully reassigned %d projects to user %s", successCount, userID);
Expand Down
22 changes: 11 additions & 11 deletions cli/src/main/java/org/justserve/util/JustServePrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
*/
public final class JustServePrinter {

private final static Ansi blue = ansi().fgRgb(0, 158, 185);
private final static Ansi orange = ansi().fgRgb(255, 140, 0); // OG color is 239, 94, 57
private final static Ansi red = ansi().fgRgb(233, 59, 84); // I definitely eyeballed this one
private final static Ansi yellow = ansi().fgRgb(225, 188, 33);

private final static Ansi normalStyle = ansi().reset();
private final static Ansi titleStyle = blue.bold();
private final static Ansi emphasisStyle = orange.bold();
private final static Ansi warningStyle = yellow;
private final static Ansi errorTitleStyle = red.bold();
private final static Ansi errorInfoStyle = ansi().reset();
private static final Ansi blue = ansi().fgRgb(0, 158, 185);
private static final Ansi orange = ansi().fgRgb(255, 140, 0); // OG color is 239, 94, 57
private static final Ansi red = ansi().fgRgb(233, 59, 84); // I definitely eyeballed this one
private static final Ansi yellow = ansi().fgRgb(225, 188, 33);

private static final Ansi normalStyle = ansi().reset();
private static final Ansi titleStyle = blue.bold();
private static final Ansi emphasisStyle = orange.bold();
private static final Ansi warningStyle = yellow;
private static final Ansi errorTitleStyle = red.bold();
private static final Ansi errorInfoStyle = ansi().reset();


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class AssignOrgToProjectSpec extends BaseCommandSpec {
def "can assign an organization to a project"() {
given:
def orgSearchResponse = authOrgClient.searchByLocation(createSearchRequestForElkGrove())
UUID orgId = orgSearchResponse.body().organizations.first().id
UUID orgId = orgSearchResponse.block().organizations.first().id
ProjectCard project = searchResults.first()
def args = ["assignOrgToProject", "-p", project.getId().toString(), "-o", orgId.toString()]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ import static org.spockframework.runtime.model.parallel.ExecutionMode.SAME_THREA
class GetTempPasswordSpec extends BaseCommandSpec {

@Unroll("getting temp password with '#flag' and '#email' #expectation")
def "commands to query temporary password should behave as expected with or without authentication"() {
def "commands to query temporary password should behave as expected with or without authentication"(
String flag,
String email,
ApplicationContext context,
String expectedOutput,
String expectedError
) {
when:
def (outputStream, errorStream) = executeCommand(context as ApplicationContext, ["getTempPassword", flag, email] as String[])

Expand Down
Loading
Loading