Skip to content

Commit e820d8d

Browse files
committed
config v2
1 parent 8c7b8d4 commit e820d8d

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/main/java/com/redhat/labs/omp/resource/ConfigResource.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,44 @@
66
import javax.ws.rs.Path;
77
import javax.ws.rs.Produces;
88
import javax.ws.rs.core.MediaType;
9+
import javax.ws.rs.core.Response;
910

11+
import org.slf4j.Logger;
12+
import org.slf4j.LoggerFactory;
13+
14+
import com.fasterxml.jackson.core.JsonProcessingException;
15+
import com.fasterxml.jackson.databind.ObjectMapper;
16+
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
1017
import com.redhat.labs.omp.models.gitlab.File;
1118
import com.redhat.labs.omp.service.ConfigService;
1219

13-
@Path("/api/v1/config")
20+
@Path("/api")
1421
@Produces(MediaType.APPLICATION_JSON)
1522
@Consumes(MediaType.APPLICATION_JSON)
1623
public class ConfigResource {
24+
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigResource.class);
1725

1826
@Inject
1927
ConfigService configService;
2028

2129
@GET
30+
@Path("/v1/config")
2231
public File get() {
2332
return configService.getConfigFile();
2433
}
2534

35+
@GET
36+
@Path("/v2/config")
37+
public Response getJson() {
38+
File configFile = configService.getConfigFile();
39+
ObjectMapper om = new ObjectMapper(new YAMLFactory());
40+
try {
41+
LOGGER.debug(configFile.getContent());
42+
Object content = om.readValue(configFile.getContent(), Object.class);
43+
return Response.ok(content).build();
44+
} catch (JsonProcessingException e) {
45+
LOGGER.error(String.format("Error processing config file %s", configFile.getFilePath()), e);
46+
return Response.serverError().build();
47+
}
48+
}
2649
}

src/test/java/com/redhat/labs/omp/resource/ConfigResourceTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,19 @@ public void testGetConfigFileSuccess() {
1919

2020
}
2121

22+
@Test
23+
public void testGetConfigFileSuccessV2() {
24+
25+
given().when().contentType(ContentType.JSON).get("/api/v2/config").then().statusCode(200).body(is(
26+
"{\"providers\":[{\"label\":\"AWS\",\"value\":\"ec2\",\"regions\":[{\"label\":\"US East 1 (N. Virginia)\","
27+
+ "\"value\":\"us-east-1\"},{\"label\":\"US East 2 (Ohio)\",\"value\":\"us-east-2\"}]}],\"openshift\":"
28+
+ "{\"versions\":[{\"label\":\"v4.1\",\"value\":\"4.1.31\"},{\"label\":\"v4.2\",\"value\":\"4.2.16\"},"
29+
+ "{\"label\":\"v4.3\",\"value\":\"4.3.0\"}],\"persistent-storage\":[{\"label\":\"None\",\"value\":\"none\"},"
30+
+ "{\"label\":\"50GB\",\"value\":\"50G\"},{\"label\":\"100GB\",\"value\":\"100G\"},{\"label\":\"250GB\",\"value\":"
31+
+ "\"250G\"},{\"label\":\"500GB\",\"value\":\"500G\"}],\"cluster-size\":[{\"label\":\"Small\",\"value\":\"small\"}]},"
32+
+ "\"user-management\":{\"rbac\":{\"roles\":[{\"label\":\"Developer\",\"value\":\"developer\"},{\"label\":\"Observer\",\"value\":\"observer\"},"
33+
+ "{\"label\":\"Admin\",\"value\":\"admin\"}]}}}"));
34+
35+
}
36+
2237
}

0 commit comments

Comments
 (0)