Skip to content

Commit

Permalink
Merge branch 'release/0.20.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Pröschel committed May 4, 2021
2 parents 67900ea + 5b4ec3d commit 68e8f05
Show file tree
Hide file tree
Showing 166 changed files with 3,625 additions and 2,182 deletions.
3 changes: 3 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,12 @@ java_library(
java_library(
name = "springboot_security",
exports = [
"@maven//:org_springframework_boot_spring_boot_starter_oauth2_client",
"@maven//:org_springframework_boot_spring_boot_starter_security",
"@maven//:org_springframework_security_oauth_spring_security_oauth2",
"@maven//:org_springframework_security_spring_security_config",
"@maven//:org_springframework_security_spring_security_core",
"@maven//:org_springframework_security_spring_security_oauth2_core",
"@maven//:org_springframework_security_spring_security_web",
],
)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.19.0
0.20.0
5 changes: 3 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ maven_install(
"com.github.everit-org.json-schema:org.everit.json.schema:1.12.2",
"com.google.auth:google-auth-library-oauth2-http:0.20.0",
"com.jayway.jsonpath:json-path:2.4.0",
"com.dinstone:beanstalkc:2.3.0",
"com.twilio.sdk:twilio:7.51.0",
"io.confluent:kafka-avro-serializer:5.5.1",
"io.confluent:kafka-schema-registry-client:5.5.1",
Expand All @@ -41,7 +42,6 @@ maven_install(
"io.jsonwebtoken:jjwt-api:0.10.5",
"io.jsonwebtoken:jjwt-impl:0.10.5",
"io.jsonwebtoken:jjwt-jackson:0.10.5",
"io.lettuce:lettuce-core:5.3.3.RELEASE",
"io.micrometer:micrometer-registry-prometheus:1.6.5",
"javax.activation:javax.activation-api:1.2.0",
"javax.validation:validation-api:2.0.1.Final",
Expand Down Expand Up @@ -77,13 +77,14 @@ maven_install(
"org.springframework.boot:spring-boot-starter-web:2.4.5",
"org.springframework.boot:spring-boot-starter-websocket:2.4.5",
"org.springframework.boot:spring-boot-starter-security:2.4.5",
"org.springframework.boot:spring-boot-starter-oauth2-client:2.4.5",
"org.springframework.security.oauth:spring-security-oauth2:2.4.1.RELEASE",
"org.springframework.retry:spring-retry:1.2.5.RELEASE",
"org.springframework:spring-aop:4.1.4.RELEASE",
"org.springframework:spring-context-support:5.3.6",
"org.springframework:spring-context:5.3.6",
"org.springframework:spring-messaging:5.3.6",
"org.springframework:spring-websocket:5.3.6",
"org.springframework.data:spring-data-redis:2.3.3.RELEASE",
"org.springframework.security:spring-security-core:5.4.6",
"org.rocksdb:rocksdbjni:5.18.3",
],
Expand Down
8 changes: 0 additions & 8 deletions backend/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ java_library(
],
)

java_library(
name = "tag",
exports = [
"//backend/avro:tag",
"//lib/java/kafka/schema:application-communication-tags",
],
)

java_library(
name = "webhook",
exports = [
Expand Down
2 changes: 1 addition & 1 deletion backend/api/admin/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ app_deps = [
"//backend:base_app",
"//:springboot_actuator",
"//backend/model/channel",
"//backend:tag",
"//backend/model/tag",
"//backend:webhook",
"//backend/model/metadata",
"//backend/model/template",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import co.airy.core.api.admin.payload.CreateTagRequestPayload;
import co.airy.core.api.admin.payload.DeleteTagRequestPayload;
import co.airy.core.api.admin.payload.ListTagsResponsePayload;
import co.airy.core.api.admin.payload.TagResponsePayload;
import co.airy.core.api.admin.payload.TagPayload;
import co.airy.core.api.admin.payload.UpdateTagRequestPayload;
import co.airy.spring.web.payload.RequestErrorResponsePayload;
import org.apache.kafka.streams.state.KeyValueIterator;
Expand Down Expand Up @@ -62,11 +62,7 @@ ResponseEntity<?> createTag(@RequestBody @Valid CreateTagRequestPayload payload)
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
}

return ResponseEntity.status(201).body(TagResponsePayload.builder()
.id(tag.getId())
.name(tag.getName())
.color(tag.getColor().toString())
.build());
return ResponseEntity.status(201).body(TagPayload.fromTag(tag));
}

@PostMapping("/tags.list")
Expand All @@ -77,13 +73,7 @@ ResponseEntity<ListTagsResponsePayload> listTags() {
List<Tag> tags = new ArrayList<>();
iterator.forEachRemaining(kv -> tags.add(kv.value));

final List<TagResponsePayload> data = tags.stream()
.map(tag -> TagResponsePayload.builder()
.id(tag.getId())
.name(tag.getName())
.color(tag.getColor().toString())
.build()
).collect(toList());
final List<TagPayload> data = tags.stream().map(TagPayload::fromTag).collect(toList());

return ResponseEntity.ok().body(ListTagsResponsePayload.builder().data(data).build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
@AllArgsConstructor
@Builder
public class ListTagsResponsePayload {
private List<TagResponsePayload> data;
private List<TagPayload> data;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package co.airy.core.api.config;

import co.airy.spring.auth.PrincipalAccess;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -13,9 +15,10 @@ public ClientConfigController(ServiceDiscovery serviceDiscovery) {
}

@PostMapping("/client.config")
public ResponseEntity<ClientConfigResponsePayload> getConfig() {
public ResponseEntity<ClientConfigResponsePayload> getConfig(Authentication auth) {
return ResponseEntity.ok(ClientConfigResponsePayload.builder()
.components(serviceDiscovery.getComponents())
.userProfile(PrincipalAccess.getUserProfile(auth))
.build());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package co.airy.core.api.config;

import co.airy.spring.auth.session.UserProfile;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand All @@ -13,4 +14,5 @@
@AllArgsConstructor
public class ClientConfigResponsePayload {
private Map<String, Map<String, Object>> components;
private UserProfile userProfile;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import java.util.concurrent.TimeUnit;

import static co.airy.test.Timing.retryOnException;
import static org.hamcrest.CoreMatchers.is;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
Expand Down Expand Up @@ -74,7 +73,7 @@ void beforeEach() throws Exception {

@Test
void canManageTags() throws Exception {
final String name = "awesome-tag";
final String name = "flag";
final String color = "tag-red";
final String payload = "{\"name\":\"" + name + "\",\"color\": \"" + color + "\"}";

Expand All @@ -87,34 +86,33 @@ void canManageTags() throws Exception {
final JsonNode jsonNode = objectMapper.readTree(createTagResponse);
final String tagId = jsonNode.get("id").textValue();

//TODO wait for tag to be there
TimeUnit.SECONDS.sleep(5);

webTestHelper.post("/tags.list", "{}")
.andExpect(status().isOk())
.andExpect(jsonPath("$.data.length()", is(1)))
.andExpect(jsonPath("$.data[0].id").value(is(tagId)))
.andExpect(jsonPath("$.data[0].name").value(is(name)))
.andExpect(jsonPath("$.data[0].color").value(is("RED")));
retryOnException(() ->
webTestHelper.post("/tags.list", "{}")
.andExpect(status().isOk())
.andExpect(jsonPath("$.data.length()", is(1)))
.andExpect(jsonPath("$.data[0].id").value(is(tagId)))
.andExpect(jsonPath("$.data[0].name").value(is(name)))
.andExpect(jsonPath("$.data[0].color").value(is("tag-red"))),
"could not create tag");

webTestHelper.post("/tags.update",
"{\"id\": \"" + tagId + "\", \"name\": \"new-name\", \"color\": \"" + color + "\"}")
"{\"id\": \"" + tagId + "\", \"name\": \"new-flag\", \"color\": \"" + color + "\"}")
.andExpect(status().isNoContent());

webTestHelper.post("/tags.list", "{}")
.andExpect(status().isOk())
.andExpect(jsonPath("$.data.length()", is(1)))
.andExpect(jsonPath("$.data[0].id").value(is(tagId)))
.andExpect(jsonPath("$.data[0].name").value(is("new-name")))
.andExpect(jsonPath("$.data[0].color").value(is("RED")));
retryOnException(() -> webTestHelper.post("/tags.list", "{}")
.andExpect(status().isOk())
.andExpect(jsonPath("$.data.length()", is(1)))
.andExpect(jsonPath("$.data[0].id").value(is(tagId)))
.andExpect(jsonPath("$.data[0].name").value(is("new-flag")))
.andExpect(jsonPath("$.data[0].color").value(is("tag-red"))),
"could not update tag");

webTestHelper.post("/tags.delete", "{\"id\": \"" + tagId + "\"}").andExpect(status().isNoContent());

//TODO wait for tag deletion
TimeUnit.SECONDS.sleep(5);

webTestHelper.post("/tags.list", "{}")
.andExpect(status().isOk())
.andExpect(jsonPath("$.data.length()", is(0)));
retryOnException(() -> webTestHelper.post("/tags.list", "{}")
.andExpect(status().isOk())
.andExpect(jsonPath("$.data.length()", is(0))),
"could not delete tag");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.util.UUID;
import java.util.concurrent.ExecutionException;

import static co.airy.spring.auth.PrincipalAccess.getUserId;

@RestController
public class SendMessageController {
private final Stores stores;
Expand All @@ -43,7 +45,7 @@ public class SendMessageController {
}

@PostMapping("/messages.send")
public ResponseEntity<?> sendMessage(@RequestBody @Valid SendMessageRequestPayload payload) throws ExecutionException, InterruptedException, JsonProcessingException {
public ResponseEntity<?> sendMessage(@RequestBody @Valid SendMessageRequestPayload payload, Authentication auth) throws ExecutionException, InterruptedException, JsonProcessingException {
final ReadOnlyKeyValueStore<String, Conversation> conversationsStore = stores.getConversationsStore();
final Conversation conversation = conversationsStore.get(payload.getConversationId().toString());

Expand All @@ -56,6 +58,8 @@ public ResponseEntity<?> sendMessage(@RequestBody @Valid SendMessageRequestPaylo
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
}

final String userId = getUserId(auth);

final Message message = Message.newBuilder()
.setId(UUID.randomUUID().toString())
.setChannelId(channel.getId())
Expand All @@ -64,8 +68,7 @@ public ResponseEntity<?> sendMessage(@RequestBody @Valid SendMessageRequestPaylo
.setHeaders(Map.of())
.setDeliveryState(DeliveryState.PENDING)
.setSource(channel.getSource())
// TODO add the oidc id here in https://github.com/airyhq/airy/issues/1518
.setSenderId("airy-core-anonymous")
.setSenderId(userId)
.setSentAt(Instant.now().toEpochMilli())
.setIsFromContact(false)
.build();
Expand Down
1 change: 1 addition & 0 deletions backend/api/websocket/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ app_deps = [
"//backend/model/event",
"//backend/model/message",
"//backend/model/metadata",
"//backend/model/tag",
"//lib/java/date",
"//lib/java/spring/auth:spring-auth",
"//lib/java/spring/web:spring-web",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import co.airy.avro.communication.Channel;
import co.airy.avro.communication.Message;
import co.airy.avro.communication.Metadata;
import co.airy.avro.communication.Tag;
import co.airy.kafka.schema.application.ApplicationCommunicationChannels;
import co.airy.kafka.schema.application.ApplicationCommunicationMessages;
import co.airy.kafka.schema.application.ApplicationCommunicationMetadata;
import co.airy.kafka.schema.application.ApplicationCommunicationTags;
import co.airy.kafka.streams.KafkaStreamsWrapper;
import co.airy.model.metadata.dto.MetadataMap;
import org.apache.kafka.streams.KeyValue;
Expand All @@ -22,13 +24,11 @@

@Component
public class Stores implements HealthIndicator, ApplicationListener<ApplicationStartedEvent>, DisposableBean {
private static final String appId = "api.WebsocketStores";
private static final String appId = "api.WebSocketStores";
private final KafkaStreamsWrapper streams;
private final WebSocketController webSocketController;

Stores(KafkaStreamsWrapper streams,
WebSocketController webSocketController
) {
Stores(KafkaStreamsWrapper streams, WebSocketController webSocketController) {
this.streams = streams;
this.webSocketController = webSocketController;
}
Expand All @@ -43,6 +43,10 @@ public void onApplicationEvent(ApplicationStartedEvent event) {
builder.<String, Channel>stream(new ApplicationCommunicationChannels().name())
.peek((channelId, channel) -> webSocketController.onChannel(channel));

builder.<String, Tag>stream(new ApplicationCommunicationTags().name())
.filter((id, tag) -> tag != null)
.peek((id, tag) -> webSocketController.onTag(tag));

builder.<String, Metadata>table(new ApplicationCommunicationMetadata().name())
.groupBy((metadataId, metadata) -> KeyValue.pair(getSubject(metadata).getIdentifier(), metadata))
.aggregate(MetadataMap::new, MetadataMap::adder, MetadataMap::subtractor)
Expand Down
Loading

0 comments on commit 68e8f05

Please sign in to comment.