2013-09-25 21:50:03 +00:00
|
|
|
|
|
|
|
import logging
|
2013-09-30 20:14:48 +00:00
|
|
|
import json
|
2013-09-25 21:50:03 +00:00
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
from flask import abort, request, jsonify, make_response, session
|
2013-09-25 21:50:03 +00:00
|
|
|
|
|
|
|
from app import app
|
|
|
|
from util.names import parse_repository_name
|
|
|
|
from auth.auth import process_auth
|
|
|
|
from auth.permissions import (ReadRepositoryPermission,
|
|
|
|
ModifyRepositoryPermission)
|
|
|
|
from data import model
|
2015-05-19 21:52:44 +00:00
|
|
|
from endpoints.decorators import anon_protect
|
2015-06-22 21:37:13 +00:00
|
|
|
from endpoints.v1 import v1_bp
|
2013-09-25 21:50:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
@v1_bp.route('/repositories/<path:repository>/tags', methods=['GET'])
|
2013-09-25 21:50:03 +00:00
|
|
|
@process_auth
|
2015-05-19 21:52:44 +00:00
|
|
|
@anon_protect
|
2013-09-25 21:50:03 +00:00
|
|
|
@parse_repository_name
|
|
|
|
def get_tags(namespace, repository):
|
|
|
|
permission = ReadRepositoryPermission(namespace, repository)
|
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
if permission.can() or model.repository.repository_is_public(namespace, repository):
|
|
|
|
tags = model.tag.list_repository_tags(namespace, repository)
|
2013-10-01 21:23:44 +00:00
|
|
|
tag_map = {tag.name: tag.image.docker_image_id for tag in tags}
|
2013-09-25 21:50:03 +00:00
|
|
|
return jsonify(tag_map)
|
|
|
|
|
|
|
|
abort(403)
|
|
|
|
|
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
@v1_bp.route('/repositories/<path:repository>/tags/<tag>', methods=['GET'])
|
2013-09-25 21:50:03 +00:00
|
|
|
@process_auth
|
2015-05-19 21:52:44 +00:00
|
|
|
@anon_protect
|
2013-09-25 21:50:03 +00:00
|
|
|
@parse_repository_name
|
|
|
|
def get_tag(namespace, repository, tag):
|
|
|
|
permission = ReadRepositoryPermission(namespace, repository)
|
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
if permission.can() or model.repository.repository_is_public(namespace, repository):
|
|
|
|
tag_image = model.tag.get_tag_image(namespace, repository, tag)
|
2013-11-12 01:00:01 +00:00
|
|
|
resp = make_response('"%s"' % tag_image.docker_image_id)
|
|
|
|
resp.headers['Content-Type'] = 'application/json'
|
|
|
|
return resp
|
2013-09-25 21:50:03 +00:00
|
|
|
|
|
|
|
abort(403)
|
|
|
|
|
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
@v1_bp.route('/repositories/<path:repository>/tags/<tag>', methods=['PUT'])
|
2013-09-25 21:50:03 +00:00
|
|
|
@process_auth
|
2015-06-02 19:56:44 +00:00
|
|
|
@anon_protect
|
2013-09-25 21:50:03 +00:00
|
|
|
@parse_repository_name
|
|
|
|
def put_tag(namespace, repository, tag):
|
|
|
|
permission = ModifyRepositoryPermission(namespace, repository)
|
|
|
|
|
|
|
|
if permission.can():
|
2013-10-01 21:23:44 +00:00
|
|
|
docker_image_id = json.loads(request.data)
|
2015-07-15 21:25:41 +00:00
|
|
|
model.tag.create_or_update_tag(namespace, repository, tag, docker_image_id)
|
2013-09-25 21:50:03 +00:00
|
|
|
|
2014-10-22 18:14:56 +00:00
|
|
|
# Store the updated tag.
|
|
|
|
if not 'pushed_tags' in session:
|
|
|
|
session['pushed_tags'] = {}
|
|
|
|
|
|
|
|
session['pushed_tags'][tag] = docker_image_id
|
|
|
|
|
2013-09-25 21:50:03 +00:00
|
|
|
return make_response('Created', 200)
|
|
|
|
|
|
|
|
abort(403)
|
|
|
|
|
|
|
|
|
2015-07-15 21:25:41 +00:00
|
|
|
@v1_bp.route('/repositories/<path:repository>/tags/<tag>', methods=['DELETE'])
|
2013-09-25 21:50:03 +00:00
|
|
|
@process_auth
|
2015-06-02 19:56:44 +00:00
|
|
|
@anon_protect
|
2013-09-25 21:50:03 +00:00
|
|
|
@parse_repository_name
|
|
|
|
def delete_tag(namespace, repository, tag):
|
|
|
|
permission = ModifyRepositoryPermission(namespace, repository)
|
|
|
|
|
|
|
|
if permission.can():
|
2015-07-15 21:25:41 +00:00
|
|
|
model.tag.delete_tag(namespace, repository, tag)
|
|
|
|
model.repository.garbage_collect_repository(namespace, repository)
|
2013-09-25 21:50:03 +00:00
|
|
|
|
2014-02-06 22:33:50 +00:00
|
|
|
return make_response('Deleted', 200)
|
2013-09-25 21:50:03 +00:00
|
|
|
|
|
|
|
abort(403)
|