biiwide / sandboxica Goto Github PK
View Code? Open in Web Editor NEWDon't play in the Jungle
License: Eclipse Public License 2.0
Don't play in the Jungle
License: Eclipse Public License 2.0
CONTEXT: I am trying to use Sandboxica to intercept PutObject requests to S3 for unit testing.
PROBLEM STATEMENT: When I use the sandboxica/with
method to override the implementation of s3/put-object and I try to call the proxied put-object
method with a valid PutObjectRequest
, I expected to be able to intercept the request that I supplied to put-object
. However, the intercepted request is missing most of the data I tried to send to the put-object
function (see below).
(def s3-req
(let [some-bytes (.getBytes "<h1>HI</h1>")]
{:bucket-name "mybucket"
:key "something.txt"
:input-stream (java.io.ByteArrayInputStream. some-bytes)
:metadata {:content-type "text/html"
:content-length (count some-bytes)
:user-metadata {"somethin" "some-value"}}}))
;; When I override the put-object method on the amazonica s3 client, the
;; intercepted request reflects that the request was not intercepted properly
(sandbox/with (sandbox/just
(s3/put-object
([req] (println "REQUEST" (type req) req))))
(s3/put-object {:profile "none"} s3-req))
;; => Running this code prints out the following `{:requester-pays? false}`, but is missing all of the supplied fields
WHAT I EXPECTED TO HAPPEN WHEN I RAN THE CODE ABOVE:
I expected the intercepted request to have the fields I supplied in the request (bucket-name, key, input-stream, metadata... and more). However, the intercepted request doesn't reflect all the fields that were used for inputs
POSSIBLE PROBLEM: The missing data in the intercepted request is due to sandboxica/coerce-method-implementation
missing a preprocessing step before marshalling resources.
TRACKING DOWN THE POSSIBLE PROBLEM:
;; The `sandboxica/coerce-method-implementation` directly calls `aws/marshall` on the incoming clojure map (`s3-req` in this case)
;; When `aws/marshall` is called directly on a Clojure map representing PutObjectRequest, it does not marshall resources properly
(aws/marshall (#'aws/create-bean com.amazonaws.services.s3.model.PutObjectRequest
s3-req))
;; => {:requester-pays? false}
EXPLANATION/VERIFICATION: In the amazonica.core
library, there is a call to aws/prepare-args
before resources are marshalled - however this call is not present in the current implementation of coerce-method-implementation
.
https://github.com/mcohen01/amazonica/blob/master/src/amazonica/core.clj#L867-L887
If aws/prepare-args
is used before marshalling, the PutObjectRequest seems to marshall properly
(let [method
(#'aws/best-method (:put-object (#'aws/client-methods com.amazonaws.services.s3.AmazonS3Client))
[{:profile "none"} s3-req])]
(bean (first (seq (aws/marshall (#'aws/prepare-args method [s3-req]))))))
;; => {:cloneSource nil,
;; :storageClass nil,
;; :key "something.txt",
;; :customQueryParameters nil,
;; :file nil,
;; :readLimit 131073,
;; :inputStream
;; #object[java.io.ByteArrayInputStream 0x1f9a0a26 "java.io.ByteArrayInputStream@1f9a0a26"],
;; :requestCredentials nil,
;; :objectLockRetainUntilDate nil,
;; :sdkClientExecutionTimeout nil,
;; :generalProgressListener
;; #object[com.amazonaws.event.ProgressListener$NoOpProgressListener 0x775e743b "com.amazonaws.event.ProgressListener$NoOpProgressListener@775e743b"],
;; :SSECustomerKey nil,
;; :cloneRoot nil,
;; :class com.amazonaws.services.s3.model.PutObjectRequest,
;; :accessControlList nil,
;; :progressListener nil,
;; :cannedAcl nil,
;; :requestClientOptions
;; #object[com.amazonaws.RequestClientOptions 0x192557b7 "com.amazonaws.RequestClientOptions@192557b7"],
;; :bucketName "mybucket",
;; :sdkRequestTimeout nil,
;; :tagging nil,
;; :requesterPays false,
;; :SSEAwsKeyManagementParams nil,
;; :redirectLocation nil,
;; :requestMetricCollector nil,
;; :customRequestHeaders nil,
;; :metadata
;; #object[com.amazonaws.services.s3.model.ObjectMetadata 0x58977f3d "com.amazonaws.services.s3.model.ObjectMetadata@58977f3d"],
;; :requestCredentialsProvider nil,
;; :objectLockLegalHoldStatus nil,
;; :objectLockMode nil}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.