Class: Katello::DockerMetaTag
- Includes:
- ScopedSearchExtensions
- Defined in:
- app/models/katello/docker_meta_tag.rb
Class Method Summary collapse
- .cleanup_tags ⇒ Object
- .delegate_to_tags(*names) ⇒ Object
- .find_by_digest(_key, operator, value) ⇒ Object
- .find_by_schema_version(_key, operator, value) ⇒ Object
- .get_tag_table_values(repo) ⇒ Object
- .import_meta_tags(repositories) ⇒ Object
- .in_repositories(repos, grouped = false) ⇒ Object
- .meta_tags_by_digest_query(operator, digest, manifest_klass) ⇒ Object
- .repository_association_class ⇒ Object
- .search_by_repo_name(_key, operator, value) ⇒ Object
- .search_in_tags(tags, grouped = false) ⇒ Object
- .with_identifiers(ids) ⇒ Object
- .with_pulp_id(ids) ⇒ Object
Instance Method Summary collapse
Methods inherited from Model
Class Method Details
.cleanup_tags ⇒ Object
132 133 134 |
# File 'app/models/katello/docker_meta_tag.rb', line 132 def self. self.where("id not in (?) OR (schema2_id IS NULL AND schema1_id IS NULL)", Katello::RepositoryDockerMetaTag.pluck(:docker_meta_tag_id) + [0]).delete_all end |
.delegate_to_tags(*names) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/models/katello/docker_meta_tag.rb', line 76 def self.(*names) names.each do |name| define_method(name) do if schema2 schema2.send(name) else schema1.send(name) end end end end |
.find_by_digest(_key, operator, value) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'app/models/katello/docker_meta_tag.rb', line 47 def self.find_by_digest(_key, operator, value) if operator == '=' conditions = (operator, value, DockerManifest) + " OR " + (operator, value, DockerManifestList) else #failure condition. No such value so must return 0 conditions = "1=0" end { :conditions => conditions } end |
.find_by_schema_version(_key, operator, value) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/models/katello/docker_meta_tag.rb', line 57 def self.find_by_schema_version(_key, operator, value) conditions = "" if operator == '=' if ["1", "2"].include?(value) column = if value == "1" "schema1_id" else "schema2_id" end = ::Katello::DockerMetaTag.arel_table conditions = [column].not_eq(nil).to_sql else #failure condition. No such value so must return 0 conditions = "1=0" end end { :conditions => conditions } end |
.get_tag_table_values(repo) ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'app/models/katello/docker_meta_tag.rb', line 169 def self.get_tag_table_values(repo) # queries DockerTags for a repo and retuns a [schema1, schema2 , name] tuple combination = ::Katello::DockerTag.where(:id => RepositoryDockerTag. where(:repository_id => repo.id). select(:docker_tag_id)) dups = .group_by(&:name) dups.map do |name, values| if values.first.docker_manifest.schema_version == 1 schema1, schema2 = values else schema2, schema1 = values end [schema1.try(:id), schema2.try(:id), name] end end |
.import_meta_tags(repositories) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'app/models/katello/docker_meta_tag.rb', line 136 def self.(repositories) repositories.each do |repo| tag_table_values = get_tag_table_values(repo) = DockerMetaTag.where(:id => repository_association_class.where(:repository_id => repo.id).select(:docker_meta_tag_id)). select(:schema1_id, :schema2_id, :name).map do || [.schema1_id, .schema2_id, .name] end # Delete [meta_tag_table_values - tag_table_values], insert [tag_table_values - meta_tag_table_values] = ::Katello::DockerMetaTag.arel_table params_to_query_for_delete = ( - tag_table_values).map do |schema1, schema2, name| conditional = [:schema1_id].eq(schema1).and( [:schema2_id].eq(schema2)).and( [:name].eq(name)).to_sql "(#{conditional})" end unless params_to_query_for_delete.empty? RepositoryDockerMetaTag.where(:repository_id => repo.id).where(:docker_meta_tag => DockerMetaTag.where(params_to_query_for_delete.join(" OR "))).delete_all end = [] (tag_table_values - ).each do |schema1, schema2, name| << DockerMetaTag.where(:schema1_id => schema1, :schema2_id => schema2, :name => name).first_or_create end repo. += end end |
.in_repositories(repos, grouped = false) ⇒ Object
96 97 98 99 100 101 102 |
# File 'app/models/katello/docker_meta_tag.rb', line 96 def self.in_repositories(repos, grouped = false) if grouped (DockerTag.in_repositories(repos), grouped) else (DockerTag.in_repositories(repos)).where(:id => repository_association_class.where(:repository_id => repos).select(:docker_meta_tag_id)) end end |
.meta_tags_by_digest_query(operator, digest, manifest_klass) ⇒ Object
40 41 42 43 44 45 |
# File 'app/models/katello/docker_meta_tag.rb', line 40 def self.(operator, digest, manifest_klass) search = "digest #{operator} ?" query = DockerMetaTag.(DockerTag.where(:docker_taggable_type => manifest_klass.name, :docker_taggable_id => manifest_klass.where(search, digest))).select(:id).to_sql "#{DockerMetaTag.table_name}.id in (#{query})" end |
.repository_association_class ⇒ Object
26 27 28 |
# File 'app/models/katello/docker_meta_tag.rb', line 26 def self.repository_association_class RepositoryDockerMetaTag end |
.search_by_repo_name(_key, operator, value) ⇒ Object
34 35 36 37 38 |
# File 'app/models/katello/docker_meta_tag.rb', line 34 def self.search_by_repo_name(_key, operator, value) conditions = sanitize_sql_for_conditions(["#{Katello::RootRepository.table_name}.name #{operator} ?", value_to_sql(operator, value)]) query = self.joins(:repositories => :root).where(conditions).select('id') {:conditions => "#{self.table_name}.id IN (#{query.to_sql})"} end |
.search_in_tags(tags, grouped = false) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/models/katello/docker_meta_tag.rb', line 104 def self.(, grouped = false) sql = .select("#{::Katello::DockerTag.table_name}.id").to_sql if grouped grouped_fields = "#{table_name}.name, katello_repositories.root_id" ids = distinct.select("ON (#{grouped_fields}) #{table_name}.id").joins(:repositories) self.where(:id => ids) else self.where("#{self.table_name}.schema1_id in (#{sql}) or #{self.table_name}.schema2_id in (#{sql})") end end |
.with_identifiers(ids) ⇒ Object
128 129 130 |
# File 'app/models/katello/docker_meta_tag.rb', line 128 def self.with_identifiers(ids) self.where(:id => ids) end |
.with_pulp_id(ids) ⇒ Object
124 125 126 |
# File 'app/models/katello/docker_meta_tag.rb', line 124 def self.with_pulp_id(ids) self.with_identifiers(ids) end |
Instance Method Details
#related_tags ⇒ Object
91 92 93 94 |
# File 'app/models/katello/docker_meta_tag.rb', line 91 def self.class.where(:id => ::Katello::RepositoryDockerMetaTag.where(:repository_id => repositories.first.group). select(:docker_meta_tag_id), :name => name) end |
#repository ⇒ Object
30 31 32 |
# File 'app/models/katello/docker_meta_tag.rb', line 30 def repository repositories.first end |
#schema1_manifest ⇒ Object
116 117 118 |
# File 'app/models/katello/docker_meta_tag.rb', line 116 def schema1_manifest schema1.try(:docker_taggable) end |
#schema2_manifest ⇒ Object
120 121 122 |
# File 'app/models/katello/docker_meta_tag.rb', line 120 def schema2_manifest schema2.try(:docker_taggable) end |