Skip to content

Commit fc5997e

Browse files
committed
Add a fw-all endpoint
1 parent 02eafff commit fc5997e

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# rebble-cohorts
2-
cohorts.rebble.io: The Rebble cohorts API
2+
cohorts.rebble.io: The Rebble cohorts API. It handles firmware delivery.
3+
4+
For archival, use `/cohort?select=fw-all`, which returns a list of all stored firmware.
35

46
## Configuration
57

cohorts/api.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ def _latest_firmware(hardware, kind):
3333
)
3434

3535

36+
def _all_firmware():
37+
return Firmware.query.order_by(Firmware.kind, Firmware.timestamp.desc()).all()
38+
39+
3640
FW_BEELINE_FIELDS = {
3741
"mobilePlatform": "user.mobile_platform",
3842
"mobileVersion": "user.mobile_version",
@@ -67,6 +71,12 @@ def generate_fw():
6771
return response
6872

6973

74+
def generate_fw_all():
75+
_add_fw_beeline_context()
76+
response = [row.to_json(archival=True) for row in _all_firmware()]
77+
return response
78+
79+
7080
generators = {
7181
"pipeline-api": lambda: {"host": "pipeline-api.rebble.io"},
7282
"linked-services": lambda: {"enabled_providers": []},
@@ -75,6 +85,7 @@ def generate_fw():
7585
"version": 11,
7686
},
7787
"fw": generate_fw,
88+
"fw-all": generate_fw_all,
7889
}
7990

8091

cohorts/models.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@ class Firmware(db.Model):
1616
timestamp = db.Column(db.Integer, nullable=False)
1717
notes = db.Column(db.Text, nullable=True)
1818

19-
def to_json(self):
20-
return {
19+
def to_json(self, archival: bool = False):
20+
result = {
2121
"url": self.url,
2222
"sha-256": self.sha256,
2323
"friendlyVersion": self.version,
2424
"timestamp": self.timestamp,
2525
"notes": self.notes if self.notes else self.version,
2626
}
27+
if archival:
28+
result["kind"] = self.kind
29+
result["hardware"] = self.hardware
30+
return result
2731

2832

2933
db.Index(

0 commit comments

Comments
 (0)