Skip to content

Commit

Permalink
Merge pull request #9 from mcanoy/rbac
Browse files Browse the repository at this point in the history
add configuration read specifically for rbac
  • Loading branch information
mcanoy authored Jul 29, 2021
2 parents 4bbf34b + 01e595b commit 5767f79
Show file tree
Hide file tree
Showing 15 changed files with 296 additions and 139 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ nb-configuration.xml

# Local environment
.env
.adhoc
4 changes: 2 additions & 2 deletions deployment/templates/deploymentconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ spec:
- envFrom:
readinessProbe:
httpGet:
path: /health/ready
path: /q/health/ready
port: 8080
scheme: HTTP
timeoutSeconds: 1
Expand All @@ -39,7 +39,7 @@ spec:
failureThreshold: 3
livenessProbe:
httpGet:
path: /health/live
path: /q/health/live
port: 8080
scheme: HTTP
timeoutSeconds: 1
Expand Down
29 changes: 6 additions & 23 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus-plugin.version>1.13.3.Final</quarkus-plugin.version>
<quarkus-plugin.version>2.0.3.Final</quarkus-plugin.version>
<quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.version>1.13.3.Final</quarkus.platform.version>
<quarkus.platform.version>2.0.3.Final</quarkus.platform.version>
<surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
<lombok.version>1.18.20</lombok.version>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
Expand Down Expand Up @@ -63,6 +63,10 @@
</dependency>
<!-- Other -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jacoco</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
Expand Down Expand Up @@ -117,27 +121,6 @@
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<phase>test-compile</phase>
</execution>
<execution>
<id>jacoco-site</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.redhat.labs.lodestar.service.RuntimeConfigService;

Expand All @@ -24,5 +25,11 @@ public class RuntimeConfigResource {
public String get(@QueryParam("type") Optional<String> type) {
return configService.getRuntimeConfiguration(type);
}

@GET
@Path("rbac")
public Response getPermission() {
return Response.ok(configService.getPermission()).build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import javax.enterprise.context.ApplicationScoped;
Expand Down Expand Up @@ -153,5 +154,23 @@ public String getRuntimeConfiguration(Optional<String> engagementType) {
return jsonb.toJson(base);

}

/**
* Returns a mapping of engagement type to rbac access indicating the groups
* that can write engagements. The purpose is to inform the front end on a user's
* ability to write data for an engagement
* @return
*/
@SuppressWarnings("unchecked")
public Map<String, Set<String>> getPermission() {

Map<String, Object> configuration = baseConfiguration.getConfiguration();
Map<String, Set<String>> typesList = Optional.of(configuration)
.map(m -> (Map<String, Set<String>>) m.get("rbac")).orElse(new HashMap<>());

LOGGER.debug("rbac {}", typesList);

return typesList;
}

}
4 changes: 2 additions & 2 deletions src/main/resources/META-INF/resources/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@

<p><a href="https://github.com/rht-labs/lodestar-config">Github Repo</p >

<p><a href="/swagger-ui">Swagger UI</a></p>
<p><a href="/q/swagger-ui">Swagger UI</a></p>

</div>
<div class="right-column">
Expand All @@ -135,4 +135,4 @@ <h3>Application</h3>
</div>
</div>
</body>
</html>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void testGetHealth() {
+ " \"status\": \"UP\",\n" + " \"data\": {\n" + " \"OK\": \"👍\"\n"
+ " }\n" + " }\n" + " ]\n" + "}";

given().when().contentType(ContentType.JSON).get("/health").then().statusCode(200).body(is(expected));
given().when().contentType(ContentType.JSON).get("q/health").then().statusCode(200).body(is(expected));

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,90 +1,71 @@
package com.redhat.labs.lodestar.resource;

import static io.restassured.RestAssured.given;
import static io.restassured.path.json.JsonPath.from;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.List;
import java.util.Map;

import org.junit.jupiter.api.Test;

import com.redhat.labs.lodestar.utils.ResourceLoader;

import io.quarkus.test.common.http.TestHTTPEndpoint;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.http.ContentType;

@QuarkusTest
@TestHTTPEndpoint(RuntimeConfigResource.class)
class RuntimeConfigResourceTest {

static final String RUNTIME_CONFIG_API = "/api/v1/configs/runtime";


@Test
void testGetPermission() {
String response = given().when().get("/rbac").then().statusCode(200).extract().asString();

Map<String, List<String>> perm = from(response).getMap("");

assertTrue(perm.containsKey("velour"));
assertTrue(perm.containsKey("velvet"));
assertTrue(perm.containsKey("felt"));
assertTrue(perm.get("velour").contains("writer"));
assertTrue(perm.get("velvet").contains("writer"));
assertTrue(perm.get("felt").contains("writer"));
assertTrue(perm.get("velour").contains("velour-writer"));
assertTrue(perm.get("felt").contains("felt-writer"));
assertEquals(3, perm.size());
assertEquals(2, perm.get("velour").size());
assertEquals(2, perm.get("felt").size());
assertEquals(1, perm.get("velvet").size());
}

@Test
void testGetRuntimeConfigurationNoType() {

given().when().contentType(ContentType.JSON).get(RUNTIME_CONFIG_API).then().statusCode(200).body(is("\n{\n" + " \"basic_information\": {\n" + " \"engagement_types\": {\n"
+ " \"options\": [\n" + " {\n"
+ " \"label\": \"Type One\",\n" + " \"value\": \"TypeOne\"\n"
+ " },\n" + " {\n" + " \"label\": \"TypeTwo\",\n"
+ " \"value\": \"TypeTwo\"\n" + " },\n" + " {\n"
+ " \"label\": \"TypeThree\",\n" + " \"value\": \"TypeThree\",\n"
+ " \"default\": true\n" + " }\n" + " ]\n" + " }\n"
+ " },\n" + " \"more_information\": {\n" + " \"some_value\": \"hello\",\n"
+ " \"another_value\": \"base\"\n" + " },\n" + " \"other_options\": {\n"
+ " \"types\": {\n" + " \"options\": [\n" + " {\n"
+ " \"label\": \"OptionOne\",\n" + " \"value\": \"optionOne\"\n"
+ " },\n" + " {\n" + " \"label\": \"OptionTwo\",\n"
+ " \"value\": \"optionTwo\"\n" + " }\n" + " ]\n"
+ " }\n" + " }\n" + "}"));
String response = ResourceLoader.load("expected/service-base-config.json");
given().when().contentType(ContentType.JSON).get().then().statusCode(200).body(is(response));

}

@Test
void testGetRuntimeConfigurationTypeOne() {

given().when().contentType(ContentType.JSON).queryParam("type", "TypeOne").get(RUNTIME_CONFIG_API).then().statusCode(200).body(is("\n" + "{\n" + " \"more_information\": {\n" + " \"another_value\": \"type one\",\n"
+ " \"some_value\": \"hello\"\n" + " },\n" + " \"basic_information\": {\n"
+ " \"engagement_types\": {\n" + " \"options\": [\n" + " {\n"
+ " \"label\": \"Type One\",\n" + " \"value\": \"TypeOne\"\n"
+ " },\n" + " {\n" + " \"label\": \"TypeTwo\",\n"
+ " \"value\": \"TypeTwo\"\n" + " },\n" + " {\n"
+ " \"label\": \"TypeThree\",\n" + " \"value\": \"TypeThree\",\n"
+ " \"default\": true\n" + " }\n" + " ]\n" + " }\n"
+ " },\n" + " \"other_options\": {\n" + " \"types\": {\n" + " \"options\": [\n"
+ " {\n" + " \"label\": \"OptionOne\",\n"
+ " \"value\": \"option1\"\n" + " }\n" + " ]\n"
+ " }\n" + " }\n" + "}"));
String response = ResourceLoader.load("expected/service-get-type-one-config.json");
given().when().contentType(ContentType.JSON).queryParam("type", "TypeOne").get().then().statusCode(200).body(is(response));

}

@Test
void testGetRuntimeConfigurationTypeTwo() {

given().when().contentType(ContentType.JSON).queryParam("type", "TypeTwo").get(RUNTIME_CONFIG_API).then().statusCode(200).body(is("\n" + "{\n" + " \"more_information\": {\n" + " \"another_value\": \"type two\",\n"
+ " \"some_value\": \"hello\"\n" + " },\n" + " \"basic_information\": {\n"
+ " \"engagement_types\": {\n" + " \"options\": [\n" + " {\n"
+ " \"label\": \"Type One\",\n" + " \"value\": \"TypeOne\"\n"
+ " },\n" + " {\n" + " \"label\": \"TypeTwo\",\n"
+ " \"value\": \"TypeTwo\"\n" + " },\n" + " {\n"
+ " \"label\": \"TypeThree\",\n" + " \"value\": \"TypeThree\",\n"
+ " \"default\": true\n" + " }\n" + " ]\n" + " }\n"
+ " },\n" + " \"other_options\": {\n" + " \"types\": {\n" + " \"options\": [\n"
+ " {\n" + " \"label\": \"OptionTwo\",\n"
+ " \"value\": \"option2\"\n" + " }\n" + " ]\n"
+ " }\n" + " }\n" + "}"));
String response = ResourceLoader.load("expected/service-get-type-two-config.json");
given().when().contentType(ContentType.JSON).queryParam("type", "TypeTwo").get().then().statusCode(200).body(is(response));

}

@Test
void testGetRuntimeConfigurationTypeUnknown() {

given().when().contentType(ContentType.JSON).queryParam("type", "TypeThree").get(RUNTIME_CONFIG_API).then().statusCode(200).body(is("\n" + "{\n" + " \"more_information\": {\n" + " \"some_value\": \"hello\",\n"
+ " \"another_value\": \"base\"\n" + " },\n" + " \"basic_information\": {\n"
+ " \"engagement_types\": {\n" + " \"options\": [\n" + " {\n"
+ " \"label\": \"Type One\",\n" + " \"value\": \"TypeOne\"\n"
+ " },\n" + " {\n" + " \"label\": \"TypeTwo\",\n"
+ " \"value\": \"TypeTwo\"\n" + " },\n" + " {\n"
+ " \"label\": \"TypeThree\",\n" + " \"value\": \"TypeThree\",\n"
+ " \"default\": true\n" + " }\n" + " ]\n" + " }\n"
+ " },\n" + " \"other_options\": {\n" + " \"types\": {\n" + " \"options\": [\n"
+ " {\n" + " \"label\": \"OptionOne\",\n"
+ " \"value\": \"optionOne\"\n" + " },\n" + " {\n"
+ " \"label\": \"OptionTwo\",\n" + " \"value\": \"optionTwo\"\n"
+ " }\n" + " ]\n" + " }\n" + " }\n" + "}"));
String response = ResourceLoader.load("expected/service-get-type-three-config.json");
given().when().contentType(ContentType.JSON).queryParam("type", "TypeThree").get().then().statusCode(200).body(is(response));

}

Expand Down
Loading

0 comments on commit 5767f79

Please sign in to comment.