<s> import flask <EOL> from docker_registry . core import compat <EOL> from docker_registry . core import exceptions <EOL> json = compat . json <EOL> from . import storage <EOL> from . import toolkit <EOL> from . lib import mirroring <EOL> from . lib import signals <EOL> from . app import app <EOL> store = storage . load ( ) <EOL> """<STR_LIT>""" <EOL> def generate_headers ( namespace , repository , access ) : <EOL> registry_endpoints = toolkit . get_endpoints ( ) <EOL> token = '<STR_LIT>' . format ( <EOL> toolkit . gen_random_string ( ) , namespace , repository , access ) <EOL> return { '<STR_LIT>' : registry_endpoints , <EOL> '<STR_LIT>' : token , <EOL> '<STR_LIT>' : token } <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> def get_post_users ( ) : <EOL> if flask . request . method == '<STR_LIT:GET>' : <EOL> return toolkit . response ( '<STR_LIT:OK>' , <NUM_LIT:200> ) <EOL> try : <EOL> json . loads ( flask . request . data . decode ( '<STR_LIT:utf8>' ) ) <EOL> except ValueError : <EOL> return toolkit . api_error ( '<STR_LIT>' , <NUM_LIT> ) <EOL> return toolkit . response ( '<STR_LIT>' , <NUM_LIT> ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT>' ] ) <EOL> def put_username ( username ) : <EOL> return toolkit . response ( '<STR_LIT>' , <NUM_LIT> ) <EOL> def update_index_images ( namespace , repository , data_arg ) : <EOL> path = store . index_images_path ( namespace , repository ) <EOL> sender = flask . current_app . _get_current_object ( ) <EOL> try : <EOL> images = { } <EOL> data = json . loads ( data_arg . decode ( '<STR_LIT:utf8>' ) ) + store . get_json ( path ) <EOL> for i in data : <EOL> iid = i [ '<STR_LIT:id>' ] <EOL> if iid in images and '<STR_LIT>' in images [ iid ] : <EOL> continue <EOL> i_data = { '<STR_LIT:id>' : iid } <EOL> for key in [ '<STR_LIT>' ] : <EOL> if key in i : <EOL> i_data [ key ] = i [ key ] <EOL> images [ iid ] = i_data <EOL> data = images . values ( ) <EOL> store . put_json ( path , data ) <EOL> signals . repository_updated . send ( <EOL> sender , namespace = namespace , repository = repository , value = data ) <EOL> except exceptions . FileNotFoundError : <EOL> signals . repository_created . send ( <EOL> sender , namespace = namespace , repository = repository , <EOL> value = json . loads ( data_arg . decode ( '<STR_LIT:utf8>' ) ) ) <EOL> store . put_content ( path , data_arg ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT>' ] ) <EOL> @ app . route ( '<STR_LIT>' , <EOL> defaults = { '<STR_LIT>' : True } , <EOL> methods = [ '<STR_LIT>' ] ) <EOL> @ toolkit . parse_repository_name <EOL> @ toolkit . requires_auth <EOL> def put_repository ( namespace , repository , images = False ) : <EOL> data = None <EOL> try : <EOL> data = json . loads ( flask . request . data . decode ( '<STR_LIT:utf8>' ) ) <EOL> except ValueError : <EOL> return toolkit . api_error ( '<STR_LIT>' , <NUM_LIT> ) <EOL> if not isinstance ( data , list ) : <EOL> return toolkit . api_error ( '<STR_LIT>' ) <EOL> update_index_images ( namespace , repository , flask . request . data ) <EOL> headers = generate_headers ( namespace , repository , '<STR_LIT>' ) <EOL> code = <NUM_LIT> if images is True else <NUM_LIT:200> <EOL> return toolkit . response ( '<STR_LIT>' , code , headers ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' ] ) <EOL> @ toolkit . parse_repository_name <EOL> @ toolkit . requires_auth <EOL> @ mirroring . source_lookup ( index_route = True ) <EOL> def get_repository_images ( namespace , repository ) : <EOL> data = None <EOL> try : <EOL> path = store . index_images_path ( namespace , repository ) <EOL> data = store . get_content ( path ) <EOL> except exceptions . FileNotFoundError : <EOL> return toolkit . api_error ( '<STR_LIT>' , <NUM_LIT> ) <EOL> headers = generate_headers ( namespace , repository , '<STR_LIT>' ) <EOL> return toolkit . response ( data , <NUM_LIT:200> , headers , True ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT>' ] ) <EOL> @ toolkit . parse_repository_name <EOL> @ toolkit . requires_auth <EOL> def delete_repository_images ( namespace , repository ) : <EOL> headers = generate_headers ( namespace , repository , '<STR_LIT>' ) <EOL> return toolkit . response ( '<STR_LIT>' , <NUM_LIT> , headers ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT>' ] ) <EOL> @ toolkit . parse_repository_name <EOL> def put_repository_auth ( namespace , repository ) : <EOL> return toolkit . response ( '<STR_LIT:OK>' ) </s>
