Sha256: bbbb87594d1701218718d5529c4fc12da3d61077f8da6781e88ff634b159fd8f

Contents?: true

Size: 1.71 KB

Versions: 1

Compression:

Stored size: 1.71 KB

Contents

class DockerRegistry < ActiveRecord::Base
  include Authorizable
  include Taxonomix
  include Encryptable

  default_scope do
    with_taxonomy_scope do
      order('docker_registries.name')
    end
  end

  has_many :containers, :foreign_key => "registry_id", :dependent => :destroy
  encrypts :password

  validates_lengths_from_database
  validates :name, :presence => true, :uniqueness => true
  validates :url,  :presence => true, :uniqueness => true,
    :url_schema => ['http', 'https']
  validate :attempt_login

  scoped_search :on => :name, :complete_value => true
  scoped_search :on => :url

  def used_location_ids
    Location.joins(:taxable_taxonomies).where(
      'taxable_taxonomies.taxable_type' => 'DockerRegistry',
      'taxable_taxonomies.taxable_id' => id).pluck("#{Taxonomy.table_name}.id")
  end

  def used_organization_ids
    Organization.joins(:taxable_taxonomies).where(
      'taxable_taxonomies.taxable_type' => 'DockerRegistry',
      'taxable_taxonomies.taxable_id' => id).pluck("#{Taxonomy.table_name}.id")
  end

  def prefixed_url(image_name)
    uri = URI(url)
    "#{uri.hostname}:#{uri.port}/#{image_name}"
  end

  def self.humanize_class_name(_name = nil)
    _("Docker/Registry")
  end

  def api
    @api ||= Service::RegistryApi.new(url: url, user: username,
                                      password: password, verify_ssl: verify_ssl)
  end

  private

  def attempt_login
    api.ok?
  rescue Excon::Error::Certificate
    message = 'Unable to verify certificate.\
              (Disable "Verify ssl" if you still want to use this Docker Registry)'
    errors.add(:base, _(message))
  rescue => error
    errors.add(:base, _('Unable to log in to this Docker Registry - %s') % error)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
foreman_docker-3.2.1 app/models/docker_registry.rb