class MU::Cloud::Azure::Id
Stub class to represent Azure's resource identifiers, which look like: /subscriptions/3d20ddd8-4652-4074-adda-0d127ef1f0e0/resourceGroups/mu/providers/Microsoft.Network/virtualNetworks/mu-vnet Various API calls need chunks of this in different contexts, and this full string is necessary to guarantee that a cloud_id
is a unique identifier for a given resource. So we'll use this object of our own devising to represent it.
Attributes
name[R]
provider[R]
raw[R]
resource_group[R]
subscription[R]
type[R]
Public Class Methods
idattr()
click to toggle source
new(*args)
click to toggle source
# File modules/mu/providers/azure.rb, line 111 def initialize(*args) if args.first.is_a?(String) @raw = args.first _junk, _junk2, @subscription, _junk3, @resource_group, _junk4, @provider, @resource_type, @name = @raw.split(/\//) if @subscription.nil? or @resource_group.nil? or @provider.nil? or @resource_type.nil? or @name.nil? # Not everything has a resource group if @raw.match(/^\/subscriptions\/#{Regexp.quote(@subscription)}\/providers/) _junk, _junk2, @subscription, _junk3, @provider, @resource_type, @name = @raw.split(/\//) if @subscription.nil? or @provider.nil? or @resource_type.nil? or @name.nil? raise MuError, "Failed to parse Azure resource id string #{@raw} (got subscription: #{@subscription}, provider: #{@provider}, resource_type: #{@resource_type}, name: #{@name}" end else raise MuError, "Failed to parse Azure resource id string #{@raw} (got subscription: #{@subscription}, resource_group: #{@resource_group}, provider: #{@provider}, resource_type: #{@resource_type}, name: #{@name}" end end else args.each { |arg| if arg.is_a?(Hash) arg.each_pair { |k, v| self.instance_variable_set(("@"+k.to_s).to_sym, v) } end } if @resource_group.nil? or @name.nil? raise MuError, "Failed to extract at least name and resource_group fields from #{args.flatten.join(", ").to_s}" end end end
Public Instance Methods
to_s()
click to toggle source
Return a reasonable string representation of this {MU::Cloud::Azure::Id}
# File modules/mu/providers/azure.rb, line 143 def to_s @name end