class Dpl::Providers::Bintray
Constants
- MAP
- PATHS
Public Instance Methods
Source
# File lib/dpl/providers/bintray.rb, line 230 def append_params(path, params) [path, *Array(params).map { |pair| pair.join('=') }].join(';') end
Source
# File lib/dpl/providers/bintray.rb, line 305 def compact(hash) hash.reject { |_, value| value.nil? } end
Source
# File lib/dpl/providers/bintray.rb, line 86 def create_package info :create_package post(path(:packages), compact(only(package, *MAP[:package]))) return unless package_attrs info :package_attrs post(path(:package_attrs), package_attrs) end
Source
# File lib/dpl/providers/bintray.rb, line 99 def create_version info :create_version post(path(:versions), compact(only(version, *MAP[:version]))) return unless version_attrs info :version_attrs post(path(:version_attrs), version_attrs) end
Source
# File lib/dpl/providers/bintray.rb, line 74 def deploy create_package unless package_exists? create_version unless version_exists? upload_files sign_version if sign_version? publish_version && update_files if publish_version? end
Source
# File lib/dpl/providers/bintray.rb, line 244 def descriptor @descriptor ||= symbolize(JSON.parse(File.read(file))) rescue StandardError error :invalid_file end
Source
# File lib/dpl/providers/bintray.rb, line 175 def excluded?(path, pattern) !pattern.to_s.empty? && path.match(/#{pattern}/) end
Source
# File lib/dpl/providers/bintray.rb, line 188 def exists?(type) case code = head(path(type), raise: false, silent: true) when 200, 201 then true when 404 then false else error :unexpected_code, code, type end end
Source
# File lib/dpl/providers/bintray.rb, line 152 def files return {} unless files = descriptor[:files] return @files if @files keys = %i[path includePattern excludePattern uploadPattern matrixParams listInDownloads] files = files.map { |file| file if file[:path] = path_for(file[:includePattern]) } @files = files.compact.map { |file| find(*file.values_at(*keys)) }.flatten end
Source
# File lib/dpl/providers/bintray.rb, line 161 def find(path, includes, excludes, uploads, params, download) paths = Find.find(path).select { |path| File.file?(path) } paths = paths.reject { |path| excluded?(path, excludes) } paths = paths.map { |path| [path, path.match(/#{includes}/)] } paths = paths.select(&:last) paths.map { |path, match| Upload.new(path, fmt(uploads, match.captures), params, download) } end
Source
# File lib/dpl/providers/bintray.rb, line 169 def fmt(pattern, captures) captures.each.with_index.inject(pattern) do |pattern, (capture, ix)| pattern.gsub("$#{ix + 1}", capture) end end
Source
# File lib/dpl/providers/bintray.rb, line 234 def handle(req, res, opts = { raise: true }) error :request_failed, req.method, req.uri, res.code if opts[:raise] && !success?(res.code) info :request_success, res.code, res.message, parse(res)['message'] unless opts[:silent] res.code.to_i end
Source
# File lib/dpl/providers/bintray.rb, line 196 def head(path, opts = {}) req = Net::HTTP::Head.new(path) req.basic_auth(user, key) request(req, opts) end
Source
# File lib/dpl/providers/bintray.rb, line 224 def http http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http end
Source
# File lib/dpl/providers/bintray.rb, line 309 def only(hash, *keys) hash.select { |key, _| keys.include?(key) } end
Source
# File lib/dpl/providers/bintray.rb, line 254 def package descriptor[:package] end
Source
# File lib/dpl/providers/bintray.rb, line 262 def package_attrs package[:attributes] end
Source
# File lib/dpl/providers/bintray.rb, line 82 def package_exists? exists?(:package) end
Source
# File lib/dpl/providers/bintray.rb, line 258 def package_name package[:name] end
Source
# File lib/dpl/providers/bintray.rb, line 298 def parse(json) hash = JSON.parse(json) hash.is_a?(Hash) ? hash : {} rescue StandardError {} end
Source
# File lib/dpl/providers/bintray.rb, line 294 def path(resource, args = {}) interpolate(PATHS[resource], args, secure: true) end
Source
# File lib/dpl/providers/bintray.rb, line 179 def path_for(str) ix = str.index('(') path = ix.to_i.zero? ? str : str[0, ix] return path if File.exist?(path) warn(:missing_path, path: path) nil end
Source
# File lib/dpl/providers/bintray.rb, line 202 def post(path, body = nil) req = Net::HTTP::Post.new(path) req.add_field('Content-Type', 'application/json') req.basic_auth(user, key) req.body = JSON.dump(body) if body request(req) end
Source
# File lib/dpl/providers/bintray.rb, line 121 def publish_version info :publish_version post(path(:version_publish)) end
Source
# File lib/dpl/providers/bintray.rb, line 290 def publish_version? descriptor[:publish] end
Source
# File lib/dpl/providers/bintray.rb, line 210 def put(path, body, params = {}, headers = {}) req = Net::HTTP::Put.new(append_params(path, params)) headers.each { |key, value| req.add_field(key.to_s, value) } req.basic_auth(user, key) req.body = body request(req) end
Source
# File lib/dpl/providers/bintray.rb, line 218 def request(req, opts = {}) res = http.request(req) handle(req, res, opts) res.code.to_i end
Source
# File lib/dpl/providers/bintray.rb, line 141 def retrying(opts) 1.upto(opts[:max]) do |count| code = yield return if code < 400 info :retrying, opts.merge(count: count, code: code) sleep opts[:pause] end error :giveup_retries end
Source
# File lib/dpl/providers/bintray.rb, line 115 def sign_version body = compact(passphrase: passphrase) info :sign_version, (passphrase? ? 'with' : 'without') post(path(:version_sign), body) end
Source
# File lib/dpl/providers/bintray.rb, line 286 def sign_version? version[:gpgSign] end
Source
# File lib/dpl/providers/bintray.rb, line 240 def success?(code) code.to_s[0].to_i == 2 end
Source
# File lib/dpl/providers/bintray.rb, line 133 def update_file(file) retrying(max: 10, pause: 5) do body = { list_in_downloads: file.download }.to_json headers = { 'Content-Type': 'application/json' } put(path(:file_metadata, target: file.target), body, {}, headers) end end
Source
# File lib/dpl/providers/bintray.rb, line 126 def update_files files.select(&:download).each do |file| info :list_download, path: file.target update_file(file) end end
Source
# File lib/dpl/providers/bintray.rb, line 108 def upload_files files.each do |file| info :upload_file, source: file.source, target: file.target put(path(:version_file, target: file.target), file.read, file.params) end end
Source
# File lib/dpl/providers/bintray.rb, line 250 def url @url ||= URI.parse(super || URL) end
Calls superclass method
Source
# File lib/dpl/providers/bintray.rb, line 69 def validate error :missing_file unless File.exist?(file) # validate that the repo exists, and we have access end
Source
# File lib/dpl/providers/bintray.rb, line 274 def version descriptor[:version] end
Source
# File lib/dpl/providers/bintray.rb, line 282 def version_attrs version[:attributes] end
Source
# File lib/dpl/providers/bintray.rb, line 95 def version_exists? exists?(:version) end
Source
# File lib/dpl/providers/bintray.rb, line 278 def version_name version[:name] end