Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bret Barker
committed
Jun 23, 2016
1 parent
17ea477
commit 25e1cc2
Showing
4 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"_embedded": { | ||
"clickindex:package": [ | ||
{ | ||
"_links": { | ||
"self": { | ||
"href": "http://localhost:5000/api/v1/package/W2pGsnY3YWr5L8TE8s5l1i6XC6sC6xQB" | ||
} | ||
}, | ||
"anon_download_url": "http://localhost:5000/anon/download-snap/foobar25.snap", | ||
"architecture": [ | ||
"amd64" | ||
], | ||
"binary_filesize": null, | ||
"channel": "stable", | ||
"confinement": "strict", | ||
"content": "application", | ||
"description": "This is a test snap", | ||
"download_sha512": "7c229e954b1e136d02b33ad14841164b85d19e5b6b2efc9bed27b01bec3bba82e8580cbce6fa4feac1680ce7ff6b1023b3633d8dec7910e1d34203fa48e1bc72", | ||
"download_url": "http://localhost:5000/download-snap/foobar25.snap", | ||
"icon_url": null, | ||
"last_updated": "2016-06-03T12:01:15.435821Z", | ||
"origin": "testuser", | ||
"package_name": "foobar25", | ||
"prices": {}, | ||
"publisher": "TestUser", | ||
"ratings_average": 0.0, | ||
"revision": 1, | ||
"snap_id": "W2pGsnY3YWr5L8TE8s5l1i6XC6sC6xQB", | ||
"summary": "This is a test snap", | ||
"version": "2.5" | ||
} | ||
] | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Flask==0.11.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
''' | ||
Minimalist "Store" for snaps. | ||
Edit /etc/environment, add | ||
SNAPPY_FORCE_CPI_URL=http://localhost:5000/api/v1/ | ||
and bounce snapd | ||
Put snaps (named as name.snap) and metadata (named as name.meta) in files/ | ||
Supports snap find <name>, snap install <name> | ||
''' | ||
from flask import Flask, Response, request, url_for, send_from_directory | ||
import sys | ||
|
||
FILES = 'files' | ||
|
||
|
||
app = Flask(__name__) | ||
|
||
|
||
@app.route("/") | ||
def hello(): | ||
return "Hello basic snap store!" | ||
|
||
|
||
@app.route("/api/v1/search") | ||
def search(): | ||
''' note in 2.0.9 snapd still uses search for package details | ||
before install as well as for find ''' | ||
name = request.args.get('q') | ||
# hackity hack hack: find passes q=package_name:"foo" | ||
if 'package_name' in name: | ||
name = name.split(':')[1].replace('"', '') | ||
|
||
# TODO: sanitize names | ||
# TODO: replace download URLs in metadata | ||
try: | ||
with open(FILES + '/' + name + '.meta', 'r') as meta: | ||
return Response(meta.read(), mimetype='application/hal+json') | ||
except Exception as e: | ||
print e | ||
return Response('{}', mimetype='application/hal+json') | ||
|
||
|
||
@app.route("/anon/download-snap/<name>") | ||
def download(name): | ||
# TODO: sanitize names | ||
return send_from_directory(FILES, name) | ||
|
||
|
||
if __name__ == "__main__": | ||
app.run(host='0.0.0.0', debug=True) |