Class: AzureBlob::EntraIdSigner

Inherits:
Object
  • Object
show all
Defined in:
lib/azure_blob/entra_id_signer.rb

Overview

:nodoc:

Defined Under Namespace

Modules: SAS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(account_name:, host:, principal_id: nil) ⇒ EntraIdSigner

Returns a new instance of EntraIdSigner.



17
18
19
20
21
# File 'lib/azure_blob/entra_id_signer.rb', line 17

def initialize(account_name:, host:, principal_id: nil)
  @token = AzureBlob::IdentityToken.new(principal_id:)
  @account_name = 
  @host = host
end

Instance Attribute Details

#account_nameObject (readonly)

Returns the value of attribute account_name.



14
15
16
# File 'lib/azure_blob/entra_id_signer.rb', line 14

def 
  @account_name
end

#hostObject (readonly)

Returns the value of attribute host.



15
16
17
# File 'lib/azure_blob/entra_id_signer.rb', line 15

def host
  @host
end

#tokenObject (readonly)

Returns the value of attribute token.



13
14
15
# File 'lib/azure_blob/entra_id_signer.rb', line 13

def token
  @token
end

Instance Method Details

#authorization_header(uri:, verb:, headers: {}) ⇒ Object



23
24
25
# File 'lib/azure_blob/entra_id_signer.rb', line 23

def authorization_header(uri:, verb:, headers: {})
  "Bearer #{token}"
end

#sas_token(uri, options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/azure_blob/entra_id_signer.rb', line 27

def sas_token(uri, options = {})
  delegation_key.refresh
  to_sign = [
    options[:permissions],
    options[:start],
    options[:expiry],
    CanonicalizedResource.new(uri, , url_safe: false, service_name: :blob),
    delegation_key.signed_oid,
    delegation_key.signed_tid,
    delegation_key.signed_start,
    delegation_key.signed_expiry,
    delegation_key.signed_service,
    delegation_key.signed_version,
    nil,
    nil,
    nil,
    options[:ip],
    options[:protocol],
    SAS::Version,
    SAS::Resources::Blob,
    nil,
    nil,
    nil,
    options[:content_disposition],
    nil,
    nil,
    options[:content_type],
  ].join("\n")

  query = {
    SAS::Fields::Permissions => options[:permissions],
    SAS::Fields::Start => options[:start],
    SAS::Fields::Expiry => options[:expiry],

    SAS::Fields::SignedObjectId => delegation_key.signed_oid,
    SAS::Fields::SignedTenantId => delegation_key.signed_tid,
    SAS::Fields::SignedKeyStartTime => delegation_key.signed_start,
    SAS::Fields::SignedKeyExpiryTime => delegation_key.signed_expiry,
    SAS::Fields::SignedKeyService => delegation_key.signed_service,
    SAS::Fields::Signedkeyversion => delegation_key.signed_version,


    SAS::Fields::SignedIp => options[:ip],
    SAS::Fields::SignedProtocol => options[:protocol],
    SAS::Fields::Version => SAS::Version,
    SAS::Fields::Resource => SAS::Resources::Blob,

    SAS::Fields::Disposition => options[:content_disposition],
    SAS::Fields::Type => options[:content_type],
    SAS::Fields::Signature => sign(to_sign, key: delegation_key.to_s),

  }.reject { |_, value| value.nil? }

  URI.encode_www_form(**query)
end