File: spec_helper.rb

package info (click to toggle)
ruby-azure-sdk 0.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 22,400 kB
  • ctags: 12,388
  • sloc: ruby: 168,299; sh: 6; makefile: 2
file content (38 lines) | stat: -rw-r--r-- 1,564 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 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 File.join(File.dirname(__FILE__), '../../../vcr_helper')
require 'azure_mgmt_graph'

include Azure::ARM::Graph

class ResourceHelper
  attr_reader :graph_client

  # Please refer to https://msdn.microsoft.com/en-us/library/azure/hh974476.aspx#AppPrereqs for creating and adding
  # new app in Azure Active Directory with correct permissions using your regular Azure subscription
  def initialize
    tenant_id = ENV['AZURE_TENANT_ID']
    client_id = ENV['AZURE_CLIENT_ID']
    secret = ENV['AZURE_CLIENT_SECRET']
    @subscription_id = ENV['AZURE_SUBSCRIPTION_ID']

    # Create ActiveDirectoryServiceSettings for graphs token audience
    settings = MsRestAzure::ActiveDirectoryServiceSettings.new
    settings.authentication_endpoint = MsRestAzure::AzureEnvironments::Azure.active_directory_endpoint_url
    settings.token_audience = MsRestAzure::AzureEnvironments::Azure.active_directory_graph_resource_id

    token_provider = MsRestAzure::ApplicationTokenProvider.new(tenant_id, client_id, secret, settings)
    @credentials = MsRest::TokenCredentials.new(token_provider)
  end

  def graph_client
    if @graph_client.nil?
      @graph_client = GraphRbacManagementClient.new(@credentials)
      @graph_client.long_running_operation_retry_timeout = ENV.fetch('RETRY_TIMEOUT', 30).to_i
      @graph_client.tenant_id = ENV['AZURE_TENANT_ID']
    end
    @graph_client
  end
end