forked from vieter-v/vieter
				
			Added x-api-key auth support
							parent
							
								
									a43ebfeaf0
								
							
						
					
					
						commit
						2663cf3dae
					
				| 
						 | 
				
			
			@ -0,0 +1,11 @@
 | 
			
		|||
module main
 | 
			
		||||
 | 
			
		||||
import net.http
 | 
			
		||||
 | 
			
		||||
fn (mut app App) is_authorized() bool {
 | 
			
		||||
	x_header := app.req.header.get_custom('X-Api-Key', http.HeaderQueryConfig{ exact: true }) or {
 | 
			
		||||
		return false
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return x_header.trim_space() == app.api_key
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -38,6 +38,10 @@ fn (mut app App) get_root(filename string) web.Result {
 | 
			
		|||
 | 
			
		||||
['/pkgs/:pkg'; put]
 | 
			
		||||
fn (mut app App) put_package(pkg string) web.Result {
 | 
			
		||||
	if !app.is_authorized() {
 | 
			
		||||
		return app.text('Unauthorized.')
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if !is_pkg_name(pkg) {
 | 
			
		||||
		app.lwarn("Invalid package name '$pkg'.")
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue