class AwsEksCluster

def fetch_from_api # rubocop:disable Metrics/AbcSize

rubocop:disable Metrics/AbcSize
def fetch_from_api # rubocop:disable Metrics/AbcSize
  backend = BackendFactory.create(inspec_runner)
  begin
    params = { name: cluster_name }
    resp = backend.describe_cluster(params)
  rescue Aws::EKS::Errors::ResourceNotFoundException
    @exists = false
    populate_as_missing
    return
  end
  @exists = true
  cluster = resp.to_h[:cluster]
  @version = cluster[:version]
  @name = cluster[:name]
  @arn = cluster[:arn]
  @certificate_authority = cluster[:certificate_authority][:data]
  @created_at = cluster[:created_at]
  @endpoint = cluster[:endpoint]
  @security_group_ids = cluster[:resources_vpc_config][:security_group_ids]
  @subnet_ids = cluster[:resources_vpc_config][:subnet_ids]
  @subnets_count = cluster[:resources_vpc_config][:subnet_ids].length
  @security_groups_count = cluster[:resources_vpc_config][:security_group_ids].length
  @vpc_id = cluster[:resources_vpc_config][:vpc_id]
  @role_arn = cluster[:role_arn]
  @status = cluster[:status]
  @active = cluster[:status] == "ACTIVE"
  @failed = cluster[:status] == "FAILED"
  @creating = cluster[:status] == "CREATING"
  @deleting = cluster[:status] == "DELETING"
end

def populate_as_missing

def populate_as_missing
  @version = nil
  @name = cluster_name # name is an alias for cluster_name, and it is retained on a miss
  @arn = nil
  @certificate_authority = nil
  @created_at = nil
  @endpoint = nil
  @security_group_ids = []
  @subnet_ids = []
  @subnets_count = nil
  @security_groups_count = nil
  @vpc_id = nil
  @role_arn = nil
  @status = nil
end

def to_s

def to_s
  "AWS EKS cluster #{cluster_name}"
end

def validate_params(raw_params)

def validate_params(raw_params)
  validated_params = check_resource_param_names(
    raw_params: raw_params,
    allowed_params: [:cluster_name],
    allowed_scalar_name: :cluster_name,
    allowed_scalar_type: String
  )
  if validated_params.empty?
    raise ArgumentError, "You must provide a cluster_name to aws_eks_cluster."
  end
  validated_params
end