Sha256: 61393b365409123f0921a17a4cc3f531cb595c58932c11681c57cfb99260d736

Contents?: true

Size: 1.66 KB

Versions: 5

Compression:

Stored size: 1.66 KB

Contents

module Katello
  class ContentViewDockerFilter < ContentViewFilter
    CONTENT_TYPE = 'docker'.freeze

    has_many :docker_rules, :dependent => :destroy, :foreign_key => :content_view_filter_id,
             :class_name => "Katello::ContentViewDockerFilterRule"
    validates_lengths_from_database

    # Returns a set of Pulp/MongoDB conditions to filter out manifests in the
    # repo repository that match parameters
    #
    # @param repo [Repository] a repository containing manifests to filter
    # @return [Array] an array of hashes with MongoDB conditions
    def generate_clauses(repo)
      manifest_tags = []

      self.docker_rules.each do |rule|
        manifest_tags.concat(query_manifests(repo, rule))
      end

      { "_id" => { "$in" => manifest_tags } } unless manifest_tags.empty?
    end

    protected

    def fetch_tag_uuids(repo, rule, manifest_klass = DockerManifest)
      query_name = rule.name.tr("*", "%")
      tags_query = ::Katello::DockerTag.where(:repository => repo).
                                        where(:docker_taggable_type => manifest_klass.name).
                                        where("name ilike ?", query_name).
                                        select(:docker_taggable_id)

      query = manifest_klass.in_repositories(repo).where("id in (#{tags_query.to_sql})")
      names = query.all.collect do |manifest|
        manifest.docker_tags.where(:repository => repo).all.collect do |tag|
          tag.uuid
        end
      end
      names.flatten.uniq
    end

    def query_manifests(repo, rule)
      (fetch_tag_uuids(repo, rule, DockerManifest) + fetch_tag_uuids(repo, rule, DockerManifestList)).flatten.uniq
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
katello-3.7.0.rc1 app/models/katello/content_view_docker_filter.rb
katello-3.6.0 app/models/katello/content_view_docker_filter.rb
katello-3.6.0.1.rc2 app/models/katello/content_view_docker_filter.rb
katello-3.6.0.rc2 app/models/katello/content_view_docker_filter.rb
katello-3.6.0.rc1 app/models/katello/content_view_docker_filter.rb