Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
nezaj committed Nov 26, 2024
1 parent 0ccb55b commit 7590603
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions server/src/instant/storage/s3.clj
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,33 @@
(list-app-objects default-bucket app-id)
(list-app-objects app-id))

(defn generate-presigned-url
([opts]
(let [access-key (config/s3-storage-access-key)
secret-key (config/s3-storage-secret-key)]
(if (and access-key secret-key)
(s3/generate-presigned-url {:access-key access-key
:secret-key secret-key} opts)
;; For OSS developers, use the default credentials provider chain
;; so they don't need to set up separate storage credentials
(s3/generate-presigned-url opts)))))

(defn signed-upload-url
([object-key] (signed-upload-url default-bucket object-key))
([bucket-name object-key]
(s3/generate-presigned-url
{:access-key (config/s3-storage-access-key)
:secret-key (config/s3-storage-secret-key)}
{:method :put
:bucket-name bucket-name
:key object-key})))
(generate-presigned-url {:method :put
:bucket-name bucket-name
:key object-key})))

(defn signed-download-url
([object-key] (let [expiration (+ (System/currentTimeMillis) (* 1000 60 60 24 7))] ;; 7 days
(signed-download-url default-bucket object-key expiration)))
([object-key expiration] (signed-download-url default-bucket object-key expiration))
([bucket-name object-key expiration]
(s3/generate-presigned-url
{:access-key (config/s3-storage-access-key)
:secret-key (config/s3-storage-secret-key)}
{:method :get
:bucket-name bucket-name
:key object-key
:expiration expiration})))
(generate-presigned-url {:method :get
:bucket-name bucket-name
:key object-key
:expiration expiration})))

(defn upload-image-to-s3
([object-key image-url] (upload-image-to-s3 default-bucket object-key image-url))
Expand Down

0 comments on commit 7590603

Please sign in to comment.