Skip to content

Commit

Permalink
Merge pull request #284 from jimmyjames/log-streams
Browse files Browse the repository at this point in the history
Add support for Log Streams
  • Loading branch information
jimmyjames authored Aug 27, 2020
2 parents 8d82c4e + 9ae1c09 commit 38611ba
Show file tree
Hide file tree
Showing 8 changed files with 609 additions and 0 deletions.
141 changes: 141 additions & 0 deletions src/main/java/com/auth0/client/mgmt/LogStreamsEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package com.auth0.client.mgmt;

import com.auth0.json.mgmt.logstreams.LogStream;
import com.auth0.net.CustomRequest;
import com.auth0.net.Request;
import com.auth0.net.VoidRequest;
import com.auth0.utils.Asserts;
import com.fasterxml.jackson.core.type.TypeReference;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;

import java.util.List;

/**
* Class that provides an implementation of the Log Streams methods of the Management API as defined in https://auth0.com/docs/api/management/v2#!/Log_Streams
* <p>
* This class is not thread-safe.
*
* @see ManagementAPI
*/
public class LogStreamsEntity extends BaseManagementEntity {

private final static String LOG_STREAMS_PATH = "api/v2/log-streams";
private final static String AUTHORIZATION_HEADER = "Authorization";

LogStreamsEntity(OkHttpClient client, HttpUrl baseUrl, String apiToken) {
super(client, baseUrl, apiToken);
}

/**
* Creates a request to get all Log Streams.
* See the <a href="https://auth0.com/docs/api/management/v2#!/Log_Streams/get_log_streams">API Documentation for more information.</a>
*
* @return the request to execute.
*/
public Request<List<LogStream>> list() {
String url = baseUrl
.newBuilder()
.addPathSegments(LOG_STREAMS_PATH)
.build()
.toString();

CustomRequest<List<LogStream>> request = new CustomRequest<>(client, url, "GET", new TypeReference<List<LogStream>>() {
});
request.addHeader(AUTHORIZATION_HEADER, "Bearer " + apiToken);
return request;
}

/**
* Creates a request to get a single Log Stream by its ID.
* See the <a href="https://auth0.com/docs/api/management/v2#!/Log_Streams/get_log_streams_by_id">API Documentation for more information.</a>
*
* @param logStreamId The ID of the Log Stream to retrieve.
* @return the request to execute.
*/
public Request<LogStream> get(String logStreamId) {
Asserts.assertNotNull(logStreamId, "log stream id");

String url = baseUrl
.newBuilder()
.addPathSegments(LOG_STREAMS_PATH)
.addPathSegment(logStreamId)
.build()
.toString();

CustomRequest<LogStream> request = new CustomRequest<>(client, url, "GET", new TypeReference<LogStream>() {
});
request.addHeader(AUTHORIZATION_HEADER, "Bearer " + apiToken);
return request;
}

/**
* Creates a request to create a Log Stream.
* See the <a href="https://auth0.com/docs/api/management/v2#!/Log_Streams/post_log_streams">API Documentation for more information.</a>
*
* @param logStream The {@linkplain LogStream} to create.
* @return the request to execute.
*/
public Request<LogStream> create(LogStream logStream) {
Asserts.assertNotNull(logStream, "log stream");

String url = baseUrl
.newBuilder()
.addPathSegments(LOG_STREAMS_PATH)
.build()
.toString();

CustomRequest<LogStream> request = new CustomRequest<>(client, url, "POST", new TypeReference<LogStream>(){});
request.addHeader(AUTHORIZATION_HEADER, "Bearer " + apiToken);
request.setBody(logStream);
return request;
}

/**
* Creates a request to update a Log Stream.
* See the <a href="https://auth0.com/docs/api/management/v2#!/Log_Streams/patch_log_streams_by_id">API Documentation for more information.</a>
*
* @param logStreamId The ID of the Log Stream to update.
* @param logStream The {@linkplain LogStream} to update.
* @return the request to execute.
*/
public Request<LogStream> update(String logStreamId, LogStream logStream) {
Asserts.assertNotNull(logStreamId, "log stream id");
Asserts.assertNotNull(logStream, "log stream");

String url = baseUrl
.newBuilder()
.addPathSegments(LOG_STREAMS_PATH)
.addPathSegment(logStreamId)
.build()
.toString();

CustomRequest<LogStream> request = new CustomRequest<>(client, url, "PATCH", new TypeReference<LogStream>(){
});
request.addHeader(AUTHORIZATION_HEADER, "Bearer " + apiToken);
request.setBody(logStream);
return request;
}

/**
* Creates a request to delete a Log Stream.
* See the <a href="https://auth0.com/docs/api/management/v2#!/Log_Streams/delete_log_streams_by_id">API Documentation for more information.</a>
*
* @param logStreamId The ID of the Log Stream to delete.
* @return the request to execute.
*/
public Request delete(String logStreamId) {
Asserts.assertNotNull(logStreamId, "log stream id");

String url = baseUrl
.newBuilder()
.addPathSegments(LOG_STREAMS_PATH)
.addPathSegment(logStreamId)
.build()
.toString();

VoidRequest request = new VoidRequest(client, url, "DELETE");
request.addHeader(AUTHORIZATION_HEADER, "Bearer " + apiToken);
return request;
}
}
9 changes: 9 additions & 0 deletions src/main/java/com/auth0/client/mgmt/ManagementAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,15 @@ public LogEventsEntity logEvents() {
return new LogEventsEntity(client, baseUrl, apiToken);
}

/**
* Getter for the Log Streams entity.
*
* @return the Log Streams entity.
*/
public LogStreamsEntity logStreams() {
return new LogStreamsEntity(client, baseUrl, apiToken);
}

/**
* Getter for the Rules entity.
*
Expand Down
122 changes: 122 additions & 0 deletions src/main/java/com/auth0/json/mgmt/logstreams/LogStream.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package com.auth0.json.mgmt.logstreams;

import com.fasterxml.jackson.annotation.*;

import java.util.Map;

/**
* Represents an Auth0 Log Stream object. Related to the {@linkplain com.auth0.client.mgmt.LogStreamsEntity}
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class LogStream {

@JsonProperty("id")
private String id;
@JsonProperty("name")
private String name;
@JsonProperty("type")
private String type;
@JsonProperty("status")
private String status;
@JsonProperty("sink")
private Map<String, Object> sink;

/**
* Creates a new LogStream instance and sets the type, which cannot be changed once set.
*
* @param type The type of the Log Stream.
*/
@JsonCreator
public LogStream(@JsonProperty("type") String type) {
this.type = type;
}

/**
* Creates a new empty LogStream. Use this when you need to create an instance for use with an update request, as
* you cannot send the {@code type} field to the update API.
*/
public LogStream() {
this(null);
}

/**
* Get the ID of this Log Stream.
*
* @return The ID of this Log Stream.
*/
@JsonProperty("id")
public String getId() {
return id;
}

/**
* Get the name of this Log Stream.
*
* @return The name of this Log Stream.
*/
@JsonProperty("name")
public String getName() {
return name;
}

/**
* Sets the name of this Log Stream.
*
* @param name the name to set.
*/
@JsonProperty("name")
public void setName(String name) {
this.name = name;
}

/**
* Gets the type of this Log Stream.
*
* @return The type of this Log Stream.
*/
@JsonProperty("type")
public String getType() {
return type;
}

/**
* Gets the status of this Log Stream.
*
* @return The status of this Log Stream.
*/
@JsonProperty("status")
public String getStatus() {
return status;
}

/**
* Sets the status of this Log Stream.
*
* @param status The status to set.
*/
@JsonProperty("status")
public void setStatus(String status) {
this.status = status;
}

/**
* Gets the sink of this Log Stream.
*
* @return the sink of this Log Stream.
*/
@JsonProperty("sink")
public Map<String, Object> getSink() {
return sink;
}

/**
* Sets the sink of this Log Stream.
*
* @param sink A key-value map representing the sink to set.
*/
@JsonProperty("sink")
public void setSink(Map<String, Object> sink) {
this.sink = sink;
}
}
2 changes: 2 additions & 0 deletions src/test/java/com/auth0/client/MockServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class MockServer {
public static final String MGMT_LOG_EVENTS_LIST = "src/test/resources/mgmt/event_logs_list.json";
public static final String MGMT_LOG_EVENTS_PAGED_LIST = "src/test/resources/mgmt/event_logs_paged_list.json";
public static final String MGMT_LOG_EVENT = "src/test/resources/mgmt/event_log.json";
public static final String MGMT_LOG_STREAM = "src/test/resources/mgmt/log_stream.json";
public static final String MGMT_LOG_STREAMS_LIST = "src/test/resources/mgmt/log_streams_list.json";
public static final String MGMT_RESOURCE_SERVERS_LIST = "src/test/resources/mgmt/resource_servers_list.json";
public static final String MGMT_RESOURCE_SERVERS_PAGED_LIST = "src/test/resources/mgmt/resource_servers_paged_list.json";
public static final String MGMT_RESOURCE_SERVER = "src/test/resources/mgmt/resource_server.json";
Expand Down
Loading

0 comments on commit 38611ba

Please sign in to comment.