-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add create audit event * Add audit-create to cli
- Loading branch information
Showing
13 changed files
with
203 additions
and
25 deletions.
There are no files selected for viewing
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
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
65 changes: 65 additions & 0 deletions
65
examples/management-cli/src/main/java/com/descope/AuditCreate.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,65 @@ | ||
package com.descope; | ||
|
||
import com.descope.client.DescopeClient; | ||
import com.descope.enums.AuditType; | ||
import com.descope.exception.DescopeException; | ||
import com.descope.model.audit.AuditSearchRequest; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.util.concurrent.Callable; | ||
import org.apache.commons.lang3.StringUtils; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.Option; | ||
|
||
@Command(name = "audit-create", description = "Create an audit event") | ||
public class AuditCreate extends HelpBase implements Callable<Integer> { | ||
|
||
@Option(names = { "-u", "--user"}, description = "User ID in the event") | ||
String userId; | ||
|
||
@Option(names = { "-i", "--actor"}, description = "Actor ID in the event") | ||
String actorId; | ||
|
||
@Option(names = { "-t", "--type"}, description = "event type (info, warn, error)") | ||
String type; | ||
|
||
@Option(names = { "-a", "--action"}, description = "the name of the action") | ||
String action; | ||
|
||
@Option(names = { "-n", "--tenant"}, description = "the tenant for the action") | ||
String tenant; | ||
|
||
@Override | ||
public Integer call() throws JsonProcessingException { | ||
int exitCode = 0; | ||
try { | ||
var builder = AuditCreate.builder(); | ||
if (StringUtils.isNotBlank(userId)) { | ||
builder.userId(userId); | ||
} | ||
if (StringUtils.isNotBlank(actorId)) { | ||
builder.actorId(actorId); | ||
} | ||
if (StringUtils.isNotBlank(type)) { | ||
builder.type(AuditType.fromString(type)); | ||
} | ||
if (StringUtils.isNotBlank(action)) { | ||
builder.action(action); | ||
} | ||
if (StringUtils.isNotBlank(tenant)) { | ||
builder.tenant(tenant); | ||
} | ||
var client = new DescopeClient(); | ||
var auditService = client.getManagementServices().getAuditService(); | ||
auditService.createEvent(builder.build()); | ||
System.out.println("Done"); | ||
} catch (DescopeException de) { | ||
exitCode = 1; | ||
System.err.println(String.format("%s - %s", de.getCode(), de.getMessage())); | ||
} | ||
return exitCode; | ||
} | ||
} |
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
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
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,28 @@ | ||
package com.descope.enums; | ||
|
||
import com.fasterxml.jackson.annotation.JsonValue; | ||
import lombok.Getter; | ||
|
||
public enum AuditType { | ||
INFO("info"), | ||
WARN("warn"), | ||
ERROR("error"); | ||
|
||
@Getter | ||
@JsonValue | ||
private final String value; | ||
|
||
AuditType(String value) { | ||
this.value = value; | ||
} | ||
|
||
public static AuditType fromString(String value) { | ||
if (ERROR.value.equalsIgnoreCase(value)) { | ||
return ERROR; | ||
} | ||
if (WARN.value.equalsIgnoreCase(value)) { | ||
return WARN; | ||
} | ||
return INFO; | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
src/main/java/com/descope/model/audit/AuditCreateRequest.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,21 @@ | ||
package com.descope.model.audit; | ||
|
||
import com.descope.enums.AuditType; | ||
import java.util.Map; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class AuditCreateRequest { | ||
String userId; | ||
String action; | ||
AuditType type; | ||
String actorId; | ||
String tenantId; | ||
Map<String, Object> data; | ||
} |
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
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
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
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.