Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
*
* <p>Without {@code pollOptions} the call submits the run and returns its id. With {@code pollOptions} the
* SDK polls the run and, on success for a file-based request, writes the outputs to disk.
*
* <p>{@code configurationId} and {@code configuration} are both optional and are sent exactly as supplied.
* With neither set, the SDK sends a configuration that carries only the vault id, so the server applies
* the vault's defaults.
*/
public final class DeidentifyFileRequest {
private final DataSourceType dataSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

/**
* Request for {@code deidentifyString}. configurationId and configuration are both optional and are sent
* exactly as supplied; the server applies its own rules for their combination.
* exactly as supplied; the server applies its own rules for their combination. With neither set, the SDK
* sends a configuration that carries only the vault id, so the server applies the vault's defaults.
*/
public final class DeidentifyStringRequest {
private final String text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,22 @@ public static DeidentifyStringRequestV2 toDeidentifyStringRequest(DeidentifyStri
if (request.getConfigurationId() != null) {
builder.configurationId(request.getConfigurationId());
}
if (request.getConfiguration() != null) {
if (sendsConfiguration(request.getConfigurationId(), request.getConfiguration())) {
builder.configuration(toDetectConfig(request.getConfiguration(), vaultId));
}
return builder.build();
}

/**
* The API needs either a configuration id or a configuration, and the vault id travels inside the
* configuration. An inline configuration is always sent; with neither field set the SDK still sends a
* configuration holding only the vault id, so the server applies the vault's defaults instead of
* rejecting the request. When only an id is set nothing else is sent.
*/
static boolean sendsConfiguration(String configurationId, DetectConfiguration configuration) {
return configuration != null || configurationId == null;
}

/**
* Builds the submit request. For file-based requests this reads and base64-encodes the file and infers
* the format from its extension when none was given.
Expand Down Expand Up @@ -107,7 +117,7 @@ public static DeidentifyFileRequestV2 toDeidentifyFileRequest(DeidentifyFileRequ
if (request.getConfigurationId() != null) {
builder.configurationId(request.getConfigurationId());
}
if (request.getConfiguration() != null) {
if (sendsConfiguration(request.getConfigurationId(), request.getConfiguration())) {
builder.configuration(toDetectConfig(request.getConfiguration(), vaultId));
}
return builder.build();
Expand Down Expand Up @@ -158,8 +168,15 @@ public static DetectGuardrailsRequestV2 toCheckGuardrailsRequest(CheckGuardrails
return builder.build();
}

/**
* @param configuration the inline configuration, or {@code null} to send a configuration that carries
* only the vault id
*/
public static DetectConfigV2 toDetectConfig(DetectConfiguration configuration, String vaultId) {
DetectConfigV2._FinalStage builder = DetectConfigV2.builder().vaultId(vaultId);
if (configuration == null) {
return builder.build();
}
if (configuration.getName() != null) {
builder.name(configuration.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public static void validateDeidentifyStringRequest(DeidentifyStringRequest reque
if (isBlank(request.getText())) {
throw invalid(ErrorLogs.INVALID_TEXT_IN_DEIDENTIFY_STRING, BaseErrorMessage.InvalidTextInDeidentifyString);
}
// configurationId and configuration are both optional on the API and are passed through as given.
// configurationId and configuration are both optional on the API and are passed through as given;
// with neither set the mapper sends a configuration carrying only the vault id.
}

public static void validateDeidentifyFileRequest(DeidentifyFileRequest request) throws SkyflowException {
Expand All @@ -52,7 +53,8 @@ public static void validateDeidentifyFileRequest(DeidentifyFileRequest request)
throw invalid(ErrorLogs.INVALID_VALUE_IN_DEIDENTIFY_FILE, BaseErrorMessage.InvalidValueInDeidentifyFile);
}
}
// configurationId and configuration are both optional on the API and are passed through as given.
// configurationId and configuration are both optional on the API and are passed through as given;
// with neither set the mapper sends a configuration carrying only the vault id.
validatePollOptions(request.getPollOptions());
if (request.getPollOptions() == null && !isBlank(request.getOutputDirectory())) {
throw invalid(ErrorLogs.OUTPUT_DIRECTORY_WITHOUT_POLL_OPTIONS, BaseErrorMessage.OutputDirectoryWithoutPollOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,25 @@ public void dataFormatIsSentLowerCase() throws Exception {
Assert.assertTrue(wire(api).contains("\"dataFormat\":\"pdf\""));
}

@Test
public void noConfigurationSendsVaultIdOnlyConfiguration() throws Exception {
DeidentifyFileRequestV2 api = DetectRequestMapper.toDeidentifyFileRequest(DeidentifyFileRequest.builder()
.dataSource(DataSourceType.BASE64).value("aGVsbG8=").build(), "vault-1");
Assert.assertFalse(api.getConfigurationId().isPresent());
Assert.assertEquals("vault-1", api.getConfiguration().get().getVaultId());
Assert.assertFalse(api.getConfiguration().get().getDetect().isPresent());
String json = ObjectMappers.JSON_MAPPER.writeValueAsString(api);
Assert.assertTrue(json, json.contains("\"configuration\":{\"vaultId\":\"vault-1\"}"));
}

@Test
public void storedConfigurationIdSendsNoConfiguration() throws Exception {
DeidentifyFileRequestV2 api = DetectRequestMapper.toDeidentifyFileRequest(DeidentifyFileRequest.builder()
.dataSource(DataSourceType.BASE64).value("aGVsbG8=").configurationId("cfg-1").build(), "vault-1");
Assert.assertEquals("cfg-1", api.getConfigurationId().get());
Assert.assertFalse(api.getConfiguration().isPresent());
}

@Test
public void inlineConfigurationGetsVaultId() throws Exception {
DeidentifyFileRequestV2 api = DetectRequestMapper.toDeidentifyFileRequest(DeidentifyFileRequest.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,28 @@ public void storedConfigurationSendsOnlyTextAndId() throws Exception {
Assert.assertFalse(json, json.contains("\"configuration\":"));
}

@Test
public void noConfigurationSendsVaultIdOnlyConfiguration() throws Exception {
DeidentifyStringRequestV2 mapped = DetectRequestMapper.toDeidentifyStringRequest(
DeidentifyStringRequest.builder().text("hello").build(), "vault-1");
Assert.assertFalse(mapped.getConfigurationId().isPresent());
DetectConfigV2 config = mapped.getConfiguration().get();
Assert.assertEquals("vault-1", config.getVaultId());
Assert.assertFalse(config.getDetect().isPresent());
Assert.assertFalse(config.getName().isPresent());
String json = ObjectMappers.JSON_MAPPER.writeValueAsString(mapped);
Assert.assertTrue(json, json.contains("\"configuration\":{\"vaultId\":\"vault-1\"}"));
}

@Test
public void storedConfigurationIdAlongsideInlineConfigurationSendsBothAsGiven() throws Exception {
DeidentifyStringRequestV2 mapped = DetectRequestMapper.toDeidentifyStringRequest(
DeidentifyStringRequest.builder().text("hello").configurationId("cfg-1")
.configuration(DetectConfiguration.builder().build()).build(), "vault-1");
Assert.assertEquals("cfg-1", mapped.getConfigurationId().get());
Assert.assertEquals("vault-1", mapped.getConfiguration().get().getVaultId());
}

@Test
public void inlineConfigurationIsScopedToVaultAndFullyMapped() throws Exception {
DetectConfiguration configuration = DetectConfiguration.builder()
Expand Down
8 changes: 4 additions & 4 deletions docs/api_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ Parameters listed with their defaults as defined in the builders.
| Builder method | Default | Description |
|----------------|---------|-------------|
| `text(String)` | _(required)_ | Text to de-identify. |
| `configurationId(String)` | `null` | Id of a Detect configuration created through the management API. |
| `configuration(DetectConfiguration)` | `null` | Inline configuration. See [`DetectConfiguration`](#detectconfiguration).|
| `configurationId(String)` | `null` | Id of a Detect configuration created through the management API. Sending it together with `configuration` is rejected by the API. |
| `configuration(DetectConfiguration)` | `null` | Inline configuration. See [`DetectConfiguration`](#detectconfiguration). With neither this nor `configurationId` set, the SDK sends only the vault id and the server applies the vault's defaults. |

### `DeidentifyFileRequest`

Expand All @@ -247,8 +247,8 @@ Parameters listed with their defaults as defined in the builders.
| `file(File)` | `null` | Local file; read and base64-encoded when sent, `dataSource` set to `BASE64`. |
| `filePath(String)` | `null` | Same as `file(File)`, from a path. |
| `dataFormat(FileDataFormat)` | inferred from the extension | File format. See [`FileDataFormat`](#filedataformat). |
| `configurationId(String)` | `null` | Id of a stored Detect configuration. |
| `configuration(DetectConfiguration)` | `null` | Inline configuration. See [`DetectConfiguration`](#detectconfiguration). |
| `configurationId(String)` | `null` | Id of a stored Detect configuration. Sending it together with `configuration` is rejected by the API. |
| `configuration(DetectConfiguration)` | `null` | Inline configuration. See [`DetectConfiguration`](#detectconfiguration). With neither this nor `configurationId` set, the SDK sends only the vault id and the server applies the vault's defaults. |
| `pollOptions(PollOptions)` | `null` | Poll the run after submitting. `null` submits only and returns the run id. See [`PollOptions`](#polloptions). |
| `outputDirectory(String)` | working directory | Where outputs are written on success. Requires `pollOptions` and a local file; setting it without `pollOptions` fails client-side validation. |

Expand Down
6 changes: 3 additions & 3 deletions flowvault/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1647,13 +1647,13 @@ Detect configurations are created in Studio or through the management API. The S
## Before you start

- **Role.** The service account needs the Detect Invoker, Detect Manager or Vault Owner role on the vault. Detect Invoker can de-identify data and write vault tokens into the vault; Detect Manager adds the ability to create, update and delete Detect configurations. Re-identifying values stored as `VAULT_TOKEN` is governed like detokenization: the caller also needs a policy that grants the Detokenization action on the destination, unless it is a Vault Owner. Detect Invoker or Detect Manager alone is not enough.
- **Configuration.** `configurationId` is the id of a Detect configuration created through the management API; the SDK does not create, update or delete them. The alternative is an inline `DetectConfiguration` passed as `configuration` (see [Detect configuration](#detect-configuration)).
- **Configuration.** `configurationId` is the id of a Detect configuration created through the management API; the SDK does not create, update or delete them. The alternative is an inline `DetectConfiguration` passed as `configuration` (see [Detect configuration](#detect-configuration)). Both are optional: with neither set the SDK sends only the vault id and the run uses the vault's default Detect settings. Sending both is rejected by the API with HTTP 400.
- **Destination for vault tokens.** An entity de-identified with `VAULT_TOKEN` stores its value in the token group named by `destination`. That token group must already exist in the vault; Detect writes into it but does not create it.
- **API reference.** Every Detect request, response and configuration class is listed in the [API reference](../docs/api_reference.md#detect-api).

## Deidentify string

`DeidentifyStringRequest` takes the text plus exactly one of `configurationId` (a stored Detect configuration) or `configuration` (an inline `DetectConfiguration`). Both fields are sent exactly as supplied and the server rejects a request that has neither or both (see [Before you start](#before-you-start)). For an inline configuration the SDK fills the vault id from the controller.
`DeidentifyStringRequest` takes the text plus, optionally, `configurationId` (a stored Detect configuration) or `configuration` (an inline `DetectConfiguration`). Both are sent exactly as supplied. With neither set the SDK sends only the vault id and the server applies the vault's defaults; sending both is rejected by the API (see [Before you start](#before-you-start)). The SDK fills the vault id into the configuration from the controller.

```java
import com.skyflow.detect.*;
Expand Down Expand Up @@ -1762,7 +1762,7 @@ File de-identification is asynchronous on the API: the submit call returns a run
- **Submit only** (default): one call, returns `getRunId()`. `getStatus()` is `null` and nothing is written to disk. Retrieve the result later with [`getRun`](#get-run).
- **Submit and poll**: set `pollOptions`. The SDK polls the run with exponential backoff (1, 2, 4, 8, 16, then 32 seconds between lookups) until it is `SUCCESS`, `FAILED` or `UNKNOWN`, or until `waitTime` (default 60 s, max 300) or `maxAttempts` (default 23, max 23) is used up. If the budget runs out the response carries the run id with `IN_PROGRESS` or `QUEUED` so you can resume with `getRun`.

The file is supplied in one of three ways: `dataSource` plus `value` (`BASE64` content, a `SKYFLOW_ID`, or a `PRESIGNED_URL`), or `file(File)` / `filePath(String)`, which read and encode a local file and infer `dataFormat` from its extension. Supply exactly one of `value`, `file` or `filePath`, and exactly one of `configurationId` or an inline `configuration`; the server rejects neither-or-both (see [Before you start](#before-you-start)).
The file is supplied in one of three ways: `dataSource` plus `value` (`BASE64` content, a `SKYFLOW_ID`, or a `PRESIGNED_URL`), or `file(File)` / `filePath(String)`, which read and encode a local file and infer `dataFormat` from its extension. Supply exactly one of `value`, `file` or `filePath`. `configurationId` and `configuration` follow the same rules as for strings: both optional, sent as supplied, vault defaults when neither is set, and both together rejected by the API (see [Before you start](#before-you-start)).

`dataFormat` accepts every `FileDataFormat`: `BMP`, `CSV`, `DCM`, `DOC`, `DOCX`, `GIF`, `JPEG`, `JPG`, `JSON`, `JSONL`, `MP3`, `PDF`, `PNG`, `PPT`, `PPTX`, `TIF`, `TIFF`, `TXT`, `WAV`, `XLS`, `XLSX`, `XML` and `ZIP`. The `VAULT_TOKEN` de-identification type is supported only for `TXT`, `CSV`, `JSON`, `JSONL`, `XML`, `DOCX`, `XLSX` and `PPTX`.

Expand Down
2 changes: 1 addition & 1 deletion flowvault/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</parent>

<artifactId>skyflow-flowvault-java</artifactId>
<version>1.2.0-dev.d4140366</version>
<version>1.2.0-dev.7bfc279c</version>
<packaging>jar</packaging>
<name>${project.groupId}:${project.artifactId}</name>
<description>Skyflow FlowVault SDK for the Java programming language</description>
Expand Down
6 changes: 3 additions & 3 deletions skyvault/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1680,13 +1680,13 @@ Detect configurations are created in Studio or through the management API. The S

## Before you start
- **Role.** The service account needs the Detect Invoker, Detect Manager or Vault Owner role on the vault. Detect Invoker can de-identify data and write vault tokens into the vault; Detect Manager adds the ability to create, update and delete Detect configurations. Re-identifying values stored as `VAULT_TOKEN` is governed like detokenization: the caller also needs a policy that grants the Detokenization action on the destination table and columns, unless it is a Vault Owner. Detect Invoker or Detect Manager alone is not enough.
- **Configuration.** `configurationId` is the id of a Detect configuration created through the management API; the SDK does not create, update or delete them. The alternative is an inline `DetectConfiguration` passed as `configuration` (see [Detect configuration](#detect-configuration)).
- **Configuration.** `configurationId` is the id of a Detect configuration created through the management API; the SDK does not create, update or delete them. The alternative is an inline `DetectConfiguration` passed as `configuration` (see [Detect configuration](#detect-configuration)). Both are optional: with neither set the SDK sends only the vault id and the run uses the vault's default Detect settings. Sending both is rejected by the API with HTTP 400.
- **Destination for vault tokens.** An entity de-identified with `VAULT_TOKEN` stores its value in the `table.column` named by `destination`. That table and column must already exist in the vault; Detect writes into them but does not create them.
- **API reference.** Every Detect request, response and configuration class is listed in the [API reference](../docs/api_reference.md#detect-api).

## Deidentify string

`DeidentifyStringRequest` takes the text plus exactly one of `configurationId` (a stored Detect configuration) or `configuration` (an inline `DetectConfiguration`). Both fields are sent exactly as supplied. For an inline configuration the SDK fills the vault id from the controller.
`DeidentifyStringRequest` takes the text plus, optionally, `configurationId` (a stored Detect configuration) or `configuration` (an inline `DetectConfiguration`). Both are sent exactly as supplied. With neither set the SDK sends only the vault id and the server applies the vault's defaults; sending both is rejected by the API (see [Before you start](#before-you-start)). The SDK fills the vault id into the configuration from the controller.

```java
import com.skyflow.detect.*;
Expand Down Expand Up @@ -1795,7 +1795,7 @@ File de-identification is asynchronous on the API: the submit call returns a run
- **Submit only** (default): one call, returns `getRunId()`. `getStatus()` is `null` and nothing is written to disk. Retrieve the result later with [`getRun`](#get-run).
- **Submit and poll**: set `pollOptions`. The SDK polls the run with exponential backoff (1, 2, 4, 8, 16, then 32 seconds between lookups) until it is `SUCCESS`, `FAILED` or `UNKNOWN`, or until `waitTime` (default 60 s, max 300) or `maxAttempts` (default 23, max 23) is used up. If the budget runs out the response carries the run id with `IN_PROGRESS` or `QUEUED` so you can resume with `getRun`.

The file is supplied in one of three ways: `dataSource` plus `value` (`BASE64` content, a `SKYFLOW_ID`, or a `PRESIGNED_URL`), or `file(File)` / `filePath(String)`, which read and encode a local file and infer `dataFormat` from its extension. Supply exactly one of `value`, `file` or `filePath`. Either `configurationId` or an inline `configuration` is passed through as given.
The file is supplied in one of three ways: `dataSource` plus `value` (`BASE64` content, a `SKYFLOW_ID`, or a `PRESIGNED_URL`), or `file(File)` / `filePath(String)`, which read and encode a local file and infer `dataFormat` from its extension. Supply exactly one of `value`, `file` or `filePath`. `configurationId` and `configuration` follow the same rules as for strings: both optional, sent as supplied, vault defaults when neither is set, and both together rejected by the API (see [Before you start](#before-you-start)).

`dataFormat` accepts every `FileDataFormat`: `BMP`, `CSV`, `DCM`, `DOC`, `DOCX`, `GIF`, `JPEG`, `JPG`, `JSON`, `JSONL`, `MP3`, `PDF`, `PNG`, `PPT`, `PPTX`, `TIF`, `TIFF`, `TXT`, `WAV`, `XLS`, `XLSX`, `XML` and `ZIP`. The `VAULT_TOKEN` de-identification type is supported only for `TXT`, `CSV`, `JSON`, `JSONL`, `XML`, `DOCX`, `XLSX` and `PPTX`.

Expand Down
Loading