Skip to content

Instantly share code, notes, and snippets.

View anishi1222's full-sized avatar

Akihiro Nishikawa anishi1222

View GitHub Profile
{
"RoleName": "MyReadWriteRole",
"Type": "CustomRole",
"AssignableScopes": ["/"],
"Permissions": [{
"DataActions": [
"Microsoft.DocumentDB/databaseAccounts/readMetadata",
"Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/items/*",
"Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/*"
]
{
"RoleName": "MyReadOnlyRole",
"Type": "CustomRole",
"AssignableScopes": ["/"],
"Permissions": [{
"DataActions": [
"Microsoft.DocumentDB/databaseAccounts/readMetadata",
"Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/items/read",
"Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/executeQuery",
"Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/readChangeFeed"
[
{
"id": "4321",
"type": "Hino",
"purchaseDate": "2020/10/20",
"remarks": "4t"
},
{
"id": "1234",
"type": "Isuzu",
// Get data from HTTP body of request
Track track = request.getBody().get();
// Update or insert data
CosmosItemResponse<Track> cosmosItemResponse = cosmosContainer.upsertItem(track);
// HTTP status code is used with response code from Cosmos DB
HttpResponseMessage responseMessage
= request.createResponseBuilder(HttpStatusType.custom(cosmosItemResponse.getStatusCode()))
.header("Content-Type", "application/json")
TokenCredential tokenCredential = new DefaultAzureCredentialBuilder().build();
[{
"specversion": "1.0",
"id": "A234-1234-1234",
"source": "io/logico-jp/source",
"type": "io.logico-jp.ExampleEventType",
"datacontenttype": "application/json",
"time": "2020-10-31T13:54:34.308619Z",
"data": {
"message": "Using CloudEvents.io API to send CloudEvents!!"
}
@Path("/updates")
@OPTIONS
public Response isWebhookEnabled() {
return Response.ok()
.allow("GET", "POST", "OPTIONS")
.header("Webhook-Allowed-Origin","eventgrid.azure.net")
.build();
}
@Path("/updates")
@POST
public Response receiveEvent(Optional<JsonObject> obj) {
if(obj.isEmpty()) return Response.noContent().status(Response.Status.OK).build();
EventFormat format = EventFormatProvider
.getInstance()
.resolveFormat(JsonFormat.CONTENT_TYPE);
CloudEvent ce = format.deserialize(obj.get().toString().getBytes(StandardCharsets.UTF_8));
<!-- for Cloud Event -->
<dependency>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-http-restful-ws</artifactId>
<version>2.0.0-milestone3</version>
</dependency>
<dependency>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-json-jackson</artifactId>
<version>2.0.0-milestone3</version>
MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>();
headers.add("aeg-sas-key", AEG_KEY);
Response response = ClientBuilder.newClient().target(AEG_ENDPOINT)
.path("/api/events")
.queryParam("api-version", "2018-01-01")
.request("application/cloudevents+json")
.headers(headers)
.post(Entity.entity(serialized, "application/cloudevents+json"));