Skip to content

Commit

Permalink
Merge branch 'master' into actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Asgeir Nilsen committed Mar 12, 2020
2 parents c5bb39f + 1228685 commit 6da0fb3
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 62 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
FROM gradle:4.10.3-jdk8-alpine as builder
USER root
COPY . .
RUN gradle --no-daemon build
ARG buildFlags=""
RUN gradle --no-daemon ${buildFlags} build

FROM gcr.io/distroless/java
FROM gcr.io/distroless/java:8
ENV JAVA_TOOL_OPTIONS -XX:+ExitOnOutOfMemoryError
COPY --from=builder /home/gradle/build/deps/external/*.jar /data/
COPY --from=builder /home/gradle/build/deps/fint/*.jar /data/
Expand Down
5 changes: 4 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
pipeline {
parameters {
string(name: 'BUILD_FLAGS', defaultValue: '', description: 'Gradle build flags')
}
agent { label 'docker' }
stages {
stage('Build') {
steps {
sh 'git clean -fdx'
sh "docker build -t ${GIT_COMMIT} ."
sh "docker build --tag ${GIT_COMMIT} --build-arg buildFlags=${params.BUILD_FLAGS} ."
}
}
stage('Publish Latest') {
Expand Down
9 changes: 8 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ dependencies {
compile('org.glassfish.jersey.core:jersey-client:2.29.1')
compile('org.glassfish.jersey.core:jersey-common:2.29.1')

compile('no.fint:fint-audit-mongo-plugin:1.7.0-rc-2')
if (project.hasProperty("eventhub")) {
compile('no.fint:fint-audit-azure-eventhub-plugin:0.3.0')
compile('io.projectreactor:reactor-core:3.3.2.RELEASE')
} else {
compile('no.fint:fint-audit-mongo-plugin:1.7.0-rc-2')
}

compile('no.fint:fint-events:2.2.0')
compile('no.fint:fint-event-model:3.0.0')
compile('no.fint:fint-springfox-extension:0.0.1')
Expand All @@ -68,6 +74,7 @@ dependencies {
compile('org.jooq:jool-java-8:0.9.14')

compile('org.springframework.boot:spring-boot-starter-web')
compile('org.apache.tomcat.embed:tomcat-embed-core:8.5.45')
runtime('org.springframework.boot:spring-boot-starter-actuator')

testCompile('no.fint:fint-test-utils:0.0.4')
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
version=2.1.0
tomcat.version=8.5.45
5 changes: 0 additions & 5 deletions hooks/pre_build

This file was deleted.

22 changes: 0 additions & 22 deletions src/main/java/no/fint/provider/events/admin/AdminController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,18 @@
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import no.fint.audit.plugin.mongo.MongoAuditEvent;
import no.fint.event.model.HeaderConstants;
import no.fint.events.FintEvents;
import no.fint.provider.events.Constants;
import no.fint.provider.events.subscriber.DownstreamSubscriber;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

import java.net.URI;
import java.time.Duration;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;
Expand All @@ -39,25 +33,9 @@ public class AdminController {
@Autowired
private AdminService adminService;

@Autowired
private MongoOperations mongo;

@Autowired
private DownstreamSubscriber downstreamSubscriber;

@GetMapping("/audit/events")
public List<MongoAuditEvent> getAllEvents() {
return mongo.findAll(MongoAuditEvent.class);
}

@GetMapping("/audit/events/since/{when}")
public List<MongoAuditEvent> queryEventsSince(@PathVariable String when) {
Duration duration = Duration.parse(when);
Criteria c = Criteria.where("timestamp").gt(ZonedDateTime.now().minus(duration).toInstant().toEpochMilli());
Query q = new Query(c);
return mongo.find(q, MongoAuditEvent.class);
}

@GetMapping("/orgIds")
public List<Map> getOrganizations() {
return adminService.getOrgIds().entrySet().stream().map(entry -> ImmutableMap.of(
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/no/fint/provider/events/sse/SseController.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import no.fint.provider.events.subscriber.DownstreamSubscriber;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
Expand All @@ -23,7 +24,7 @@

@Slf4j
@Api(tags = {"sse"}, description = "These endpoint is for handling SSE clients.")
@RequestMapping(value = "/sse")
@RequestMapping(value = "/sse", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@RestController
public class SseController {

Expand All @@ -43,7 +44,7 @@ public class SseController {
private ProviderProps props;

@ApiOperation(value = "Connect SSE client", notes = "Endpoint to register SSE client.")
@GetMapping("/{id}")
@GetMapping(value = "/{id}", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public ResponseEntity<SseEmitter> subscribe(
@ApiParam(Constants.SWAGGER_X_ORG_ID) @RequestHeader(HeaderConstants.ORG_ID) String orgId,
@ApiParam("ID of client.") @RequestHeader(HeaderConstants.CLIENT) String client,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package no.fint.provider.events.testmode.adapter;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import no.fint.event.model.Event;
import no.fint.event.model.HeaderConstants;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,54 +1,29 @@
package no.fint.provider.events.admin

import no.fint.audit.plugin.mongo.MongoAuditEvent
import no.fint.event.model.Event

import no.fint.event.model.HeaderConstants
import no.fint.events.FintEvents
import no.fint.provider.events.subscriber.DownstreamSubscriber
import no.fint.test.utils.MockMvcSpecification
import org.springframework.data.mongodb.core.MongoOperations
import org.springframework.data.mongodb.core.query.Query
import org.springframework.http.HttpHeaders
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.result.MockMvcResultMatchers

class AdminControllerSpec extends MockMvcSpecification {
private DownstreamSubscriber downstreamSubscriber
private AdminController controller
private MongoOperations mongoOperations
private FintEvents fintEvents
private AdminService adminService
private MockMvc mockMvc

void setup() {
downstreamSubscriber = Mock(DownstreamSubscriber)
adminService = Mock(AdminService)
mongoOperations = Mock(MongoOperations)
fintEvents = Mock(FintEvents)
controller = new AdminController(mongo: mongoOperations, fintEvents: fintEvents, adminService: adminService, downstreamSubscriber: downstreamSubscriber)
controller = new AdminController(fintEvents: fintEvents, adminService: adminService, downstreamSubscriber: downstreamSubscriber)
mockMvc = standaloneSetup(controller)
}

def "GET all audit events"() {
when:
def response = mockMvc.perform(get('/admin/audit/events'))

then:
1 * mongoOperations.findAll(MongoAuditEvent) >> [new MongoAuditEvent(new Event(orgId: 'rogfk.no'), true)]
response.andExpect(status().isOk())
.andExpect(jsonPath('$[0].orgId').value(equalTo('rogfk.no')))
}

def "GET audit events since some timestamp"() {
when:
def response = mockMvc.perform(get('/admin/audit/events/since/PT1H'))

then:
1 * mongoOperations.find(_ as Query, MongoAuditEvent) >> [new MongoAuditEvent(new Event(orgId: 'rogfk.no'), true)]
response.andExpect(status().isOk())
.andExpect(jsonPath('$[0].orgId').value(equalTo('rogfk.no')))
}

def "POST new orgId"() {
when:
def response = mockMvc.perform(post('/admin/orgIds/123').header(HeaderConstants.CLIENT, 'spock'))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package no.fint.provider.events.eventstate

import com.hazelcast.core.HazelcastInstance
import com.hazelcast.core.IMap
import no.fint.event.model.Event
import no.fint.provider.events.ProviderProps
import spock.lang.Specification
Expand Down

0 comments on commit 6da0fb3

Please sign in to comment.