Class: Mnenv::Snap::Fetcher
Overview
Fetches Snap versions from Snapcraft API and merges with historical YAML data. The YAML file (data/snap/versions.yaml) is the single source of truth. Fetcher loads existing YAML, merges with API data, saves back to YAML. Snap cannot support “revamp” as it would lose historical data.
Constant Summary
collapse
- SNAP_NAME =
'metanorma'
- SNAP_ID =
'QkvhpBkFKaDwHMR2LTS3S9Bm0Ek6io11'
- METADATA_API_URL =
'https://api.snapcraft.io/api/v1/snaps/metadata'
- CHANNELS =
%w[stable candidate beta edge].freeze
- ARCHITECTURES =
%w[amd64 arm64].freeze
Instance Attribute Summary
Attributes inherited from Fetcher
#repository
Instance Method Summary
collapse
Methods inherited from Fetcher
#fetch_and_save, #initialize
Constructor Details
This class inherits a constructor from Mnenv::Fetcher
Instance Method Details
#fetch_all ⇒ Object
29
30
31
|
# File 'lib/mnenv/snap/fetcher.rb', line 29
def fetch_all
fetch_all_from_snapcraft
end
|
#fetch_all_from_cache ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/mnenv/snap/fetcher.rb', line 33
def fetch_all_from_cache
version_map = repository.all
current_versions = fetch_current_heads
current_versions.each_key do |k|
next if repository.exists?(k)
version_map << SnapVersion.new(
version: k,
parsed_at: DateTime.now,
channels: current_versions[k].map do |cv|
SnapChannel.new(
name: cv.fetch('channel'),
revision: cv.fetch('revision'),
arch: cv.fetch('arch')
)
end
)
end
version_map
end
|
#fetch_all_from_snapcraft ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/mnenv/snap/fetcher.rb', line 60
def fetch_all_from_snapcraft
raise MissingCredentialsError unless ENV['SNAPCRAFT_STORE_CREDENTIALS']
raise SnapcraftNotAvailableError unless snapcraft_available?
login_result = system('echo "$SNAPCRAFT_STORE_CREDENTIALS" | snapcraft login --with -')
raise LoginFailedError unless login_result
ENV.delete('SNAPCRAFT_STORE_CREDENTIALS')
result = `snapcraft revisions metanorma`
snap_revisions = parse_snap_revisions(result)
build_snap_version_map(snap_revisions)
end
|