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 (48 lines) | stat: -rw-r--r-- 1,621 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
39
40
41
42
43
44
45
46
47
48
# 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_resources'
require 'azure_mgmt_storage'
require 'ms_rest_azure'

include MsRest
include MsRestAzure
include Azure::ARM::Resources
include Azure::ARM::Storage

class ResourceHelper
  attr_accessor :storage_client
  attr_accessor :resource_client

  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']

    token_provider = ApplicationTokenProvider.new(tenant_id, client_id, secret)
    credentials = TokenCredentials.new(token_provider)

    @storage_client = StorageManagementClient.new(credentials)
    @storage_client.long_running_operation_retry_timeout = ENV['RETRY_TIMEOUT'].to_i || 30
    @storage_client.subscription_id = subscription_id

    @resource_client = ResourceManagementClient.new(credentials)
    @resource_client.subscription_id = subscription_id
    @resource_client.long_running_operation_retry_timeout = ENV['RETRY_TIMEOUT'].to_i || 30
  end

  def create_resource_group
    resource_group_name = 'RubySDKTest_azure_mgmt_storage'
    params = Azure::ARM::Resources::Models::ResourceGroup.new
    params.location = 'westus'

    @resource_client.resource_groups.create_or_update(resource_group_name, params)
  end

  def delete_resource_group(name)
    @resource_client.resource_groups.delete(name)
  end
end