azure-blob 0.5.2 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72003b15ad78aeab66adc7aca2e6786ae2921ad1469cf94145e049705f52c33c
4
- data.tar.gz: a77f87dff2f59a22476f0c5e490540a73166cf88dbf3616de8a15a87132aaa5f
3
+ metadata.gz: c6c4e076840dd6671c28c99b5fca03057782e81686c0c06890b42cedd3b83788
4
+ data.tar.gz: '00668582cecce526ad816a5c537469af7e646d6f64d7392655d1c7e60396393c'
5
5
  SHA512:
6
- metadata.gz: 910c2d759b83d7b56168fd42a239ffb5da1b4aced25b8f39bc84a1beb63e736690a72586f64313d5fcebf7250808b27d15e23450e850635e24558891eed375ff
7
- data.tar.gz: 2d4ecfb6e3e5318d8c6cb07569da7b83bccd49ee3a7d153d43c41e655474dcd43d7a73d28d68fb2baa4124326a1b41562275314348730250610420640c3dc3bd
6
+ metadata.gz: fdd32b7f8547ac428bf0eb19d884860e94d1ab9471df0022356119c5ec28aca8589d1b1925d0085b2361c4c16d5898123a1fc18f57b5b2cb9ae7e53dbc4b4379
7
+ data.tar.gz: 44a4592046d5d33432762cfd4d3636500f9c13db00cf5c705fbc2f472b7c322bd37bc05d9765e03079e0966dcb44d0e5cc844db303906aaa18435c8db7ee422f
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
3
 
4
+ ## [0.5.3] 2024-10-31
5
+
6
+ - Add support for setting tags when uploading a blob
7
+ - Add get_blob_tags
8
+
4
9
  ## [0.5.2] 2024-09-12
5
10
 
6
11
  - Add get_container_properties
@@ -4,6 +4,7 @@ require_relative "block_list"
4
4
  require_relative "blob_list"
5
5
  require_relative "blob"
6
6
  require_relative "container"
7
+ require_relative "tags"
7
8
  require_relative "http"
8
9
  require_relative "shared_key_signer"
9
10
  require_relative "entra_id_signer"
@@ -28,7 +29,7 @@ module AzureBlob
28
29
  )
29
30
  end
30
31
  @signer = using_managed_identities ?
31
- AzureBlob::EntraIdSigner.new(account_name:, host:, principal_id: ) :
32
+ AzureBlob::EntraIdSigner.new(account_name:, host:, principal_id:) :
32
33
  AzureBlob::SharedKeySigner.new(account_name:, access_key:)
33
34
  end
34
35
 
@@ -157,6 +158,20 @@ module AzureBlob
157
158
  Blob.new(response)
158
159
  end
159
160
 
161
+ # Returns the tags associated with a blob
162
+ #
163
+ # Calls to the {Get Blob Tags}[https://learn.microsoft.com/en-us/rest/api/storageservices/get-blob-tags] endpoint.
164
+ #
165
+ # Takes a key (path) of the blob.
166
+ #
167
+ # Returns a hash of the blob's tags.
168
+ def get_blob_tags(key)
169
+ uri = generate_uri("#{container}/#{key}?comp=tags")
170
+ response = Http.new(uri, signer:).get
171
+
172
+ Tags.from_response(response).to_h
173
+ end
174
+
160
175
  # Returns a Container object.
161
176
  #
162
177
  # Calls to {Get Container Properties}[https://learn.microsoft.com/en-us/rest/api/storageservices/get-container-properties]
@@ -230,7 +245,7 @@ module AzureBlob
230
245
  "x-ms-blob-content-disposition": options[:content_disposition],
231
246
  }
232
247
 
233
- Http.new(uri, headers, metadata: options[:metadata], signer:).put(nil)
248
+ Http.new(uri, headers, signer:, **options.slice(:metadata, :tags)).put(nil)
234
249
  end
235
250
 
236
251
  # Append a block to an Append Blob
@@ -305,7 +320,7 @@ module AzureBlob
305
320
  "x-ms-blob-content-disposition": options[:content_disposition],
306
321
  }
307
322
 
308
- Http.new(uri, headers, metadata: options[:metadata], signer:).put(content)
323
+ Http.new(uri, headers, signer:, **options.slice(:metadata, :tags)).put(content)
309
324
  end
310
325
 
311
326
  private
@@ -337,7 +352,7 @@ module AzureBlob
337
352
  "x-ms-blob-content-disposition": options[:content_disposition],
338
353
  }
339
354
 
340
- Http.new(uri, headers, metadata: options[:metadata], signer:).put(content.read)
355
+ Http.new(uri, headers, signer:, **options.slice(:metadata, :tags)).put(content.read)
341
356
  end
342
357
 
343
358
  def host
@@ -24,12 +24,16 @@ module AzureBlob
24
24
 
25
25
  include REXML
26
26
 
27
- def initialize(uri, headers = {}, signer: nil, metadata: {}, debug: false, raise_on_error: true)
27
+ def initialize(uri, headers = {}, signer: nil, metadata: {}, tags: {}, debug: false, raise_on_error: true)
28
28
  @raise_on_error = raise_on_error
29
29
  @date = Time.now.httpdate
30
30
  @uri = uri
31
31
  @signer = signer
32
- @headers = headers.merge(Metadata.new(metadata).headers)
32
+ @headers = headers.merge(
33
+ Metadata.new(metadata).headers,
34
+ Tags.new(tags).headers,
35
+ )
36
+
33
37
  sanitize_headers
34
38
 
35
39
  @http = Net::HTTP.new(uri.hostname, uri.port)
@@ -0,0 +1,35 @@
1
+ require "rexml/document"
2
+
3
+ module AzureBlob
4
+ class Tags # :nodoc:
5
+ def self.from_response(response)
6
+ document = REXML::Document.new(response)
7
+ tags = {}
8
+ document.elements.each("Tags/TagSet/Tag") do |tag|
9
+ key = tag.elements["Key"].text
10
+ value = tag.elements["Value"].text
11
+ tags[key] = value
12
+ end
13
+ new(tags)
14
+ end
15
+
16
+ def initialize(tags = nil)
17
+ @tags = tags || {}
18
+ end
19
+
20
+ def headers
21
+ return {} if @tags.empty?
22
+
23
+ {
24
+ "x-ms-tags":
25
+ @tags.map do |key, value|
26
+ %(#{key}=#{value})
27
+ end.join("&"),
28
+ }
29
+ end
30
+
31
+ def to_h
32
+ @tags
33
+ end
34
+ end
35
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AzureBlob
4
- VERSION = "0.5.2"
4
+ VERSION = "0.5.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: azure-blob
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joé Dupuis
@@ -51,6 +51,7 @@ files:
51
51
  - lib/azure_blob/identity_token.rb
52
52
  - lib/azure_blob/metadata.rb
53
53
  - lib/azure_blob/shared_key_signer.rb
54
+ - lib/azure_blob/tags.rb
54
55
  - lib/azure_blob/user_delegation_key.rb
55
56
  - lib/azure_blob/version.rb
56
57
  homepage: https://github.com/testdouble/azure-blob