Module: Everywhere::Config::Updates

Included in:
Everywhere::Config
Defined in:
lib/everywhere/config/updates.rb

Constant Summary collapse

UPDATES_LOOPBACK =

A dev machine serving a feed to itself is the one case http is fine.

/\A(localhost|127(\.\d+){3}|::1)\z/

Instance Method Summary collapse

Instance Method Details

#updatesObject

The updates: section — self-hosted auto-updates. Two halves: a client half (url/channel/public_key/auto/interval) that ships to the shell, and a publish-side s3: half that NEVER leaves the dev machine. channel here is a release channel (stable/beta) — not the receipt's distribution_channel (direct vs app stores).



11
# File 'lib/everywhere/config/updates.rb', line 11

def updates = @data.fetch("updates", nil) || {}

#updates_autoObject

off — never check; check — check + notify (default); download — also fetch/verify in the background; install — silent auto-update.



23
# File 'lib/everywhere/config/updates.rb', line 23

def updates_auto = updates["auto"] || "check"

#updates_channelObject



15
# File 'lib/everywhere/config/updates.rb', line 15

def updates_channel = updates["channel"] || "stable"

#updates_errorsObject

An http updates.url is not a smaller version of a working updater: the shell refuses to fetch it and silently stops checking, so the app ships looking fine and never updates again. Say so at build/publish time.



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/everywhere/config/updates.rb', line 33

def updates_errors
  url = updates_url.to_s
  return [] if url.empty?

  require "uri"
  uri = URI.parse(url)
  return [] if uri.scheme == "https"
  return [] if uri.scheme == "http" && uri.host.to_s.delete("[]").match?(UPDATES_LOOPBACK)

  ["updates.url #{url.inspect} must be https — the shell disables the updater otherwise"]
rescue URI::Error => e
  ["updates.url #{url.inspect} is not a URL (#{e.message})"]
end

#updates_intervalObject



25
# File 'lib/everywhere/config/updates.rb', line 25

def updates_interval = [(updates["interval"] || 21_600).to_i, 300].max

#updates_public_keyObject



19
# File 'lib/everywhere/config/updates.rb', line 19

def updates_public_key = updates["public_key"]

#updates_s3Object



13
# File 'lib/everywhere/config/updates.rb', line 13

def updates_s3 = updates.fetch("s3", nil) || {}

#updates_shell_hashObject

The client subset for the shell; nil (and thus absent from everywhere.json) until both url and public_key are configured — an unsigned update feed is not a thing.



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/everywhere/config/updates.rb', line 50

def updates_shell_hash
  return nil unless updates_url && updates_public_key

  {
    "url" => updates_url,
    "channel" => updates_channel,
    "public_key" => updates_public_key,
    "auto" => updates_auto,
    "interval" => updates_interval
  }
end

#updates_urlObject



17
# File 'lib/everywhere/config/updates.rb', line 17

def updates_url = updates["url"]&.chomp("/")