Skip to content

Commit

Permalink
Merge branch 'policies'
Browse files Browse the repository at this point in the history
  • Loading branch information
jzonthemtn committed Oct 17, 2023
2 parents 6db5ad1 + 0f16d86 commit 90554fb
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 67 deletions.
56 changes: 28 additions & 28 deletions src/main/java/ai/philterd/philter/PhilterClient.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2020 Mountain Fog, Inc.
* Copyright 2023 Philterd, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
Expand Down Expand Up @@ -37,7 +37,7 @@

/**
* Client class for Philter's API. Philter finds and manipulates sensitive information in text.
* For more information on Philter see https://www.mtnfog.com.
* For more information on Philter see https://www.philterd.ai.
*/
public class PhilterClient extends AbstractClient {

Expand Down Expand Up @@ -146,14 +146,14 @@ private void configureSSL(final OkHttpClient.Builder okHttpClientBuilder, String
* Send text to Philter to be filtered.
* @param context The context. Contexts can be used to group text based on some arbitrary property.
* @param documentId The document ID. Leave empty for Philter to assign a document ID to the request.
* @param filterProfileName The name of the filter profile to apply to the text.
* @param policyName The name of the policy to apply to the text.
* @param text The text to be filtered.
* @return The filtered text.
* @throws IOException Thrown if the request can not be completed.
*/
public FilterResponse filter(String context, String documentId, String filterProfileName, String text) throws IOException {
public FilterResponse filter(String context, String documentId, String policyName, String text) throws IOException {

final Response<String> response = service.filter(context, documentId, filterProfileName, text).execute();
final Response<String> response = service.filter(context, documentId, policyName, text).execute();

if(response.isSuccessful()) {

Expand Down Expand Up @@ -184,17 +184,17 @@ public FilterResponse filter(String context, String documentId, String filterPro
* Send a PDF document to Philter to be filtered.
* @param context The context. Contexts can be used to group text based on some arbitrary property.
* @param documentId The document ID. Leave empty for Philter to assign a document ID to the request.
* @param filterProfileName The name of the filter profile to apply to the text.
* @param policyName The name of the policy to apply to the text.
* @param file The PDF file to be filtered.
* @return The filtered text.
* @throws IOException Thrown if the request can not be completed.
*/
public BinaryFilterResponse filter(String context, String documentId, String filterProfileName, File file) throws IOException {
public BinaryFilterResponse filter(String context, String documentId, String policyName, File file) throws IOException {

final byte[] params = FileUtils.readFileToByteArray(file);
final RequestBody body = RequestBody.create(MediaType.parse("application/pdf"), params);

final Response<ResponseBody> response = service.filter(context, documentId, filterProfileName, body).execute();
final Response<ResponseBody> response = service.filter(context, documentId, policyName, body).execute();

if(response.isSuccessful()) {

Expand Down Expand Up @@ -225,14 +225,14 @@ public BinaryFilterResponse filter(String context, String documentId, String fil
* Send text to Philter to be filtered and get an explanation.
* @param context The context. Contexts can be used to group text based on some arbitrary property.
* @param documentId The document ID. Leave empty for Philter to assign a document ID to the request.
* @param filterProfileName The name of the filter profile to apply to the text.
* @param policyName The name of the policy to apply to the text.
* @param text The text to be filtered.
* @return The filter {@link ExplainResponse}.
* @throws IOException Thrown if the request can not be completed.
*/
public ExplainResponse explain(String context, String documentId, String filterProfileName, String text) throws IOException {
public ExplainResponse explain(String context, String documentId, String policyName, String text) throws IOException {

final Response<ExplainResponse> response = service.explain(context, documentId, filterProfileName, text).execute();
final Response<ExplainResponse> response = service.explain(context, documentId, policyName, text).execute();

if(response.isSuccessful()) {

Expand Down Expand Up @@ -323,13 +323,13 @@ public StatusResponse status() throws IOException {
}

/**
* Gets a list of filter profile names.
* @return A list of filter profile names.
* Gets a list of policy names.
* @return A list of policy names.
* @throws IOException Thrown if the call not be executed.
*/
public List<String> getFilterProfiles() throws IOException {
public List<String> getPolicies() throws IOException {

final Response<List<String>> response = service.getFilterProfile().execute();
final Response<List<String>> response = service.Policy().execute();

if(response.isSuccessful()) {

Expand All @@ -356,14 +356,14 @@ public List<String> getFilterProfiles() throws IOException {
}

/**
* Gets the content of a filter profile.
* @param filterProfileName The name of the filter profile to get.
* @return The content of the filter profile.
* Gets the content of a policy.
* @param policyName The name of the policy to get.
* @return The content of the policy.
* @throws IOException Thrown if the call not be executed.
*/
public String getFilterProfile(String filterProfileName) throws IOException {
public String Policy(String policyName) throws IOException {

final Response<String> response = service.getFilterProfile(filterProfileName).execute();
final Response<String> response = service.Policy(policyName).execute();

if(response.isSuccessful()) {

Expand All @@ -390,13 +390,13 @@ public String getFilterProfile(String filterProfileName) throws IOException {
}

/**
* Saves (or overwrites) the filter profile.
* @param json The body of the filter profile.
* Saves (or overwrites) the policy.
* @param json The body of the policy.
* @throws IOException Thrown if the call not be executed.
*/
public void saveFilterProfile(String json) throws IOException {
public void savePolicy(String json) throws IOException {

final Response<Void> response = service.saveFilterProfile(json).execute();
final Response<Void> response = service.savePolicy(json).execute();

if(!response.isSuccessful()) {

Expand All @@ -419,13 +419,13 @@ public void saveFilterProfile(String json) throws IOException {
}

/**
* Deletes a filter profile.
* @param filterProfileName The name of the filter profile to delete.
* Deletes a policy.
* @param policyName The name of the policy to delete.
* @throws IOException Thrown if the call not be executed.
*/
public void deleteFilterProfile(String filterProfileName) throws IOException {
public void deletePolicy(String policyName) throws IOException {

final Response<Void> response = service.deleteFilterProfile(filterProfileName).execute();
final Response<Void> response = service.deletePolicy(policyName).execute();

if(!response.isSuccessful()) {

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/ai/philterd/philter/model/Alert.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2020 Mountain Fog, Inc.
* Copyright 2023 Philterd, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
Expand Down Expand Up @@ -76,11 +76,11 @@ public void setId(String id) {
this.id = id;
}

public String getFilterProfile() {
public String Policy() {
return this.filterProfile;
}

public void setFilterProfile(String filterProfile) {
public void setPolicy(String filterProfile) {
this.filterProfile = filterProfile;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2020 Mountain Fog, Inc.
* Copyright 2023 Philterd, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2020 Mountain Fog, Inc.
* Copyright 2023 Philterd, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ai/philterd/philter/model/Explanation.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2020 Mountain Fog, Inc.
* Copyright 2023 Philterd, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2020 Mountain Fog, Inc.
* Copyright 2023 Philterd, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ai/philterd/philter/model/FilteredSpan.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2020 Mountain Fog, Inc.
* Copyright 2023 Philterd, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ai/philterd/philter/model/Span.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2020 Mountain Fog, Inc.
* Copyright 2023 Philterd, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2020 Mountain Fog, Inc.
* Copyright 2023 Philterd, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/ai/philterd/philter/services/PhilterService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2020 Mountain Fog, Inc.
* Copyright 2023 Philterd, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
Expand Down Expand Up @@ -32,16 +32,16 @@ public interface PhilterService {

@Headers({"Accept: text/plain", "Content-Type: text/plain"})
@POST("/api/filter")
Call<String> filter(@Query("c") String context, @Query("d") String documentId, @Query("p") String filterProfileName, @Body String text);
Call<String> filter(@Query("c") String context, @Query("d") String documentId, @Query("p") String policyName, @Body String text);

@Streaming
@Headers({"Accept: application/zip", "Content-Type: application/pdf"})
@POST("/api/filter")
Call<ResponseBody> filter(@Query("c") String context, @Query("d") String documentId, @Query("p") String filterProfileName, @Body RequestBody bytes);
Call<ResponseBody> filter(@Query("c") String context, @Query("d") String documentId, @Query("p") String policyName, @Body RequestBody bytes);

@Headers({"Accept: application/json", "Content-Type: text/plain"})
@POST("/api/explain")
Call<ExplainResponse> explain(@Query("c") String context, @Query("d") String documentId, @Query("p") String filterProfileName, @Body String text);
Call<ExplainResponse> explain(@Query("c") String context, @Query("d") String documentId, @Query("p") String policyName, @Body String text);

@GET("/api/replacements")
Call<List<FilteredSpan>> replacements(@Query("d") String documentId);
Expand All @@ -54,19 +54,19 @@ public interface PhilterService {
// Filter Profiles

@Headers({"Accept: application/json"})
@GET("/api/profiles")
Call<List<String>> getFilterProfile();
@GET("/api/policies")
Call<List<String>> Policy();

@Headers({"Accept: text/plain"})
@GET("/api/profiles/{name}")
Call<String> getFilterProfile(@Path("name") String filterProfileName);
@GET("/api/policies/{name}")
Call<String> Policy(@Path("name") String policyName);

@Headers({"Content-Type: application/json"})
@POST("/api/profiles")
Call<Void> saveFilterProfile(@Body String json);
@POST("/api/policies")
Call<Void> savePolicy(@Body String json);

@DELETE("/api/profiles/{name}")
Call<Void> deleteFilterProfile(@Path("name") String filterProfileName);
@DELETE("/api/policies/{name}")
Call<Void> deletePolicy(@Path("name") String policyName);

// Alerts

Expand Down
34 changes: 17 additions & 17 deletions src/test/java/com/mtnfog/test/philter/PhilterClientTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2020 Mountain Fog, Inc.
* Copyright 2023 Philterd, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
Expand Down Expand Up @@ -66,32 +66,32 @@ public void filterPdf() throws Exception {
}

@Test
public void getFilterProfiles() throws Exception {
public void getPolicies() throws Exception {

final PhilterClient client = new PhilterClient.PhilterClientBuilder()
.withEndpoint(ENDPOINT)
.withOkHttpClientBuilder(getUnsafeOkHttpClientBuilder())
.build();

final List<String> filterProfileNames = client.getFilterProfiles();
final List<String> policyNames = client.getPolicies();

Assert.assertTrue(filterProfileNames != null);
Assert.assertFalse(filterProfileNames.isEmpty());
Assert.assertTrue(policyNames != null);
Assert.assertFalse(policyNames.isEmpty());

for(final String name : filterProfileNames) {
LOGGER.info("Filter profile: {}", name);
for(final String name : policyNames) {
LOGGER.info("Policy: {}", name);
}

}

@Test(expected = SSLHandshakeException.class)
public void getFilterProfilesNoCertificate() throws Exception {
public void getPoliciesNoCertificate() throws Exception {

final PhilterClient client = new PhilterClient.PhilterClientBuilder()
.withEndpoint(ENDPOINT)
.build();

client.getFilterProfiles();
client.getPolicies();

}

Expand All @@ -104,13 +104,13 @@ public void get() throws Exception {
"/tmp/keystore-server.jks", "changeit")
.build();

final List<String> filterProfileNames = client.getFilterProfiles();
final List<String> policyNames = client.getPolicies();

Assert.assertTrue(filterProfileNames != null);
Assert.assertFalse(filterProfileNames.isEmpty());
Assert.assertTrue(policyNames != null);
Assert.assertFalse(policyNames.isEmpty());

for(final String name : filterProfileNames) {
LOGGER.info("Filter profile: {}", name);
for(final String name : policyNames) {
LOGGER.info("Policy: {}", name);
}

}
Expand All @@ -124,12 +124,12 @@ public void getByName() throws Exception {
"/tmp/keystore-server.jks", "changeit")
.build();

final String filterProfile = client.getFilterProfile("default");
final String filterProfile = client.Policy("default");

Assert.assertTrue(filterProfile != null);
Assert.assertTrue(filterProfile.length() > 0);

LOGGER.info("Filter profile:\n{}", filterProfile);
LOGGER.info("Policy:\n{}", filterProfile);

}

Expand All @@ -144,7 +144,7 @@ public void save() throws Exception {

final String json = IOUtils.toString(this.getClass().getResource("/default2.json"), Charset.defaultCharset());

client.saveFilterProfile(json);
client.savePolicy(json);

}

Expand Down

0 comments on commit 90554fb

Please sign in to comment.