Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Bret Barker committed Jun 23, 2016
1 parent 17ea477 commit 25e1cc2
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
35 changes: 35 additions & 0 deletions files/foobar25.meta
@@ -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 added files/foobar25.snap
Binary file not shown.
1 change: 1 addition & 0 deletions requirements.txt
@@ -0,0 +1 @@
Flask==0.11.1
52 changes: 52 additions & 0 deletions store.py
@@ -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)

0 comments on commit 25e1cc2

Please sign in to comment.