ms_rest_azure 0.11.1 → 0.11.2
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 +5 -5
- data/README.md +1 -1
- data/lib/ms_rest_azure.rb +2 -0
- data/lib/ms_rest_azure/azure_cli_error.rb +12 -0
- data/lib/ms_rest_azure/credentials/application_token_provider.rb +9 -3
- data/lib/ms_rest_azure/credentials/azure_cli_token_provider.rb +97 -0
- data/lib/ms_rest_azure/credentials/msi_token_provider.rb +9 -3
- data/lib/ms_rest_azure/version.rb +1 -1
- metadata +20 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ef2cf1db2beb396b143bf3ddec0c4df1ca7f8dfe38af73c13c4c81d6f039e0b2
|
4
|
+
data.tar.gz: f2461d024ada41c6e5ef4991928d376c82cdf8bef9be47fb40fb783a64155293
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff3bf9e1d8ce8e7aee10f9ad5b0fe7648b770a3ebfc22fbc7dacc4f828a6afaf5a8c0ac5e0a1b77b0d8431dece3bb0d948c3a21ce4c94087159f11725279ec60
|
7
|
+
data.tar.gz: 41154e27f1f815e40a2ed1ab4ed0b31e6a9e28d7d52dedef4aca0473d219db3ef6ad4c756ba7df68295078529375978678ee13fa9ad8e7666b431b5029a51ccd
|
data/README.md
CHANGED
@@ -37,7 +37,7 @@ To start working on the gem the only additional dev dependecy is required - rspe
|
|
37
37
|
Reference it in the gemfile and also add this line to your client's gemspec file:
|
38
38
|
|
39
39
|
```ruby
|
40
|
-
spec.add_runtime_dependency 'ms_rest_azure', '~> 0.11.
|
40
|
+
spec.add_runtime_dependency 'ms_rest_azure', '~> 0.11.1'
|
41
41
|
```
|
42
42
|
Don't forget to correct the version.
|
43
43
|
|
data/lib/ms_rest_azure.rb
CHANGED
@@ -15,6 +15,8 @@ require 'ms_rest_azure/credentials/application_token_provider.rb'
|
|
15
15
|
require 'ms_rest_azure/credentials/cognitive_services_credentials.rb'
|
16
16
|
require 'ms_rest_azure/credentials/topic_credentials.rb'
|
17
17
|
require 'ms_rest_azure/credentials/msi_token_provider.rb'
|
18
|
+
require 'ms_rest_azure/credentials/azure_cli_token_provider.rb'
|
19
|
+
require 'ms_rest_azure/azure_cli_error.rb'
|
18
20
|
require 'ms_rest_azure/polling_state.rb'
|
19
21
|
require 'ms_rest_azure/serialization.rb'
|
20
22
|
require 'ms_rest_azure/typed_error_info.rb'
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
4
|
+
|
5
|
+
module MsRestAzure
|
6
|
+
#
|
7
|
+
# Class which represents an error with the Azure CLI.
|
8
|
+
#
|
9
|
+
class AzureCliError < StandardError
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
@@ -27,18 +27,24 @@ module MsRestAzure
|
|
27
27
|
attr_accessor :client_secret
|
28
28
|
|
29
29
|
# @return [String] auth token.
|
30
|
-
|
30
|
+
attr_writer :token
|
31
31
|
|
32
32
|
# @return [Time] the date when the current token expires.
|
33
|
-
|
33
|
+
attr_writer :token_expires_on
|
34
34
|
|
35
35
|
# @return [Integer] the amount of time we refresh token before it expires.
|
36
36
|
attr_reader :expiration_threshold
|
37
37
|
|
38
|
+
public
|
39
|
+
|
40
|
+
# @return [Time] the date when the current token expires.
|
41
|
+
attr_reader :token_expires_on
|
42
|
+
|
38
43
|
# @return [String] the type of token.
|
39
44
|
attr_reader :token_type
|
40
45
|
|
41
|
-
|
46
|
+
# @return [String] auth token.
|
47
|
+
attr_reader :token
|
42
48
|
|
43
49
|
#
|
44
50
|
# Creates and initialize new instance of the ApplicationTokenProvider class.
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
3
|
+
# Licensed under the MIT License. See License.txt in the project root for license information.
|
4
|
+
|
5
|
+
require 'time'
|
6
|
+
|
7
|
+
module MsRestAzure
|
8
|
+
#
|
9
|
+
# Class that provides access to access tokens generated by the azure cli.
|
10
|
+
#
|
11
|
+
class AzureCliTokenProvider < MsRest::TokenProvider
|
12
|
+
private
|
13
|
+
|
14
|
+
# @return [String] the type of token.
|
15
|
+
attr_reader :cli_path
|
16
|
+
|
17
|
+
# @return [ActiveDirectoryServiceSettings] settings.
|
18
|
+
attr_accessor :settings
|
19
|
+
|
20
|
+
# @return [String] auth token.
|
21
|
+
attr_accessor :token
|
22
|
+
|
23
|
+
# @return [Time] the date when the current token expires.
|
24
|
+
attr_accessor :token_expires_on
|
25
|
+
|
26
|
+
# @return [Integer] the amount of time we refresh token before it expires.
|
27
|
+
attr_reader :expiration_threshold
|
28
|
+
|
29
|
+
# @return [String] the type of token.
|
30
|
+
attr_reader :token_type
|
31
|
+
|
32
|
+
public
|
33
|
+
|
34
|
+
#
|
35
|
+
# Creates and initialize new instance of the AzureCliTokenProvider class.
|
36
|
+
# @param settings [ActiveDirectoryServiceSettings] active directory setting.
|
37
|
+
def initialize(settings = ActiveDirectoryServiceSettings.get_azure_settings)
|
38
|
+
fail ArgumentError, 'Azure AD settings cannot be nil' if settings.nil?
|
39
|
+
raise AzureCliError, 'Azure CLI is not installed' unless locate_azure_cli
|
40
|
+
|
41
|
+
@settings = settings
|
42
|
+
|
43
|
+
@expiration_threshold = 5 * 60
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# Gets an authentication header string using an access token from the Azure cli
|
48
|
+
# @param settings [ActiveDirectoryServiceSettings] active directory settings.
|
49
|
+
#
|
50
|
+
# @return [String] The authenticaiton header string
|
51
|
+
def get_authentication_header
|
52
|
+
acquire_token if token_expired?
|
53
|
+
"#{token_type} #{token}"
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
#
|
59
|
+
# Checks whether token is about to expire.
|
60
|
+
#
|
61
|
+
# @return [Bool] True if token is about to expire, false otherwise.
|
62
|
+
def token_expired?
|
63
|
+
@token.nil? || Time.now >= @token_expires_on + expiration_threshold
|
64
|
+
end
|
65
|
+
|
66
|
+
#
|
67
|
+
# Checks if the Azure CLI is installed
|
68
|
+
#
|
69
|
+
# @return [Boolean] Does the az command exist on the path
|
70
|
+
def locate_azure_cli
|
71
|
+
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
72
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
73
|
+
exts.each do |ext|
|
74
|
+
executable = File.join(path, "az#{ext}")
|
75
|
+
return @cli_path = executable if File.executable?(executable) && !File.directory?(executable)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
return nil
|
80
|
+
end
|
81
|
+
|
82
|
+
#
|
83
|
+
# Acquires a new access token from teh azure CLI
|
84
|
+
#
|
85
|
+
# @return [String] The access token to the desired resource
|
86
|
+
def acquire_token()
|
87
|
+
response_body = JSON.load(`#{cli_path} account get-access-token -o json --resource #{@settings.token_audience}`)
|
88
|
+
|
89
|
+
@token_expires_on = Time.parse(response_body['expiresOn'])
|
90
|
+
@token_type = response_body['tokenType']
|
91
|
+
@token = response_body['accessToken']
|
92
|
+
rescue
|
93
|
+
raise AzureCliError, 'Error acquiring token from the Azure CLI'
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
@@ -32,18 +32,24 @@ module MsRestAzure
|
|
32
32
|
attr_accessor :msi_res_id
|
33
33
|
|
34
34
|
# @return [String] auth token.
|
35
|
-
|
35
|
+
attr_writer :token
|
36
36
|
|
37
37
|
# @return [Time] the date when the current token expires.
|
38
|
-
|
38
|
+
attr_writer :token_expires_on
|
39
39
|
|
40
40
|
# @return [Integer] the amount of time we refresh token before it expires.
|
41
41
|
attr_reader :expiration_threshold
|
42
42
|
|
43
|
+
public
|
44
|
+
|
45
|
+
# @return [Time] the date when the current token expires.
|
46
|
+
attr_reader :token_expires_on
|
47
|
+
|
43
48
|
# @return [String] the type of token.
|
44
49
|
attr_reader :token_type
|
45
50
|
|
46
|
-
|
51
|
+
# @return [String] auth token.
|
52
|
+
attr_reader :token
|
47
53
|
|
48
54
|
#
|
49
55
|
# Creates and initialize new instance of the MSITokenProvider class.
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ms_rest_azure
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Microsoft Corporation
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,16 +84,22 @@ dependencies:
|
|
84
84
|
name: faraday
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0.9'
|
90
|
+
- - "<"
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 2.0.0
|
90
93
|
type: :runtime
|
91
94
|
prerelease: false
|
92
95
|
version_requirements: !ruby/object:Gem::Requirement
|
93
96
|
requirements:
|
94
|
-
- - "
|
97
|
+
- - ">="
|
95
98
|
- !ruby/object:Gem::Version
|
96
99
|
version: '0.9'
|
100
|
+
- - "<"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 2.0.0
|
97
103
|
- !ruby/object:Gem::Dependency
|
98
104
|
name: faraday-cookie_jar
|
99
105
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,14 +120,14 @@ dependencies:
|
|
114
120
|
requirements:
|
115
121
|
- - "~>"
|
116
122
|
- !ruby/object:Gem::Version
|
117
|
-
version: 0.7.
|
123
|
+
version: 0.7.6
|
118
124
|
type: :runtime
|
119
125
|
prerelease: false
|
120
126
|
version_requirements: !ruby/object:Gem::Requirement
|
121
127
|
requirements:
|
122
128
|
- - "~>"
|
123
129
|
- !ruby/object:Gem::Version
|
124
|
-
version: 0.7.
|
130
|
+
version: 0.7.6
|
125
131
|
description: Azure Client Library for Ruby.
|
126
132
|
email: azsdkteam@microsoft.com
|
127
133
|
executables: []
|
@@ -134,6 +140,7 @@ files:
|
|
134
140
|
- lib/ms_rest_azure.rb
|
135
141
|
- lib/ms_rest_azure/active_directory_service_settings.rb
|
136
142
|
- lib/ms_rest_azure/async_operation_status.rb
|
143
|
+
- lib/ms_rest_azure/azure_cli_error.rb
|
137
144
|
- lib/ms_rest_azure/azure_environment.rb
|
138
145
|
- lib/ms_rest_azure/azure_operation_error.rb
|
139
146
|
- lib/ms_rest_azure/azure_operation_response.rb
|
@@ -142,6 +149,7 @@ files:
|
|
142
149
|
- lib/ms_rest_azure/common/configurable.rb
|
143
150
|
- lib/ms_rest_azure/common/default.rb
|
144
151
|
- lib/ms_rest_azure/credentials/application_token_provider.rb
|
152
|
+
- lib/ms_rest_azure/credentials/azure_cli_token_provider.rb
|
145
153
|
- lib/ms_rest_azure/credentials/cognitive_services_credentials.rb
|
146
154
|
- lib/ms_rest_azure/credentials/msi_token_provider.rb
|
147
155
|
- lib/ms_rest_azure/credentials/topic_credentials.rb
|
@@ -158,7 +166,7 @@ metadata:
|
|
158
166
|
changelog_uri: https://github.com/Azure/azure-sdk-for-ruby/blob/master/runtime/ms_rest_azure/CHANGELOG.md
|
159
167
|
documentation_uri: https://azure.microsoft.com/en-us/develop/ruby/
|
160
168
|
homepage_uri: https://aka.ms/azure-sdk-for-ruby
|
161
|
-
source_code_uri: https://github.com/Azure/azure-sdk-for-ruby/tree/ms_rest_azure-v0.11.
|
169
|
+
source_code_uri: https://github.com/Azure/azure-sdk-for-ruby/tree/ms_rest_azure-v0.11.2
|
162
170
|
post_install_message:
|
163
171
|
rdoc_options: []
|
164
172
|
require_paths:
|
@@ -175,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
183
|
version: '0'
|
176
184
|
requirements: []
|
177
185
|
rubyforge_project:
|
178
|
-
rubygems_version: 2.
|
186
|
+
rubygems_version: 2.7.8
|
179
187
|
signing_key:
|
180
188
|
specification_version: 4
|
181
189
|
summary: Azure Client Library for Ruby.
|