Top Level Namespace
Defined Under Namespace
Modules: ZotPlus
Constant Summary collapse
- ID =
Nokogiri::XML(File.open('install.rdf')).at('//em:id').inner_text
- EXTENSION =
ID.gsub(/@.*/, '')
- RELEASE =
Nokogiri::XML(File.open('install.rdf')).at('//em:version').inner_text + DEBUGBUILD
- XPI =
"zotero-#{EXTENSION}-#{RELEASE}.xpi"- NODEBIN =
"node_modules/.bin"
Instance Method Summary collapse
Instance Method Details
#sign ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 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 |
# File 'lib/zotplus-rakehelper.rb', line 107 def sign token = lambda { payload = { jti: SecureRandom.base64, iss: ENV['MOZJWTissuer'], iat: Time.now.utc.to_i, exp: Time.now.utc.to_i + 60, } return JWT.encode(payload, ENV['MOZJWTsecret'], 'HS256') } duration = lambda{|secs| secs = secs.to_i mins = secs / 60 hours = mins / 60 days = hours / 24 if days > 0 "#{days} days and #{hours % 24} hours" elsif hours > 0 "#{hours} hours and #{mins % 60} minutes" elsif mins > 0 "#{mins} minutes and #{secs % 60} seconds" elsif secs >= 0 "#{secs} seconds" end } url = "https://addons.mozilla.org/api/v3/addons/#{ID}/versions/#{RELEASE}/" wait = nil begin puts "Submit #{XPI} to #{url} for signing" RestClient.put(url, {upload: File.new(XPI)}, { 'Authorization' => "JWT #{token.call}", 'Content-Type' => 'multipart/form-data' }) wait = Time.now.to_i sleep 10 rescue RestClient::Conflict puts "#{XPI} already signed" wait = Time.now.to_i end status = {} (1..100).each{|attempt| status = JSON.parse(RestClient.get(url, { 'Authorization' => "JWT #{token.call}"} ).to_s) files = (status['files'] || []).length signed = (files > 0 ? status['files'][0]['signed'] : false) puts "attempt #{attempt} after #{duration.call(Time.now.to_i - wait)}, #{files} files, signed: #{signed}" break if signed sleep 5 } raise "Unexpected response: #{status['files'].inspect}" if !status['files'] || status['files'].length != 1 || !status['files'][0]['download_url'] raise "Not signed: #{status['files'][0].inspect}" unless status['files'][0]['signed'] puts "\ngetting signed XPI from #{status['files'][0]['download_url']}" File.open(XPI, 'wb'){|f| f.write(RestClient.get(status['files'][0]['download_url'], { 'Authorization' => "JWT #{token.call}"} ).body) } end |