Class AssemblylineClient
- java.lang.Object
-
- ca.gc.cyber.ops.assemblyline.java.client.clients.AssemblylineClient
-
public class AssemblylineClient extends Object
-
-
Field Summary
Fields Modifier and Type Field Description protected org.springframework.web.reactive.function.client.ExchangeFilterFunctionaddSessionprotected AssemblylineAuthenticationMethodassemblylineAuthenticationMethodstatic StringBASE_URLstatic StringFILE_DOWNLOAD_URLstatic StringFILE_INFO_URLstatic StringFILE_RESULT_FOR_SERVICE_URLstatic StringFILE_RESULTS_URLstatic StringHASH_SEARCHstatic StringHASH_SEARCH_LIST_DATA_SOURCESstatic StringINGEST_GET_MESSAGE_LIST_URLstatic StringINGEST_URLstatic StringLOGIN_URLprotected com.fasterxml.jackson.databind.ObjectMappermapperstatic StringRESULT_URLprotected Stringsessionstatic StringSUBMISSION_COMPLETE_URLstatic StringSUBMISSION_FILE_RESULTS_URLstatic StringSUBMISSION_FULL_URLstatic StringSUBMISSION_TREE_URLstatic StringSUBMISSION_URLstatic StringSUBMIT_URLprotected org.springframework.web.reactive.function.client.WebClientwebClient
-
Constructor Summary
Constructors Constructor Description AssemblylineClient(AssemblylineClientProperties assemblylineClientProperties, ProxyProperties proxyProperties, com.fasterxml.jackson.databind.ObjectMapper defaultMapper, AssemblylineAuthenticationMethod assemblylineAuthenticationMethod)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidbuildWebClient(AssemblylineClientProperties assemblylineClientProperties, ProxyProperties proxyProperties)protected <T> reactor.core.publisher.Mono<T>clientResponseToMono(org.springframework.web.reactive.function.client.ClientResponse clientResponse, org.springframework.core.ParameterizedTypeReference<AssemblylineApiResponse<T>> type)Convert ClientResponse to AssemblylineApiResponse content mono.InputStreamdownloadFile(String sha256)InputStreamdownloadFile(String sha256, DownloadFileParams params)protected <T> reactor.core.publisher.Mono<T>get(Function<org.springframework.web.util.UriBuilder,URI> uriBuilder, org.springframework.core.ParameterizedTypeReference<AssemblylineApiResponse<T>> responseType)Helper method to perform a JSON GET request.reactor.core.publisher.Mono<FileInfo>getFileInfo(String sha256)reactor.core.publisher.Mono<FileResultForService>getFileResultForService(String sha256, String serviceName)reactor.core.publisher.Mono<FileResults>getFileResults(String sha256)reactor.core.publisher.Mono<List<String>>getHashSearchDataSources()reactor.core.publisher.Flux<IngestSubmissionResponse>getIngestMessageList(String notification)reactor.core.publisher.Mono<ResultBlock>getResult(String cacheKey)reactor.core.publisher.Mono<Submission>getSubmission(String sid)reactor.core.publisher.Mono<SubmissionFileResults>getSubmissionFileResults(String sid, String sha256)reactor.core.publisher.Mono<SubmissionFull>getSubmissionFull(String sid)reactor.core.publisher.Mono<SubmissionTree>getSubmissionTree(String sid)reactor.core.publisher.Mono<Map<String,HashSearchResult>>hashSearch(String fileHash)Search for a hash in multiple data sources, using default values for optional parameters.reactor.core.publisher.Mono<Map<String,HashSearchResult>>hashSearch(String fileHash, List<String> dataSources, Integer maxTimeout)Search for a hash in multiple data sources.reactor.core.publisher.Mono<IngestResponse>ingestBinary(BinaryFile<IngestBase> binaryIngest)reactor.core.publisher.Mono<IngestResponse>ingestUrlOrSha256(NonBinaryIngest ingest)reactor.core.publisher.Mono<Boolean>isSubmissionComplete(String sid)reactor.core.publisher.Mono<LoginResponse>login()protected <T> reactor.core.publisher.Mono<T>post(Function<org.springframework.web.util.UriBuilder,URI> uriBuilder, org.springframework.core.ParameterizedTypeReference<AssemblylineApiResponse<T>> responseType, org.springframework.web.reactive.function.BodyInserter<?,? super org.springframework.http.client.reactive.ClientHttpRequest> bodyInserter, org.springframework.http.MediaType contentType)Helper method to perform a JSON POST request.protected <T> reactor.core.publisher.Mono<T>retryWrapper(reactor.core.publisher.Mono<T> monoContent)protected voidsetSession(org.springframework.web.reactive.function.client.ClientResponse clientResponse)reactor.core.publisher.Mono<Submission>submitBinary(BinaryFile<SubmitMetadata> binaryIngest)reactor.core.publisher.Mono<Submission>submitUrlOrSha256(NonBinarySubmit submit)AssemblylineClientwithAuthBearerToken(String authBearerToken)Creates a copy of the current AssemblylineClient that will use the given authentication bearer token.
-
-
-
Field Detail
-
BASE_URL
public static final String BASE_URL
- See Also:
- Constant Field Values
-
LOGIN_URL
public static final String LOGIN_URL
- See Also:
- Constant Field Values
-
FILE_DOWNLOAD_URL
public static final String FILE_DOWNLOAD_URL
- See Also:
- Constant Field Values
-
FILE_INFO_URL
public static final String FILE_INFO_URL
- See Also:
- Constant Field Values
-
FILE_RESULTS_URL
public static final String FILE_RESULTS_URL
- See Also:
- Constant Field Values
-
FILE_RESULT_FOR_SERVICE_URL
public static final String FILE_RESULT_FOR_SERVICE_URL
- See Also:
- Constant Field Values
-
HASH_SEARCH
public static final String HASH_SEARCH
- See Also:
- Constant Field Values
-
HASH_SEARCH_LIST_DATA_SOURCES
public static final String HASH_SEARCH_LIST_DATA_SOURCES
- See Also:
- Constant Field Values
-
INGEST_URL
public static final String INGEST_URL
- See Also:
- Constant Field Values
-
INGEST_GET_MESSAGE_LIST_URL
public static final String INGEST_GET_MESSAGE_LIST_URL
- See Also:
- Constant Field Values
-
RESULT_URL
public static final String RESULT_URL
- See Also:
- Constant Field Values
-
SUBMISSION_COMPLETE_URL
public static final String SUBMISSION_COMPLETE_URL
- See Also:
- Constant Field Values
-
SUBMISSION_URL
public static final String SUBMISSION_URL
- See Also:
- Constant Field Values
-
SUBMISSION_FILE_RESULTS_URL
public static final String SUBMISSION_FILE_RESULTS_URL
- See Also:
- Constant Field Values
-
SUBMISSION_FULL_URL
public static final String SUBMISSION_FULL_URL
- See Also:
- Constant Field Values
-
SUBMISSION_TREE_URL
public static final String SUBMISSION_TREE_URL
- See Also:
- Constant Field Values
-
SUBMIT_URL
public static final String SUBMIT_URL
- See Also:
- Constant Field Values
-
session
protected String session
-
webClient
protected org.springframework.web.reactive.function.client.WebClient webClient
-
mapper
protected com.fasterxml.jackson.databind.ObjectMapper mapper
-
assemblylineAuthenticationMethod
protected AssemblylineAuthenticationMethod assemblylineAuthenticationMethod
-
addSession
protected org.springframework.web.reactive.function.client.ExchangeFilterFunction addSession
-
-
Constructor Detail
-
AssemblylineClient
public AssemblylineClient(AssemblylineClientProperties assemblylineClientProperties, ProxyProperties proxyProperties, com.fasterxml.jackson.databind.ObjectMapper defaultMapper, AssemblylineAuthenticationMethod assemblylineAuthenticationMethod)
-
-
Method Detail
-
withAuthBearerToken
public AssemblylineClient withAuthBearerToken(String authBearerToken)
Creates a copy of the current AssemblylineClient that will use the given authentication bearer token.- Parameters:
authBearerToken- The authentication bearer token for the new client to use.- Returns:
- the new client.
-
buildWebClient
protected void buildWebClient(AssemblylineClientProperties assemblylineClientProperties, ProxyProperties proxyProperties)
-
login
public reactor.core.publisher.Mono<LoginResponse> login()
-
getFileResults
public reactor.core.publisher.Mono<FileResults> getFileResults(String sha256)
-
getFileResultForService
public reactor.core.publisher.Mono<FileResultForService> getFileResultForService(String sha256, String serviceName)
-
getResult
public reactor.core.publisher.Mono<ResultBlock> getResult(String cacheKey)
-
getSubmissionFileResults
public reactor.core.publisher.Mono<SubmissionFileResults> getSubmissionFileResults(String sid, String sha256)
-
getSubmissionTree
public reactor.core.publisher.Mono<SubmissionTree> getSubmissionTree(String sid)
-
getSubmission
public reactor.core.publisher.Mono<Submission> getSubmission(String sid)
-
getSubmissionFull
public reactor.core.publisher.Mono<SubmissionFull> getSubmissionFull(String sid)
-
ingestUrlOrSha256
public reactor.core.publisher.Mono<IngestResponse> ingestUrlOrSha256(NonBinaryIngest ingest)
-
ingestBinary
public reactor.core.publisher.Mono<IngestResponse> ingestBinary(BinaryFile<IngestBase> binaryIngest)
-
getIngestMessageList
public reactor.core.publisher.Flux<IngestSubmissionResponse> getIngestMessageList(String notification)
-
submitUrlOrSha256
public reactor.core.publisher.Mono<Submission> submitUrlOrSha256(NonBinarySubmit submit)
-
submitBinary
public reactor.core.publisher.Mono<Submission> submitBinary(BinaryFile<SubmitMetadata> binaryIngest)
-
downloadFile
public InputStream downloadFile(String sha256)
-
downloadFile
public InputStream downloadFile(String sha256, DownloadFileParams params)
-
getHashSearchDataSources
public reactor.core.publisher.Mono<List<String>> getHashSearchDataSources()
-
hashSearch
public reactor.core.publisher.Mono<Map<String,HashSearchResult>> hashSearch(String fileHash, List<String> dataSources, Integer maxTimeout)
Search for a hash in multiple data sources.- Parameters:
fileHash- Hash to search in the multiple data sources (MD5, SHA1 or SHA256)dataSources- list of data sources. Set to null to use server default.maxTimeout- Maximum execution time for the call in seconds. Set to null to use server default.- Returns:
- Search results
- See Also:
hashSearch(String)
-
hashSearch
public reactor.core.publisher.Mono<Map<String,HashSearchResult>> hashSearch(String fileHash)
Search for a hash in multiple data sources, using default values for optional parameters.- Parameters:
fileHash- Hash to search in the multiple data sources (MD5, SHA1 or SHA256)- Returns:
- Search results
- See Also:
hashSearch(String, List, Integer)
-
setSession
protected void setSession(org.springframework.web.reactive.function.client.ClientResponse clientResponse)
-
retryWrapper
protected <T> reactor.core.publisher.Mono<T> retryWrapper(reactor.core.publisher.Mono<T> monoContent)
-
get
protected <T> reactor.core.publisher.Mono<T> get(Function<org.springframework.web.util.UriBuilder,URI> uriBuilder, org.springframework.core.ParameterizedTypeReference<AssemblylineApiResponse<T>> responseType)
Helper method to perform a JSON GET request. This helper covers the most common GET requests. For more specialized requests, use webClient directly.- Type Parameters:
T- The type of data that will be in the response.- Parameters:
uriBuilder- UriBuilder that will generate the URI to GET.responseType- A parameterized type reference representing the type of data that will be in the response. The declaration of this object must only include concrete type parameters. For example,new ParameterizedTypeReference<ALApiResponse<Boolean>>is OK, butnew ParameterizedTypeReference<ALApiResponse<T>>(whereTis a type parameter on a method) is not OK.- Returns:
- The content of the "api_response" section of the response.
-
post
protected <T> reactor.core.publisher.Mono<T> post(Function<org.springframework.web.util.UriBuilder,URI> uriBuilder, org.springframework.core.ParameterizedTypeReference<AssemblylineApiResponse<T>> responseType, org.springframework.web.reactive.function.BodyInserter<?,? super org.springframework.http.client.reactive.ClientHttpRequest> bodyInserter, org.springframework.http.MediaType contentType)
Helper method to perform a JSON POST request. This helper covers the most common POST requests. For more specialized requests, use webClient directly.- Type Parameters:
T- The type of data that will be in the response.- Parameters:
uriBuilder- UriBuilder that will generate the URI to POST.responseType- A parameterized type reference representing the type of data that will be in the response. The declaration of this object must only include concrete type parameters. For example,new ParameterizedTypeReference<ALApiResponse<Boolean>>is OK, butnew ParameterizedTypeReference<ALApiResponse<T>>(whereTis a type parameter on a method) is not OK.bodyInserter- BodyInserter to construct the body of the Post RequestcontentType- MediaType of the request body- Returns:
- The content of the "api_response" section of the response.
-
clientResponseToMono
protected <T> reactor.core.publisher.Mono<T> clientResponseToMono(org.springframework.web.reactive.function.client.ClientResponse clientResponse, org.springframework.core.ParameterizedTypeReference<AssemblylineApiResponse<T>> type)Convert ClientResponse to AssemblylineApiResponse content mono.- Type Parameters:
T- The type of data that will be in the response.- Parameters:
clientResponse- ClientResponse returned by calltype- A parameterized type reference representing the type of data that will be in the response. The declaration of this object must only include concrete type parameters. For example,new ParameterizedTypeReference<ALApiResponse<Boolean>>is OK, butnew ParameterizedTypeReference<ALApiResponse<T>>(whereTis a type parameter on a method) is not OK.- Returns:
- Mono
-
-