Skip to content

Commit

Permalink
Fix RuboCop issues in AzureSdkAdapter
Browse files Browse the repository at this point in the history
  • Loading branch information
ekohl authored and evgeni committed Dec 11, 2024
1 parent e7f3b3d commit a44b2c9
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions app/lib/foreman_azure_rm/azure_sdk_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(tenant, app_ident, secret_key, sub_id, azure_environment)
end

def resource_client
#resource_manager_endpoint_url
# resource_manager_endpoint_url
@resource_client ||= Resources::Client.new(azure_credentials(@environment_settings.resource_manager_endpoint_url))
end

Expand All @@ -33,11 +33,12 @@ def subscription_client

def azure_credentials(base_url)
provider = MsRestAzure::ApplicationTokenProvider.new(
@tenant,
@app_ident,
@secret_key,
@ad_settings)

@tenant,
@app_ident,
@secret_key,
@ad_settings
)

credentials = MsRest::TokenCredentials.new(provider)

{
Expand All @@ -46,7 +47,7 @@ def azure_credentials(base_url)
client_id: @app_ident,
client_secret: @secret_key,
subscription_id: @sub_id,
base_url: base_url
base_url: base_url,
}
end

Expand Down Expand Up @@ -91,7 +92,7 @@ def list_resources(filter)
end

def rgs
rgs = resource_client.resource_groups.list
rgs = resource_client.resource_groups.list
rgs.map(&:name)
end

Expand All @@ -107,7 +108,7 @@ def public_ip(rg_name, pip_name)
network_client.public_ipaddresses.get(rg_name, pip_name)
end

def vm_nic(rg_name,nic_name)
def vm_nic(rg_name, nic_name)
network_client.network_interfaces.get(rg_name, nic_name)
end

Expand All @@ -120,14 +121,15 @@ def get_vm_extension(rg_name, vm_name, vm_extension_name)
end

def list_vm_sizes(region)
return [] unless region.present?
return [] if region.blank?

stripped_region = region.gsub(/\s+/, '').downcase
compute_client.virtual_machine_sizes.list(stripped_region).value()
compute_client.virtual_machine_sizes.list(stripped_region).value
end

def list_vms(region)
# List all VMs in a resource group
virtual_machines = compute_client.virtual_machines.list_by_location(region)
compute_client.virtual_machines.list_by_location(region)
end

def get_vm(rg_name, vm_name)
Expand Down Expand Up @@ -166,7 +168,7 @@ def list_gallery_image_versions(rg_name, gallery_name, gallery_image_name)
compute_client.gallery_image_versions.list_by_gallery_image(rg_name, gallery_name, gallery_image_name)
end

def get_storage_accts
def get_storage_accts # rubocop:disable Naming/AccessorMethodName
result = storage_client.storage_accounts.list
result.value
end
Expand All @@ -177,9 +179,9 @@ def create_or_update_vm(rg_name, vm_name, parameters)

def create_or_update_vm_extensions(rg_name, vm_name, vm_extension_name, extension_params)
compute_client.virtual_machine_extensions.create_or_update(rg_name,
vm_name,
vm_extension_name,
extension_params)
vm_name,
vm_extension_name,
extension_params)
end

def create_or_update_pip(rg_name, pip_name, parameters)
Expand Down Expand Up @@ -207,17 +209,15 @@ def delete_disk(rg_name, disk_name)
end

def check_vm_status(rg_name, vm_name)
virtual_machine = compute_client.virtual_machines.get(rg_name, vm_name, expand:'instanceView')
virtual_machine = compute_client.virtual_machines.get(rg_name, vm_name, expand: 'instanceView')
get_status(virtual_machine)
end

def get_status(virtual_machine)
vm_statuses = virtual_machine.instance_view.statuses
vm_status = nil
vm_statuses.each do |status|
if status.code.include? 'PowerState'
vm_status = status.code.split('/')[1]
end
vm_status = status.code.split('/')[1] if status.code.include? 'PowerState'
end
vm_status
end
Expand All @@ -238,11 +238,10 @@ def self.gallery_caching(rg_name)

def actual_gallery_image_id(rg_name, image_id)
gallery_names = list_galleries.map(&:name)
gallery_names.each do |gallery|
gallery_image = list_gallery_images(rg_name, gallery).detect { |image| image.name == image_id }
return gallery_image&.id
end
nil
return unless (gallery = gallery_names.first)

gallery_image = list_gallery_images(rg_name, gallery).detect { |image| image.name == image_id }
gallery_image&.id
end

def fetch_gallery_image_id(rg_name, image_id)
Expand Down

0 comments on commit a44b2c9

Please sign in to comment.