...

Source file src/github.com/go-kivik/kivik/v4/x/server/security.go

Documentation: github.com/go-kivik/kivik/v4/x/server

     1  // Licensed under the Apache License, Version 2.0 (the "License"); you may not
     2  // use this file except in compliance with the License. You may obtain a copy of
     3  // the License at
     4  //
     5  //  http://www.apache.org/licenses/LICENSE-2.0
     6  //
     7  // Unless required by applicable law or agreed to in writing, software
     8  // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
     9  // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
    10  // License for the specific language governing permissions and limitations under
    11  // the License.
    12  
    13  //go:build !js
    14  
    15  package server
    16  
    17  import (
    18  	"net/http"
    19  
    20  	"github.com/go-chi/chi/v5"
    21  	"gitlab.com/flimzy/httpe"
    22  
    23  	"github.com/go-kivik/kivik/v4"
    24  )
    25  
    26  func (s *Server) getSecurity() httpe.HandlerWithError {
    27  	return httpe.HandlerWithErrorFunc(func(w http.ResponseWriter, r *http.Request) error {
    28  		dbName := chi.URLParam(r, "db")
    29  		security, err := s.client.DB(dbName).Security(r.Context())
    30  		if err != nil {
    31  			return err
    32  		}
    33  		return serveJSON(w, http.StatusOK, security)
    34  	})
    35  }
    36  
    37  func (s *Server) putSecurity() httpe.HandlerWithError {
    38  	return httpe.HandlerWithErrorFunc(func(w http.ResponseWriter, r *http.Request) error {
    39  		dbName := chi.URLParam(r, "db")
    40  		var security kivik.Security
    41  		if err := s.bind(r, &security); err != nil {
    42  			return err
    43  		}
    44  		if err := s.client.DB(dbName).SetSecurity(r.Context(), &security); err != nil {
    45  			return err
    46  		}
    47  		return serveJSON(w, http.StatusOK, map[string]bool{
    48  			"ok": true,
    49  		})
    50  	})
    51  }
    52  

View as plain text