All Projects → oscaro → clj-gcloud-storage

oscaro / clj-gcloud-storage

Licence: EPL-1.0 license
Clojure wrapper for google-cloud-storage Java client.

Programming Languages

clojure
4091 projects

Projects that are alternatives of or similar to clj-gcloud-storage

go-bqloader
bqloader is a simple ETL framework to load data from Cloud Storage into BigQuery.
Stars: ✭ 16 (-20%)
Mutual labels:  google-cloud-storage, google-cloud
server
The ViUR application development framework - legacy version 2.x for Python 2.7
Stars: ✭ 12 (-40%)
Mutual labels:  google-cloud-storage, google-cloud
ob bulkstash
Bulk Stash is a docker rclone service to sync, or copy, files between different storage services. For example, you can copy files either to or from a remote storage services like Amazon S3 to Google Cloud Storage, or locally from your laptop to a remote storage.
Stars: ✭ 113 (+465%)
Mutual labels:  google-cloud-storage, google-cloud
arc gcs
Provides an Arc backend for Google Cloud Storage
Stars: ✭ 48 (+140%)
Mutual labels:  google-cloud-storage, google-cloud
Kubernetes Nexus
Run Sonatype Nexus Repository Manager OSS on top of Kubernetes (GKE). Includes instructions for automated backups (GCS) and day-to-day usage.
Stars: ✭ 122 (+510%)
Mutual labels:  google-cloud-storage, google-cloud
Flysystem Google Cloud Storage
Flysystem Adapter for Google Cloud Storage
Stars: ✭ 237 (+1085%)
Mutual labels:  google-cloud-storage, google-cloud
bazel-cache
Minimal cloud oriented Bazel gRPC cache
Stars: ✭ 33 (+65%)
Mutual labels:  google-cloud-storage, google-cloud
Laravel Google Cloud Storage
A Google Cloud Storage filesystem for Laravel
Stars: ✭ 415 (+1975%)
Mutual labels:  google-cloud-storage, google-cloud
Berglas
A tool for managing secrets on Google Cloud
Stars: ✭ 959 (+4695%)
Mutual labels:  google-cloud-storage, google-cloud
Google Cloud Cpp
C++ Client Libraries for Google Cloud Services
Stars: ✭ 233 (+1065%)
Mutual labels:  google-cloud-storage, google-cloud
Php Ffmpeg Video Streaming
📼 Package media content for online streaming(DASH and HLS) using FFmpeg
Stars: ✭ 246 (+1130%)
Mutual labels:  google-cloud-storage, google-cloud
osrm-backend-k8s
Open Source Routing Machine (OSRM) osrm-backend for Kubernetes on Google Container Engine (GKE).
Stars: ✭ 34 (+70%)
Mutual labels:  google-cloud
streamlit-project
This repository provides a simple deployment-ready project layout for a Streamlit app. Simply swap out the code in `app.py` for your own and hit deploy!
Stars: ✭ 33 (+65%)
Mutual labels:  google-cloud
perspectiveapi-authorship-demo
Example code to illustrate how to build an authorship experience using the perspective API
Stars: ✭ 62 (+210%)
Mutual labels:  google-cloud
deploy-appengine
A GitHub Action that deploys source code to Google App Engine.
Stars: ✭ 184 (+820%)
Mutual labels:  google-cloud
grucloud
Generate diagrams and code from cloud infrastructures: AWS, Azure,GCP, Kubernetes
Stars: ✭ 76 (+280%)
Mutual labels:  google-cloud
multer-sharp
Streaming multer storage engine permit to resize and upload to Google Cloud Storage.
Stars: ✭ 21 (+5%)
Mutual labels:  google-cloud
spannerz
Google Cloud Spanner Query Planner Visualizer
Stars: ✭ 60 (+200%)
Mutual labels:  google-cloud
auth
A GitHub Action for authenticating to Google Cloud.
Stars: ✭ 567 (+2735%)
Mutual labels:  google-cloud
nominatim-k8s
Nominatim for Kubernetes on Google Container Engine (GKE).
Stars: ✭ 59 (+195%)
Mutual labels:  google-cloud

clj-gcloud-storage

Clojars Project

cljdoc badge

Clojure wrapper for google-cloud-storage Java client.

Usage

[com.oscaro/clj-gcloud-storage "0.172-1.0"]

Initializing a client

As any other Google cloud service, Storage requires the user to be authentified. Thus, you must create a client you will then pass to every operation :

There are several ways to authenticate, two major ones :

;; Local credentials, require them to have been created on your side
;; Default project will be used
(def client (st/init))
;; or equivalent
(def client (st/init {}))

;; Service account usage for portable applications
(def client
  (st/init
    {:project-id "my-project"
     :credentials "my-service-account.json"}))

Uploading and downloading files

Uploading and downloading files is one the most basic operation in Google Cloud Storage and one of the core need you expect from it in most cases. Note however that data can be streamed in a more sophisticated way from and to Storage blobs, however it requires more work on byte arrays.

;; Let's download a file and upload it back

;; Local credentials
(def client (st/init {}))

;; Actual (blocking) download
;; The file will be downloaded on disk
(download-file-from-storage storage-client "gs://mybucket/myfolder/myotherfolder/myfile.ext" "mylocalfile.ext")

;; Now we upload a the file again to a copy location
(copy-file-to-storage storage-client (io/file "mylocalfile.ext") "gs://mybucket/myfolder/myotherfolder/myfilecopy.ext")

Objects creation, deletion and copy

Common operations you expect from a "file-system" are available. Two main object types can be found in Google Storage : buckets which are "folders" at the root of the project and blobs which are everything else.

Creation

;; You can create a bucket this way
;; See other options in code and documentation
(create-bucket
  client
  (bucket-info
    "mybucket"
    {:location "europe-west1"}))

;; Blobs are created similarly
;; Subfolders under buckets (which must be constructed before)
;; are created automatically
;; Blob IDs can be inferred from a gs uri
(create-blob
  client
  (blob-info
    (->blob-id "mybucket" "whatever/again/myfile.ext")
    {}))

Deletion

;; Bucket deletion is straightforward
(delete-bucket client "mybucket")

;; Blobs require coercion to BlobId
(delete-blob client (->blob-id "gs://mybucket/whatever/again/myfile.ext"))

Copy

;; Buckets cannot be copied
;; Blobs can
;; Here is one method
(copy client
  (->blob-id "gs://mybucket/whatever/again/myfile.ext")
  (->blob-id "gs://mybucket/whatever/again-archive/myfile.ext"))

You can also get buckets or blobs to work directly on it. This can be useful when you perform multiple operations on the same blob.

Listing blobs

You can list blobs under a specific uri. You can then coerce back the result to uris.

;; Basic usage
(ls client "gs://mybucket/whatever/again/")

;; Full coercion to GS uris
(->> (ls client "gs://mybucket/whatever/again/")
     (map
       (fn [obj]
         (let [{:keys [blob-id]} (clj-gcloud.coerce/->clj blob-id)]
           (str "gs://mybucket/" (:name blob-id))))))

License

Copyright © 2017-2021 Oscaro

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].