mirror of
				https://github.com/restic/rest-server.git
				synced 2025-11-03 23:00:58 +00:00 
			
		
		
		
	Config: per-user overrides for some settings
Allow per-user overrides for AppendOnly and PrivateRepos.
This commit is contained in:
		
							parent
							
								
									383514ad7a
								
							
						
					
					
						commit
						36c7652c9b
					
				
					 1 changed files with 14 additions and 2 deletions
				
			
		
							
								
								
									
										16
									
								
								handlers.go
									
										
									
									
									
								
							
							
						
						
									
										16
									
								
								handlers.go
									
										
									
									
									
								
							| 
						 | 
					@ -83,8 +83,20 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Allow per-user overrides
 | 
				
			||||||
 | 
						appendOnly := s.AppendOnly
 | 
				
			||||||
 | 
						privateRepos := s.PrivateRepos
 | 
				
			||||||
 | 
						if uc, ok := s.Config.Users[username]; ok {
 | 
				
			||||||
 | 
							if uc.AppendOnly != nil {
 | 
				
			||||||
 | 
								appendOnly = *uc.AppendOnly
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if uc.PrivateRepos != nil {
 | 
				
			||||||
 | 
								privateRepos = *uc.PrivateRepos
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Check if the current user is allowed to access this path
 | 
						// Check if the current user is allowed to access this path
 | 
				
			||||||
	if !s.NoAuth && s.PrivateRepos {
 | 
						if !s.NoAuth && privateRepos {
 | 
				
			||||||
		if len(folderPath) == 0 || folderPath[0] != username {
 | 
							if len(folderPath) == 0 || folderPath[0] != username {
 | 
				
			||||||
			httpDefaultError(w, http.StatusUnauthorized)
 | 
								httpDefaultError(w, http.StatusUnauthorized)
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
| 
						 | 
					@ -102,7 +114,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Pass the request to the repo.Handler
 | 
						// Pass the request to the repo.Handler
 | 
				
			||||||
	opt := repo.Options{
 | 
						opt := repo.Options{
 | 
				
			||||||
		AppendOnly:   s.AppendOnly,
 | 
							AppendOnly:   appendOnly,
 | 
				
			||||||
		Debug:        s.Debug,
 | 
							Debug:        s.Debug,
 | 
				
			||||||
		QuotaManager: s.quotaManager, // may be nil
 | 
							QuotaManager: s.quotaManager, // may be nil
 | 
				
			||||||
		PanicOnError: s.PanicOnError,
 | 
							PanicOnError: s.PanicOnError,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue