-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #284 from jimmyjames/log-streams
Add support for Log Streams
- Loading branch information
Showing
8 changed files
with
609 additions
and
0 deletions.
There are no files selected for viewing
141 changes: 141 additions & 0 deletions
141
src/main/java/com/auth0/client/mgmt/LogStreamsEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
src/main/java/com/auth0/json/mgmt/logstreams/LogStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.