зеркало из
1
0
Форкнуть 0

Reusing ActiveDirectorySericeSettings for MSITokenProvider

This commit is contained in:
Vishrut Shah 2017-08-14 15:16:50 -07:00
Родитель dc7b1aa2f8
Коммит 13b2fb257a
5 изменённых файлов: 4 добавлений и 72 удалений

Просмотреть файл

@ -12,7 +12,6 @@ require 'ms_rest_azure/azure_service_client.rb'
require 'ms_rest_azure/cloud_error_data.rb'
require 'ms_rest_azure/credentials/application_token_provider.rb'
require 'ms_rest_azure/credentials/msi_token_provider.rb'
require 'ms_rest_azure/msi_active_directory_service_settings.rb'
require 'ms_rest_azure/polling_state.rb'
require 'ms_rest_azure/sub_resource.rb'
require 'ms_rest_azure/resource.rb'

Просмотреть файл

@ -41,8 +41,8 @@ module MsRestAzure
# Creates and initialize new instance of the MSITokenProvider class.
# @param tenant_id [String] tenant id (also known as domain).
# @param port [Integer] port number where MSI service is running.
# @param settings [MSIActiveDirectoryServiceSettings] MSI active directory setting.
def initialize(tenant_id, port = 50342, settings = MSIActiveDirectoryServiceSettings.get_azure_settings)
# @param settings [ActiveDirectoryServiceSettings] active directory setting.
def initialize(tenant_id, port = 50342, settings = ActiveDirectoryServiceSettings.get_azure_settings)
fail ArgumentError, 'Tenant id cannot be nil' if tenant_id.nil?
fail ArgumentError, 'Port cannot be nil' if port.nil?
fail ArgumentError, 'Port must be an Integer' unless port.is_a? Integer

Просмотреть файл

@ -1,25 +0,0 @@
# encoding: utf-8
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
module MsRestAzure
#
# Class which represents an settings for MSI Azure AD authentication.
#
class MSIActiveDirectoryServiceSettings < ActiveDirectoryServiceSettings
private
#
# Returns a set of properties required to login into Azure Cloud via MSI.
#
# @param azure_environment [AzureEnvironment] An instance of AzureEnvironment.
# @return [MSIActiveDirectoryServiceSettings] settings required for authentication.
def self.get_settings(azure_environment = MsRestAzure::AzureEnvironments::Azure)
settings = ActiveDirectoryServiceSettings.new
settings.authentication_endpoint = azure_environment.active_directory_endpoint_url
settings.token_audience = azure_environment.resource_manager_endpoint_url
settings
end
end
end

Просмотреть файл

@ -1,42 +0,0 @@
# encoding: utf-8
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
require 'rspec'
require 'ms_rest_azure'
module MsRestAzure
describe 'MSI Active Directory Service Settings' do
it 'should initialize with Azure Cloud properties' do
msi_msi_aad_settings = MSIActiveDirectoryServiceSettings.get_azure_settings
expect(msi_msi_aad_settings).to be_a(ActiveDirectoryServiceSettings)
expect(msi_msi_aad_settings.authentication_endpoint).to eq(MsRestAzure::AzureEnvironments::AzureCloud.active_directory_endpoint_url)
expect(msi_msi_aad_settings.token_audience).to eq(MsRestAzure::AzureEnvironments::AzureCloud.resource_manager_endpoint_url)
end
it 'should initialize with Azure China Cloud properties' do
msi_aad_settings = MSIActiveDirectoryServiceSettings.get_azure_china_settings
expect(msi_aad_settings).to be_a(ActiveDirectoryServiceSettings)
expect(msi_aad_settings.authentication_endpoint).to eq(MsRestAzure::AzureEnvironments::AzureChinaCloud.active_directory_endpoint_url)
expect(msi_aad_settings.token_audience).to eq(MsRestAzure::AzureEnvironments::AzureChinaCloud.resource_manager_endpoint_url)
end
it 'should initialize with Azure US Government Cloud properties' do
msi_aad_settings = MSIActiveDirectoryServiceSettings.get_azure_us_government_settings
expect(msi_aad_settings).to be_a(ActiveDirectoryServiceSettings)
expect(msi_aad_settings.authentication_endpoint).to eq(MsRestAzure::AzureEnvironments::AzureUSGovernment.active_directory_endpoint_url)
expect(msi_aad_settings.token_audience).to eq(MsRestAzure::AzureEnvironments::AzureUSGovernment.resource_manager_endpoint_url)
end
it 'should initialize with Azure German Cloud properties' do
msi_aad_settings = MSIActiveDirectoryServiceSettings.get_azure_german_settings
expect(msi_aad_settings).to be_a(ActiveDirectoryServiceSettings)
expect(msi_aad_settings.authentication_endpoint).to eq(MsRestAzure::AzureEnvironments::AzureGermanCloud.active_directory_endpoint_url)
expect(msi_aad_settings.token_audience).to eq(MsRestAzure::AzureEnvironments::AzureGermanCloud.resource_manager_endpoint_url)
end
end
end

Просмотреть файл

@ -24,13 +24,13 @@ module MsRestAzure
expect(token_provider.send(:port)).to eq(50342)
settings = token_provider.send(:settings)
expect(settings.authentication_endpoint).to eq(azure_cloud.active_directory_endpoint_url)
expect(settings.token_audience).to eq(azure_cloud.resource_manager_endpoint_url)
expect(settings.token_audience).to eq(azure_cloud.active_directory_resource_id)
end
it 'should set customs for managed service identity' do
tenant = 'xxxx-xxxx-xxxxx-xxxxx'
port = 50333
settings = MSIActiveDirectoryServiceSettings.new()
settings = ActiveDirectoryServiceSettings.new()
settings.authentication_endpoint = 'https://login.microsoftonline.com/'
settings.token_audience = 'https://vault.azure.net'