Skip to content

Commit

Permalink
fix(InstructionFileConfig): allow for None
Browse files Browse the repository at this point in the history
  • Loading branch information
texastony committed Oct 28, 2024
1 parent 816f5f3 commit 9146098
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ public static Builder builder() {
}

public enum InstructionFileClientType {
DISABLED,
SYNCHRONOUS,
ASYNC
ASYNC;
}

ResponseInputStream<GetObjectResponse> getInstructionFile(GetObjectRequest request) {
Expand All @@ -43,6 +44,7 @@ ResponseInputStream<GetObjectResponse> getInstructionFile(GetObjectRequest reque
return _s3Client.getObject(request);
case ASYNC:
return _s3AsyncClient.getObject(request, AsyncResponseTransformer.toBlockingInputStream()).join();
case DISABLED:
default:
throw new S3EncryptionClientException("Unknown Instruction File Type");
}
Expand Down Expand Up @@ -86,6 +88,14 @@ public Builder instructionFileAsyncClient(S3AsyncClient instructionFileAsyncClie
return this;
}
public InstructionFileConfig build() {
if ((_s3AsyncClient != null || _s3Client != null) && _disableInstructionFile) {
throw new S3EncryptionClientException("Instruction File have been disabled but a client has been passed!");
}
if (_disableInstructionFile) {
// We know both clients are null, so carry on.
this._clientType = InstructionFileClientType.DISABLED;
return new InstructionFileConfig(this);
}
if (_s3Client != null && _s3AsyncClient != null) {
throw new S3EncryptionClientException("Only one instruction file client may be set.");
}
Expand All @@ -94,7 +104,9 @@ public InstructionFileConfig build() {
} else if (_s3AsyncClient != null){
_clientType = InstructionFileClientType.ASYNC;
} else {
throw new S3EncryptionClientException("At least one instruction file client must be set.");
throw new S3EncryptionClientException(
"At least one instruction file client must be set or Instruction Files MUST be disabled."
);
}

return new InstructionFileConfig(this);
Expand Down

0 comments on commit 9146098

Please sign in to comment.