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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ mvn clean install
``` sh
# NOTE: use the latest version of the CRT here


git clone --branch v0.11.5 https://github.com/awslabs/aws-crt-java.git

git clone https://github.com/awslabs/aws-iot-device-sdk-java-v2.git
Expand Down
1 change: 0 additions & 1 deletion samples/BasicPubSub/src/main/java/pubsub/PubSub.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import software.amazon.awssdk.iot.AwsIotMqttConnectionBuilder;
import software.amazon.awssdk.iot.iotjobs.model.RejectedError;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package greengrass;

import software.amazon.awssdk.crt.CRT;
import software.amazon.awssdk.crt.CrtResource;
import software.amazon.awssdk.crt.CrtRuntimeException;
import software.amazon.awssdk.crt.Log;
Expand All @@ -25,7 +24,6 @@
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.regex.Pattern;

import static software.amazon.awssdk.iot.discovery.DiscoveryClient.TLS_EXT_ALPN;

Expand Down Expand Up @@ -165,8 +163,8 @@ public static void main(String[] args) {
try(final DiscoveryClientConfig discoveryClientConfig =
new DiscoveryClientConfig(clientBootstrap, tlsCtxOptions,
new SocketOptions(), region, 1, proxyOptions);
final DiscoveryClient discoveryClient = new DiscoveryClient(discoveryClientConfig);
final MqttClientConnection connection = getClientFromDiscovery(discoveryClient, clientBootstrap)) {
final DiscoveryClient discoveryClient = new DiscoveryClient(discoveryClientConfig);
final MqttClientConnection connection = getClientFromDiscovery(discoveryClient, clientBootstrap)) {

if ("subscribe".equals(mode) || "both".equals(mode)) {
final CompletableFuture<Integer> subFuture = connection.subscribe(topic, QualityOfService.AT_MOST_ONCE, message -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,10 @@
import software.amazon.awssdk.iot.iotidentity.model.RegisterThingSubscriptionRequest;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import java.util.HashMap;
import java.util.Map;
import com.google.gson.Gson;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
Expand Down
1 change: 1 addition & 0 deletions samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* [fleet provisioning](#fleet-provisioning)

**Additional sample apps not described below:**

* [BasicPubSub](https://github.com/aws/aws-iot-device-sdk-java-v2/tree/main/samples/BasicPubSub)
* [Greengrass](https://github.com/aws/aws-iot-device-sdk-java-v2/tree/main/samples/Greengrass)
* [PubSubStress](https://github.com/aws/aws-iot-device-sdk-java-v2/tree/main/samples/PubSubStress)
Expand Down
1 change: 0 additions & 1 deletion samples/RawPubSub/src/main/java/rawpubsub/RawPubSub.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import software.amazon.awssdk.crt.mqtt.*;
import software.amazon.awssdk.iot.iotjobs.model.RejectedError;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
Expand Down
6 changes: 6 additions & 0 deletions sdk/greengrass/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# These are explicitly windows files and should use crlf
*.bat text eol=crlf

9 changes: 9 additions & 0 deletions sdk/greengrass/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Ignore Gradle project-specific cache directory
.gradle

# Ignore Gradle build output directory
build

.idea
*.swp
*.swo
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package software.amazon.awssdk.eventstreamrpc;

/**
* Exact implementation of this is between the EventStreamRPCServiceHandler at the Authentication handler itself
*/
public interface AuthenticationData {

/**
* Return a human readable string for who the identity of the client/caller is. This
* string must be appropriate for audit logs and enable tracing specific callers/clients
* to relevant decision and operations executed
*
* @return
*/
public String getIdentityLabel();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package software.amazon.awssdk.eventstreamrpc;

import software.amazon.awssdk.crt.eventstream.Header;

import java.util.List;
import java.util.function.BiFunction;

/**
* apply() accepts the connection message and produces authentication data from it to at least be
* used for authorization decisions
*
* Exact implementation is up to service implementations to decide what it is and how to handle it
*/
public interface AuthenticationHandler extends BiFunction<List<Header>, byte[], AuthenticationData> { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package software.amazon.awssdk.eventstreamrpc;

/**
* Authorization decision object contains the decision in general
* and the authentication data along with it.
*
*/
public enum Authorization {
ACCEPT,
REJECT
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package software.amazon.awssdk.eventstreamrpc;

import java.util.function.Function;

/**
* Handler receives the input data of the connection message and produces an authorization result
* which is a decision on accept or rejecting the connection
*
* -The apply function must return an Authorization object with a non-null AuthenticationData object
* returned. It's great idea for implementations to log appropriate input
*
*/
public interface AuthorizationHandler extends Function<AuthenticationData, Authorization> { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package software.amazon.awssdk.eventstreamrpc;

import com.google.gson.Gson;
import software.amazon.awssdk.eventstreamrpc.model.EventStreamJsonMessage;

import java.nio.charset.StandardCharsets;
import java.util.logging.Logger;

/**
* Useful to set as a handler for an operation with no implementation yet.
*/
public class DebugLoggingOperationHandler extends OperationContinuationHandler
<EventStreamJsonMessage, EventStreamJsonMessage, EventStreamJsonMessage, EventStreamJsonMessage> {
private static final Logger LOGGER = Logger.getLogger(DebugLoggingOperationHandler.class.getName());
private final OperationModelContext operationModelContext;

public DebugLoggingOperationHandler(final OperationModelContext modelContext, final OperationContinuationHandlerContext context) {
super(context);
this.operationModelContext = modelContext;
}

@Override
public OperationModelContext<EventStreamJsonMessage, EventStreamJsonMessage, EventStreamJsonMessage, EventStreamJsonMessage> getOperationModelContext() {
return operationModelContext;
}

/**
* Called when the underlying continuation is closed. Gives operations a chance to cleanup whatever
* resources may be on the other end of an open stream. Also invoked when an underlying ServerConnection
* is closed associated with the stream/continuation
*/
@Override
protected void onStreamClosed() {
LOGGER.info(String.format("%s operation onStreamClosed()",
operationModelContext.getOperationName()));
}

@Override
public EventStreamJsonMessage handleRequest(EventStreamJsonMessage request) {
LOGGER.info(String.format("%s operation handleRequest() :: %s", operationModelContext.getOperationName(),
operationModelContext.getServiceModel().toJson(request)));
return new EventStreamJsonMessage() {
@Override
public byte[] toPayload(Gson gson) {
return "{}".getBytes(StandardCharsets.UTF_8);
}

@Override
public String getApplicationModelType() {
return operationModelContext.getResponseApplicationModelType();
}
};
}

@Override
public void handleStreamEvent(EventStreamJsonMessage streamRequestEvent) {
LOGGER.info(String.format("%s operation handleStreamEvent() :: %s", operationModelContext.getOperationName(),
operationModelContext.getServiceModel().toJson(streamRequestEvent)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package software.amazon.awssdk.eventstreamrpc;

import java.util.Collection;

public abstract class EventStreamRPCServiceHandler implements OperationContinuationHandlerFactory {
private AuthenticationHandler authenticationHandler;
private AuthorizationHandler authorizationHandler;

public EventStreamRPCServiceHandler() {
authorizationHandler = null;
}

protected abstract EventStreamRPCServiceModel getServiceModel();

/**
* Probably only useful for logging
* @return Returns the service name for the set of RPC operations
*/
public String getServiceName() {
return getServiceModel().getServiceName();
}

/**
* TODO: How may we want to protect this from being re-assigned after service creation?
* @param handler
*/
public void setAuthorizationHandler(final AuthorizationHandler handler) {
this.authorizationHandler = handler;
}

/**
* Use this to determine if the connection should be accepted or rejected for this service
*
* @return
*/
public AuthorizationHandler getAuthorizationHandler() {
return authorizationHandler;
}

@Override
public Collection<String> getAllOperations() {
return getServiceModel().getAllOperations();
}

/**
* Pulls caller/client identity when server connection occurs
* @return
*/
public AuthenticationHandler getAuthenticationHandler() {
return authenticationHandler;
}

/**
* TODO: How may we want to protect this from being re-assigned after service creation?
* @param authenticationHandler
*/
public void setAuthenticationHandler(AuthenticationHandler authenticationHandler) {
this.authenticationHandler = authenticationHandler;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package software.amazon.awssdk.eventstreamrpc;

public class InvalidServiceConfigurationException extends RuntimeException {
public InvalidServiceConfigurationException(String msg) {
super(msg);
}

public InvalidServiceConfigurationException(String msg, Throwable cause) {
super(msg, cause);
}

public InvalidServiceConfigurationException(Throwable cause) {
super(cause);
}
}
Loading