Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump bom 0.234.0 #15

Merged
merged 2 commits into from
Feb 3, 2025
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
16 changes: 8 additions & 8 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
;; dependency versions that work well with each other.
;;
;; based on versions from
;; https://mvnrepository.com/artifact/com.google.cloud/google-cloud-bom/0.215.0
;; https://mvnrepository.com/artifact/com.google.cloud/google-cloud-bom/0.234.0
;; which corresponds to
;; https://mvnrepository.com/artifact/com.google.cloud/libraries-bom/26.34.0
[[com.google.cloud/google-cloud-bom "0.215.0"
;; https://mvnrepository.com/artifact/com.google.cloud/libraries-bom/26.53.0
[[com.google.cloud/google-cloud-bom "0.234.0"
:extension "pom"
:scope "import"]
[com.google.cloud/google-cloud-shared-dependencies "3.27.0"
[com.google.cloud/google-cloud-shared-dependencies "3.42.0"
:extension "pom"
:scope "import"]]
:dependencies [[org.clojure/clojure "1.11.3"]
[com.oscaro/clj-gcloud-common "0.215-1.0"]
[com.google.cloud/google-cloud-nio "0.127.14"]
[com.google.cloud/google-cloud-storage "2.35.0"]
:dependencies [[org.clojure/clojure "1.11.4"]
[com.oscaro/clj-gcloud-common "0.234-1.0"]
[com.google.cloud/google-cloud-nio "0.127.29"]
[com.google.cloud/google-cloud-storage "2.47.0"]
[org.clojure/tools.logging "1.3.0"]]
:plugins [[io.github.borkdude/lein-lein2deps "0.1.0"]]
:prep-tasks [["lein2deps" "--write-file" "deps.edn" "--print" "false"]]
Expand Down
45 changes: 24 additions & 21 deletions src/clj_gcloud/storage.clj
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
(ns clj-gcloud.storage
(:require [clj-gcloud
[coerce :refer [create-clj-coerce ->clj page->seq]]
[common :refer [build-service array-type]]]
[clojure.java.io :as io]
[clojure.string :as str]
[clojure.tools.logging :as log])
(:import (com.google.cloud.storage BucketInfo Blob BlobId BlobInfo BucketInfo$Builder Storage StorageOptions
Storage$BucketGetOption Storage$BucketTargetOption
Storage$BucketSourceOption BlobInfo$Builder Storage$CopyRequest
Storage$BlobTargetOption Storage$BlobWriteOption
Blob$BlobSourceOption Storage$BlobListOption CopyWriter)
(java.nio.channels Channels ReadableByteChannel WritableByteChannel)
(java.nio.file Paths)
(java.io InputStream OutputStream FileInputStream File)
(com.google.cloud WriteChannel)
(com.google.common.io ByteStreams)))
(:require
[clj-gcloud
[coerce :refer [create-clj-coerce ->clj page->seq]]
[common :refer [build-service array-type]]]
[clojure.java.io :as io]
[clojure.string :as str]
[clojure.tools.logging :as log])
(:import
(com.google.cloud WriteChannel)
(com.google.cloud.storage BucketInfo Blob BlobId BlobInfo BucketInfo$Builder Storage StorageOptions
Storage$BucketGetOption Storage$BucketTargetOption
Storage$BucketSourceOption BlobInfo$Builder Storage$CopyRequest
Storage$BlobTargetOption Storage$BlobWriteOption
Blob$BlobSourceOption Storage$BlobListOption CopyWriter)
(com.google.common.io ByteStreams)
(java.io InputStream OutputStream FileInputStream File)
(java.nio.channels Channels ReadableByteChannel WritableByteChannel)
(java.nio.file Paths)))

(create-clj-coerce BucketInfo [:name :location :storage-class])
(create-clj-coerce Blob [:blob-id :name :content-type
Expand Down Expand Up @@ -58,10 +60,10 @@
(.create storage bucket-info no-options)))

(defn get-or-create-bucket
"Fetches or creates a bucket if it doesn't exist"
"Fetches or creates a bucket if it doesn't exist."
[^Storage storage ^BucketInfo info]
(let [bucket-name (.getName info)
bucket (get-bucket storage bucket-name)]
bucket (get-bucket storage bucket-name)]
(or bucket
(do
(log/info "Creating new bucket:" bucket-name)
Expand Down Expand Up @@ -172,7 +174,8 @@
[bucket name]))

(defn ls
"Usage:
"List files.
Usage:
(ls storage gs-uri [options])
(ls storage bucket path [options])"
([^Storage storage gs-uri]
Expand Down Expand Up @@ -210,12 +213,12 @@
(Channels/newOutputStream channel))

(defn stream->file
"Writes an input stream to disk"
"Writes an input stream to disk."
[^InputStream input-stream local-path]
(io/copy input-stream (io/file local-path)))

(defn file->stream
"Writes an local file to stream"
"Writes an local file to stream."
[local-path ^OutputStream output-stream]
(io/copy (io/file local-path) output-stream))

Expand Down
14 changes: 7 additions & 7 deletions test/clj_gcloud/storage_test.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns clj-gcloud.storage-test
(:require
[clj-gcloud.coerce :refer [->clj]]
[clj-gcloud.storage :refer [copy-file-to-storage read-channel ->input-stream delete-blob ls]]
[clj-gcloud.storage :as sut]
[clojure.java.io :as io]
[clojure.test :refer [deftest is use-fixtures testing]])
(:import
Expand Down Expand Up @@ -32,8 +32,8 @@
dest-uri (str "gs://" bucket "/tmp.json")
data "{\"test\":\"data\"}"]
(spit tmp data)
(copy-file-to-storage *storage* tmp dest-uri)
(let [^Blob blob (first (ls *storage* dest-uri))
(sut/copy-file-to-storage *storage* tmp dest-uri)
(let [^Blob blob (first (sut/ls *storage* dest-uri))
coerced-blob (->clj blob)]
(is (= {:blob-id {:bucket bucket :name "tmp.json"}
:content-type "application/json"
Expand All @@ -51,10 +51,10 @@
:content-encoding
:delete-time}
(set (keys coerced-blob))))
(is (= data (-> (read-channel blob)
(->input-stream)
(is (= data (-> (sut/read-channel blob)
(sut/->input-stream)
(io/reader)
(slurp))))
(is (delete-blob *storage* (.getBlobId blob)))
(is (= 0 (count (ls *storage* dest-uri)))))
(is (sut/delete-blob *storage* (.getBlobId blob)))
(is (= 0 (count (sut/ls *storage* dest-uri)))))
(.delete tmp))))